akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a<b){
		printf ("a < b\n");
	}else if (a>b){
		printf("a > b\n");
	}else{
		printf("a == b\n");
	}
	
	
	
	return 0;
}

Measured memory_bytes: 580
k, n = list(map(int,input().split()))
a =  list(map(int,input().split()))

n_prev= a[n-1]-k

m=0

for nn in a:
    if (nn-n_prev) > m:
        m=nn-n_prev
        res=(k-m)
    n_prev=nn

print(res)



Measured memory_bytes: 26444
#include <cstdio>
using namespace std;

int main(){
	int x, y;
	while(scanf("%d", &x)){
		if(x == 0){
			break;
		}
		x = 1000 - x;
		y = 0;
		while (x >= 500){
			x -= 500;
			y++;
		}
		while (x >= 100){
			x -= 100;
			y++;
		}
		while (x >= 50){
			x -= 50;
			y++;
		}
		while (x >= 10){
			x -= 10;
			y++;
		}
		while (x >= 5){
			x -= 5;
			y++;
		}
		while (x >= 1){
			x -= 1;
			y++;
		}
		printf("%d\n", y);
	}
	return 0;
}

Measured memory_bytes: 1028
/*
// Sample code to perform I/O:

cin >> name;                            // Reading input from STDIN
cout << "Hi, " << name << ".\n";        // Writing output to STDOUT

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
*/

// Write your code here


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define  mod 1000000007 

int main(){
    ll n;
     cin>>n;
     ll k=0;
     while(n){
         if(n%10==7)
         k=1;
         n/=10;

     }
     if(k)
     cout<<"Yes";
     else cout<<"No";
    return 0;
}


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

#define int long long

const int mex = 1e5;

int dp[3][mex+5];

signed main(){
     int n;
     cin >> n;
     
     int data[n+5];
     
     for(int i = 1; i <= n; i++){
              cin >> data[i];
     }
     
     dp[1][2] = (-data[1] - data[2]);
     dp[0][2] = (data[1] + data[2]);
     
     for(int i = 3; i <= n; i++){
         dp[0][i] = max(dp[1][i-1] + data[i], dp[0][i-1] + data[i]);
         dp[1][i] = max(dp[0][i-1] - data[i] - 2*data[i-1], dp[1][i-1] - data[i] + 2*data[i-1]);
         
     }
     
     cout << max(dp[0][n], dp[1][n]) << '\n';
     
}

Measured memory_bytes: 2560
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
}
int main() {
	vi primes;
	for(int i=11;;i++){
		if(i%5==1&&isPrime(i))
			primes.pb(i);
		if(sz(primes)==55)break;
	}
	int n;cin>>n;
	loop(n,i,0)
		cout<<primes[i]<<' ';
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

    Node() : parent(nullptr), left(nullptr), right(nullptr), key(2000000001) {}
    Node(Node* p, Node* l, Node* r, int k) : parent(p), left(l), right(r), key(k) {}

    void insert(int k) {
        if (key == 2000000001) { key = k; }
        else if (k <= key) {
            if (left != nullptr) { left->insert(k); }
            else { left = new Node(this, nullptr, nullptr, k); }
        } else {
            if (right != nullptr) { right->insert(k); }
            else { right = new Node(this, nullptr, nullptr, k); }
        }
    }
    bool find(int k) {
        if (k == key) { return true; }
        if (k < key && left != nullptr) { return left->find(k); }
        if (k > key && right != nullptr) { return right->find(k); }
        return false;
    }
    void del() {

        // If this has 2 children.
        if (left != nullptr && right != nullptr) {
            Node *next = right;
            while (next->left != nullptr) { next = next->left; }
            key = next->key;
            next->del();
            return;
        }

        if (left != nullptr) {
            left->parent = parent;
            if (parent->left == this) { parent->left = left; }
            else { parent->right = left; }
        } else if (right != nullptr) {
            right->parent = parent;
            if (parent->left == this) { parent->left = right; }
            else { parent->right = right; }
        } else {
            if (parent->left == this) { parent->left = nullptr; }
            else { parent->right = nullptr; }
        }
        // delete this;
    }

    void erase(int k) {
        if (k == key) { del(); }
        else if (k < key && left != nullptr) { return left->erase(k); }
        else if (k > key && right != nullptr) { return right->erase(k); }
    }
};

void in_print(Node* node) {
    if (node->left != nullptr) { in_print(node->left); }
    cout << " " << node->key;
    if (node->right != nullptr) { in_print(node->right); }
}

void pre_print(Node* node) {
    cout << " " << node->key;
    if (node->left != nullptr) { pre_print(node->left); }
    if (node->right != nullptr) { pre_print(node->right); }
}

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

    Node* tree = new Node();

    rep(i, 0, n) {
        char s[20];
        scanf("%s", s);

        if (s[0] == 'i') {
            int x;
            cin >> x;
            tree->insert(x);
        } else if (s[0] == 'f') {
            int x;
            cin >> x;
            cout << (tree->find(x) ? "yes" : "no") << endl;
        } else if (s[0] == 'd') {
            int x;
            cin >> x;
            tree->erase(x);
        } else {
            in_print(tree);
            cout << endl;
            pre_print(tree);
            cout << endl;
        }
    }
}


