akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
           int n = sc.nextInt();
           int s = sc.nextInt();
           if(n+s == 0) break;
           System.out.println(sol(n, s, 0));
        }
    }
    public static int sol(int n, int s, int c) {
    	if(n==1 && s>=c && s<10) return 1;
        if(n==1) return 0;
        int sum = 0;
        for(int i=c; i<10 && i<s; i++){
            sum += sol(n-1,s-i,i+1);
        }
        return sum;
    }
}


Measured memory_bytes: 26236
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
const ll MOD = 1000003;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX

ll fact[MOD];
ll invfact[MOD];

ll mpow(ll a, ll b){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

void solve(){
	fact[0]=invfact[0]=1;
	forsn(i,1,MOD){
		fact[i]=(fact[i-1]*i)%MOD;
		invfact[i] =mpow(fact[i],MOD-2);
	}
	ll q;
	cin >> q;
	forn(i,q){
		ll x,d,n;
		cin >> x >> d >> n;
		if(d==0){
			cout << mpow(x,n) << ln;
		}
		else if(n>=MOD){
			cout << 0 << ln;
		}
		else{
			ll nx = (x*mpow(d,MOD-2));
			nx %= MOD;
			ll factor = mpow(d,n);
			// ll ans = 0;
			ll ans = (nx+n-1>=MOD) ? 0 : factor*((fact[(nx+n-1)%MOD])*(nx==0 ? 0 : invfact[nx-1])%MOD)%MOD;
			// if(nx == 0) ans = 0;
			cout << ans << ln; 
		}
	}
}


int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin >> t;
    forn(i,t) solve();
    return 0;
}

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

using namespace std;

int nr[5];

