akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion






int main() {
	int h, w; put h >> w;
	char map[9][9];
	int num = 0;
	rep(i, h) {
		string s; put s;
		rep(j, w) {
			if (s[j] == '#') {
				map[i][j] = '#';
				num++;
			}
			else {
				map[i][j] = '.';
			}
		}
	}
	if (num != ( h + w - 1)) {
		putans("Impossible");
		goto END;
	}
	else {
		int x = 0;
		int y = 0;
		while (x < w-1 || y < h-1) {
			if (x < w-1 && map[y][x+1] == '#') {
				x++;
			}
			else if (y < h-1 && map[y+1][x] == '#') {
				y++;
			}
			else {
				putans("Impossible");
				goto END;
			}
			dbg2(x, y);
		}
		putans("Possible");
	}
END:
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a,b;
int main()
{
    scanf("%d%d",&a,&b);
    if(a>0)
        printf("Positive\n");
    else if(b>=0)
        printf("Zero\n");
    else if((b-a+1)%2==0)
        printf("Positive\n");
    else
        printf("Negative\n");
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll a, b;
	cin >> a >> b;
	cout << (a-1)+(b>=a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>

using namespace std;

int main()
{
    int l1,l2,i,j,ans,m;
    char s1[1002],s2[1002];

    scanf("%s%s",s1,s2);
    l2=strlen(s2);
    l1=strlen(s1);
    l1=l1-l2+1;
    for(i=0,ans=0;i<l1;i++)
    {
        for(j=0,m=0;j<l2;j++)
        {
            if(s1[i+j]==s2[j])
                m++;
        }
        ans=max(ans,m);
    }
    printf("%d\n",l2-ans);
    return 0;
}


Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int x=a*100;
    int y=b*100;
    vi dp(3001);
    dp[0]=0;
    REP(i,3000){
        chmax(dp[i+1],dp[i]);
        if(i+c<=3000)chmax(dp[i+c],dp[i]+c);
        if(i+d<=3000)chmax(dp[i+d],dp[i]+d);
    }
    int ana=-1,anb=-1;
    double ans=-1;
    REP(i,f/x+1){
        REP(j,(f-x*i)/y+1){
            int l=x*i+y*j;
            int z=max(0,min(f-l,l*e/100));
            int k=dp[z];
            if(ans<=1.0*k/(1.0*(l+k))){
                ans=(1.0*k)/(1.0*(l+k));
                ana=l+k;
                anb=k;
            }
        }
    }
    cout<<ana<<endl<<anb<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;

const long long int M = 1000000007;
const int MAX_N = 1000;
bool is_prime[MAX_N+1];

void sieve()
{
  is_prime[0] = is_prime[1] = false;
  FOR(i,2,MAX_N+1) is_prime[i] = true;
  FOR(i,2,MAX_N+1)
    if(is_prime[i])
      for(int j = i*2; j <= MAX_N; j+=i)
        is_prime[j] = false;
}

int main()
{
  int N;
  cin >> N;
  long long int ans = 1;
  sieve();
  FOR(i,2,N+1){
    if(is_prime[i]){
      long long int x = i;
      long long int y = 0;
      while(x <= N){
        y += N/x;
        x *= i;
      }
      ans *= y+1;
      ans %= M;
    }
  }
  cout << ans << endl;
}

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

signed main(){
	ll n,k;
	cin>>n>>k;
	ll max=0,min=0,ans=0;
	for(ll i=k;i<=n+1;i++){
		min=(i*(i-1))/2;
		max=((n+1)*n)/2;
        max-=((n-i+1)*(n-i))/2;
		ans+=(max-min+1);
	}
  	ans%=MOD;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int mp[1005][1005] = {};

int main() {
	int h, w, m;
	cin >> h >> w >> m;
	vector<int> height(h), width(w);
	set<pair<int, int>> block;
	rep(i, m) {
		int hei, wid;
		cin >> hei >> wid;
		hei--; wid--;
		block.emplace(hei, wid);
		height[hei]++;
		width[wid]++;
	}
	int mh = 0, mw = 0;
	rep(i, h) mh = max(mh, height[i]);
	rep(i, w) mw = max(mw, width[i]);
	int ans = mh + mw;
	vector<int> tate, yoko;
	rep(i, h) if (mh == height[i]) tate.push_back(i);
	rep(i, w) if (mw == width[i]) yoko.push_back(i);
	for (int i : tate) {
		for (int j : yoko) {
			if (block.count(pair<int, int> (i, j))) continue;
			cout << ans << endl;
			return 0;
		}
	}
	cout << ans - 1 << endl;
	return 0;
}


Measured memory_bytes: 23844
# 素因数分解（辞書型で返ってくるので今回は使いにくい）
"""
pf={}
n = int(input())
for i in range(2,int(n**0.5)+1):
    while n % i == 0:
        pf[i] = pf.get(i,0)+1
        n//= i
if n > 1 : pf[n] = 1
print(pf)
"""
"""
# Return a list of the prime factors for a natural number bigger than 1
def trial_division(n):
    if n < 2:
        return []

    prime_factors = []

    for i in range(2, int(n**0.5)+1):
        # nがi（の累乗）で割り切れるかを調べる
        while n % i == 0:
            # nがiで割り切れる場合、iを素因数としてリストに追加する
            prime_factors.append(i)
            # nをiで割った商で更新しておく
            n //= i
    # nの平方根より大きい素因数が存在する場合
    if n > 1:
        prime_factors.append(n)

    return prime_factors

n = int(input())
# print(trial_division(n)) # 結果がリストで返ってくる
"""

""" TLE
n=int(input())

for i in range(1,10000):
    for j in range(1,i+1):
        seki=i*j
        if seki==n:
            print(i+j-2)
            exit()
"""

# 対称性よりNの√を取り、1~√nまで全探索
import sys
input = sys.stdin.readline
 
N=int(input())
ans=10**12
for i in range(1,int(N**0.5)+1):
    if N%i==0: # 割り切れる場合
        ans=min(ans,i+N//i) # N//iはもう一個の解 N=i*N//i
print(ans-2) # -2はもともと(1,1)にいるからその分の差し引き

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

int main(){
  int n,cnt=0,c=0,e=0;
  string s;
  cin >> n >> s;
  int a[n];
  for(int i=0;i<n;i++){
    if(s.at(i)=='E') cnt++;
    else cnt--;
    a[i] = cnt;
  }
  for(int i=0;i<n;i++){
    if(c<a[i]){
      e = i;
      c = max(c,a[i]);
    }
  }
  int cnt1=0;
  for(int i=0;i<e;i++){
    if(s.at(i)=='W') cnt1++;
  }
  for(int i=e+1;i<n;i++){
    if(s.at(i)=='E') cnt1++;
  }
  cout << cnt1 << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,command,x;
    string key,l,r;
    multimap<string,int> myMap;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> command;
        // insert
        if(command == 0){
            cin >> key >> x;
            myMap.insert(pair<string,int>(key,x));
            // find
        }else if(command == 1){
            cin >> key;
            map<string,int>::iterator begin = myMap.find(key);
            unsigned long cnt = myMap.count(key);
            for(int i = 0;i < cnt;++i){
                cout << begin->second << endl;
                ++begin;
            }
        }
        // delete
        else if(command == 2){
            cin >> key;
            myMap.erase(key);
        }
        // dump
        else if(command == 3){
            cin >> l >> r;
            map<string,int>::iterator begin,end;
            begin = myMap.lower_bound(l);
            end = myMap.upper_bound(r);
            for(;begin != end;++begin){
                cout << begin->first << " " << begin->second << endl;
            }
        }
    }
}



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

typedef long long ll;
const ll INF = (ll)1e18 + 1;

// print(x, y, z);
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main(int argc, char* argv[])
{
  ll N;
  std::cin >> N;
  std::string S;
  std::cin >> S;

  std::vector<ll> ve(N+1, 0LL);
  std::vector<ll> vw(N+1, 0LL);

  for (ll i = 1; i <= N; i++) {
    ve[i] = ve[i-1];
    vw[i] = vw[i-1];
    if (S[i-1] == 'W') { ve[i]++; }
    if (S[i-1] == 'E') { vw[i]++; }
  }

  ll ans = INF;
  for (ll i = 0; i < N; i++) {
    ll cnt = vw[N] - vw[i+1] + ve[i];
    ans = std::min(ans, cnt);
  }

  print(ans);
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{
    ll N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;
    vector<ll> ans(N);
    REP(i, N) {
        FOR(j, i+1, N) {
            ll k = j - i;
            k = min(k, min(abs(X - i) + 1 + abs(Y - j), abs(X-j) + 1 + abs(Y-i)));
            ans[k]++;
        }
    }
    FOR(i, 1, N) {
        PRINT(ans[i]);
    }
    return 0;
} 

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  deque<ll> q;
  ll ans=0;
  rep(i,n){
    auto itr=lower_bound(all(q),a[i]);
    if(itr==q.begin()) q.push_front(a[i]);
    else itr--,*itr=a[i];
  }
  cout<<q.size()<<endl;
}

Measured memory_bytes: 1920
#include<cstdio>
#include<iostream>
using namespace std;
const int N=3e2+10;
const int mod=998244353;
int n,m,a[N][N],c[N][N],b[N],Max=N-5,cnt;
inline int fas(int x,int p){int res=1;while(p){if(p&1)res=1ll*res*x%mod;p>>=1;x=1ll*x*x%mod;}return res;}
int main(){
	scanf("%d%d",&n,&m);
	for(register int i=1;i<=n;i++)
		for(register int j=1;j<=m;j++)
			scanf("%d",&a[i][j]);
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=m;j++)b[j]=a[i][j];
		for(register int p=Max;p;p--){
			if(b[p]){
				if(!c[p][p]){
					for(register int k=p;k;k--)c[p][k]=b[k];
					cnt++;break;
				}
				else for(register int k=p;k;k--)b[k]^=c[p][k];
			}
		}
	}
	printf("%lld\n",1ll*(fas(2,n)-fas(2,n-cnt)+mod)%mod*fas(2,m-1)%mod);
	return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

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


int main(){
	
	string str;cin >> str;
	ll ans = 0;
	ll now = 0;
	REP(i, str.size()){
		if(str[i] == 'A' || str[i] == 'T' || str[i] == 'C' || str[i] == 'G')now++;
		else now = 0;
		ans = max(ans, now);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
R1=R2=0

for i in range(1,X):
    if i in A:
        R1+=1
for i in range(X+1,N):
    if i in A:
        R2+=1
    
print(min(R1,R2))

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int x[10000],y[10000];
	int a,b,i;
	for(i=0;;i++){
	scanf("%d%d",&x[i],&y[i]);
	if(x[i]==0 && y[i]==0){
		break;
	}
	if(x[i]<y[i]){
		a=x[i];
		b=y[i];
	}
		else if(x[i]>y[i]){
		b=x[i];
		a=y[i];
		}
		else{
		a=x[i];
		b=y[i];
	}
		printf("%d %d\n",a,b);
	}
	return 0;
}



Measured memory_bytes: 2048
//Volume5-0543
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true){
			int sum = sc.nextInt();
			if(sum==0){break;}
			for(int i=0;i<9;i++){sum -= sc.nextInt();}
			System.out.println(sum);
		}
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

void Main(){
    int n; cin >> n;
    map<P, ll> mp;
    
    rep(i, n){
        long double a; cin >> a;
        ll x = round(a * 1e9);
        // cout << x << endl;
        
        int t2 = -9, t5 = -9;
        while(x % 2 == 0){
            x /= 2;
            t2++;
        }
        while(x % 5 == 0){
            x /= 5;
            t5++;
        }
        mp[{t2, t5}]++;        
    }
    
    ll ans = 0;
    for(auto [d, c] : mp) {
        for(auto [D, C] : mp){
            if(d == D && d.fi >= 0 && d.se >= 0) {
                ans += c * (c - 1);
            }
            else if(d.fi + D.fi >= 0 && d.se + D.se >= 0) {
                ans += c * C;
            }
        } 
    }
    cout << ans/2 << endl;
    return;
}

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

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

int least(int nw,int cost,int mn,vector<vector<int>>&c,vector<bool>psd){
	if(nw==1)return min(cost,mn);
	else if(cost>=mn) return mn;
	psd.at(nw)=true;
	for(int i=0;i<=9;++i){
		if(psd.at(i))continue;
		mn=least(i,cost+c.at(nw).at(i),mn,c,psd);
	}
	return mn;
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<vector<int>>c(10,vector<int>(10)); for(auto&i:c)for(auto&j:i)cin>>j;
	vector<int>mn(10); for(int i=0;i<10;++i)mn.at(i)=c.at(i).at(1);
	for(int i=0;i<10;++i){
		vector<bool>psd(10,false); psd.at(i)=true;
		mn.at(i)=least(i,0,mn.at(i),c,psd);
	}
	//for(auto&i:mn)cout<<" "s<<i;cout<<"\n"s;
	int64_t ans=0;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			int a; cin>>a;
			if(a>=0)ans+=mn.at(a);
		}
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=620;
const int mod=1e9+7;

int n,a[maxn],vis[maxn],Sum;

inline void init()
{
	n=read();
	REP(i,1,2*n)
	{
		a[i]=read();
	}
	REP(i,1,n)
	{
		int x=a[i*2-1],y=a[i*2];
		if(~x && ~y)vis[x]=vis[y]=2;
		else if(~x || ~y)vis[x&y]=1;
		else Sum++;
	}
}

int dp[2][320][320];

inline void pls(int &a,int b){ a+=b; if(a>=mod)a-=mod;}

inline void doing()
{
	dp[0][0][0]=1;
	int u=0,sk=0,sj=0;
	DREP(i,n*2,1)if(vis[i]!=2)
	{
		u^=1; memset(dp[u],0,sizeof(dp[u]));
		if(i==1)
			i=1;
		if(vis[i])
		{
			REP(j,0,n)REP(k,0,n)if(dp[!u][j][k])
			{
				if(k)pls(dp[u][j][k-1],dp[!u][j][k]);
				pls(dp[u][j+1][k],dp[!u][j][k]);
			}
			sj++;
		}else
		{
			REP(j,0,n)REP(k,0,n)if(dp[!u][j][k])
			{
				if(j)pls(dp[u][j-1][k],(ll)dp[!u][j][k]*j%mod);
				pls(dp[u][j][k+1],dp[!u][j][k]);
				if(k)pls(dp[u][j][k-1],(ll)dp[!u][j][k]*(Sum-((sk-k)-(sj-j)>>1))%mod );
			}
			sk++;
		}
	}
	printf("%d\n",dp[u][0][0]);
}

int main()
{
	init();
	doing();
	return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;


const int maxN=1e5+10;
int f[maxN],n,q;

void solve(){
    cin>>n;
    ll s=0;
    for(int i=0;i<n;i++) {
        ll t;
        cin>>t;
        f[t]++;
        s+=t;
    }
    cin>>q;
    while(q--) {
        int a,b;
        cin>>a>>b;
        s=s+f[a]*(b-a);
        cout<<s<<"\n";
        f[b]+=f[a] , f[a]=0;
    }
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 4016
#define _CRT_SECURE_NO_WARNINGS
#define MaxSize 7629395
#include <stdio.h>
#include <stdlib.h>


void insert(unsigned int *D, unsigned int a) {
	unsigned int bitP = a % 32u;
	unsigned int mask = 1u << bitP;

	D[a / 32u] |= mask;
}

int find(unsigned int *D, unsigned int a) {
	unsigned int bitP = a % 32u;
	unsigned int mask = 1u << bitP;

	return (int)((D[a / 32u] & mask) >> bitP);

}

unsigned int conv(char s[]) {
	int i = -1;
	unsigned int a = 0u;
	while (s[++i]) {
		a *= 5u;
		if (s[i] == 'A') {
			a++;
		}
		else if (s[i] == 'C') {
			a += 2u;
		}
		else if (s[i] == 'G') {
			a += 3u;
		}
		else {
			a += 4u;
		}
	}
	return a;
}

int main() {
	unsigned int *D = (unsigned int *)malloc(sizeof(unsigned int) * MaxSize);
	int i;
	for (i = 0; i < MaxSize; ++i) {
		D[i] = 0u;
	}

	char com[7];
	char s[13];
	int n;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) {
		scanf("%s%s", com, s);
		if (com[0] == 'i') {
			insert(D, conv(s));
		}
		else {
			if (find(D, conv(s))) {
				printf("yes\n");
			}
			else {
				printf("no\n");
			}
		}
	}


	free(D);

	return 0;
}

Measured memory_bytes: 30368
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
	//変数の宣言
	char s[100010];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	long int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%s",&s);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	len=strlen(s);
	
	if(s[0]==s[len-1]){
		if(len%2==0) printf("First");
		if(len%2==1) printf("Second");
	}else{
		if(len%2==1) printf("First");
		if(len%2==0) printf("Second");
	}
//	printf("計算部分終了\n");
	//出力
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

typedef vector<int> vec;
typedef vector<vec> mat;

int R, C;

void solve() {
    mat v(R, vec(C));
    for (auto& i : v) for (auto& j : i) cin >> j;

    int ans = 0;
    for (int i = 0; i < (1 << R); i++) {
        int tmp = 0;
        vector<int> tb(R);
        for (int j = 0; j < R; j++)
            if (i & (1 << j)) tb[j] = 1;
        for (int j = 0; j < C; j++) {
            int count = 0;
            for (int k = 0; k < R; k++)
                count += tb[k]^v[k][j] ? 1 : 0;

            tmp += max(count, R - count);
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

int main() {
    while (cin >> R >> C, R || C) solve();

    return 0;
}

Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static List<int> primes = new List<int>();

    public static void Main()
    {
        primes.Add(2);
        for (int i = 3; i < 246913; i += 2)
        {
            foreach (int p in primes)
            {
                if (i % p == 0) goto noPrime;
            }
            primes.Add(i);
        noPrime: ;
        }
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            Console.WriteLine(primes.Count((i) => n < i && i <= n * 2));
        }
    }
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

const ll mod = 1e9+7;
//const ll mod = 998244353;

const int MAX_N = 200010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int n) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[n] = pow_mod(fact[n],-1);
    for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
    for (int i = 1;i <= n;++i) inv[i] = fact_inv[i]*fact[i-1]%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    create_table(200010);
    ll n,a,b,c;
    cin >> n >> a >> b >> c;
    (a *= pow_mod(100,-1)) %= mod;
    (b *= pow_mod(100,-1)) %= mod;
    ll ans = 0;
    ll d = pow_mod(a+b,-1);
    for (int i = 0;i < n;++i) {
        (ans += pow_mod(a,i)*pow_mod(b,n)%mod*pow_mod(d,n+i)%mod*combi(n-1+i,i)%mod*d%mod*(n+i)%mod) %= mod;
    }
    for (int i = 0;i < n;++i) {
        (ans += pow_mod(b,i)*pow_mod(a,n)%mod*pow_mod(d,n+i)%mod*combi(n-1+i,i)%mod*d%mod*(n+i)%mod) %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
string s;
bool s1;
int main(){
	getline(cin,s);
	for(int i=0;i<s.size();i++){
		if(s[i]=='C') s1=true;
		if(s1&&s[i]=='F'){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int gcdf(unsigned long long int a,unsigned long long int b);
int gcd(unsigned long long int a,unsigned long long int b);

int main(){
 	unsigned long long int a,b;
	unsigned long long int G,L;
	 
	while(cin>>a>>b){
		G=gcd(a,b);
		L=(a*b)/G;
		cout<<G<<" "<<L<<endl;
		
}
}
	
int gcdf(unsigned long long int a,unsigned long long int b)
{
	return (b == 0?a:gcdf(b,a%b));
}

int gcd(unsigned long long int a,unsigned long long int b)
{
	return (a>b?gcdf(a,b):gcdf(b,a));
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppiii;

ll l[1000000];
int n;

ll solve(bool neg) {
  ll curr = 0;
  ll ret = 0;
  for(int i = 0; i < n; i++) {
    curr += l[i];
    if(neg && curr >= 0) {
      ret += curr + 1;
      curr = -1;
    }
    else if(!neg && curr <= 0) {
      ret += 1 - curr;
      curr = 1;
    }
    neg ^= true;
  }
  return ret;
}

void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) cin >> l[i];
  cout << min(solve(false), solve(true)) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;
    String[]       in_str_split;

    int in_A;
    int in_B;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      /*----------------
       * 引数
       *----------------*/
      in_str = new String(in_stream.readLine());
      if("1".equals(in_str))
      {
        System.out.println("Hello World");
      }
      else
      {
        in_str = new String(in_stream.readLine());
        in_A   = Integer.parseInt(in_str);
        in_str = new String(in_stream.readLine());
        in_B   = Integer.parseInt(in_str);

        System.out.println(String.valueOf(in_A + in_B));
      }
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}


Measured memory_bytes: 22356
s = input()
cnt = int(input())

for _ in range(cnt):
    cmd = input().split()
    a=int(cmd[1])
    b=int(cmd[2]) +1

    if cmd[0] == "print":
        print(s[a:b])

    if cmd[0] == "reverse" :
        s= s[:a] +s[a:b][::-1]+s[b:]

    if cmd[0] == "replace":
        c = cmd[3]
        s = s[:a] + c +s[b:]


Measured memory_bytes: 5612
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a = sum(A)
b = sum(B)

if a < b:
	print(-1)

else:
	X = []
	for i in range(N):
		X.append(A[i] - B[i])
	X = sorted(X)
	
	x = 0
	c = 0
	for i in range(N):
		if X[i] < 0:
			x += X[i]
			c += 1
		else:
			break

	for i in range(N):
		if x >= 0:
			break
		else:
			c += 1
			x += X[-1 - i]

	print(c)

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

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

    int A, B;
    cin >> A >> B;
    int ans = ceil((B - A) / float(A - 1)) + 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
}

class MyLib {
    public static int gcd(int a, int b) {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static long gcd(long a, long b) {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static long countMultiples(long min, long max, long base) {
        return max / base - (min - 1) / base;
    }
}

Measured memory_bytes: 22740
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Handstand
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

char s[MAX_N + 4];
pii rs[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d%s", &n, &k, s);

  int m = 0;
  rs[m++] = pii(0, 0);

  for (int i = 0; i < n;) {
    while (i < n && s[i] == '0') i++;
    if (i >= n) break;

    int j = i + 1;
    while (j < n && s[j] == '1') j++;
    rs[m++] = pii(i, j);

    i = j;
  }

  rs[m++] = pii(n, n);
  if (k >= m) {
    printf("%d\n", n);
    return 0;
  }

  int maxl = 0;
  for (int i = 0, j = k; j < m; i++, j++) {
    int l = rs[j].second - rs[i].first;
    if (maxl < l) maxl = l;
  }

  printf("%d\n", maxl);
  return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long 
#define m 1000000007
using namespace std;
int main()
{
    int r,c;
    cin>>r>>c;

    char arr[r][c];
    for(int i=0;i<r;i++)
        for(int j=0;j<c;j++)
            cin>>arr[i][j];
 
    ll dp[r][c];
    bool f = true;
    for(int i=1;i<c;i++)
    {
        if(arr[0][i]=='#')
            f = false;
        if(f)
            dp[0][i]=1;
        else
            dp[0][i]=0;
    }

    f = true;
    for(int i=1;i<r;i++)
    {
        if(arr[i][0]=='#')
            f = false;
        if(f)
            dp[i][0]=1;
        else
            dp[i][0]=0;
    }


    for(int i=1;i<r;i++)
        for(int j=1;j<c;j++)
        {
            dp[i][j] = 0;
            if(arr[i][j]=='.')
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%m;
        }
    cout<<dp[r-1][c-1]<<endl;
    return 0;
}

Measured memory_bytes: 12416
#include <algorithm>
#include <cstdio>
#include <cstdlib>
const int INFN = 1e9+7;
const int MAXN = 1e5+5;
int dp[MAXN];
int H[MAXN];
int K, N;

int main() {
  scanf(" %d%d", &N, &K);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &H[i]);
    dp[i] = INFN;
  }
  dp[1] = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; (j <= K) && (i+j <= N); ++j) {
      dp[i+j] = std::min(dp[i] + std::abs(H[i] - H[i+j]), dp[i+j]);
    }
  }
  printf("%d\n", dp[N]);
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    queue<int> que[n];
    for(int i = 0; i < q; i++)
    {
        int v, t, x;
        cin >> v;
        if(v == 0)
        {
            cin >> t >> x;
            que[t].push(x);
        }
        else if(v == 1)
        {
            cin >> t;
            if(que[t].size() != 0) cout << que[t].front() << "\n";
        }
        else if(v == 2)
        {
            cin >> t;
            if(que[t].size() != 0) que[t].pop();
        }
    }
    return 0;
}




Measured memory_bytes: 4392
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Mat = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5+10;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int ans = min(b,d) - max(a,c);
    if(ans<0) ans = 0;
    cout(ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000009;

int main(){
	int s,w;
	cin >> s >> w;
	if(s <= w)cout << "unsafe" << endl;
	else cout << "safe" << endl;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"

using namespace std;

size_t calc_digits(size_t num) {
    return log10(num) + 1;
}

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

    double sq = sqrt(n);

    size_t ret = n;

    for (auto i = 1; i <= sq; ++i) {
        if (n % i == 0) {
            size_t f = calc_digits(n / i);
            ret = min(ret, f);
        }
    }

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::string s; std::cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) std::cout << "Yes" << std::endl;
    else std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = fastpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int comb(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};

signed main(){

    int H, W, A, B; cin >> H >> W >> A >> B;
    int mod = 1000000007;

    Combination C(H + W, mod);
    
    int ans = C.comb(H + W - 2, W - 1);

    REP(i, B){
        int tmp = C.comb(i + H - A - 1, i) * C.comb(W + A - i - 2, W - i - 1);
        tmp %= mod;
        ans = (ans + (mod - tmp)) % mod;
    }

    cout << ans;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 3328
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    h, w = map(int, input().split())
    su = 0
    for i in range(h):
        line = input()
        su += line.count("#")
    print("Possible" if su == h + w - 1 else "Impossible")

main()


Measured memory_bytes: 3444
k, n = map(int, input().split())
a = [int(_) for _ in input().split()]

dis = a[0] + (k - a[n-1])
for i in range(n):
    if i == 0:
        dis = max(dis, a[1]-a[0])
    else:
        dis = max(dis, a[i]-a[i-1])
print(k-dis)

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

int n, k;
int r, s, p;
char A[100005];

int scorBataus(char x) {
    if (x == 's')
        return r;
    if (x == 'p')
        return s;
    if (x == 'r')
        return p;
}

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

    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> A + 1;

    int total = 0;
    for (int m = 0; m < k; m++) {
        bool ign = 1;
        for (int i = m; i <= n; i += k) {
            if (i == 0)
                continue;
            
            if (ign) {
                ign = 0;
                total += scorBataus(A[i]);
            }
            else {
                if (i == m || A[i] != A[i - k]) { // pot lua; e diferit de ce am avut inainte
                    total += scorBataus(A[i]);
                }
                else {// nu pot lua
                    ign = 1;
                }
            }
        }
    }

    cout << total;

    return 0;
}

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

#define LL long long
#define pa pair<int,int>
using namespace std;
const int inf = 2147483647;
const int mod = 998244353;
const int N = 500001;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int jc[N], inv[N];

int add(int x, int y) {
	x += y;
	return x >= mod ? x - mod : x;
}

int dec(int x, int y) {
	x -= y;
	return x < 0 ? x + mod : x;
}

int pow_mod(int a, int k) {
	int ans = 1;
	while(k) {
		if(k & 1) ans = (LL)ans * a % mod;
		a = (LL)a * a % mod, k /= 2;
	} return ans;
}

int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}

int A(int n, int m) {return (LL)jc[n] * inv[n - m] % mod;}

int main() {
	int n = read(), m = read();
	if(n < m) swap(n, m);
	jc[0] = 1; for(int i = 1; i <= n; i++) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[n] = pow_mod(jc[n], mod - 2); for(int i = n; i >= 1; i--) inv[i - 1] = (LL)inv[i] * i % mod;
	int ans = (LL)pow_mod(n + 1, m) * pow_mod(m + 1, n) % mod;
	for(int i = 1; i <= m; i++) {
		if(i & 1) ans = dec(ans, (LL)C(n, i) * A(m, i) % mod * pow_mod(n + 1, m - i) % mod * pow_mod(m + 1, n - i) % mod);
		else ans = add(ans, (LL)C(n, i) * A(m, i) % mod * pow_mod(n + 1, m - i) % mod * pow_mod(m + 1, n - i) % mod);
	} put(ans);
	return 0;
}



Measured memory_bytes: 4096
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
#define INF         1000000005

typedef long long ll;
typedef unsigned long long ull;
// }}}

int main() {
    string s;cin >> s;
    cout << ((s.size()%2 == 0) ^ (s[0] == s[s.size()-1]) ? "Second" : "First") << endl;
    return 0;
}


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

int main(){

 LL K; cin>>K;
 int ans=-1;
 LL p=0;
 rep(k,K*2){
  p=p*10+7; p%=K;
  if(p==0){ ans=k+1; break; }
 }
 cout<<ans<<endl;
 
 return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define nl '\n'
#define precision(n) setprecision(n)
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int main() { _
    int a, b, k; cin >> a >> b >> k;
    set<int> s;
    forn(i, 0, k) {
        if (a + i > b) break;
        s.insert(a + i);
    }
    forn(i, 0, k) {
        if (b - i < a) break;
        s.insert(b - i);
    }
    for (int x : s) {
        cout << x << nl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int r,g;
cin>>r>>g;
cout<<g*2-r<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
max_int = 10 ** 6
MOD = 10 ** 9 + 7

factorial = [1] * (max_int + 1)
for i in range(2, max_int + 1):
    factorial[i] = (factorial[i - 1] * i) % MOD

def nCr(n, r):
    return (factorial[n] * pow(factorial[n - r], MOD - 2, MOD) * pow(factorial[r], MOD - 2, MOD)) % MOD

N = int(input())
MOD = 10 ** 9 + 7

dp = [[0] * 4 for i in range(N)]
dp[0][0] = 8
dp[0][1] = 1
dp[0][2] = 1
for i in range(1, N):
    dp[i][0] = (dp[i - 1][0] * 8) % MOD
    dp[i][1] = (dp[i - 1][0] + dp[i - 1][1] * 9) % MOD
    dp[i][2] = (dp[i - 1][0] + dp[i - 1][2] * 9) % MOD
    dp[i][3] = (dp[i - 1][1] + dp[i - 1][2] + dp[i - 1][3] * 10) % MOD
print(dp[-1][3])

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

int main() {
  int H, W;
  cin >> H >> W;
  int wall = 0;
  vector<vector<char>> maze(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> maze.at(i).at(j);
      if(maze.at(i).at(j) == '#'){
        wall++;
      }
    }
  }
  int x = 10000;
  vector<vector<int>> dist(H,vector<int>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      dist.at(i).at(j) = x;
    }
  }
  
  queue<pair<int,int>> que;
  vector<int> dx = {1,0,-1,0};
  vector<int> dy = {0,1,0,-1};
  
  pair<int,int> P(0,0);
  que.push(P);
  dist.at(0).at(0) = 0;
  pair<int,int> q;
  
  while(que.size()){
    q = que.front();
    que.pop();
    if(q.first == H-1 && q.second == W-1){
      break;
    }
    for(int i=0; i<4; i++){
      int nx = q.first + dx.at(i);
      int ny = q.second + dy.at(i);
      if(nx >= 0 && nx <= H-1 && ny >= 0 && ny <= W-1){
        if(maze.at(nx).at(ny) != '#' && dist.at(nx).at(ny) == x){
          P = make_pair(nx,ny);
          que.push(P);
          dist.at(nx).at(ny) = dist.at(q.first).at(q.second) + 1;
        }
      }
    }
  }
  
  if(dist.at(H-1).at(W-1) == x){
    cout << -1 << endl;
  }
  else{
    cout << H*W - wall -(dist.at(H-1).at(W-1)+1) << endl;
  }
    
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int ans=0;
    for (int i=1;i<n-1;i++){
        if (a.at(i)>a.at(i+1) && a.at(i)<a.at(i-1)) ans++;
        if (a.at(i)<a.at(i+1) && a.at(i)>a.at(i-1)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] p = new int[n];
		for(int i=0;i<n;i++) p[i] = in.nextInt();
		int ans = 0;
		for(int i=1;i<n-1;i++) {
			int tmp = p[i];
			int[] array = new int[3];
			array[0] = p[i-1];
			array[1] = p[i];
			array[2] = p[i+1];
			Arrays.sort(array);
			if(tmp==array[1]) ans++;
		}
		System.out.println(ans);
		in.close();
	}

}


Measured memory_bytes: 22868
n,m = map(int,input().split())
d = {}
for i in range(m):
  p,s = input().split()
  if p not in d:
    d[p] = [s]
  else:
    d[p].append(s)

wa_c = 0
ac_c = 0
for k in d.keys():
  target = d[k]
  if target.count("AC") != 0:
    ind = d[k].index("AC")
    ac_c += 1
    wa_c += target[:ind].count("WA")
print(ac_c,wa_c)
  
  

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

int main() {
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0) return 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) cout << "#";
      cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3084