Measured memory_bytes: 21996
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var S = rs();
		var boin = "aiueo";
		for(int i=0;i<boin.Length;i++){
			if(S[0] == boin[i]){
				Console.WriteLine("vowel");
				return;
			}
		}
		Console.WriteLine("consonant");
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main() {
  string s;
  cin>>s;
  for (int i=0; i<s.length(); i++) {
    if (i % 2 == 0) {
      if (s[i] == 'L') {
        cout<<"No"<<endl;
        return 0;
      }
    } else {
      if (s[i] == 'R') {
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
}

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

int main() {
    int n, m;
    cin >> n >> m;
    std::priority_queue<long> a;
    for (int i = 0; i < n; i++) {
        long v;
        cin >> v;
        a.push(v);
    }

    for (int i = 0; i < m; i++) {
        long head = a.top();
        a.pop();
        head /= 2;
        a.push(head);
    }

    long sum = 0;
    for (int i = 0; i < n; i++) {
        sum += a.top();
        a.pop();
    }

    cout << sum << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int t;
		cin >> t;
		n -= t;
	}
	if(n < 0) cout << - 1<< endl;
	else cout << n << endl;

}





Measured memory_bytes: 3696
fun main(args: Array<String>) {
    val line = readLine()!!
    val A = line.split(" ")[0].toInt()
    val B = line.split(" ")[1].toInt()

    val tasu = A + B
    val hiku = A - B
    val kakeru = A * B

    if (tasu >= hiku) {
        if (tasu >= kakeru) {
            println(tasu)
        } else {
            println(kakeru)
        }
    } else {
        if (hiku >= kakeru) {
            println(hiku)
        } else {
            println(kakeru)
        }
    }
}

Measured memory_bytes: 37912
<?php

$nk = explode(" ", trim(fgets(STDIN)));
$n = $nk[0];
$k = $nk[1];
$k_nums = explode(" ", trim(fgets(STDIN)));

$i = 0;
$n_inc = strval($n);
while(true){

  $n_inc = strval($n_inc);
  
  $match = 0;
  for ($l=0; $l<strlen($n_inc); $l++){
      for ($r=0; $r<$k; $r++){  
    	if ($n_inc[$l] == $k_nums[$r]) $match++;
      }
  }
  if ($match == 0) break;
  
  $n_inc = intval($n_inc);
  $n_inc++;
  
}

echo $n_inc;


?>

Measured memory_bytes: 4856
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <valarray>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstring>
#include <sstream>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-9;

struct Edge {
  int src,dst,cost;
  Edge(int s,int d,int c) : src(s), dst(d), cost(c) {;}
};
bool operator<(const Edge &e,const Edge &f) {
  return (e.cost != f.cost) ? e.cost > f.cost : e.src < f.src;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void outputV(int v) {
  int k = v%6;
  v /= 6;
  int x = v%202;
  int y = v/202;
  cout<<"("<<x<<","<<y<<","<<k<<")"<<endl;
}

int gx,gy;
void dijkstra(const Graph &g, vector<int> &dist, int s) {
  const int n = g.size();
  dist.resize(n);
  for (int i=0; i<n; ++i) dist[i] = INF;
  vector<int> prev(n, -1);

  priority_queue<Edge> q;
  q.push(Edge(-2,s,0));
  dist[s] = 0;
  while(!q.empty()) {
    Edge e = q.top(); q.pop();
    if(prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;

    for (int i=0; i<g[e.dst].size(); ++i) {
      int w = g[e.dst][i].dst;
      if(dist[w] > dist[e.dst] + g[e.dst][i].cost) {
	dist[w] = dist[e.dst] + g[e.dst][i].cost;
	q.push(Edge(e.dst, w, dist[w]));
      }
    }
  }
}

int lx,ly;
bool ok(int x,int y) {
  int ax = abs(x-100), ay = abs(y-100);
  return ax <= lx && ay <= ly;
}

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

bool kagu[202][202];
const int MAP_SIZE = 202;

inline int index(int x,int y,int k) {
  return (y*MAP_SIZE+x)*6+k;
}

int main() {
  int sx,sy;
  int n;
  memset(kagu, false, sizeof(kagu));

  cin>>sx>>sy>>gx>>gy;
  cin>>n;
  sx += 100, sy += 100, gx += 100, gy += 100;
  for (int i=0; i<n; ++i) {
    int x,y;
    cin>>x>>y; x+= 100, y += 100;
    kagu[y][x] = true;
  }
  cin>>lx>>ly;

  Graph g(202*202*6);
  for (int i=0; i<=201; ++i) {
    for (int j=0; j<=201; ++j) {
      if (kagu[i][j]) continue;
      if (!ok(j,i)) continue;
      for (int k=0; k<6; ++k) {
	int seed = abs((j-100)*(i-100)*k)%6;

	for (int next=0; next<6; ++next) {
	  int nx = j+dx[abs(j-100)%2][next], ny = i+dy[abs(j-100)%2][next];
	  int cost = (next == seed) ? 0 : 1;
	  if (!ok(nx,ny)) continue;
	  if (kagu[ny][nx]) continue;
	  assert(index(j,i,k) < 202*202*6);
	  assert(index(nx,ny,k) < 202*202*6);
	  g[index(j,i,k)].push_back(Edge(index(j,i,k), index(nx,ny,(k+1)%6), cost));
	}
	g[index(j,i,k)].push_back(Edge(index(j,i,k), index(j,i,(k+1)%6), 1));
      }
    }
  }

  vector<int> dist(g.size());
  dijkstra(g, dist, index(sx,sy,0));
  int ans = INF;
  for (int k=0; k<6; ++k) {
    ans = min(ans, dist[index(gx,gy,k)]);
  }

  if (ans == INF) ans = -1;
  cout<<ans<<endl;
}

Measured memory_bytes: 34772
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <locale>
using namespace std;
#define MS0(I) memset(I, 0, sizeof(I));
#define MS1(I) memset(I, -1, sizeof(I));
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, s, n) for(int i = (s); i < (n); ++i)
#define per1(i, a, b) for(int i = a; i >= b; --i)
#define DRI(A) int A; scanf("%d", &A);
#define DRII(A, B) int A, B; scanf("%d %d", &A, &B);
#define DRIII(A, B, C) int A, B, C; scanf("%d %d %d", &A, &B, &C);
#define MP make_pair 
#define pb push_back
#define F first
#define S second
#define ALL(I) (I).begin(), (I).end()
typedef const void CV;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const int INF = (int)1e9;
const int mod = (int)1e9+7;
const int MAX = (int)1e2+5;
int main(void){
	DRIII(a, b, c); DRII(x, y);
	x<<=1; y<<=1;
	int ans = 0;
	int z = min(x, y);
	if(a + b > 2*c){
		ans += c*z;
		x -= z; y -= z;
		if(x){
			if(x % 2){
				if(a > c) ans += c;
				else ans += a;
				x--;
			}
			if(a > 2*c) ans += x*c;
			else ans += x/2*a;
		}
		else{
			if(y % 2){
				if(b > c) ans += c;
				else ans += b;
				y--;
			}
			if(b > 2*c) ans += y*c;
			else ans += y/2*b;
		}
	}
	else{
		z /= 2;
		ans += (a+b)*z;
		x -= 2*z; y -= 2*z;
		if(x % 2 && y % 2){
			if(a + b > c){
				ans += c;
			}
			else{
				ans += a+b;
			}
			x--; y--;
		}
		else if(x % 2){
			if(a > c) ans += c;
			else ans += a;
			x--;
		}
		else if(y % 2){
			if(b > c) ans += c;
			else ans += b;
			y--;
		}
		ans += a*(x/2);
		ans += b*(y/2);
	}
	printf("%d\n", ans);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
#define MAX_P 100010
//// 階乗(mod p)
ll fact[MAX_P];
void mod_fact(ll n,ll p){
  fact[0]=1;
  for(ll i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%p;
}

//// 冪乗(mod p)
//// xの逆元 mod_pow(x,p-2,p)
ll mod_pow(ll x,ll n,ll p){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%p;
    x=x*x%p;
    n>>=1;
  }
  return res;
}

//// コンビネーション(mod p)
ll mod_comb(ll n,ll k,ll p){
  if(n<0||k<0||n<k)return 0;
  return ((fact[n]*mod_pow(fact[k],p-2,p))%p)*mod_pow(fact[n-k],p-2,p)%p;
}

int main(){
  cin.sync_with_stdio(false);
  ll n;
  ll pos;
  cin >> n;
  n++;
  Vector a(MAX_P,0), li(MAX_P,0);
  rep(i,n)cin >> a[i], li[a[i] - 1]++;
  rep(i,n)if(li[i] == 2)pos = i + 1;

  fact[0] = 1;
  rep(i,n+1) fact[i + 1] = fact[i] * (i + 1) % MOD;

  ll pot = 0;
  bool f = true;
  rep(i,n){
    if(f && a[i] == pos)f = false, pot += i;
    else if(!f && a[i] == pos)pot += n - 1 - i;
  }

  cout << n - 1 << endl;
  repl(i,1,n-1){
    cout << (mod_comb(n, i + 1,MOD) - mod_comb(pot, i,MOD) + MOD) % MOD << endl;
  }
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main(){

	int a , b , c , d;
	int sum = 0;

	cin >> a >> b >> c >> d ;

	sum = a + b + c + d;

	int ans1 = sum / 60;
	int ans2 = sum % 60;

	cout << ans1 << endl;
	cout << ans2 << endl;

	return 0;
}

Measured memory_bytes: 3076
main :: IO ()
main = do
  s <- getLine
  putStrLn $ if solve s 0
    then "Yes"
    else "No"

solve :: String-> Int -> Bool
solve "" n = n == 2
solve (c:cs) n = case n of
  0 -> if c == 'C' then solve cs 1 else solve cs 0
  1 -> (c == 'F') || solve cs 1
  _ -> False


Measured memory_bytes: 508
def levenshtein(str1, str2):
    prev_dp = list(range(len(str2) + 1))

    for i1, c1 in enumerate(str1):
        current_dp = [i1 + 1]
        for i2, c2 in enumerate(str2):
            current_dp.append(min(prev_dp[i2 + 1] + 1, current_dp[i2] + 1, prev_dp[i2] + int(c1 != c2)))
        prev_dp = current_dp

    return prev_dp[-1]


print(levenshtein(input(), input()))

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef queue<int> qi;

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << ((b-a)%2?"Borys":"Alice") << endl;
    return 0;
}


Measured memory_bytes: 256
let get_input () =
    read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let () =
    let _ = read_int () in
    let upper = get_input () in
    let lower = get_input () in
    List.fold_left2 (fun (usum, lsum) uelem lelem ->
        (usum + uelem, max (lsum + lelem) (usum + uelem + lelem))
    ) (0, 0) upper lower
    |> (fun (x, y) -> max x y)
    |> string_of_int
    |> print_endline


Measured memory_bytes: 384
# B - Making Triangle

N = int(input())
L = list(int(x) for x in input().split())
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[i] == L[j] or L[i] == L[k] or L[j] == L[k]:
                continue
            if L[i] + L[j] > L[k]:
                ans += 1

print(ans)

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if((i>=b && j<a) || (i<b && j>=a)) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
using namespace std;
static const int YUKICHI = 10000;
static const int HIGUCHI = 5000;
static const int NOGUCHI = 1000;

int main(){
    int N, X; cin >> N >> X;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int k = N - i - j;
            if(k < 0) continue;
            if(YUKICHI * i + HIGUCHI * j + NOGUCHI * k == X){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int dp[100001];
int n;
int a[101];
int fun(int k){
if(k==0)
    return 0;
if(dp[k]!=-1)
    return dp[k];
int x=1;
for(int i=0;i<n && k>=a[i];i++ ){
    x&=fun(k-a[i]);
}
if(x)
    dp[k]=0;
    else dp[k]=1;
    return dp[k];


}




int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);

memset(dp,-1,sizeof(dp));
int k;

cin>>n>>k;
for(int i=0;i<n;i++){
    cin>>a[i];
}
int ans=fun(k);
if(ans)
    cout<<"First"<<endl;
else cout<<"Second"<<endl;

}


Measured memory_bytes: 5376
n=gets.to_i
array=[]
n.times{
    array.push(gets.chomp.split(''))
}

ans=0
righta=0
leftb=0
double=0

array.map{|str|
    str.map.with_index{ |char,index|
       if str[index+1] && str[index]=="A" && str[index+1]=="B"
           ans+=1
       end
    }
    
    if str[0]=="B"
        leftb+=1
    end
    
    if str[-1]=="A"
        righta+=1
    end
    
    if str[-1]=="A" && str[0]=="B"
        double+=1
    end
}

if double==leftb && double==righta && double>0
    puts ans+double-1
else
   puts ans+[leftb,righta].min 
end

Measured memory_bytes: 11900
#include<iostream>
using namespace std;
int main(){
    int A, B, C, X, Y, money;
    cin >> A >> B >> C >> X >> Y;

    if(A + B >= 2 * C){

        if(X <= Y){
            if(B <= 2 * C) money = X * 2 * C + (Y - X) * B;
            else money = Y * 2 * C;
        }
        else{
            if(A <= 2 * C) money = Y * 2 * C + (X - Y) * A;
            else money = X * 2 * C;
        }

    }

    else money = A * X + B * Y;
    cout << money << endl;
}


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

int main()
{
    int iPerW = 0;
    int iPerH = 0;
    
    while (cin >> iPerH >> iPerW)
    {
        if ((0 == iPerH) && (0 == iPerW))
        {
            break;
        }
        
        for (int i = 0; i < iPerH; i++)
        {
            for (int j = 0; j < iPerW; j++)
            {
                cout << "#";
            }
            
            cout << endl;
        }
        
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include <bits/stdc++.h>
//1000000000000223
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, m, x, y;
ll a[600][600], sum;
int main()
{
    IO
    cin>>n>>m>>x>>y;
    ll p=n/x;
    ll z=501;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            a[i][j]= (i%x==0 && j%y==0) ? -z*(x*y-1)-1 : z ;
            sum+=a[i][j];
        }
    if(sum<=0)
        return cout<<"No",0;
    cout<<"Yes\n";
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3712
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var a,b,x int64
    fmt.Scan(&a,&b,&x)
    if a==0 {
        fmt.Println(b/x+1)
    } else {
        fmt.Println(b/x-(a-1)/x)
    }
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

ll L[87] = {};
ll lyu(ll n){
	if(n == 0) return 2;
	if(n == 1) return 1;
	if(L[n] != 0) return L[n];
	return L[n] = lyu(n-1) + lyu(n-2);
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n;
	cin >> n;

	cout << lyu(n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
using namespace std;
int main(){
    int n,p;
    cin >> n >> p;
    string s;
    cin >> s;

    //下の桁から見て,それが最下位の桁となる連続文字列を考えれば良い.
    ll ans = 0;
    if(p == 2 || p == 5){
        reverse(s.begin(),s.end());
        for(int i = 0;i < n;i++){
            int now = (int)(s[i] - '0');
            if(now % p == 0){
                ans += (n - i);
            }
        }

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

    vector<int> digit_mod(n+1);

    digit_mod[0] = 1;
    digit_mod[1] = 1;
    for(int i = 1;i < n;i++){
        digit_mod[i+1] = digit_mod[i] * 10 % p;
    }

    vector<int> digit_mod_sum(n+1);
    map<int,int> mp;
    digit_mod_sum[0] = 0;
    reverse(s.begin(),s.end());
    for(int i = 1;i <= n;i++){
        int now = (int)(s[i-1] - '0'); 
        digit_mod_sum[i] = (now * digit_mod[i] + digit_mod_sum[i-1]) % p;
        ans += mp[digit_mod_sum[i]];
        if(digit_mod_sum[i] == 0)ans += 1;
        mp[digit_mod_sum[i]]++;
    }

    cout << ans << endl;
}



Measured memory_bytes: 2436
//Vinay
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define flash ios::sync_with_stdio(false);cin.tie(0);
//const int INF = 1e9+7;

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

    ll a, b , c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*c ,max(a*d, max(b*d, b*c)));
}


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

using namespace std;

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

  vector<int> ret;

  for(int i=2;i<=n;i++){
    int temp=i;
    for(int j=2;j<=i;j++){
      while(temp%j == 0){
        ret.push_back(j);
        temp=temp/j;
      }
    }
  }

  if(!ret.size()){
    cout << 1 << endl;
    return 0;
  }

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

  vector<int> temp2;

  int now = ret[0];
  temp2.push_back(0);
  for(auto e:ret){
    if(e != now){
      now = e;
      temp2.push_back(1);
    }else{
      temp2[temp2.size()-1]++;
    }
  }
  
  long ans=1;

  for(const auto t:temp2){
    ans *= t+1;
    if(ans > 1000000007) ans = ans%1000000007;
  }

  cout << ans << endl;

        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ctype.h>
#include <string>
#include <sstream>
using namespace std;

int main(void){
  string input;
  bool loop = true;
  while (loop) {
    cin >> input;
    if (input == "0") {
      loop = false;
      continue;
    }
    unsigned int sum = 0;
    for (int i = 0; i < input.length() ; i++) {
      int num;
      string numstring;
      numstring = input[i];
      stringstream ss;
      ss << numstring;
      ss >> num;

      sum += num;
    }
    cout << sum << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
    long N, M;
    cin >> N >> M;

    vector< vector<long> > A(N, vector<long>(2));
    for (long i=0; i<N; i++) cin >> A[i][0] >> A[i][1];
    sort(A.begin(), A.end(), [](vector<long> x, vector<long> y){return x[0] < y[0];});

    long cnt = M, yen = 0;
    for (long i=0; i<N; i++) {
        if (A[i][1] <= cnt) {
            yen += A[i][0] * A[i][1];
            cnt -= A[i][1];
        } else {
            yen += A[i][0] * cnt;
            cnt = 0;
        }
        if (cnt == 0) break;
    }

    cout << yen << endl;

    return 0;
}


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

int main() {
    string S; cin >> S;
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '0') cnt0++;
        else cnt1++;
    }
    if (cnt0 == cnt1) cout << S.size() << endl;
    else if (cnt0 > cnt1) cout << 2 * cnt1 << endl;
    else cout << 2 * cnt0 << endl;
}

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

int main(){
	ll h,w,m;
	cin >> h >> w >> m;
	map<pair<int,int>, int> bomb;
	vector<ll> r(h);
	vector<ll> c(w);
	rep(i,m){
		int a,b;
		cin >> a >> b;
		a--;b--;
		bomb[make_pair(a,b)]++;
		r[a]++;
		c[b]++;
	}
	vector<int> r_index, c_index;
	ll r_max = *max_element(r.begin(), r.end());
	ll c_max = *max_element(c.begin(), c.end());
	rep(i,h) if(r_max == r[i]) r_index.push_back(i);
	rep(i,w) if(c_max == c[i]) c_index.push_back(i);
	ll ans = r_max + c_max;
	rep(i,r_index.size()){
		rep(j,c_index.size()){
			if(bomb[make_pair(r_index[i], c_index[j])] == 0){
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << ans - 1 << endl;
    return 0;
}



Measured memory_bytes: 30876
#include<stdio.h>
long long CO[100010],co[400010];
int ta[100010],nt[400010],to[400010];
long long R=1,C=1,H[2000010],N[2000010];
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//?????\??¢??°
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//??????????????¢??°
int hout(){
  long long rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
void dijk(int v,int mi){
  int i,id[100010],f[100010]={0};
  R=C=1;
  for(i=0;i<=v;i++)CO[i]=1e18;
  CO[mi]=0;
  while(f[mi]-1){
    f[mi]=1;
    for(i=ta[mi];i+1;i=nt[i]){
      if(CO[to[i]]>CO[mi]+co[i])hin(CO[id[R]=to[i]]=CO[mi]+co[i]);
    }
    while(f[mi]&&C-1)mi=id[hout()];
  }
}
void prls(int v){
  int i,j;
  for(i=1;i<=v;i++){
    printf("%d:",i);
    for(j=ta[i];j+1;j=nt[j])printf("%d,%lld ",to[j],co[j]);
    printf("\n");
  }
  printf("\n");
}
int main(){
  int n,m,k,s,m1,m2,i,a,b;
  long long c[100010],q[100010],t,r,mv[100010]={};
  scanf("%d %d %d %d %d %d",&n,&m,&k,&s,&m1,&m2);
  for(i=0;i<n;i++)c[i+1]=m1;
  for(i=0;i<n;i++)ta[i+1]=-1;
  for(r=0;r<k;r++){
    scanf("%lld",&q[r]);
    c[q[r]]=1e18;
    mv[q[r]]=s-1;
  }
  for(i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    nt[i  ]=ta[a];
    nt[i+m]=ta[b];
    ta[to[i+m]=a]=i  ;
    ta[to[i  ]=b]=i+m;
  }
  for(t=0;r-t;t++){
    for(i=ta[q[t]];i+1;i=nt[i]){
      if(c[to[i]]>m1)continue;
      c[to[i]]=m2;
      if(mv[q[t]]){
	mv[to[i]]=mv[q[t]]-1;
	q[r++]=to[i];
      }
    }
  }
  c[n]=0;
  //for(i=0;i<n;i++)printf("%d %lld\n",i+1,c[i+1]);
  for(i=0;i<2*m;i++)co[i]=c[to[i]];
  //prls(n);
  dijk(n,1);
  //for(i=0;i<n;i++)printf("%d %lld\n",i+1,CO[i+1]);
  printf("%lld\n",CO[n]);
  return 0;
}

Measured memory_bytes: 15776
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	string s,t;
  	cin >>s >>t;
  	sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>()); 
		if(s<t){cout << "Yes" <<endl;
		}else{cout <<"No"<<endl;}
}


Measured memory_bytes: 256
module Main where

  import           Control.Monad
  import           Data.List
  import           Data.Ord
  import           Data.List.Split
  import           Data.Array.IO
  import qualified Data.Vector.Unboxed as V
  
  main :: IO ()
  main = do
    as <- replicateM 5 readLn :: IO [Int]
    let (zero, nonzero) = partition (\i -> i `mod` 10 == 0) as
        m = if null nonzero then 0 else head $ sortBy (\a b -> (a `mod` 10) `compare` (b `mod` 10)) nonzero
    if m == 0 then
        print $ sum as
      else
        print $ (sum zero) + (m + ((sum . (map up) . delete m) nonzero))
  
  up i = i + (10 - (i `mod` 10))
  

Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Enu = System.Linq.Enumerable;

class Program
{
    static readonly long INF = (long)1e17;
    static readonly int MaxV = 10;

    void Solve()
    {
        int N;
        while ((N = read.Int()) > 0)
        {
            var dist = Enu.Range(0, MaxV).Select(i => Enu.Repeat(INF, MaxV).ToArray()).ToArray();
            var city = new HashSet<int>();

            for (int i = 0; i < N; i++)
            {
                int a = read.Int(), b = read.Int();
                long c = read.Long();
                city.Add(a); city.Add(b);
                dist[a][b] = Math.Min(dist[a][b], c);
                dist[b][a] = Math.Min(dist[b][a], c);
            }
            int V = city.Count;
            for (int i = 0; i < V; i++)
                dist[i][i] = 0;
            for (int k = 0; k < V; k++)
                for (int i = 0; i < V; i++)
                    for (int j = 0; j < V; j++)
                        dist[i][j] = Math.Min(dist[i][j], dist[i][k] + dist[k][j]);
            int best = 0;
            long minSum = INF;
            for (int i = 0; i < V; i++)
            {
                long sum = city.Sum(j => dist[i][j]);
                if (sum < minSum) { minSum = sum; best = i; }
            }
            Console.WriteLine(best + " " + minSum);
        }
    }

    static void Main() { new Program().Solve(); }
    static Read read = new Read(Console.In);
    class Read
    {
        private readonly TextReader reader;
        private Queue<string> que = new Queue<string>();
        public Read(TextReader r) { reader = r; }
        public bool HasNext() { return Enqueue(); }
        public string String() { return Dequeue(); }
        public int Int() { return int.Parse(Dequeue()); }
        public long Long() { return long.Parse(Dequeue()); }
        public double Double() { return double.Parse(Dequeue()); }
        public int[] IntArray() { return Array.ConvertAll(Line().Split(), int.Parse); }
        public int[][] IntGrid(int H) { return Enumerable.Range(0, H).Select(i => IntArray()).ToArray(); }
        public string[] StringArray(int N) { return Enumerable.Range(0, N).Select(i => Line()).ToArray(); }
        public string Line() { return reader.ReadLine().Trim(); }
        private bool Enqueue()
        {
            if (que.Count > 0) return true;
            string line = Line();
            if (string.IsNullOrEmpty(line)) return false;
            foreach (var s in line.Split()) que.Enqueue(s);
            return true;
        }
        private string Dequeue() { Enqueue(); return que.Dequeue(); }
    }
}

Measured memory_bytes: 6784
class ConvexHullTrick:
	def __init__(self):
		self.AB = []

	def check(self,a,b):
		a1,b1 = self.AB[-1][0],self.AB[-1][1]
		a2,b2 = self.AB[-2][0],self.AB[-2][1]
		lhs = (b2-b1)*(a -a1)
		rhs = (b1-b )*(a1-a2)
		return lhs>=rhs

	# 一次関数 y=a*x+b を追加
	# 追加の際、傾きaは単調減少（既存の傾きより最小？）であること
	def append(self,a,b):
		while 2<=len(self.AB) and self.check(a,b):
			self.AB.pop()
		self.AB.append((a,b))
		return
	# min_i {a[i]*x+b[i]}
	def query(self,x):
		l,r = -1, len(self.AB)-1
		while l+1<r:
			m = (l+r)//2
			if self.eval(m+1,x)<=self.eval(m,x):
				l = m
			else:
				r = m
		return self.eval(r,x)
	def eval(self,k,x):
		a,b = self.AB[k][0],self.AB[k][1]
		return a*x+b

N,C = map(int,input().split())
h = list(map(int,input().split()))
#print(h)

cht = ConvexHullTrick()

dp = [0]*N
dp[0] = 0
cht.append(-2*h[0],h[0]**2+dp[0])
for i in range(1,N):
	#best = 99999999999999
	# for j in range(i):
	# 	#cost = dp[j]+(h[i]-h[j])**2+C
	# 	cost = (-2*h[j])*h[i]+(h[j]**2+dp[j])
	# 	best = min(best,cost)
	best = cht.query(h[i])
	dp[i] = best+h[i]**2+C

	cht.append(-2*h[i],h[i]**2+dp[i])

ans = dp[N-1]
print(ans)


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define f first
#define s second

//Aを0 Cを1 Gを2 Tを3に対応させる
ll N;
ll dp[105][5][5][5];
ll ans;

int main(){

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

cin>>N;

rep(i,4){
	rep(j,4){
		rep(k,4){
			//AGC, ACG, GACはダメ
			if((i==0&&j==2)&&k==1) continue;
			if((i==0&&j==1)&&k==2) continue;
			if((i==2&&j==0)&&k==1) continue;
			dp[2][i][j][k]=1;
		}
	}
}

for(ll n=3; n<N; n++){
	rep(i,4){
		rep(j,4){
			rep(k,4){ 
				if((i==0&&j==2)&&k==1) continue;
				if((i==0&&j==1)&&k==2) continue;
				if((i==2&&j==0)&&k==1) continue;
				rep(x,4){
					if((i!=0&&j==2)&&k==1){
						if((x==0&&i!=0)&&j==2) continue;
					}
					if((i==2&&j!=0)&&k==1){
						if((x==0&&i==2)&&j!=0) continue;
					}
					dp[n][i][j][k]=(dp[n][i][j][k]+dp[n-1][x][i][j])%mod;
				}
			}
		}
	}
}


rep(i,4){
	rep(j,4){
		rep(k,4){
			ans=(ans+dp[N-1][i][j][k])%mod;
		}
	}
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 384
import itertools

N = int(input())
P = list(map(int, input().split(" ")))
Q = list(map(int, input().split(" ")))
a, b = 0, 0

for i, perm in enumerate(itertools.permutations(range(N))):
    if all([p1 == (p2 + 1) for p1, p2 in zip(P, perm)]):
        a = i
    if all([p1 == (p2 + 1) for p1, p2 in zip(Q, perm)]):
        b = i

print(abs(a - b))


Measured memory_bytes: 3064
from collections import deque


def bfs(si, sj, gi, gj):
    visited = set()
    q = deque([(si, sj, {(si, sj)})])
    while q:
        i, j, path = q.popleft()
        for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
            ni, nj = i + di, j + dj
            if (ni, nj) not in visited and 0 <= ni < H and 0 <= nj < W and field[ni][nj] == '.':
                if (ni, nj) == (gi, gj):
                    return path | {(gi, gj)}
                visited.add((ni, nj))
                q.append((ni, nj, path | {(ni, nj)}))
    return set()


H, W = map(int, input().split())
field = [input() for _ in range(H)]
path = bfs(0, 0, H - 1, W - 1)
if path:
    print(sum(field[i][j] == '.' for i in range(H) for j in range(W)) - len(path))
else:
    print(-1)


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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }
  for(int i = 0; i < M; i++){
    cin >> B[i];
  }
  for(int i = 0; i < N - M + 1; i++){
    for(int j = 0; j < N - M + 1; j++){
      bool flag = false;
      for(int k = 0; k < M; k++){
        for(int l = 0; l < M; l++){
          if(A[i + k][j + l] == B[k][l])flag = true;
          else {
            flag = false;
            break;
          }
        }
        if(!flag)break;
      }
      if(flag){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    k <- readLn 
    let xs = [1..k] 
    print $ sum $ [gcd (gcd a b) c | a<-xs,b<-xs,c<-xs ]



Measured memory_bytes: 5032
n=int(input())
s=input()

def sw(animal,maeanimal,flag):
    if animal == "S":
        if maeanimal == "S":
            if flag == "o":
                return "S"
            else:
                return "W"
        else:
            if flag == "o":
                return "W"
            else:
                return "S"
    else:
        if maeanimal == "S":
            if flag == "o":
                return "W"
            else:
                return "S"
        else:
            if flag == "o":
                return "S"
            else:
                return "W"
def main():
    r = ["" for _ in range(n)]
    r[0] = "S"
    if s[0] == "o":
        r[1] = "S"
        r[-1]= "S"
    else:
        r[1] = "S"
        r[-1] = "W"

    for i in range(1,n-2):
        r[i+1] = sw(r[i],r[i-1],s[i])
    if r[n-1] == sw(r[n-2],r[n-3],s[n-2]) and r[0] == sw(r[n-1],r[n-2],s[n-1]):
        return "".join(map(str, r))

    r = ["" for _ in range(n)]
    r[0] = "S"
    if s[0] == "o":
        r[1] = "W"
        r[-1]= "W"
    else:
        r[1] = "W"
        r[-1] = "S"

    for i in range(1,n-2):
        r[i+1] = sw(r[i],r[i-1],s[i])
    if r[n-1] == sw(r[n-2],r[n-3],s[n-2]) and r[0] == sw(r[n-1],r[n-2],s[n-1]):
        return "".join(map(str, r))

    r = ["" for _ in range(n)]
    r[0] = "W"
    if s[0] == "o":
        r[1] = "S"
        r[-1]= "W"
    else:
        r[1] = "S"
        r[-1] = "S"

    for i in range(1,n-2):
        r[i+1] = sw(r[i],r[i-1],s[i])
    if r[n-1] == sw(r[n-2],r[n-3],s[n-2]) and r[0] == sw(r[n-1],r[n-2],s[n-1]):
        return "".join(map(str, r))

    r = ["" for _ in range(n)]
    r[0] = "W"
    if s[0] == "o":
        r[1] = "W"
        r[-1]= "S"
    else:
        r[1] = "W"
        r[-1] = "W"

    for i in range(1,n-2):
        r[i+1] = sw(r[i],r[i-1],s[i])
    if r[n-1] == sw(r[n-2],r[n-3],s[n-2]) and r[0] == sw(r[n-1],r[n-2],s[n-1]):
        return "".join(map(str, r))

    return "-1"

print(main())

Measured memory_bytes: 63732
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == t[i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AOJ.Volume2
{
    public class ProgrammingContest
    {
        public static int Main()
        {
            var input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);    // ???????????°
            int r = int.Parse(input[1]);    // ?????°?????°
            int l = int.Parse(input[2]);    // ?????????????????????

            var point = new int[n + 1]; // ??????(???????????????????????¢???????????§n+1?????????)
            var time = new int[n + 1];  // ?????£?????????

            // ???????????¨??????????????????0???????????§1?????????????????????
            int bef_time = 0;
            int current_team = 1;
            for (int cnt = 0; cnt < r; cnt++)
            {
                input = Console.ReadLine().Split(' ');
                // ???????????????
                int t = int.Parse(input[0]);
                int now_time = int.Parse(input[1]);
                int p = int.Parse(input[2]);
                point[t] += p;

                // ???????????????????????????????????¢???
                // ?????¬??????????????????????????¨???????????????????????????
                // ???????????±????????¨????????????????????????????????????????????´????????????
                int tmp_team = current_team;
                if(t == current_team && p < 0)
                {
                    int tmp_point = int.MinValue;
                    for (int i = 1; i <= n; i++)
                    {
                        if (point[i] > tmp_point)
                        {
                            tmp_point = point[i];
                            tmp_team = i;
                        }
                    }
                }
                else if (point[t] > point[current_team]) { tmp_team = t; }
                else if(point[t] == point[current_team] && t < current_team) { tmp_team = t; }

                if(current_team != tmp_team)
                {
                    // ??????????????????????????????????????§?????????????¨?
                    time[current_team] += now_time - bef_time;
                    bef_time = now_time;
                    current_team = tmp_team;
                }
            }
            // ?????????????????????????????????
            time[current_team] += l - bef_time;

            int ans = 0;
            int tmp_time = 0;
            for(int i = 1; i <= n; i++)
            {
                if (time[i] > tmp_time)
                {
                    ans = i;
                    tmp_time = time[i];
                }
            }
            Console.WriteLine(ans);

            return 0;
        }
    }
}

Measured memory_bytes: 10364