akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;


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


int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n){
    cin >> h[i];
  }
  vector<int> dp(n + 1);
  dp[0] = 0;
  dp[1] = abs(h[0] - h[1]);

  for(int i = 2; i < n; ++i){
    dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i -2]));

  }

  cout << dp[n-1] << endl;

}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

fn main() {
  input! {
    n: usize, m: usize, q: usize,
    abcdv: [(Usize1, Usize1, usize, usize); q]
  };

  let mut res = 0;
  for v in (1..=m).combinations_with_replacement(n) {
    let mut v = v;
    v.sort();
    let mut sum = 0;
    for (a, b, c, d) in &abcdv {
      if v[*b] - v[*a] == *c {
        sum += d;
      }
    }
    if sum > res {
      res = sum;
    }
  }
  println!("{}", res);
}


Measured memory_bytes: 2196
#include <iostream>

using namespace std;

int n;
int a[124][124] = {{}};
static const int INFTY = 1000000;

void dijkstra(){
  int flag[124] = {};
  int d[124] = {};
  int p[124] = {};
  int minv;
  int u;

  for (int i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;

    for(int i = 0;i < n;i++){
      if(flag[i] == 0 && minv > d[i]){
        minv = d[i];
        u = i;
      }
    }
  //  cout << "u = " << u << endl;
  //  cout << "minv = " << minv << endl;
    if(u == -1) break;
    flag[u] = 1;

    for(int i = 0;i < n;i++){
      if(d[i] > d[u] + a[u][i] && a[u][i] != INFTY && flag[i] == 0){
        d[i] = d[u] + a[u][i];
        p[i] = u;
      }
    }
  }

  for(int i = 0;i < n;i++){
    if(d[i] != -1){
      cout << i <<  " " << d[i] << endl;
    }
    else cout << i << " " << -1 << endl;
  }
}



int main(){

  cin >> n;

  for (int i = 0 ;i < n;i++){
    for(int j = 0;j < n;j++){
      a[i][j] = INFTY;
    }
  }


  int u;
  int k;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for (int j = 0;j < k;j++){
      int v;
      cin >> v;
      cin >> a[u][v];
    }
  }
  dijkstra();
}

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

using namespace std;