int main()
{
	for(int i = 1; i <= 3; i++)
	{
		int x, y;
		cin >> x >> y;
		
		nr[x]++;
		nr[y]++;
	}
	
	int n1 = 0;
	int n2 = 0;
	
	for(int i = 1; i <= 4; i++)
		if(nr[i] == 1)
			n1++;
		else
			if(nr[i] == 2)
				n2++;
	
	if(n1 == 2 && n2 == 2)
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 256
#include"iostream"
#include"stdio.h"
#include"string"

using namespace std;

int a[100];

int main()
{
    int a, b;
    int ans = 0;
    scanf("%d%d" ,&a, &b);
    ans +=  a - 1;
    if(a <= b) ans ++;
    cout << ans<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	int N ; cin >> N;
	long a[10000]; for (int i = 1; i <= N; i++) cin >> a[i];
	int res = 0;
	long A = 0, B = 0;
	sort(a + 1, a + N + 1);

	for (int i = 1; i <= N; i = i + 2) A += a[i];
	for (int i = 2; i <= N; i = i + 2) B += a[i];
	
	res = abs(B - A);

	cout << res << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int m, f, r;
    while(1){
        scanf("%d %d %d ", &m, &f, &r);
        if(m==-1&&f==-1&&r==-1)break;
        if(m==-1||f==-1){
            printf("F\n");
        }else if(m+f>=80){
            printf("A\n");
        }else if(m+f>=65){
            printf("B\n");
        }else if(m+f>=50){
            printf("C\n");
        }else if(m+f>=30){
            if(r>=50){
                printf("C\n");
            }else{
                printf("D\n");
            }
        }else{
            printf("F\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

bool x[10];
int n, k;

bool cn(int n) {
	while (n) {
		if (x[n % 10])return false;
		n /= 10;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &k);
	f(i, 0, k) {
		int t;
		scanf("%d", &t);
		x[t] = true;
	}
	f(i, n, 1000000) {
		if (cn(i)) {
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; i < n; i++)
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, ans = 0;
    cin >> n;
    int P[n];
    REP(i,n) cin >> P[i];
    for (int i = 1; i < n-1; i++) {
        if (P[i] != min({P[i-1], P[i], P[i+1]}) && P[i] != max({P[i-1], P[i], P[i+1]})) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

long long int i,j,ans=1;
 
int ascSort(const void* v1, const void* v2) {
    const int _v1 = *((const int*)v1);
    const int _v2 = *((const int*)v2);
 
    if ( _v1 < _v2 ) {
        return 1;
    } else if ( _v1 > _v2 ) {
        return -1;
    } else {
        return 0;
    }
}
int INF = 1<<29;
const int mod = 1000000007;

int main(){
	long int a,b;
	char s[2];
	cin>>a>>s>>b;
	if(s[0]=='+'){
		cout << a+b<<endl;
	}else{
		cout << a-b<<endl;
	}
	return 0;
}

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

using namespace std;

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

	int ret = 0;
	for (int i = a; i <= b; ++i){
		if (c % i == 0)ret++;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

int main(void){
    int n, p[200020];
    bool ans[200020];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
        ans[i] = false;
    }
    
    vector<int> door;
    for (int i = 0; i < n; i++) {
        if (p[i] == 0) ;
        else if (!ans[p[i] - 1]) {
            door.push_back(p[i] - 1);
        }
        ans[p[i]] = true;
    }
    
    sort(door.begin(), door.end());
    door.push_back(n - 1);
    int mx = door[0] + 1;
    for (int i = 1; i < door.size(); i++) {
        mx = max(mx, door[i] - door[i - 1]);
    }
    
    cout << n - mx << endl;
    
    
    
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n-1){
    int x;
    cin>>x;
    x--;
    a[x]++;
  }
  rep(i,n){
    cout << a[i] << endl;
  }
}

Measured memory_bytes: 3988
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll K; ll N;
  cin >> K >> N;
  vi A(N);
  rep(i, N) cin >> A[i];
  sort(all(A));
  
  ll d1 = A[0] + (K - A[N-1]);
  int maxi = 0;
  for(int i=0; i<N-1; i++) {
    if(d1 < (ll)A[i+1] - A[i]) {
      maxi = i + 1;
      d1 = (ll)A[i+1] - A[i];
    }
  }
  
  //距離
  ll dist = 0;
  if(maxi != 0) dist += A[0] + (K - A[N-1]);
  for(int i=0; i<N-1; i++) {
    if(maxi != i+1) {
      dist += A[i+1] - A[i];
    }
  }
  
  fin(dist);
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
  int a, b, c, min;
  scanf("%d %d %d", &a, &b, &c);
  if(a < b){
    min = a;
  }
  else{
    min = b;
  }
  
  int i;
  int cnt = 0;
  for(i = min; i > 0; i--){
    if((a % i == 0) && (b % i == 0)){
      cnt++;
      if(cnt == c){
        printf("%d\n", i);
        break;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll f[100005];
ll ct[100005];
ll exp(int a, int x){
    if(x == 0) return 1ll;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x % 2 == 1){
        p *= a;
        p %= mod;
    }
    return p;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    ll ans = 0;
    for (int i = 1; i <= k; i++){
        f[i] = exp(i,n);
    }
    for (int i = 1; i <= k; i++){
        int numd = k/i;
        ll num = f[numd];
        ct[i] = num;
    }
    for (int i = k ;i >= 1; i--){
        for (int j = 1; j*j <= i; j++){
            if (i % j == 0 && i != j){
                //printf("%d -> %d\n",j,i);
                ct[j] -= ct[i];
                ans %= mod;
                if (j*j != i && j != 1){
                    ct[i/j] -= ct[i];
                }
            }
        }
    }
    for (int i = 1; i <= k; i++){
        //printf("%d %lld\n",i,ct[i]);
        ans += ct[i]*i;
        ans %= mod;
    }
    printf("%lld",ans);
}


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

const int DIM = 1e5 + 5;
const int EXP = 1e1 + 7;

int anc[2][EXP][DIM], arr[DIM];

int main( void ) {
    
    int n;
    cin >> n;
    
    for( int i = 1; i <= n; i ++ )
        cin >> arr[i];
    
    int l;
    cin >> l;
    
    for( int i = 1, j = 1; j <= n; j ++ ) {
        while( arr[j] - arr[i] > l )
            i ++;
        
        anc[0][0][j] = i;
    }
    
    for( int i = n, j = n; i >= 1; i -- ) {
        while( arr[j] - arr[i] > l )
            j --;
        
        anc[1][0][i] = j;
    }
    
    for( int t = 0; t <= 1; t ++ )
    for( int k = 1; k < EXP; k ++ )
    for( int i = 1; i <= n; i ++ )
        anc[t][k][i] = anc[t][k - 1][ anc[t][k - 1][i] ];
    
    int q;
    cin >> q;
    
    while( q -- ) {
        int x, y;
        cin >> x >> y;
        
        int ans = 1, t = (x < y);
        
        if( x < y ) {
            for( int i = EXP - 1; i >= 0; i -- ) {
                if( anc[t][i][x] < y ) {
                    ans += (1 << i);
                    x = anc[t][i][x];
                }
            }
        } else {
            for( int i = EXP - 1; i >= 0; i -- ) {
                if( anc[t][i][x] > y ) {
                    ans += (1 << i);
                    x = anc[t][i][x];
                }
            }
        }
        
        cout << ans << "\n";
    }
    
    return 0;
}

Measured memory_bytes: 14464
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#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 IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
LL A[maxn];
LL ans[maxn];
int main(void)
{
	int N;
	cin >> N;
	for (int i = 1; i <= N; ++i)
		cin >> A[i];
	LL s = 0;
	for (int i = 1; i <= N; ++i)
		if (i & 1)
			s += A[i];
		else
			s -= A[i];

	ans[1] = s;
	for (int i = 2; i <= N; ++i) {
		A[i - 1] -= ans[i - 1] / 2;
		ans[i] = A[i - 1] * 2;
	}

	for (int i = 1; i <= N; ++i) {
		cout << ans[i] << " ";
	}
	return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.0000000001
#define pi acosl(-1)
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound 
#define stp fixed<<setprecision(20)
#define endl '\n'
void solve()
{
    ll n,k;
    cin>>n>>k;
    ll q=(n-1)/k;
    q*=k;
    n-=q;
    ll ans=n;
    for(ll i=0;i<=10;i++)
    {
        n=abs(n-k);
        ans=min(ans,n);
    }
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1LL<<60;
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; }

int main(void) {
    ll n, mn = INF; cin >> n;
    bool t = true;
    for (ll a = 1; a <= (ll)sqrt(n); a++) {
        ll b = n / a;
        if (n % a == 0) t = false;
        if (a * b == n) chmin(mn, a + b - 2);
    }
    if (t) mn = n - 1;
    cout << mn << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,a,b,c;
    cin>>a>>b>>c;
    if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5)
    {
        cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3576
#include<cstdio>
#include<algorithm>
using namespace std;
int N,k,a[20];
bool book[20];
bool Check(int i) {
	char s[20]={};
	sprintf(s,"%d",i);
	for(int i=0;s[i]!='\0';i++)
		if(book[s[i]-'0'])
			return false;
	return true;
}
int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	scanf("%d %d",&N,&k);
	for(int i=1;i<=k;i++) {
		scanf("%d",&a[i]);
		book[a[i]]=true;
	}
	for(int i=N;;i++)
		if(Check(i)) {
			printf("%d\n",i);
			break;
		}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

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

    vector<bool> L(2*N, false);
    int lr = 0;
    int tmp = 0;
    bool valid = true;
    for(int i = 0; i < 2*N; i++){
        char c = S[i];
        if(c == 'W'){
            if(tmp%2){
                lr++;
                L[i] = true;
                tmp++;
            }
            else{
                tmp--;
                if(lr > 0){
                    lr--;
                    L[i] = false;
                }
                else{
                    valid = false;
                }
            }
        }
        else{
            if(tmp%2){
                tmp--;
                if(lr > 0){
                    lr--;
                    L[i] = false;
                }
                else{
                    valid = false;
                }
            }
            else{
                lr++;
                L[i] = true;
                tmp++;
            }
        }
    }

    if(lr != 0)
        valid = false;

    if(!valid){
        cout << 0 << endl;
        return 0;
    }

    int nl = 0;
    ll ans = 1;
    for(auto&& l : L){
        if(l){
            nl++;
        }
        else{
            ans *= nl;
            ans %= MOD;
            nl--;
        }
    }

    for(int i = 1; i <= N; i++){
        ans *= i;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int i,j;
  int h,w,u=0;
  cin>>h>>w;
  vector<vector<char>> c(h,vector<char>(w));
  vector<vector<int>> s(h,vector<int>(w));
  for(i=0;i<h;++i)
    for(j=0;j<w;++j){
      cin>>c.at(i).at(j);
      if(c.at(i).at(j)=='.')s.at(i).at(j)=0;
      else if(c.at(i).at(j)=='#')s.at(i).at(j)=-9;
    }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      if(s.at(i).at(j)<0){
        if(i!=0){
          if(j!=0)s.at(i-1).at(j-1)+=1;
          s.at(i-1).at(j)+=1;
          if(j!=w-1)s.at(i-1).at(j+1)+=1;
        }if(i!=h-1){
          if(j!=0)s.at(i+1).at(j-1)+=1;
          s.at(i+1).at(j)+=1;
          if(j!=w-1)s.at(i+1).at(j+1)+=1;
        }if(j!=0)s.at(i).at(j-1)+=1;
        if(j!=w-1)s.at(i).at(j+1)+=1;
      }
    }
  }
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      if(s.at(i).at(j)>=0)cout<<s.at(i).at(j);
      else if(s.at(i).at(j)<0)cout<<'#';
    }
    if(i<h-1)cout<<endl;
  }
}


Measured memory_bytes: 256
MOD=998244353
a,b,c,d=map(int,input().split())
dp=[[0 for j in range(d+1)] for i in range(c+1)]
dp[a][b]=1
for i in range(a+1,c+1):
    dp[i][b]=(b*dp[i-1][b])%MOD
for i in range(b+1,d+1):
    dp[a][i]=(a*dp[a][i-1])%MOD
for i in range(a+1,c+1):
    for j in range(b+1,d+1):
      dp[i][j]=(i*dp[i][j-1])%MOD
      dp[i][j]=(dp[i][j]+(j*dp[i-1][j])%MOD)%MOD
      dp[i][j]=(dp[i][j]-((i-1)*(j-1)*dp[i-1][j-1])%MOD)%MOD
print(dp[c][d])



Measured memory_bytes: 152892
#include <stdio.h>

int main(void){
	int data[10],i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		int data2[10]={0},data3[10]={0},count=0,a=1,b=1;
		for(j=0;j<10;j++){
			scanf("%d",&data[j]);
		}
		for(j=2;j<10;j++){
			if(data2[a-1]<data[j]){
				data2[a]=data[j];
				count++;
				a++;
			}
			else if(data3[b-1]<data[j]){
				data3[b]=data[j];
				count++;
				b++;
			}
			else	break;
		}
		if(count==8) puts("YES");
		else		 puts("NO");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cmath>

const long long INF = 1LL << 60;

int main() {
  int n;
  std::cin >> n;
  int h[n];
  long long dp[100000];
  for (int i = 0; i < 100000; i++)
    dp[i] = INF;
  
  for (int i = 0; i < n; i++)
    std::cin >> h[i];
  
  dp[0] = 0;
  for (int i = 1; i < n; i++)
  {
    if (i - 2 < 0) {
      dp[i] = abs(h[i - 1] - h[i]);
    } else {
      int d;
      if (dp[i - 2] + abs(h[i] - h[i - 2]) < dp[i - 1] + abs(h[i] - h[i - 1])) {
        d = dp[i - 2] + abs(h[i] - h[i - 2]);
      } else {
        d = dp[i - 1] + abs(h[i] - h[i - 1]);
      }
      dp[i] = dp[i] > d? d : dp[i];
    }
  }
  std::cout << dp[n - 1] << "\n";
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int n,ans,s;
string a;
int main()
{
    cin>>n>>a;   
    ans=0;s=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]=='D') ans--;
          else ans++;
        s=max(ans,s);
    }
    cout<<s<<endl; 
    return 0;
}

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

using namespace std;
long double pi = 3.1415926536;

/*bool secgreat(pair<int, int> a, pair<int, int> b){
    return a.second>b.second;
}
 */

long long MAXN = 1e6+3;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n;
    cin>>n;
    long long a[n];
    long long i;
    long long sum = 0;
    for(i = 0; i<n; i++){
        cin>>a[i];
        if(i!=0){
            if(a[i]<a[i-1]){
                sum+=a[i-1]-a[i];
                a[i] = a[i-1];
            }
        }
    }
    cout<<sum;

}

Measured memory_bytes: 5188
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

def Topo_sort(x,y):
	co = cl.Counter(n for m in x.values() for n in m)
	S = cl.deque([i for i in range(y) if co[i] == 0])
	while S:
		n = S.popleft()
		yield n
		for i in x[n]:
			co[i] -= 1
			if co[i] <= 0:
				S.append(i)
# g = cl.dafaultdict(set)に有向グラフを作成し(g[~] != ~) リストが帰ってくる

v,e = m()

g = cl.defaultdict(set)

for i in range(e):
	s,t = m()
	g[s] |= {t}
a = Topo_sort(g,v)
#print(list(a))
for i in Topo_sort(g,v):
	print(i)



Measured memory_bytes: 12176
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int num[5000],n;
long long ans = 0;
int max(int a,int b)
{
	return a>b?a:b;
}
int min(int a,int b)
{
	return a<b?a:b;
}
int main()
{
	int i,j,k,maxn = 0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&num[i]);
		ans += num[i];
	}
	ans -= n;
	printf("%lld",ans);  
	return 0;
}

Measured memory_bytes: 3240
#include<cstdio>
#include<iostream>
using namespace std;
#define _USE_MATH_DEFINES
#include<math.h>

int main() {
	double r;
	cin >> r;

	printf("%lf %lf", M_PI * (double)r * (double)r, 2 * M_PI * (double)r);
	return 0;
}



Measured memory_bytes: 3200
use std::io;
use std::io::prelude::*;
use std::io::BufReader;

fn main() {
    let mut lines = BufReader::new(io::stdin()).lines().into_iter();
    let line = lines.next().unwrap().unwrap();
    let n: usize = line.parse().unwrap();
    let m = n + 1 >> 1; // nを2で割って切り上げ
    let mut v: Vec<usize> = lines
        .next()
        .unwrap()
        .unwrap()
        .split(' ')
        .map(|x| x.parse().unwrap())
        .collect();
    v.sort_unstable_by(|a, b| b.cmp(a));
    let mut ans = v.iter().take(m).sum::<usize>() * 2 - v[0];
    ans -= v[m - 1] * (n & 1);
    println!("{}", ans);
}

Measured memory_bytes: 5916
#include<iostream>
#include<string>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int N;
	cin >> N;
    if(64<=N) cout << 64 << "\n";
    else if(32<=N) cout << 32 << "\n";
    else if(16<=N) cout << 16 << "\n";
	else if(8<=N) cout << 8 << "\n";
    else if(4<=N) cout << 4 << "\n";
    else if(2<=N) cout << 2 << "\n";
    else cout << 1 << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader sc = new FastReader();
    static final double E = 0.000000001;
    static final long MOD = (long) (1e9 + 7);
    static final long MAX = (long) 1e9;

    public static void main(String[] args) throws IOException {
        long a = sc.nextLong();
        long b = sc.nextLong();
        long gcd = gcd(a, b);
        int res = 1;
        if(gcd%2 == 0)
        {
            res++;
            while(gcd%2 == 0)
            {
                gcd/=2;
            }
        }
        for (long i = 3; i*i <=gcd ; i+=2) {
            if(gcd % i == 0)
            {
                res++;
                while(gcd%i == 0)
                    gcd/=i;
            }
        }
        if(gcd > 2)
            res++;
        System.out.println(res);
    }

    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);

    }


}


