akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int n;cin >> n;
	string s;cin >> s;
	int cnt = 0;//R
	rep(i,n){
		cnt += (s[i] == 'R');
	}
	int ret = 0;
	for(int i = cnt;i < n ;i++){
		ret += (s[i] == 'R');
	}
	cout << ret << endl;
	return 0;
}

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

using namespace std;

const int maxn = 2e5+7;
vector<int> g[maxn];
int xx[maxn], yy[maxn], len  = 0;
int dep[maxn], in[maxn];
void dfs(int u,int pre){
  	dep[u] = dep[pre] + 1;
    for(int i=0;i<g[u].size();i++){
        int v = g[u][i];
      	if(v==pre)continue;
        if(dep[v]==0){
            dfs(v, u);
        }
        else if(dep[v]>dep[u]){
            in[u]++;
            xx[++len] = u;    
            yy[len] = v;
        }
    }
    if(in[u]&1){
        assert(pre != 0);
        len++;
        in[u]++;
        xx[len] = u;
        yy[len] = pre;
    }
    else{
        len++;
        in[pre]++;
        xx[len] = pre;
        yy[len] = u;
    }
}
int main()
{
    int n,m;scanf("%d%d", &n, &m);
    for(int i=1;i<=m;i++){
        int a,b;
        scanf("%d%d", &a, &b);
        g[a].push_back(b);   
        g[b].push_back(a);   
    }
    if(m & 1){
        printf("-1\n");
        return 0;    
    }
    dfs(1, 0);
    for(int i=1;i<=n;i++)assert((in[i]&1)==0);
    for(int i=1;i<=m;i++)printf("%d %d\n", xx[i], yy[i]);
    return 0;
}


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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> osts;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        osts[i % k]++;
    }
    for (int first = 1; first <= n; first++) {
        int needost = (k - first % k) % k;
        if ((needost + needost) % k != 0) {
            continue;
        }
        else {
            ans += (long long)osts[needost] * osts[needost];
        }
    }
    cout << ans;
}


Measured memory_bytes: 4992
#include <cstdio>

int main()
{
	for (int i = 0; i < 9; ++i) {
		for (int j = 0; j < 9; ++j) {
			int a = i + 1;
			int b = j + 1;
			printf("%dx%d=%d\n", a, b, a * b);
		}
	}
    return 0;
}

Measured memory_bytes: 2652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 String S = sc.next();
		 String T = sc.next();
		 int min = Integer.MAX_VALUE;	 
		 for (int i = 0; i < S.length()-T.length()+1; i++) {
			 int count = 0;
			 for (int j= 0; j < T.length(); j++) {
				 if(S.charAt(i+j) != T.charAt(j)) {
					 count++;
				 }
			 }
			 if(min > count) {
				 min = count;
			 }
		 }
		 System.out.print(min);
	}

}