int main()
{
    int f[105][15],p[105][15],n,ans=-(1e10),temp,num;
    scanf("%d",&n);
    for (int i=0;i<n;i++)
        for (int j=0;j<10;j++)
            scanf("%d",&f[i][j]);
    for (int i=0;i<n;i++)
        for (int j=0;j<11;j++)
            scanf("%d",&p[i][j]);
    for (int x=1;x<1024;x++)
        {
            temp=0;
            for (int i=0;i<n;i++)
                {
                    num=0;
                    for (int j=0;j<10;j++)
                        if (x>>j&f[i][j]) num++;
                    temp+=p[i][num];
                }
            ans=max(ans,temp);
        }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main(){
  int k = 0;
  int a,b;
  std::cin >> k;
  std::cin >> a;
  std::cin >> b;
  for(int i = 0;i < 1000;i++){
    int x = k*i;
    if(x > 1000){
      std::cout << "NG" << std::endl;
      break;
    }
    if(x >= a&&x <= b){
      std::cout <<"OK"<< std::endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <numeric>
#include <functional>
using namespace std;

using LL = long long;

//~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~


int main() {

	int N;
	cin >> N;

	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	LL ans = 0;

	for (int i = 0; i < N; i++) {
		LL pre = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		LL over = C.end() - upper_bound(C.begin(), C.end(), B[i]);
		ans += pre * over;
	}


	cout << ans;

	return 0;
}


Measured memory_bytes: 1408
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int H, W, R[2000][2000], maximum = 0;
  bool S[2000][2000];
  string s;

  cin >> H >> W;
  REP(i, H)
  {
    cin >> s;
    REP(j, W)
    {
      S[i][j] = s[j] == '.';
    }
  }

  int cnt;
  REP(i, H)
  {
    REP(j, W)
    {
      if (S[i][j])
      {
        cnt = 1;
        FOR(k, j + 1, W)
        {
          if (S[i][k])
            cnt++;
          else
            break;
        }
        REP(k, cnt)
        {
          R[i][j + k] = cnt;
        }
        j += cnt - 1;
      }
      else
      {
        R[i][j] = 0;
      }
    }
  }
  REP(i, W)
  {
    REP(j, H)
    {
      if (S[j][i])
      {
        cnt = 1;
        FOR(k, j + 1, H)
        {
          if (S[k][i])
            cnt++;
          else
            break;
        }
        REP(k, cnt)
        {
          R[j + k][i] += cnt - 1;
        }
        j += cnt - 1;
      }
    }
  }

  REP(i, H)
  {
    REP(j, W)
    {
      maximum = max(maximum, R[i][j]);
    }
  }

  cout << maximum << '\n';

  return 0;
}


Measured memory_bytes: 19840
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:14/03/2020
*/
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define tc(t) cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)
ll max(ll a,ll b){if(a>b)return a;else return b;} 
ll min(ll a,ll b){if(a<b)return a;else return b;}
const ll inf=0x3f3f3f3f;

vector<int>primeFactorization(int n)
{
    vector<int>prime_fact;
    for(int i=2;i<=sqrt(n);++i)
    {
        while(n%i==0)
        {
            prime_fact.push_back(i);
            n/=i;
        }
    }
    if(n!=1)
    prime_fact.push_back(n);
    return prime_fact;
}

vector<int>sieve(int n)
{
    bool primes[n+5];
    memset(primes,true,sizeof(primes));
    vector<int>res;//res vector all the prime no between 1 to n
    for(int i=2;i<=sqrt(n);++i)
    {
        if(primes[i]==true)
        {
            res.push_back(i);
            for(int j=i*2;j<=n;j+=i)
            primes[j]=false;
        }
    }
    return res;
}








ll const Mxn=3000;
bool test=0;
void solve()
{
    ll n,f=0,q,c,ans=0,i,m;
    cin>>n;
    // vector<ll>a(n);
    // fab(i,0,n)
    // cin>>a[i];
    ll a[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
    cout<<a[n-1];
}





























int main()
{
    fio;
    ll t=1,s;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))

ub = 10 ** 9 + 7
lb = 0
while ub - lb > 1:
    mid = (ub + lb) // 2

    res = 0
    for v in X:
        res += (v - 1) // mid

    if res <= K:
        ub = mid
    else:
        lb = mid

print(ub)


Measured memory_bytes: 94108
#include "bits/stdc++.h"
#define YES "YES"
#define NO "NO"
#define Yes "Yes"
#define No "No"
#define DEFAULT LL ans=solve();\
 	if(ans==NONE){\
 	}else{\
 		cout << ans << endl;\
 	}
#define YESNO three(solve(),OUT(YES),OUT(NO))
#define YesNo three(solve(),OUT(Yes),OUT(No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b-1);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,zero,b)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<pr, Vpr > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 998244353;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
const LL NONE=-2;
#define endl "\n"
ut N, M,K,  Q, D, H, W;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL A[SIZE],B[SIZE],C[SIZE];
LL DP[SIZE];
LL last[SIZE];

LL solve(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a!=c) return 1;
	else return 0;
	return NONE;
}
 signed main() {
 
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	string s;
	LL T;
	DEFAULT;
	
	
//	YesNo;
//	YESNO;
//	three(solve(),OUT("First"),OUT("Second"));
	//cin >> N;
	return 0;
 
}


Measured memory_bytes: 13568
//BISMILLAH
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
   int i,j,x,n,flag=0,temp,countt,check=0;
   cin>>x>>n;
   int under=x,up=x;

   int arr[102]={0};
   for(int i=0;i<n;i++)
   {
       cin>>temp;
       arr[temp]=1;
   }

   while(true)
   {
       if(arr[under]==0)
       {
           cout<<under<<endl;
           return 0;
       }
       else under--;

       if(arr[up]==0)
       {
           cout<<up<<endl;
           return 0;
       }
       else up++;
   }
   
   return 0;



}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    double r;cin>>r;
    CST(10)<<r*r*M_PI<<" "<<2*r*M_PI<<endl;
    return 0;
}


Measured memory_bytes: 3292
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
using namespace std;

const long long MOD = 1000000007;

long gcd(long a, long b) {
    if(a < b) return gcd(b, a);
    long r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main(){
    long a, b, c, d;
    cin >> a >> b >> c >> d;
//    b++;
    a--;

    long lcs = c*d / gcd(c, d);

    long bc = b/c;
    long bd = b/d;
    long bcd = b/lcs;

    long ac = a/c;
    long ad = a/d;
    long acd = a/lcs;

    long bb = b-bc-bd+bcd;
    long aa = a-ac-ad+acd;

//    if(b%c==0 || b%d==0){
//        bb++;
//    }
//    if(a%c==0 || a%d==0){
//        aa++;
//    }
    cerr << bb << endl;
    cerr << aa << endl;

    cout << bb-aa << endl;
    
    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3132
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {

	int S, W;

	cin >> S;
	cin >> W;

	if (W < S) {
		cout << "safe";
	}
	else {
		cout << "unsafe";
	}

	return 0;

}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector<int> va;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		va.push_back(a);
	}

	for (int i = 0; i < n; i++) {
		int v = va.at(i);
		for (int j = 0; j < i; j++) {
			int w = va.at(j);
			if (v < w) {
				va.erase(va.cbegin() + i);
				va.insert(va.cbegin() + j, v);
				break;
			}
		}

		for_each(va.begin(), va.end() - 1, [](int x) {
			cout << x << " ";
		});
		cout << va.at(n - 1) << "\n";
	}

	return 0;
}