Measured memory_bytes: 23124
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();
        long w = sc.nextLong();
        if(h == 1 || w == 1){
            System.out.println(1);
        }else if(h % 2 == 1 && w % 2 == 1){
            System.out.println(h*w/2 + 1);
        }else{
            System.out.println(h*w/2);
        }
        
    }
}


Measured memory_bytes: 22612
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, b, N);
    vi ans;
    for (ll i = N; i > 0; --i)
    {
        bool ok = false;
        for (ll j = i; j > 0; --j)
        {
            if (b[j - 1] == j)
            {
                ans.push_back(j);
                b.erase(b.begin() + (j - 1));
                ok = true;
                break;
            }
        }
        if (not ok)
        {
            OUT(-1);
            return 0;
        }
    }
    for (ll i = N - 1; i >= 0; --i)
    {
        OUT(ans[i]);
    }
}

Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

void mul_mod(ll &a, ll b){
	a *= b;
	a %= MOD;
}

int n;
ll b[225816],a[225816];

ll f(ll x){
	int p;
	ll ret;
	p = (int)(upper_bound(a,a+n,x)-a);
	if(p == n){
		ret = x*n - b[n];
	}else if(p){
		ret = (b[n]-b[p-1]-x*(n-p))+(x*(p)-b[p-1]);
	}else{
		ret = b[n] - x*n;
	}
	return ret;
}