Measured memory_bytes: 35644
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const int INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    string S1, S2; cin >> S1 >> S2;
    ll ans;
    int start;
    if(S1[0] == S2[0])
        ans = 3, start = 1;
    else
        ans = 6, start = 2;
    for(int i = start; i < N; ++i) {
        if(S1[i] == S2[i]) {
            if(S1[i - 1] == S2[i - 1]) {
                ans *= 2;
                ans %= MOD;
            }
        }else {
            if(S1[i - 1] == S2[i - 1]) {
                ans *= 2;
                ans %= MOD;
            }else {
                ans *= 3;
                ans %= MOD;
            }
            i += 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
A = {}
for i in range(1, 4):
    for j, a in enumerate(map(int, input().split()), 1):
        A[a] = (i,j)

memo = set()

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A:
        memo.add(A[b])

bingo = [
    set([(1,1),(1,2),(1,3)]),
    set([(2,1),(2,2),(2,3)]),
    set([(3,1),(3,2),(3,3)]),
    set([(1,1),(2,1),(3,1)]),
    set([(1,2),(2,2),(3,2)]),
    set([(1,3),(2,3),(3,3)]),
    set([(1,1),(2,2),(3,3)]),
    set([(3,1),(2,2),(1,3)])
]

for b in bingo:
    if len(b.intersection(memo)) == 3:
        print("Yes")
        break
else:
    print("No")

Measured memory_bytes: 9272
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include <cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#pragma comment(linker, "/STACK:880999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<pll, ll> ppll;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const ll settled = 400007;

int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	//freopen("qual.in", "r", stdin);
	//freopen("qual.out", "w", stdout);
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string key;
	cin >> key;
	string sample = "keyence";
	ll le, ri;
	le = 0;
	ri = sample.size() - 1;
	for (char c : key)
	{
		if (le == sample.size())
			break;
		if (sample[le] == c)
			le++;
		else
			break;
	}
	for (ll i = key.size() - 1; i >= 0; i--)
	{
		char c = key[i];
		if (ri == -1)
			break;
		if (sample[ri] == c)
			ri--;
		else
			break;
	}
	if (le > ri)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N;
    cin >> N;
    vector<int> A(N);
    CINVEC(A);
    REP(i, N)A[i]--;

    int cur = 0;
    int cnt = 0;
    REP(i, N) {
        if (A[cur] == -1)break;
        int a = A[cur];
        A[cur] = -1;
        cur = a;
        cnt++;
        if (cur == 1) {
            cout << cnt << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
require 'set'

W = 15
H = 19
BLACK = 1
EMPTY = 0
OUT = -1
GOAL = -2

class Board
    def initialize
        @bits = 0
        y_max = 0
        H.times do |i|
            s = gets.chomp
            (0..W-1).each do |j|
                if s[j] == ?O
                    @y = i
                    @x = j
                end
                if s[j] == ?X
                    y_max = i
                end
            end
            s.reverse!
            x = s.gsub(/./) {|c| c == ?X ? ?1 : ?0}.to_i(2)
            @bits += (x << W * i)
        end
        if y_max <= H - 3 && @y <= H - 2
            puts -1
            exit
        end
        @depth = 0
    end

    def jump(dx, dy)
        return unless get(@x+dx, @y+dy) == BLACK
        loop do
            @x += dx
            @y += dy
            break if get(@x, @y) != BLACK
            @bits -= (1 << @y * W + @x)
        end
        @depth += 1
    end

    def get(x, y)
        return OUT if x < 0 or x >= W or y < 0 or y >= H
        return @bits[y * W + x]
    end

    def hash
        (@bits << 10) + (@y << 5) + @x
    end

    def eql?(other)
        hash == other.hash
    end

    def goal?
        @y >= H or (@y == H-1 && @x >= 0 && @x <= W-1)
    end

    def out?
        get(@x, @y) == OUT
    end

    def inspect
        super.inspect + (0..H-1).map {|i| (0..W-1).map {|j| @x == j && @y == i ? ?X : @bits[i*W+j].to_s}.join + "\n"}.join
    end

    attr_reader :depth
end

b = Board.new
queue = [b]
reached = Set[b]

until queue.empty?
    b0 = queue.shift
    [-1, 0, 1].repeated_permutation(2).each do |dx, dy|
        next if dx == 0 && dy == 0
        b = b0.dup
        b.jump(dx, dy)
        next if reached.include?(b)
        if b.goal?
            puts b.depth
            exit
        end
        next if b.out?
        reached << b
        queue << b
    end
end

puts -1

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

int main (int argc, char **argv) {

  vector<int> i_task(3);

  cin >> i_task[0] >> i_task[1] >> i_task[2];
  sort(i_task.begin(), i_task.end());

  int cost=0;

  cost += abs(i_task[0] - i_task[1]);
  cost += abs(i_task[1] - i_task[2]);

  cout << cost << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
using namespace std;
int main(){
   int a[5];
   
   for(int i=0;i<5;i++) {
       cin>>a[i];
       if(a[i]==0){
           cout<<i+1;
           break;
       }
   }
   
    return 0;
    
}

Measured memory_bytes: 3564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (Scanner sc = new Scanner(System.in)) {
			char[] s = sc.next().toCharArray();
			int countX = 0;
			for (int i = 0; i < s.length; i++) {
				if (s[i] == 'x') countX++; 
			}
			if (countX > 7) System.out.println("NO");
			else System.out.println("YES");
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


Measured memory_bytes: 21588
Point = complex


N, *XY = map(int, open(0).read().split())

P = [Point(x, y) for x, y in zip(*[iter(XY)] * 2)]

def max_distance(center):
    return max(abs(center - p) for p in P)

def g(x):
    left, right = -1000, 1000
    for _ in range(100):
        m1 = (left * 2 + right) / 3
        m2 = (left + right * 2) / 3
        if max_distance(Point(x, m1)) < max_distance(Point(x, m2)):
            right = m2
        else:
            left = m1

    return max_distance(Point(x, left))

left, right = -1000, 1000
for _ in range(100):
    m1 = (left * 2 + right) / 3
    m2 = (left + right * 2) / 3
    if g(m1) < g(m2):
        right = m2
    else:
        left = m1

print(g(left))

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

int main (){
	while(1){
		string input = "";
		int m = 0;
		cin >> input;
		if(input == "-") break;
		cin >> m;

		int *H = new int[m]();
		for(int i=0; i<m; i++){
			cin >> H[i];
		}

		for(int i=0; i<m; i++){
			input = input.substr(H[i]) + input.substr(0, H[i]);
		}
		cout << input << endl;
	}

	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

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

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    string s;
    cin >> s;
    char a[] = {'-', '+'};
    for(ll i = 0; i < 8; i++){
        ll v = s[0] - '0'; string ss;
        ss += s[0];
        for(ll j = 0; j < 3; j++){
            ll f = (i & (1<<j)) != 0; //cout << f << " ";
            ss += a[f];
            ss += s[j+1];
            if(f) v += (s[j+1] - '0');
            else v -= (s[j+1] - '0');
        }
        ss += '=';
        ss += '7'; //cout << ss << endl;
        if(v == 7) ANS(ss);
    }

}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    FOR(x, 1, 50000) {
        double X = double(x);
        if(int(X*1.08) == N) {
            cout << X << endl;
            return 0;
        }
    }
    
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define eb emplace_back
#define precision(n) cout << fixed << setprecision(n);
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{
    fast;
    string s;
    cin>>s;
    int f=0;
    if(s[0]!=s[1]||s[1]!=s[2]||s[0]!=s[2])
    {
        f=1;
    }
    if(f)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;

return 0;
}


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

using namespace std;

int main(){

  int n, l;
  int sum = 0;
  int min = 10000;

  cin >> n >> l;
    
  for(int i = 0; i < n; i++){
    int taste = l + i;
    if(abs(taste) < abs(min)){
      min = taste;
    }
    sum += taste;
  }

  cout << sum - min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i=0;i<N;i++) cin >> p[i];

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

  int ans=0;
  for(int i=0;i<K;i++) ans+=p[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
x=int(input())
if 400<=x<=599:
    print(8)
elif 600<=x<=799:
    print(7)
elif 800<=x<=999:
    print(6)
elif 1000<=x<=1199:
    print(5)
elif 1200<=x<=1399:
    print(4)
elif 1400<=x<=1599:
    print(3)
elif 1600<=x<=1799:
    print(2)
elif 1800<=x<=1999:
    print(1)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
class UnionFind{
  public:
      vector<ll> uni; //親の番号 or 根のときは木の要素数×(-1)
      UnionFind(ll s) : uni(s, -1) { }
      //頂点aが所属するグループを調べる
      ll root(ll a){ if (uni[a] < 0) return a; return uni[a] = root(uni[a]);}
      //頂点aと頂点bを繋ぐ。もともと同じグループの時falseを返す
      bool unite(ll a,ll b){
        a = root(a);
        b = root(b);
        if (a == b) return false;
        if (uni[a] > uni[b]){ swap(a,b); }//a ^= b; b ^= a; a ^= b;
        uni[a] = uni[a] + uni[b];
        uni[b] = a;
        return true;
      }
        //頂点a,bが同じグループであるかを調べる
      bool isConnect(ll a,ll b){return root(a) == root(b);}
        //頂点aを含むグループの頂点数を調べる
      int size(ll a){return -uni[root(a)];}
};
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M, A[100000], B[100000];
  cin>>N>>M;
  vector<ll> ans(M);
  REP(i,M){
    cin>>A[i]>>B[i];
    A[i]--;B[i]--;
  }
  ans[M-1]=N*(N-1)/2;
  UnionFind uf(N);
  ll ret = 0;
  for(int i = M - 1; i >= 0; i--) {
    ans[i] = 1LL * N * (N - 1) / 2 - ret;
    if(!uf.isConnect(A[i],B[i])) {
      ret += 1LL * uf.size(A[i]) * uf.size(B[i]);
      uf.unite(A[i], B[i]);
    }
  }

  REP(i,M) cout << ans[i] << "\n";

  return 0;
}

Measured memory_bytes: 3712
import java.util.*

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
private fun <K, V> Map<out K, V>.toMutableMap(): MutableMap<K, V> = LinkedHashMap(this)
private fun <K, V> mutableMapOf(): MutableMap<K, V> = LinkedHashMap()
private fun <K, V> mutableMapOf(vararg pairs: Pair<K, V>) = pairs.toMap().toMutableMap()

fun main(args: Array<String>) {
    var (a, b, c) = readInts()
    var count = 0
    for (i in 0 until c) {
        b -= a
        if (b < 0 || count == c) break
        count++
    }
    println(count)
}

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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			var c = s.ToCharArray();
			for (int i = 0; i <= s.Length-5; i++)
			{
				if (s.Substring(i, 5) == "apple")
					"peach".ToArray().CopyTo(c, i);
				else if (s.Substring(i, 5) == "peach")
					"apple".ToArray().CopyTo(c, i);
			}
			Console.WriteLine(new string(c));
		}
	}
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#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 uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
int a[200010];

int main(){
  cin>>n;
  rep(i,n)cin>>a[i];
  ll res=0;
  rep(i,n){
    if(a[i]>i||(i<n-1&&a[i+1]-a[i]>1)){
      cout<<-1<<endl;
      return 0;
    }
    res+=a[i];
  }
  ll pre=a[0];
  for(int i=1;i<n;i++){
    if(pre+1==a[i]){
      res-=pre;
      pre=a[i];
    }
    pre=a[i];
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> a(n);
    REP(i,n) cin >> a[i];
    ll asum = accumulate(ALL(a),0LL);
    ll snuke = a[0];
    ll arai = asum - a[0];
    ll ans = abs(snuke-arai);
    FOR(i,1,n-1) {
        snuke += a[i];
        arai -= a[i];
        ans = min(ans,abs(snuke-arai));
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N,A,B; cin >> N >> A >> B;
    vector<ll> H(N);
    rep(i,N) cin >> H[i];

    ll left = 0;
    ll right = 1e9;
    while (right - left > 1) {
        ll mid = (left+right)/2;
        ll cnt = 0;
        rep(i,N) {
            ll val = H[i] - mid*B;
            if (val <= 0) continue;
            cnt += (val + (A-B)-1)/(A-B);
        }

        if (cnt <= mid) right = mid;
        else left = mid;
    }

    cout << right << ln;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main(){
	long long n;
	cin >> n;
	
	cout << n*(n-1)/2<<endl;
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()

    var sum = 0L

    for (i in 1..n) {
        for (j in 1..n) {
            for (k in 1..n) {
                sum += gcd(i, j, k)
            }
        }
    }

    println(sum)
}

fun gcd(a : Int, b : Int, c : Int) : Int {
    val min = Math.min(Math.min(a, b), c)

    for (i in min downTo 1) {
        if (a % i == 0 && b % i == 0 && c % i == 0) return i
    }

    return 1
}


Measured memory_bytes: 35352
data = []
while True:
  a,b = map(int, input().split())
  if a == 0:
    break
  else:
    data.append([a,b])

for i in range(len(data)):
  for x in range(data[i][0]):
    if x != 0 and x != data[i][0]-1:
      print("#"+"."*int(data[i][1]-2)+"#")
    else:
      print("#"*data[i][1])
  print("")


Measured memory_bytes: 5624
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		int youso = sc.nextInt();
		int hairetsu[] = new int[youso];
		for(int i = 0;i < youso;i++) {
			hairetsu[i] = sc.nextInt();
		}
		int count = 0;
		for(int i = 0;i < youso - 1;i++) {
			for(int j = 0;j < youso - (i + 1);j++) {
				if(hairetsu[j] > hairetsu[j + 1]) {
					int swap = hairetsu[j];
					hairetsu[j] = hairetsu[j + 1];
					hairetsu[j + 1] = swap;
					count++;
				}
			}
		}
		for(int i = 0;i < youso;i++) {
			System.out.printf("%d",hairetsu[i]);
			if(i != youso - 1) System.out.printf(" ");
		}
		System.out.printf("\n%d\n",count);
		sc.close();
	}	
}


Measured memory_bytes: 26640
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define nl '\n'
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int M = 1e9+7;
const int N = 2*1e5;


int main(){
    AC
    int x, y;
    cin>>x>>y;
    int b = y/2-x;
    int a = 2*x-y/2;

    if(a>=0 && b>=0 && a+b==x && 2*a+4*b==y)
        cout<<"Yes"<<nl;
    else
        cout<<"No"<<nl;
}

Measured memory_bytes: 3636
#include <stdio.h>

int socket = 0;
int kuchi = 1;

void setuzoku(int *x, int *y, int a)
{
	*x += 1;
	*y += a - 1;
}

int main(int argc, char const *argv[])
{
	int a, b;
	scanf("%d%d", &a, &b);

	while (kuchi < b)
	{
		setuzoku(&socket, &kuchi, a);
	}

	printf("%d\n", socket);

	return 0;
}

Measured memory_bytes: 128
static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  for(i=1;i<n;i++){
    trace(A, n);
    v=A[i];
    j=i-1;       
    while(j>=0 && A[j] > v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
  }
  trace(A, n);
  return 0;
}

Measured memory_bytes: 608
// FizzBuzz Sum


func main(){
  let s = readLine()!
  let n = Int(s)!
  let range = 1...n
  print(
    range
      .map {$0 % 3 == 0 || $0 % 5 == 0 ? 0 : $0}
      .reduce(0, +)
  )
}

main()

Measured memory_bytes: 14344
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 200001;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
        signed main() {
    COMinit();
    int n,a,b;
    cin>>n>>a>>b;
    int a0=1,b0=1;
    for(int i=1;i<=a;i++){
             a0=(((a0*(n+1-i))%MOD)*inv[i])%MOD;
    }
     for(int i=1;i<=b;i++){
            b0=(((b0*(n+1-i))%MOD)*inv[i])%MOD;
    }
   int ans=(MOD+modpow(2,n,MOD)-1)%MOD;
   //cerr<<ans<<' ';
   ans=(ans+MOD-a0+MOD-b0)%MOD;
   cout<<ans;

    
      }

        


Measured memory_bytes: 4992
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

using namespace std;

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

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i < n; ++i) {
        if (s[i] == s[i - 1]) {
            cout << i << " " << i + 1 << endl;
            return 0;
        }
    }
    for (int i = 2; i < n; ++i) {
        if (s[i] == s[i - 2]) {
            cout << i - 1 << " " << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1;
}


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

int main() {
    long long A;
    double B;

    cin >> A >> B;
  
  B+= 0.00001;

    long long C = B*100;
  
  long long Ans = A*C/100;

    cout << Ans << endl;

	

}


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

int main(){
  int D;
  cin >> D;
  if(D==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }
  else if(D==23){
    cout << "Christmas Eve Eve" << endl;
  }
  else if(D==24){
    cout << "Christmas Eve" << endl;
  }
  else{
    cout << "Christmas" << endl;
  }
}

Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int a; cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define per(i,n,k) for(int i=n;i>=k;i--)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define modp(x) (long long)((x+modn)%modn)
using namespace std;
const int maxn=105,maxk=100005;
const ll modn=1e9+7;
int n,k,a[maxn],sum;
ll f[maxn][maxk];
void pre()
{
	sort(a+1,a+n+1);
	rep(i,0,n) f[i][0]=1;
	rep(i,0,k) f[0][i]=1;
}
inline ll getsum(int i,int r,int len)
{
	if(r-len-1<0) return modp(f[i][r]);
	else return modp(f[i][r]-f[i][r-len-1]);
}
int main()
{
	cin>>n>>k;
	rep(i,1,n) cin>>a[i]; pre();
	rep(i,1,n-1)
	{
		if((sum+a[i])>=k) sum=k; else sum+=a[i];
		rep(j,1,k) if(j<=sum) f[i][j]=modp(f[i][j-1]+getsum(i-1,j,a[i]));
		else f[i][j]=modp(f[i][j-1]);
	}
//	rep(i,0,n-1){rep(j,0,k) cout<<f[i][j]<<" ";cout<<endl;}
	cout<<getsum(n-1,k,a[n]);
	return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 300005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define bg begin()
#define ed end()
#define pii pair<int,int>

int main()
{
	int n,k;
	int cnt[4]={};
		f(3){
			int add1,add2;
			cin >> add1 >> add2;
			cnt[add1]++,cnt[add2]++;
		}
		int s=0;
		f1(4){
			s+=(cnt[i]&1);
		}
		if(s==0||s==2){
			cout<<"YES"<<endl;
		}
		else{
			cout<<"NO"<<endl;
		}
	
}


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

int main(void)
{		
	for (int i = 1; i <= 3000; i++) {
		int x, y;
		cin >> x >> y;
		if (x == 0 && y == 0) break;
		if (x < y) {
			cout << x << " " << y << endl;
		} else {
			cout << y << " " << x << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3020
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		string a;
		cin >> a;
		int b, c;
		cin >> b >> c;
		if (a == "print") {
			cout << s.substr(b, c - b + 1) << endl;
		}
		else if (a == "replace") {
			string d;
			cin >> d;
			s.replace(b, c - b + 1, d);
		}
		else {
			reverse(s.begin() + b, s.begin() + c + 1);
		}
	}
	return 0;
}


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

int main() {
        int r, c, f;
        cin >> r >> c;

        int sheet[r+1][c+1];

        for(int i=0; i<r; i++){
                int col_sum = 0;
                for(int j=0; j<=c; j++){
                        if(j<c){
                                cin >> sheet[i][j];
                                col_sum += sheet[i][j];
                        }
                        else if(j==c){
                                sheet[i][j] = col_sum;
                        }
                }
        }

        for(int j=0; j<=c; j++){
                int row_sum =0;
                for(int i=0; i<=r; i++){
                        if(i<r) row_sum += sheet[i][j];
                        else if(i==r) sheet[i][j] = row_sum;
                }
        }

        for(int i=0; i<=r; i++){
                for(int j=0; j<=c; j++){
                        if(j>0) cout << ' ' << flush;
                        cout << sheet[i][j] << flush;
                        if(j==c) cout << endl;
                }
        }
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
 string s,t;
  int a,b;
  cin>>s>>t>>a>>b;
  string u;
  cin>>u;
  if(s==u){
    cout<<a-1<<' '<<b<<endl;
  }
  else if(t==u){
    cout<<a<<' '<<b-1<<endl;
  }
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b)cout << "delicious" << endl;
	else if (a + x >= b )cout << "safe" << endl;
	else cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H, W, M = map(int, input().split())
s = set()
ys = [0] * (H + 1)
xs = [0] * (W + 1)
for _ in range(M):
  y, x = map(int, input().split())
  s.add((y, x))
  ys[y] += 1
  xs[x] += 1

res = 0
mxy = []
mx = max(ys)
for i in range(H + 1):
  if ys[i] == mx: mxy.append(i)
res += mx

mxx = []
mx = max(xs)
for i in range(W + 1):
  if xs[i] == mx: mxx.append(i)
res += mx - 1

for x in mxx:
  for y in mxy:
    if (y, x) in s: continue
    res += 1
    break
  else: continue
  break
print(res)

Measured memory_bytes: 166208
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define MAX 1024
using namespace std;

typedef pair<int,int> P;

int n,p[MAX],d[MAX];
vector<P> e[MAX];
bool leaf[MAX];
bool visited[MAX];

void init(){
  for(int i=0;i<MAX;i++){
    e[i].clear();
    leaf[i]=false;
  }
}

int dfs(int v){
  visited[v]=true;
  int res=0;
  for(int i=0;i<e[v].size();i++){
    P next=e[v][i];
    if(!visited[next.f] && !leaf[next.f])res=max(res,dfs(next.f)+next.s);
  }
  return res;
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=1;i<n;i++)cin>>p[i];
    for(int i=1;i<n;i++)cin>>d[i];
    for(int i=1;i<n;i++){
      p[i]--;
      e[i].push_back(mp(p[i],d[i]));
      e[p[i]].push_back(mp(i,d[i]));
    }

    for(int i=0;i<n;i++)if(e[i].size()==1)leaf[i]=true;

    int ans=0;
    for(int i=1;i<n;i++){
      if(leaf[i] || leaf[p[i]])ans+=d[i];
      else ans+=d[i]*3;
    }
    int tmp=0;
    for(int i=0;i<n;i++){
      if(leaf[i])continue;
      for(int i=0;i<n;i++)visited[i]=false;
      tmp=max(tmp,dfs(i));
    }
    cout<<ans-tmp<<endl;
  }
  return 0;
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  preprocess();
  int a; cin>>a;
  string s; cin>>s;
  if(a>=3200) cout<<s<<endl;
  else cout<<"red"<<endl;
}



Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a_min = min(a)
a_max = max(a)
if a_max - a_min <= 2:
  print(N)
else:
  b = [0] * (a_max-a_min+1)
  for i in range(N):
    b[a[i]-a_min] += 1
  #print(b)
  s = b[0] + b[1] + b[2]
  s_max = s
  for i in range(len(b)-3):
    s += b[3+i]-b[i]
    if s > s_max:
      s_max = s
  print(s_max)


Measured memory_bytes: 13964
#include <stdio.h>

int main(void)
{
	int n;
	char buf[100];
	int counter[26];
	int counterBuf[26];
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		int elem;
		for (elem = 0; elem < 26; elem++){
			counterBuf[elem] = 0;
		}

		scanf("%s", buf);

		for (elem = 0; buf[elem] != '\0'; elem++){
			counterBuf[buf[elem] - 'a']++;
		}

		for (elem = 0; elem < 26; elem++){
			if (i == 0 || counterBuf[elem] < counter[elem]){
				counter[elem] = counterBuf[elem];
			}
		}
	}

	for (i = 0; i < 26; i++){
		int j;

		for (j = 0; j < counter[i]; j++){
			printf("%c", i + 'a');
		}
	}
	printf("\n");

	return 0;
}

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

int main(){
    int n;cin>>n;
    int ans=0;
    for(int i=1;i<n+1;i+=2){
        int c=0;
        for(int j=1;j<i+1;j+=2){
            if(i%j==0) c++;
        }
        if(c==8) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
const int maxn = 1e5+10;
struct node
{
	int index,value;
	bool operator<(node x)
	{
		return value<x.value;
	}
};
 
node res[maxn];
int N; 
int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	int tmp=0;
	for(int i=1;i<=N;++i)
	{
		tmp++;
		cin>>res[tmp].value;
		res[tmp].index=i;
	}
	sort(res,res+tmp+1);
	for(int i=1;i<=tmp;++i)
	cout<<res[i].index<<" ";
	
	
	
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

ll gcd(ll a, ll b){
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int H,W;
bool seen[8][8];

const int dh[2] = {1,0};
const int dw[2] = {0,1};

void dfs(vector<string> &G, int h, int w){
  seen[h][w] = true;
  if(h+1 < H && G[h+1][w] == '#' && w+1 < W && G[h][w+1] == '#') return;
  rep(dir, 2){
    int nh = h + dh[dir];
    int nw = w + dw[dir];
    if(nh == -1 || nh == H || nw == -1 || nw == W ) continue;
    if(G[nh][nw] == '#') dfs(G, nh, nw);
  }
}

int main(){
  cin >> H >> W;
  vector<string> G(H); rep(i, H) cin >> G[i];

  memset(seen, false, sizeof(seen));
  dfs(G, 0, 0);

  bool ok = true;
  rep(h, H) rep(w, W){
    if(G[h][w] == '#' && !seen[h][w]) ok = false;
  }

  std::cout << (ok ? "Possible" : "Impossible") << '\n';

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>

using namespace std;

int main(){

    int x;
    for(int i=1; ;i++){
        cin >> x;
        if(x==0){
            break;
        }
        cout << "Case " << i << ": " << x << endl;
    }


    return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define ms(s,x) memset(s,x,sizeof(s))
#define pb push_back
#define inf 0x3f3f3f3f
#define IOS ios::sync_with_stdio(false)
typedef long long ll;
using namespace std;

const double PI = acos(-1.0);
const double eps = 1e-8;
const int MAXN = 1e6+5;
const ll MOD = 1e9+7;

int n;
int num[25];

bool dfs(int step, int sum, int val)
{
    if (sum == val)
        return 1;
    if (step == n+1 || sum > val)
        return 0;
    return dfs(step+1, sum, val) || dfs(step+1, sum+num[step], val);
}

int main()
{
    IOS;
    int q, val;
    cin >> n;
    rep(i, 1, n){
        cin >> num[i];
    }
    cin >> q;
    while (q--)
    {
        cin >> val;
        if (dfs(1, 0, val) || dfs(1, 0, val))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }

    return 0;
}



Measured memory_bytes: 3132
// ###### Sat Mar 28 14:19:29 IST 2020
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long    
#define MOD                998244353
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"  
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             (x).begin(),(x).end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;
int tests(){ 
  int n ;
  cin >> n ;  
  vector <vector <int>> d(2020,vector <int> (2020,0));
  int x,y ;
  vector <int> v(2);
  for(auto &it : v )
    cin >> it ;
  sort(all(v));
  x = v[0],y =v[1];
  int i,j ;
  forn(i,1,n+1)
    forn(j,1,n+1)
      d[i][j] = abs(j-i);

  d[x][y] = 1;
  forn(i,1,n+1)
    forn(j,1,n+1)
      d[i][j] = min(d[i][j],d[x][i]+1+d[j][y]);
  map <int,int> m ; 
  forn(i,1,n+1){
    forn(j,i+1,n+1)
      m[d[i][j]]++ ;
    // cout << '\n' ;  
  }    
  forn(i,1,n)
    cout << m[i] << '\n'; 


  return 0 ;
} 
int main(){
    I__O ;            
    int cases = 1 ; 
    // cin >> cases ;  
    while(cases--){   
    // cout << "Case #" << cases << ": ";
      tests(); 
    }
    return 0 ; 
}

// -Wall -Wextra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

Measured memory_bytes: 16384
#include <stdio.h>
char s[4001];
long long i,j,pair,n,r,g,b;
int main(){
	scanf("%lld",&n);
	scanf("%s",s);
	for (i=0;i<n;i++){
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
 }
	pair=r*g*b;
	for(i=0;i<n;i++)
		for(j=1;i+j*2<n;j++)
			if(s[i]!=s[i+j]&&s[i]!=s[i+j*2]&&s[i+j]!=s[i+j*2])
				pair--;
	printf("%lld",pair);
}

Measured memory_bytes: 1704
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define readc(a) scanf("%c", &a)
#define debug(a, b) printf("%s = %d\n", a, b)
#define debug1(a, i, b) printf("%s[%d] = %d", a, i, b)
#define show(a) putchar(a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
typedef long long LL;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
map<string, int> id;
struct node
{
    int cnt;
    string s;
    node(){}
    node(string s, int cnt): s(s), cnt(cnt){}
}a[N];
bool cmp(const node& A, const node& B)
{
    return A.cnt > B.cnt || (A.cnt == B.cnt && A.s < B.s);
}
string str;
signed main()
{
    Buff;
    int n, cnt = 0;
    int maxv = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> str;
        if(!id.count(str))
        {
            id[str] = ++cnt;
            a[cnt] = node(str, 1);
        }
        else
            a[id[str]].cnt++;
        maxv = max(maxv, a[id[str]].cnt);
    }
    sort(a + 1, a + cnt + 1, cmp);
    for(int i = 1; i <= cnt; i++)
        if(a[i].cnt == maxv) cout << a[i].s << "\n";
        else    break;
    return 0;
}
/**
    A
**/


Measured memory_bytes: 27008
from heapq import*
i=input
for s in[0]*int(i()):
 n,x,*y=int(i()),[]
 for _ in'_'*n:k,l,r=t=[*map(int,i().split())];x+=[t]*(l>r);y+=[[n-k,r,l]]*(l<=r)
 for x in x,y:
  h=[]
  for k,l,r in sorted(x):heappush(h,l-r);s+=l-(k<len(h)and heappop(h))
 print(s)

Measured memory_bytes: 51448
/*  */
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000")

#define sti				set<int>
#define stpii			set<pair<int, int> >
#define mpii			map<int,int>
#define vi				vector<int>
#define pii				pair<int,int>
#define vpii			vector<pair<int,int> >
#define rep(i, a, n) 	for (int i=a;i<n;++i)
#define per(i, a, n) 	for (int i=n-1;i>=a;--i)
#define clr				clear
#define pb 				push_back
#define mp 				make_pair
#define fir				first
#define sec				second
#define all(x) 			(x).begin(),(x).end()
#define SZ(x) 			((int)(x).size())
#define lson			l, mid, rt<<1
#define rson			mid+1, r, rt<<1|1
#define getBits(x)		__builtin_popcount(x)
#define getBitIdx(x)	__builtin_ffs(x)

typedef long long LL;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// #ifndef ONLINE_JUDGE
		// freopen("data.in", "r", stdin);
		// freopen("data.out", "w", stdout);
	// #endif
	
	string s;
	int c = 0;
	
	cin >> s;
	while (s.size() > 2) {
		bool flag = true;
		int sz = s.size();
		
		for (int i=1; i+1<sz; ++i) {
			if (s[i-1] != s[i+1]) {
				s.erase(i, 1);
				flag = false;
				break;
			}
		}
		
		if (flag) break;
		++c;
	}
	
	if (c%2 == 0)
		puts("Second");
	else
		puts("First");
	
	// #ifndef ONLINE_JUDGE
		// printf("time = %ldms.\n", clock());
	// #endif
	
	return 0;
}


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

int H,W,A,B;
long fact[220000];
long rfact[220000];
const long MOD = 1000000007;
long extgcd(long a,long b,long &x,long &y){
  long d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}

long mod_inverse(long a) {
  long x, y;
  extgcd(a, MOD, x, y);
  x %= MOD;
  if(x < 0) x += MOD;
  return x;
}
void init() {
  rfact[0] = fact[0] = 1;
  for(int i = 1; i < 220000; i++) {
    fact[i] = (fact[i - 1] * i) % MOD;
    rfact[i] = mod_inverse(fact[i]);
  }
}

long comb(long N, long K) {
  if(K < 0) return 0;
  if(N - K < 0) return 0;
  return ((fact[N] * rfact[K]) % MOD * rfact[N - K]) % MOD;
}

int main() {
  init();
  cin >> H >> W >> A >> B;
  long res = comb(H + W - 2, H - 1);
  for(int i = 0; i < B; i++) {
    res -= (comb(i + (H - A - 1), i) * comb(A - 1 + (W - 1 - i), A - 1)) % MOD;
    if(res < 0) res += MOD;
  }
  cout << res << endl;
}


Measured memory_bytes: 4344