Measured memory_bytes: 3212
import math
n=int(input())
l = [list(map(int, input().split())) for _ in range(n)]
a=0
for i in range(n-1):
    for j in range(i+1,n):
        a+=math.sqrt((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2)
print(a*2/n)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int sz[200005],q[200005],h[200005];
    int i;
    cin>>n;
    for(i=1;i<=n;i++)
    {scanf("%d",&sz[i]);
    }
    int maxn=sz[1];
    q[1]=-1;
    for(i=2;i<=n;i++)
    {
        q[i]=maxn;
        if(sz[i]>maxn)
            maxn=sz[i];
    }
    h[n]=-1;
    maxn=sz[n];
    for(i=n-1;i>=1;i--)
    {
        h[i]=maxn;
        if(sz[i]>maxn)
            maxn=sz[i];
    }
    for(i=1;i<=n;i++)
    {
        cout<<max(q[i],h[i])<<endl;
    }
    return 0;
}


Measured memory_bytes: 3968
using namespace std;
#include<string.h>
#include <sstream>
typedef long long int ll;
typedef long double ld;
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <map>
//#define N 4
#include <stack>
#include <unordered_set>
#include <math.h>
#include <cstring>
#include <bitset>
#include <set>
#include <sstream>
#include <queue>
#define PI 3.14159265358979323846264338327950
#define mp make_pair
#define inf 1e9
//#define M 1000000007
#define M 8888888888
//#define N 1000000009

int main() {

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

	ld a, b, h, m;
	cin >> a >> b >> h >> m;

	ld aa = 2 * PI * (((h / 12) + (m / 60) / 12) - (m / 60));

	ld ans = (a * a + b * b) - (2 * a * b * cosl(aa));
	printf("%20.20Lf\n", sqrtl(ans));
}



Measured memory_bytes: 4192
p = [True] * (123456*2)
p[0] = p[1] = False
for i in range(2, int(len(p)**0.5)+1):
	if p[i]:
		for j in range(i*2, len(p), i):
			p[j] = False

while True:
	n = int(input())
	if n == 0:
		break
	print(p[n+1:n*2+1].count(True))

Measured memory_bytes: 10848
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    cout << S[0] << S.size()-2 << S[S.size()-1] << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#define f first
#define s second
using namespace std;
int n, i, j, u, sol, sum, oka, okb, x;
char a[2005], b[2005];
int st2[2005], dr2[2005];
pair<int, int> st[2005], dr[2005];
int poz(int p){
    if(p <= 0){
        return p + n;
    }
    if(p > n){
        return p - n;
    }
    return p;
}
int main(){
    cin>> a + 1;
    cin>> b + 1;
    n = strlen(a + 1);
    for(i = 1; i <= n; i++){
        a[i] -= '0';
        b[i] -= '0';
        if(a[i] == 1){
            oka = 1;
        }
        if(b[i] == 1){
            okb = 1;
        }
    }
    if(okb == 0){
        if(oka == 0){
            cout<< 0;
        }
        else{
            cout<< -1;
        }
        return 0;
    }
    u = 1;
    for(i = 1; i <= n; i++){
        while(b[u] == 0){
            u++;
            if(u == n + 1){
                u = 1;
            }
        }
        dr[i] = make_pair( (u - i + n) % n, i);
        dr2[i] = dr[i].f;
        if(u == i){
            u++;
        }
    }
    u = n;
    for(i = n; i >= 1; i--){
        while(b[u] == 0 || u > i + n){
            u--;
            if(u == 0){
                u = n;
            }
        }
        st[i] = make_pair( (i - u + n) % n, i);
        st2[i] = st[i].f;
        if(u == i){
            u--;
        }
    }
    sort(st + 1, st + n + 1);
    sort(dr + 1, dr + n + 1);
    sol = 1000000;
    for(i = 0; i < n; i++){
        u = n;
        x = 0;
        for(j = 1; j <= n; j++){
            if(b[ poz(j - i) ] != a[j]){
                x++;
            }
        }
        for(j = 0; j < n; j++){
            while(u >= 1 && (dr2[ st[u].s ] <= j || a[ st[u].s ] == 0 || b[ poz(st[u].s - i) ] == 1) ){
                u--;
            }
            if(st[u].f <= i){
                sum = i + 2 * j + x;
            }
            else{
                sum = i + 2 * (st[u].f - i) + 2 * j + x;
            }
            sol = min(sol, sum);
        }
    }
    for(i = 0; i < n; i++){
        u = n;
        x = 0;
        for(j = 1; j <= n; j++){
            if(b[ poz(j + i) ] != a[j]){
                x++;
            }
        }
        for(j = 0; j < n; j++){
            while(u >= 1 && (st2[ dr[u].s ] <= j || a[ dr[u].s ] == 0 || b[ poz(dr[u].s + i) ] == 1) ){
                u--;
            }
            if(dr[u].f <= i){
                sum = i + 2 * j + x;
            }
            else{
                sum = i + 2 * (dr[u].f - i) + 2 * j + x;
            }
            sol = min(sol, sum);
        }
    }
    cout<< sol;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b)
        cout << 0;
    else if(n == 1){
        cout << (a == b);
    }
    else{
        ll L = b+(n-1)*a;
        ll R = a+(n-1)*b;
        ll res = (R-L+1);
        cout << res;
    }
    return 0;
}