int main(void){
	int i;
	ll r,l,p,q,ans=INFLL;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		a[i] -= i;
	}
	sort(a,a+n);
	b[0] = a[0];
	for(i=1; i<n; ++i){
		b[i] += a[i]+b[i-1];
	}
	b[n] = b[n-1];
	l = a[0];
	r = a[n-1];
	while(r-l>3ll){
		p = l+(r-l)/3;
		q = r-(r-l)/3;
		if(f(p) == f(q)){
			l = p;
		}else{
			r = q;
		}
	}
	p = l+1;
	q = r-1;
	ans = min(min(f(l),f(r)),min(f(p),f(q)));
	for(i=0; i<n; ++i){
		ans = min(ans,f(a[i]));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
/**
 * File    : A.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-1 15:52:06
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main()
{
  ll N;
  cin >> N;
  if (N % 2 == 0)
  {
    cout << N << endl;
  }
  else
  {
    cout << 2 * N << endl;
  }
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <time.h>
using namespace std;
long double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
typedef long long int LL;
const long double PI = acos((long double)-1);
const LL INF=0x3f3f3f3fll;
const int MOD =1000000007ll;
const int maxn=2005;
LL dp[maxn][2];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("in1.txt", "w", stdout);
    //::iterator iter;                  %I64d
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d",&a);
    //printf("%d\n",ans);
    LL n,a,b,c,d;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    for(int x=0;x<=n;x++)
    {
        LL l=x*c-(n-1-x)*d;
        LL r=x*d-(n-1-x)*c;
        if(l<=b-a&&b-a<=r)
        {
            puts("YES");
            return 0;
        }
    }
    puts("NO");
    return 0;
}


Measured memory_bytes: 256
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h,w,m = map(int,input().split())
yoko = [0] * h
tate = [0] * w
S = set()
for _ in range(m):
  i,j = map(int,input().split())
  i-=1
  j-=1
  yoko[i] += 1
  tate[j] += 1
  S.add((i,j))
MY = max(yoko)
MT = max(tate)
max_yokos = []
max_tates = []
for i in range(h):
  if yoko[i] == MY:
    max_yokos.append(i)
for j in range(w):
  if tate[j] == MT:
    max_tates.append(j)
lmy = len(max_yokos)
lmt = len(max_tates)
for i in max_yokos:
  for j in max_tates:
    if not (i,j) in S:
      print(MY + MT)
      exit()
print(MY + MT - 1)


# print(tate)
# print(yoko)

Measured memory_bytes: 162804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll>PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
ll MOD = 1e4+7;
int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int pass_lim = a + b;
    string s;
    cin >> s;
    int cnt_japan = 0;
    int cnt_foreign = 0;
    rep(i, s.length()) {
        if ( s[i] == 'c' ) {
            cout << "No" << endl;
        }
        if ( s[i] == 'a' ) {
            if ( cnt_japan + min(b, cnt_foreign) < pass_lim ) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
            ++cnt_japan;
        }
        if ( s[i] == 'b' ) {
            if ( cnt_japan + cnt_foreign < pass_lim && cnt_foreign < b ) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
            ++cnt_foreign;
        }
    }
    return 0;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

struct data{
    int id;
    int ok;
    int pena;
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int T,P,R;cin>>T>>P>>R;
        if(T+P+R==0) break;
        vector<data> S(T);
        vector<vector<int>> A(T,vector<int>(P));
        
        for(int i=0;i<T;i++) S[i].id=i+1;
        
        for(int i=0;i<R;i++){
            int a,b,c;cin>>a>>b>>c;
            a--;b--;
            string d;cin>>d;
            if(d[0]=='C'){
                S[a].ok++;
                S[a].pena+=c+A[a][b]*1200;
            }else{
                A[a][b]++;
            }
        }
        
        sort(all(S),[](data a,data b){
            if(a.ok==b.ok){
                if(a.pena==b.pena){
                    return a.id<b.id;
                }
                return a.pena<b.pena;
            }
            return a.ok>b.ok;
        });
        
        for(int i=0;i<T;i++){
            cout<<S[i].id<<" "<<S[i].ok<<" "<<S[i].pena<<endl;
        }
    }
}



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

 long long N, K, A[1 << 18];

 int main() {
 cin >> N >> K;
 for (int i = 1; i <= N; i++) cin >> A[i];
 for (int i = K + 1; i <= N; i++) {
 if (A[i - K] < A[i]) cout << "Yes" << endl;
 else cout << "No" << endl;
 }
 return 0;
 }


Measured memory_bytes: 5196
from collections import deque

N, K = list(map(int, input().split()))

V = list(map(int, input().split()))

ans = 0
for left in range(min(N + 1, K + 1)):
    for right in range(min(N + 1 - left, K + 1 - left)):
        dq = deque(V)
        l = []
        for i in range(left):
            l.append(dq.popleft())
        for i in range(right):
            l.append(dq.pop())
        l.sort(key=lambda x: -x)
        for _ in range(K - left - right):
            if not l:
                break
            if l[-1] < 0:
                l.pop()
        ans = max(ans, sum(l))
        # print(left,right,sum(l),l)
print(ans)


Measured memory_bytes: 3444
#include<stdio.h>

int main()
{
    int a, b, i, j;
    
    while(1){
        scanf("%d%d", &a, &b);
	if(a == 0 && b ==0) break;

        for(i =1; i <=a;i++){
            for(j =1; j <=b;j++) printf("#");
            printf("\n");
	    }
        printf("\n");  
    }
    return 0;
}


Measured memory_bytes: 1960
def f(q):
    for i in range(len(q)):
        if q[i]!=q[len(q)-1-i]: return 0
    return 1

s=input()
n=len(s)
if f(s)==1 and f(s[:(n-1)//2])==1 and f(s[(n+1)//2:])==1:
    print("Yes")
else: print("No")


Measured memory_bytes: 38384
A = 0
N, M, C = map(int, input().split())
listB = list(map(int, input().split()))
for i in range(N):
    listA = list(map(int, input().split()))
    x = [b * a for (b, a) in zip(listA, listB)]
    if sum(x) + C > 0:
        A += 1
print(A)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define N 200001
int main(){
	int n;
	cin>>n;
	int a[n];
	int sxor=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sxor^=a[i];
	}
	for(int i=0;i<n;i++){
		sxor^=a[i];
		cout<<sxor<<" ";
		sxor^=a[i];
	}
	return 0;
}



Measured memory_bytes: 4332
import sys

n, *uv = map(int, sys.stdin.buffer.read().split())
ans = 0
for i in range(1, n + 1):
    ans += i * (n - i + 1)
for u, v in zip(uv[0::2], uv[1::2]):
    if u > v:
        u, v = v, u
    connect = u * (n - v + 1)
    ans -= connect
print(ans)


Measured memory_bytes: 46920
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

fn solve(a: &Vec<i64>) -> Option<i64> {
  let mut p = 1i64;
  for &x in a {
    p = p.checked_mul(x)?;
    if p > 1_000_000_000_000_000_000 {
      return None;
    }
  }
  Some(p)
}

#[fastout]
fn main() {
  input! {
    n: usize,
    mut a: [i64; n],
  }
  a.sort();

  println!("{}", solve(&a).unwrap_or(-1));
}


Measured memory_bytes: 5068
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// 二項係数計算
long long 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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int dp[60][60] = {};
int t[60][60] = {};
int main() {
	int h, w;
	cin >> h >> w;
	int xhoukou[4] = { 0,0,-1,1 };
	int yhoukou[4] = { 1,-1,0,0 };
	int sum = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char a;
			cin >> a;
			if (a == '.') {
				dp[i][j] = 1;
				sum = sum + 1;
			}
			else {
				dp[i][j] = 0;
			}
		}
	}
	queue<pair<int, int>> s;
	s.push(make_pair(0, 0));
	t[0][0] = 1;
	while (s.size()) {
		pair<int, int> k;
		k = s.front();
		s.pop();
		for (int i = 0; i < 4; i++) {
			int x, y;
			y = yhoukou[i] + k.first;
			x = xhoukou[i] + k.second;
			if (y < 0 || y > h - 1 || x < 0 || x > w - 1) {
				continue;
			}
			if (t[y][x] != 0) {
				continue;
			}
			if (dp[y][x] == 0) {
				continue;
			}
			t[y][x] = t[k.first][k.second] + 1;
			s.push(make_pair(y, x));
		}
	}
	if (t[h - 1][w - 1] == 0) {
		cout << -1;
		return 0;
	}
	cout << sum - t[h - 1][w - 1]<<endl;
}

Measured memory_bytes: 256
import sys
n = int(input())
inf_ls = [[0]*3 for _ in range(n)]
for i in range(n):
    x,y,h = map(int,input().split())
    inf_ls[i] = x,y,h
for Cx in range(101):
    for Cy in range(101):
        this_is_C = True
        H_set = set()
        zero_ls = []
        for i in range(n):
            x,y,h = inf_ls[i]
            if h > 0:
                H = abs(x-Cx) + abs(y-Cy) + h
                H_set.add(H)
            else:
                zero_ls.append([x,y])
        if len(H_set) != 1:
            this_is_C = False
            continue
        H = list(H_set)[0]
        for x,y in zero_ls:
            if H - abs(x-Cx) - abs(y-Cy) > 0:
                this_is_C = False
        if this_is_C:
            print(Cx,Cy,H)
            exit()





Measured memory_bytes: 9244
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
INF = 10 ** 9
A = np.array([lr() for _ in range(N)])
np.fill_diagonal(A, INF)
answer = 0
for i in range(N-1):
    for j in range(i+1, N):
        detour = np.min(A[i]+A[j])
        if detour > A[i, j]:
            answer += A[i, j]
        elif detour < A[i, j]:
            print(-1)
            exit()

print(answer)
# 38

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

public class Main {
    String s;

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

    void run() {
        FastReader sc = new FastReader();
        String discard = sc.next();
        s = sc.next();
        discard = sc.next();
        solve();
    }

    void solve() {
        System.out.println("A" + s.charAt(0) + "C");
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main (){/* 
    ll A;
    double B;
    cin >> A >> B;
    B *= 100;
    ll b = B;
    ll ans = A*b/100;
    cout << ans << endl;
 */
    ll A;
    string B;
    cin >> A >> B;
    if(B.size() == 1) {
        cout << A*(B.at(0) - '0') << endl;
    } else if(B.size() == 4){
        ll temp = 100*(B.at(0) - '0') + 10*(B.at(2) - '0') + B.at(3) - '0';
        cout << (A*temp)/100 << endl;
    } else {
        ll temp = 100*(B.at(0) - '0') + 10*(B.at(2) - '0');
        cout << (A*temp)/100 << endl;
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int a, b, c, d, k;
  cin >> a >> b >> c >> d >> k;

  int e = (c * 60 + d) - (a * 60 + b) - k;
  if(e >= 0) cout << e << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	ll minv = 10000000, maxv = -1; 
	rep(i,N) {
		minv = min(minv, a[i]);
		maxv = max(maxv, a[i]);
	}
	if (maxv-minv > 1) {
		cout << "No" << endl;
		return 0;
	}
	if (maxv-minv == 0) {
		if (minv <= N/2 || minv == N-1) {
			cout << "Yes" << endl;
			return 0;
		} else {
			cout << "No" << endl;
			return 0;
		}
	}
	ll c = 0;
	rep(i,N) {
		if (a[i] == minv) c++;
	}
	if (c+1 <= maxv && maxv <= c+(N-c)/2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 1024
#Satoooh  https://www.planeta.tokyo/entry/6464/
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    def __str__(self):  # print 表示用
        return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


N, M = map(int, input().split())
bridge = [list(map(int, input().split())) for _ in range(M)]
ans = [0]*M
uf = UnionFind(N)

# うしろからつないでいく
ans[M-1] = N*(N-1)//2
for i in range(M-2, -1, -1):
    A, B = bridge[i+1]
    if uf.is_same(A-1, B-1):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - uf.group_size(A-1) * uf.group_size(B-1)
    uf.unite(A-1, B-1)

for a in ans:
    print(a)

Measured memory_bytes: 36428