Measured memory_bytes: 256
import math
s = str(input())
m = (len(s) - 1) / 2
c = True
for i in range(math.floor(m / 2)):
    if s[i] != s[int(m-1-i)]:
        c = False
for i in range(math.floor(m / 2)):
    if s[int(m+1+i)] != s[int(len(s)-1-i)]:
        c = False
for i in range(math.floor(m)):
    if s[i] != s[int(math.floor(len(s)-1-i))]:
        c = False
if c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
m=0
ans=0
for i in range(n):
    if i==0:
        m=max(a[i],m)
    else:
        if a[i]<m:
            ans+=m-a[i]
        else:
            m=a[i]
print(ans)

Measured memory_bytes: 32224
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

using ll = long long;

int main(){

	int n,k;

	cin >> n >> k;
	vector<int>x(n),y(n);
	vector<int>xary,yary;

	for(int i = 0;i < n;i++){
		cin >> x[i] >> y[i];

		xary.push_back(x[i]);
		yary.push_back(y[i]);
	}

	sort(begin(xary),end(xary));
	sort(begin(yary),end(yary));

	ll ans = 1LL*(xary[n-1] - xary[0])*(yary[n-1] - yary[0]);


	for(int xi = 0;xi < n;++xi){
		for(int xj = xi + 1;xj < n;++xj){
		   for(int yi = 0;yi < n;++yi){
			   for(int yj = yi + 1;yj < n;++yj){
				  int num = 0;
				  ll lx = xary[xi],rx = xary[xj];
				  ll by = yary[yi],uy = yary[yj];


				  for(int i = 0;i < n;i++){
					  if(lx <= x[i] && x[i] <=rx && by <= y[i] && y[i] <= uy){
						  num++;
					  }
				  }

				  if(num >= k){
					  ans = min(ans,1LL*(rx-lx)*(uy-by));
				  }

			   }
		   }
		}
	}

	cout << ans << endl;


    return 0;
}


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

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> ret;
    for(ll i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main() {
    const int mod = 1000000007;
    int n;
    cin >> n;
    map<ll, ll> ans;
    for (int i = 1; i <= n; ++i) {
        map<ll, ll> a = prime_factor(i);
        for (auto j : a) ans[j.first] += j.second;
    }
    ll ret = 1;
    for (auto i : ans) {
        ret *= (i.second + 1);
        ret %= mod;
    }
    cout << ret << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"s=int(input())\n"
"i=2\n"
"while~-s:s=[s//2,s*3+1][s%2];i+=1\n"
"print(max(i,4))\n"
"\"";
  system(s);
  return 0;
}            

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

typedef long long ll;
const int MOD = 1000000007;

int main(){
  int N,x;
  cin >> N >> x;
  vector<int> a(N);
  ll res = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  if(a[0] > x){
    res += a[0] - x;
    a[0] = x;
  }
  for(int i = 1; i < N; i++){
    ll tmp = a[i] + a[i-1];
    if(tmp > x){
      res += tmp - x;
      a[i] = x - a[i-1];
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 768
//API???????????????
import java.io.IOException;
import java.util.Scanner;
class Main {
  	public static void main(String[] args)throws IOException{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] A = new int[n];
		
		for(int i = 0; i < n; i++){
			A[i] = scan.nextInt();
		}
		
		int pivot = Partition(A, 0, n);
		
		for(int i = 0; i < n; i++){
			if(i == pivot){
				System.out.print("[" + A[i] + "]" + " ");
			}else if(i != n - 1){
				System.out.print(A[i] + " ");
			}else{
				System.out.println(A[i]);
			}
		}
	}
	
	public static int Partition(int[] A, int l, int r){
		int threshold = A[r - 1];
		int i = l - 1;
		for(int j = l; j < r - 1; j++){
			if(A[j] <= threshold){
				i++;
				exchange(A, i, j);
			}
		}
		i++;
		exchange(A, i, r - 1);
		
		return i;
	}
		
	public static void exchange(int[] A, int i, int j){
		int tmp = A[i];
		A[i] = A[j];
		A[j] = tmp;
	}
} 

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

int main() {
  int H,W;
  cin>>H>>W;
  vector<vector<char>> vec(H,vector<char>(W,0));
  for(int i=0;i<H;i++){
  	for(int j=0;j<W;j++){
    cin >> vec.at(i).at(j);
    }
  }
  for(int i=0;i<W+2;i++){
  cout<<"#";
  }
  cout<<endl;
  for(int i=0;i<H;i++){
  cout<<"#";
    for(int j=0;j<W;j++){
  	cout<<vec.at(i).at(j);
  	}
  cout<<"#"<<endl;
  }
  for(int i=0;i<W+2;i++){
  cout<<"#";
  }
  cout<<endl;
}

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

ll gcd(ll a, ll b) {
    if(a < b){
        return gcd(b, a);
    }
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

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

void solve(long long A, long long B){
    cout << lcm(A, B) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

int d()
{
    long long n, k;
    std::cin >> n >> k;
    
    std::vector<int> destList(n + 1);
    
    for(int i = 0; i < n; i++)
    {
        std::cin >> destList[i + 1];
    }
    
    if(destList[1] == 1)
    {
        std::cout << 1 << std::endl;
        return 0;
    }
    
    std::vector<bool> isPassed(n + 1, false);
    int cp = 1;
    int length = 0;
    int loopStart = 0;
    // ループするまで進む
    while(true)
    {
        length++;
        isPassed[cp] = true;
        cp = destList[cp];
        if(length == k)
        {
            std::cout << cp << std::endl;
            return 0;
        }
        if(isPassed[cp])
        {
            loopStart = cp;
            break;
        }
    }
    
    // ループの長さと前置部の長さに分ける
    cp = 1;
    int preLength = 0;
    while(true)
    {
        if(cp == loopStart)
        {
            break;
        }
        preLength++;
        cp = destList[cp];
    }
    int loopLength = length - preLength;
    
    k = k - preLength;
    long long rem = k % loopLength;
    
    cp = loopStart;
    for(int i = 0; i < rem; i++)
    {
        cp = destList[cp];
    }
    
    std::cout << cp << std::endl;
    
    return 0;
}

int main(int argc, const char * argv[])
{
    d();
    return 0;
}

Measured memory_bytes: 4032
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramD
    {
        static int[][] _graph;
        static int[] _costList;
        static bool[] _seen;

        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var h = long.Parse(inputs[0]);
            var w = long.Parse(inputs[1]);

            // グラフ作成
            _graph = new int[10][];
            for (var i = 0; i < 10; i++)
            {
                _graph[i] = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            }

            // dfsで変換コスト表作成
            _costList = Enumerable.Range(0, 10).Select(x => _graph[x][1]).ToArray();
            for (var i = 0; i < 10; i++)
            {
                if (i == 1) continue;
                _seen = new bool[10];
                dfs(i, 0, i, "", "");
                // Console.WriteLine(i + ": " + _costList[i]);
            }

            // 変換
            var result = 0;
            for (var i = 0; i < h; i++)
            {
                var wall = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
                for (var j = 0; j < w; j++)
                {
                    if (wall[j] == -1 || wall[j] == 1) continue;
                    result += _costList[wall[j]];
                }
            }
            Console.WriteLine(result);
        }

        static void dfs(int v, int dist, int target, string ind, string path)
        {
            // Console.WriteLine(ind + "v: " + v + ", dist: " + dist);
            _seen[v] = true;
            path += v.ToString();

            //更新
            if (v == 1)
            {
                _costList[target] = Math.Min(_costList[target], dist);
                // Console.WriteLine(ind + "_costList[" + target + "]: " + _costList[target] + ", dist: " + dist);
                return;
            }

            // 各変換パターンを探索
            for (var i = 0; i < 10; i++)
            {
                // 同数の変換 || 1以外の通過済みはスキップ
                if (i == v || (i != 1 && path.Contains(i.ToString()))) continue;
                var nextCost = _graph[v][i];

                // 設定済みコストを超えなければ(安くなる見込みがあれば)探索
                if (_costList[target] > dist + nextCost)
                {
                    dfs(i, dist + nextCost, target, ind + "  ", path);
                }
            }
        }
    }
}


Measured memory_bytes: 30668
#include "bits/stdc++.h"
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> list;
	list.push_back(2);
	int x = 2;
	int count = 0;
	while(1){
		for(int y : list){
			if(x%y==0){
				count = 1;
				break;
			}
		}
		if(count==0){
			list.push_back(x);
		}
		if(list.back() >= N){
			cout << list.back();
			return 0;
		}
		count = 0;
		x++;
	}
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    sort(A.begin(), A.end());

    vector<ll> Asum(N + 1);
    for (int i = 0; i < N; ++i)
        Asum[i + 1] = Asum[i] + A[i];

    int ans = P;
    P = N - P;
    for (int i = 0; i < P; ++i) {
        ll tmp = A[i] + M;
        auto itr = upper_bound(A.begin(), A.end(), tmp);
        if (itr - A.begin() <= P)
            continue;
        ll cost = (i + N - P - 1) * M;
        cost += (P + 1 - i) * tmp - (Asum[P + 1] - Asum[i]);
        if (cost >= M * V)
            ans++;
    }

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


Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	int x[11][11];
	REP(i, n) {
		REP(j, d) {
			cin >> x[i][j];
		}
	}
	int ans = 0;
	REP(i, n) {
		for (int j = i + 1; j < n; j++) {
			double num = 0;
			REP(k, d) {
				num += pow(x[j][k] - x[i][k], 2);
			}
			num = pow(num, 0.5);
			double num1 = ceil(num);
			if (num1==num) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val balls = (0 until n).map {
        readLine()!!.split(' ').map { it.toInt() }.let { it[0] to it[1] }
    }

    fun f(p: Int, q: Int): Int {
        var cnt = 0
        for (i in 0 until n) {
            for (j in 0 until n) {
                if (i == j) continue
                val x = balls[i].first - balls[j].first
                val y = balls[i].second - balls[j].second
                if (x == p && y == q) cnt++
            }
        }
        return cnt
    }

    var ans = 0

    for (i in 0 until n) {
        for (j in 0 until n) {
            if (i == j) continue
            val p = balls[i].first - balls[j].first
            val q = balls[i].second - balls[j].second
            ans = Math.max(f(p, q), ans)
        }
    }

    println(n - ans)
}


Measured memory_bytes: 40644
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {
    int x; cin >> x;
    if(x) cout << 0;
    else cout << 1;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  ll x;
  cin>>x;
  ll ans=0;
  ll c=x/11;
  if(x%11==0) ans=c*2;
  else if(x%11<=6){
    ans+=c*2+1;
  }
  else{
    ans+=c*2+2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import math


def pattern(x, y, z):
    if x == y == z:
        return 1
    elif x != y and y != z and x != z:
        return 6
    else:
        return 3


def check(ans):
    cnt = 0
    upper = int(math.sqrt(ans))
    for x in range(1, upper):
        if pow(x, 2) > ans:
            break
        for y in range(x, upper):
            if pow(x+y, 2) > ans:
                break
            for z in range(y, upper):
                tmp = x*(x+y+z) + y*(y+z) + z*z
                # tmp = pow(x+y+z, 2) - x*(y+z) - y*z
                if tmp == ans:
                    cnt += pattern(x, y, z)
                    if x == y and y == z and z == x:
                        print(cnt)
                        return
                elif tmp > ans:
                    break
    print(cnt)


N = int(input())
# x^2 + y^2 + z^2 + x*y + y*z + z*x = n

for i in range(1, N+1):
    # upper_value = int(math.sqrt(i))
    check(i)


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

vector<int> par(100005,-1);

void initialize(int n){
	for (int i=0;i<n;i++){
		par[i]=i;
	}
	return;
}

int root(int x){
	if (x==par[x]){
		return x;
	}else{
		return par[x]=root(par[x]);
	}
}

bool find(int x,int y){
	return root(x)==root(y);
}

void uni(int x,int y){
	x=root(x);
	y=root(y);
	if(x==y){
		return;
	}else{
		par[x]=y;
	}
}

int main(){
	int n,m,q,i,j;
	int s,t;
	
	cin >> n >> m;
	
	initialize(n);
	
	for(i=0;i<m;i++){
		cin >> s >> t;
		uni(s,t);
	}
	
	cin >> q;
	
	for (i=0;i<q;i++){
		cin >> s >> t;
		if (find(s,t)){
			cout << "yes" <<endl;
		}else{
			cout << "no" <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
using namespace std;
int n,c[100005],ans,x;
int main(void){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        if(c[a]==0)ans++;
        else x++;
        c[a]++;
    }
    if(x%2)ans--;
    printf("%d\n",ans);
}

Measured memory_bytes: 640
def main():
    n, *a = map(int, open(0).read().split())

    c = 1
    f = 0
    d = [-1,1]
    for i, j in zip(a, a[1:]):
      if i == j:
        continue
      else:
        g = d[i < j]
        if f * g == -1:
          f = 0
          c += 1
        else:
          f = g
    
    print(c)


if __name__ == '__main__':
    main()


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

#define mp(x,y) make_pair(x,y) 
#define M 1000000007
#define endl "\n"
#define pb(x) push_back(x)
#define llip(t) long long t ; cin >> t ;
#define llip2(a,b) long long a,b ; cin >> a >> b ;
#define dip(a) double a ; cin >> a ;
#define dip2(a,b) double a,b ; cin >> a >> b ; 
#define pll pair<long long,long long>  
typedef long long ll;
 
int main(){ 
    ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    llip(n) ;
    vector<ll> a(n) ;
    vector<ll> b(n) ;
    vector<ll> c(n) ;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i] >> b[i] >> c[i] ;
    }
    vector<ll> t(n) ;
    vector<vector<ll>> dp(3,t) ;
    dp[0][0] = a[0] ;
    dp[1][0] = b[0] ;
    dp[2][0] = c[0] ;
    for(int i = 1 ; i < n ; i++){
        dp[0][i] = max(dp[1][i-1],dp[2][i-1]) + a[i] ;
        dp[1][i] = max(dp[0][i-1],dp[2][i-1]) + b[i] ;
        dp[2][i] = max(dp[1][i-1],dp[0][i-1]) + c[i] ;
    } 
    ll ans = -1 ;
    for(int i = 0 ; i < 3 ; i++){
        ans = max(ans,dp[i][n-1]) ;
    }
    cout << ans << endl ;
}
 

Measured memory_bytes: 5760
import sys
[n,a,b] = [int(s) for s in sys.stdin.read().split()] #リスト作成

mod = 10**9+7
def comb(p,q,A): #pCq modA
  X = 1
  Y = 1
  for i in range(1, q+1):
    X = (X*(p-i+1))%A
    Y = (Y*i)%A
  return (X*pow(Y, A-2, A))%A #X*Y^(-1) modA
print((pow(2,n,mod)-comb(n,a,mod)-comb(n,b,mod)-1)%mod)

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

int main () {
  char a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int A, B, C, D;
  A = a - '0';
  B = b - '0';
  C = c - '0';
  D = d - '0';
  
  char op1, op2, op3;
  bool iserror = false;
  if (A + B + C + D == 7) {
    op1 = '+';
    op2 = '+';
    op3 = '+';
  }
  else if (A + B + C - D == 7) {
    op1 = '+';
    op2 = '+';
    op3 = '-';
  }
  else if (A + B - C + D == 7){
	op1 = '+';
    op2 = '-';
    op3 = '+';
  }
  else if (A + B - C - D == 7) {
    op1 = '+';
    op2 = '-';
    op3 = '-';
  }
  else if (A - B + C + D == 7)  {
    op1 = '-';
    op2 = '+';
    op3 = '+';
  }
  else if (A - B + C - D == 7) {
	op1 = '-';
    op2 = '+';
    op3 = '-';
  }
  else if (A - B - C + D == 7) {
    op1 = '-';
    op2 = '-';
    op3 = '+';
  }
  else if (A - B - C - D == 7) {
    op1 = '-';
    op2 = '-';
    op3 = '-';
  }
  else {
	cout << "error" << endl;
    iserror = true;
  }

  if (!iserror) {
    cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe



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

int n,num = 0;

cin >> n;

if (n % 4 == 0 || n % 7 == 0)
{
   cout << "Yes" << endl;
}else
{
   for(int i = 1;i < n;i++){
      for(int j = 1;j < n;j++){
         
         num = (4*i) + (7*j);
         if (num == n)
         {
            cout << "Yes" << endl;
            return 0;
         }
         
     
      }
      
   }
   cout << "No" << endl;

}





//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
N,K,Q=map(int,input().split())

S=[]
T=[0]*N
cutline=Q-K+1
count=0
for i in range(Q):
    R=int(input())
    T[R-1]+=1

for i in range(N):
    if T[i]>=cutline:
        print("Yes")
    else:
        print("No")






Measured memory_bytes: 4680
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.util.HashSet;
import java.util.Iterator;

class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int[] arr = new int[S.length() + 1];
        ArrayList<Integer> holes = new ArrayList<Integer>();
        if (S.charAt(0) == '<')
            holes.add(-1);
        for (int i = 1; i < S.length(); i++) {
            if (S.substring(i - 1, i + 1).equals("><"))
                holes.add(i - 1);
        }
        if (S.charAt(S.length() - 1) == '>')
            holes.add(S.length() - 1);
        for (int k = 0; k < holes.size(); k++) {
            int st = holes.get(k);
            for (int i = st; i >= 0; --i) {
                if (i >= 1 && S.charAt(i - 1) == '<') {
                    arr[i] = Math.max(arr[i - 1] + 1, arr[i + 1] + 1);
                    break;
                } else {
                    arr[i] = arr[i + 1] + 1;
                }
            }
            for (int i = st + 2; i < S.length(); i++) {
                arr[i] = arr[i - 1] + 1;
                if (S.charAt(i) == '>')
                    break;
            }
        }
        if (S.charAt(S.length() - 1) == '<')
            arr[S.length()] = arr[S.length() - 1] + 1;
        long ans = 0;

        for (int i = 0; i < arr.length; i++) {
            ans += arr[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 47732
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  int n,m;
  S2(n,m);
  if(n > m) swap(n,m);
  if(n == 1) {
    if(m == 1) P(1);
    else P(m - 2);
    return 0;
  }
  if(n == 2) {
    P(0);
    return 0;
  }
  LL ans = (n - 2) * 1LL * (m - 2);
  cout << ans << "\n";
  return 0;
}


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

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

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

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > A(N), S(N + 1);
	rep(i, N) cin >> A[i];
	S[0] = 0;
	rep(i, N) S[i + 1] = S[i] + A[i];
	int tmp = LINF;
	rep(i, N) chmin(tmp, abs(S[N] - S[i] * 2));
	//cout << S;
	cout << tmp << endl;
	return 0;
}

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

const int fx[] = { 0, 1, 0,-1};
const int fy[] = { 1, 0,-1, 0};

int n,m,k,sx,sy;
char s[1010];
bool b[1010][1010];
bool a[1010][1010];
bool flag;
queue<pair<int,int> > q;
queue<int> qs;
int main() 
{
	cin>>n>>m>>k;
    for (int i=1;i<=n;i++) 
	{
    	scanf("%s",s+1);
		for (int j=1;j<=m;j++) a[i][j] = s[j]!='#';
        for (int j=1;j<=m;j++) if (s[j]=='S') sx=i, sy=j;
    }

    if (sx == 1 || sx == n || sy == 1 || sy == m) return puts("0"), 0;

    b[sx][sy] = 1;
    q.push(make_pair(sx,sy));
	qs.push(0);
    while (!q.empty()) {
        int ux = q.front().first;
        int uy = q.front().second;
		q.pop();
        int us = qs.front(); qs.pop();
        if (us == k) continue;
        if (ux == 1 || ux == n || uy == 1 || uy == m) flag = 1;

        for (int i=0;i<4;i++) 
		{
            int vx = ux + fx[i], vy = uy + fy[i];
            if (vx<1 || vx>n || vy<1 || vy>m) continue;
            if (!b[vx][vy] && a[vx][vy]) 
			{
                b[vx][vy] = 1;
                q.push(make_pair(vx,vy));
				qs.push(us+1);
            }
        }
    }

    if (flag) return puts("1"), 0;

    int ans = 2147483647;   
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++) 
			if (b[i][j]) 
			{
            	int t = min( min(i-1,j-1) , min(n-i,m-j) );
            	int cur = (t+k-1) / k;
            	ans = min(ans, cur+1);
        	}
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
    const int MaxN=200010,mod=1000000007;
    int N;
    long long fac[MaxN],ifac[MaxN];
    long long inv(int a,int p=mod){return a==1?1:(1+p*(a-inv(p%a,a)))/a%p;}
    struct edge{int to;edge*next;}E[MaxN*2],*ne=E,*fir[MaxN];
    void link(int u,int v){*ne=(edge){v,fir[u]};fir[u]=ne++;}
    int Q[MaxN],deg[MaxN],S[MaxN],fa[MaxN],siz[MaxN],C[MaxN];
    bool vis[MaxN];
    int dfs(int i){
    	siz[i]=1;
    	int s=1;
    	for(edge*e=fir[i];e;e=e->next)
    		if(fa[e->to]==i&&e->to<fa[i])s=1ll*s*dfs(e->to)%mod,siz[i]+=siz[e->to];
    	return 1ll*s*ifac[siz[i]]%mod*fac[siz[i]-1]%mod;
    }
    int solve(int v){
    	int*h=Q,*t=Q+1,es=0;
    	vis[*Q=v]=1;
    	for(;h<t;es+=deg[*h++])
    		for(edge*e=fir[*h];e;e=e->next,deg[*h]++)
    			if(!vis[e->to])vis[*t++=e->to]=1;
    	if(es!=(t-Q)*2)return 0;
    	int*tp=S;
    	for(int*i=Q;i<t;i++)if(deg[*i]==1)*tp++=*i;
    	while(tp>S){
    		int x=*--tp;
    		for(edge*e=fir[x];e;e=e->next)
    			if(--deg[e->to])deg[fa[x]=e->to]==1?*tp++=e->to:1;
    	}
    	int len=0;
    	for(int*i=Q;i<t;i++)if(deg[*i]>1){
    		for(int j=*i;deg[j];){
    			deg[C[len++]=j]=0;
    			for(edge*e=fir[j];e;e=e->next)
    				if(deg[e->to]>1){j=e->to;break;}
    		}
    		break;
    	}
    	int sum=0;
    	for(int dir=0;dir<2;dir++){
    		int s=1;
    		for(int i=0;i<len;i++)fa[C[i]]=C[(dir?i+len-1:i+1)%len];
    		for(int*i=Q;i<t;i++)if(*i>fa[fa[*i]])s=1ll*s*dfs(*i)%mod;
    		(sum+=s)%=mod;
    	}
    	return sum;
    }
    int main(){
    	scanf("%d",&N);
    	for(int i=*fac=1;i<=N*2;i++)fac[i]=fac[i-1]*i%mod;
    	ifac[N*2]=inv(fac[N*2]);
    	for(int i=N*2;i;i--)ifac[i-1]=ifac[i]*i%mod;
    	for(int i=0,x,y;i<N*2;i++)scanf("%d%d",&x,&y),link(x,y+=N),link(y,x);
    	int s=fac[N*2];
    	for(int i=1;i<=N*2;i++)if(!vis[i])s=1ll*s*solve(i)%mod;
    	printf("%d\n",s);
    }

Measured memory_bytes: 15232