akhauriyash/Code-Regression huggingface dataset:
N, M, X, Y = map(int, input().split())
 
x = list(map(int, input().split()))
y = list(map(int, input().split()))
 
for z in range(X, Y+1):
    if X < z <= Y and max(x) < z and min(y) >= z:
        print('No War')
        break
else:
    print('War')

Measured memory_bytes: 9164
{-# LANGUAGE
    BangPatterns, MultiWayIf, TupleSections, TypeApplications #-}
{-# OPTIONS_GHC -O2 #-}

import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO

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

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

sqI n = ceiling (sqrt $ fromIntegral n)
main = do
    n <- readLn :: IO Int
    vec <- UM.replicate (n+1) (0 :: Int)
    forM_ [1..n] (\k ->
            forM_ [k,2*k..n] (\l -> do
                UM.modify vec succ l
            )
        )
    vec2 <- U.freeze vec
    print $ U.sum $ U.imap (*) vec2


Measured memory_bytes: 160148
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int maxn = 1e5+5;
int dp[maxn][2];
string s;

int dfs(const int i, const int j)
{
    if (i == s.size())
        return 0;
    int& ans = dp[i][j];
    if (-1 == ans) {
        const int c = s[i]-'0';
        if (c == j)
            ans = 1 + dfs(i+1,c^1);
        else
            ans = dfs(i+1,c);
    }
    return ans;
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> s) {
        memset(dp,-1,sizeof(dp));
        const int a = dfs(0,0);
        const int b = dfs(0,1);
        const int ans = min(a,b);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 5968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
	{
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
	{
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
int main()
{
//    freopen("input.in","r",stdin);
//    freopen("output.out","w",stdout);
	n=read(),m=read();
    printf("%d",n-m*2>0?n-m*2:0);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int d[N];
    for(int i=0;i<N;i++)cin>>d[i];

    long long int ans=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            ans+=d[i]*d[j];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
//#include <ostream>


using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  ll N,K;
  cin >> K >> N;
  vector<ll> A(N);
  rep(i,N)cin >> A[i];
  ll ans = 0;
  rep(i,N-1){
    ans = max(A[i+1]-A[i],ans);
  }
  ans = max(ans,K-(A[N-1]-A[0]));
  cout << K-ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int n;
vector<vector<int>> res;

void dfs(int now, vector<int> v){
    int h = 0;
    rep(i, n){
        if(v[i] == 0) break;
        h++;
    }

    if(h == n){
        res.push_back(v);
        return;
    }

    int zero = 0;
    rep(i, n){
        if(v[i] == 0) zero++;
    }

    for(int bit=0; bit<(1<<zero); bit++){
        if(bit&1){
            int p = 0;
            vector<int> y = v;
            rep(i, n){
                if(v[i] == 0){
                    if((bit>>p) & 1){
                        y[i] = now;
                    } 
                    p++;
                }
            }
            dfs(now+1, y);
        }
    }
}

int main(){
    cin >> n;
    vector<int> x(n);
    dfs(1, x);

    vector<string> ans;
    rep(i, res.size()){
        string s = "";
        rep(j, n){
            s += ""s + (char)(res[i][j] + 'a' -1);
        }
        ans.push_back(s);
    }

    sort(all(ans));

    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}



Measured memory_bytes: 17840
n=gets.to_i

arr=gets.split.map(&:to_i)
ans=1

i=0
mode=0
(n-1).times{
    
   if arr[i]==arr[i+1]
       i+=1
       
       
     elsif  arr[i]>arr[i+1]  && mode==1
     
     i+=1
     
       
   elsif arr[i]<arr[i+1]  && mode==1
   ans+=1
    i+=1
    mode=0
   
      
     elsif  arr[i]>arr[i+1]  && mode==0
     
     i+=1
     mode=1
     
       
   elsif arr[i]<arr[i+1]  && mode==0
    i+=1
    mode=-1
    
     elsif  arr[i]>arr[i+1]  && mode==-1
     ans+=1
     mode=0
     i+=1
     
       
   elsif arr[i]<arr[i+1]  && mode==-1
    i+=1
   
    
    
end


}


puts ans

Measured memory_bytes: 8460
N=int(input())
B=list(map(int,input().split()))
A=[0]*N
A[0]=B[0]
A[-1]=B[-1]
ans=A[0]+A[-1]

for i in range(1,N-1):
    A[i]=min(B[i],B[i-1])
    ans+=A[i]

print(ans)

Measured memory_bytes: 3188
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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(){
    int k;cin>>k;
    int s=7,ans=1;
    if(k%2==0){
        cout<<-1<<endl;
    }
    
    else{
        
        while(ans<=k){
            if(s%k==0){
                cout<<ans<<endl;
                break;
            }
            else{
                s=s%k;
                s=s*10+7;
                ans++;
            }
        }
    }
    if(ans==k+1){
        cout<<-1<<endl;
    }
}



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

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

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    string s;
    cin >> s;
    vector<ll> childlen(s.size(), 0);
    ll left = 0, right = 1;
    while(true)
    {
        if (right == s.size()) break;
        if (s[right] == 'L')
        {
            if (s[left] == 'R')
            {
                if ((right - left) % 2 == 0)
                {
                    childlen[right]++;
                }
                else
                {
                    childlen[right - 1]++;
                }
            }
            left++;
            if (left == right)
            {
                right++;
            }
        }
        else
        {
            right++;
        }
    }
    left = s.size() - 2, right = s.size() - 1;
    while(true)
    {
        if (left == -1) break;
        if (s[left] == 'R')
        {
            if (s[right] == 'L')
            {
                if ((right - left) % 2 == 0)
                {
                    childlen[left]++;
                }
                else
                {
                    childlen[left + 1]++;
                }
            }
            right--;
            if (left == right)
            {
                left--;
            }
        }
        else
        {
            left--;
        }
    }

    REP(i, s.size()) cout << childlen[i] << " ";
}


Measured memory_bytes: 1408
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double ld;

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


int main() {
    ll N;
    cin >> N;
    ll ans = LLONG_MAX;

    for(ll i=1; i*i <= N ; i++){
        if(N % i != 0){
            continue;
        }

        ll j = N/i;
        ans = min(ans,i+j-2);
    }
    cout << ans << endl;
}


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

using namespace std;

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

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int n, m;
int cnt[112345];

int main() {
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		cnt[a]++;
		cnt[b]++;
	}
	
	bool ans = true;
	REP(i, n) if (cnt[i] & 1) ans = false;
	puts(ans ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 640
v,e=map(int,raw_input().split())
glist=[[float('inf')]*v for i in xrange(v)]
A=[[0]*v for i in xrange(v)]
negativect=0
for i in xrange(e):
    s,t,d=map(int,raw_input().split())
    glist[s][t]=d
for i in xrange(v):
    for j in xrange(v):
        if i==j:
            A[i][j]=0
        else:
            A[i][j]=glist[i][j]
for k in xrange(v):
    for i in xrange(v):
        for j in xrange(v):
            A[i][j]=min(A[i][j],A[i][k]+A[k][j])
for i in xrange(v):
    for j in xrange(v):
        if A[i][j]==float('inf'):
            A[i][j]='INF'
        if i==j and A[i][j]<0:
            negativect+=1
        A[i][j]=str(A[i][j])
if negativect>0:
    print('NEGATIVE CYCLE')
else:
    for i in xrange(v):
        print(" ".join(A[i]))

Measured memory_bytes: 7392
#include<iostream>
using namespace std;
int p[100010];
int sosu(int n){
  int i,j;
  for(i=0;i<=n;i++){
    p[i]=1;
  }
  p[0]=0,p[1]=0;
  for(i=2;i*i<=n;i++){
    if(p[i]==1){
      for(j=2;i*j<=n;j++){
        p[i*j]=0;
      }
    }
  }
};
int main(){
  int s[100010],q,l,r,i,a[100010];
  scanf("%d\n",&q);
  sosu(100000);
  for(i=0;i<=100000;i++){
    if(p[i]==1){
    }
    a[i]=0;
  }
  for(i=1;i<=100000;i=i+2){
    if(p[i]==1 && p[(i+1)/2]==1){
      a[i]=1;
    }
  }
  s[0]=0;
  for(i=0;i<=100000;i++){
    s[i+1]=s[i]+a[i];
  }
  for(i=0;i<q;i++){
    scanf("%d %d\n",&l,&r);
    printf("%d\n",s[r+1]-s[l]);
  }
  return 0;
}

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

#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int, int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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 UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[a]+=siz[b];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
const int MOD=1e9+7;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		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;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(){
	int n,m;
	cin>>n>>m;
	cout<<(n==m?"Yes":"No")<<endl;
}

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

int main(){
 int n,Y,y;
 cin >> n >> Y;
 y = Y/1000;
 
 for(int i=0; i<=n; i++){
   for(int j=0; j<=n-i; j++){
       int k=n-i-j;
       if(10*i+5*j+k==y){
         cout << i << " " << j << " " << k << endl;
         return 0;
       
     }
   }
 }
  
  cout << "-1 -1 -1" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

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

  for (ll i = 1; i <= 100000; i++)
  {
    if (i * 108 / 100 == N)
      FINALANS(i);
  }
  FINALANS(":(");
}

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

int main(){
  int X;
  cin >> X;
  if(X >= 400 && X < 600){
    cout << 8 << endl;
  }else if(X < 800){
    cout << 7 << endl;
  }else if(X < 1000){
    cout << 6 << endl;
  }else if(X < 1200){
    cout << 5 << endl;
  }else if(X < 1400){
    cout << 4 << endl;
  }else if(X < 1600){
    cout << 3 << endl;
  }else if(X < 1800){
    cout << 2 << endl;
  }else if(X < 2000){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
    int W, a, b;
    cin >> W >> a >> b;
    if (a <= b + W && b <= a + W) {
        cout << 0 << endl;
    } else if (b + W < a) {
        cout << a - (b + W) << endl;
    } else {
        cout << b - (a + W) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){

  int data[10][10];
  string in;

  while(cin >> in){

    for(int i = 0; i < 10; i++){
      data[0][i] = in[i] - 48;
      //cout << in[i] << " " <<data[0][i]<<" ";
    }
    // cout << endl;
    

    for(int i = 1; i < 10; i++){
      for(int j = 0; j < 10-i; j++){
	if(data[i-1][j] + data[i-1][j+1] >= 10){
	  data[i][j] = (data[i-1][j] + data[i-1][j+1] % 10);
	}else{
	  data[i][j] = data[i-1][j] + data[i-1][j+1];
	}
      }
    }

    cout << data[9][0] % 10<< endl;
  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    V< P<int, int> > ab(m);
    for (int i = 0; i < m; i++) {
        int b; cin >> ab[i].first >> b;
        ab[i].second = 0;
        for (int j = 0; j < b; j++) {
            int c; cin >> c; c--;
            ab[i].second += 1 << c;
        }
    }

    V<int> dp(1 << n, INF); dp[0] = 0;
    for (int state = 0; state < (1 << n); state++) {
        for (int i = 0; i < m; i++) chmin(dp[state | ab[i].second], dp[state] + ab[i].first);
    }
    if (dp.back() == INF) cout << -1 << '\n';
    else cout << dp.back() << '\n';
    return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

int exp(int n, int k)
{
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2)
    ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b)
{
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution()
{
  map<ii, int> m;
  int ans = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    double x;
    cin >> x;
    ii frac(round(x * 1e9), 1e9);
    int g = gcd(frac.ff, frac.ss);
    frac.ff /= g;
    frac.ss /= g;
    int pot5 = 0;
    int pot2 = 0;
    while (frac.ff % 2 == 0)
    {
      frac.ff /= 2;
      pot2++;
    }
    while (frac.ff % 5 == 0)
    {
      frac.ff /= 5;
      pot5++;
    }
    while (frac.ss % 2 == 0)
    {
      frac.ss /= 2;
      pot2--;
    }
    while (frac.ss % 5 == 0)
    {
      frac.ss /= 5;
      pot5--;
    }
    ii cur(pot5, pot2);
    for (auto p : m)
    {
      if (p.ff.ff + cur.ff >= 0 && p.ff.ss + cur.ss >= 0)
        ans += p.ss;
    }
    m[cur]++;
  }
  cout << ans << endl;
}

int32_t main()
{
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--)
    solution();
}


Measured memory_bytes: 3780
#include<iostream>
#include<cmath>
using namespace std;
int x,a,b,c,d,e; 
int main(){
	cin>>x>>a>>b;
	d=abs(x-a);
	e=abs(x-b);
	if(d>e){
		cout<<"B"<<endl;
	}
	if(d<e){
		cout<<"A"<<endl;
	}
	return 0;
} 

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

using ll = long long;
using ld = long double;

signed main(){
    ll n;
    cin >> n;

    ld a[n+2];
    bool iszero = false;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0)
            iszero = true;
    }

    if(iszero)
    {
        cout << "0\n";
        exit(0);
    }

    ll res = 1;

    for(ll i = 0; i < n; i++){
        if (a[i] > 1e18 || res * a[i] > 1e18){
            res = -1;
            break;
        }
        else{
            res = res * a[i];
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 5264
import sys
input = sys.stdin.readline

x, y, a, b, c = map(int, input().split())
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = sorted(list(map(int, input().split())))

n = 0
np = 0
nq = 0
ans = 0
while n < x + y:
    cs = []
    if p and np < x:
        cs.append(p[-1])
    if q and nq < y:
        cs.append(q[-1])
    if r:
        cs.append(r[-1])
    m = max(cs)
    if r and m == r[-1]:
        ans += r.pop()
    elif p and m == p[-1]:
        ans += p.pop()
        np += 1
    else:
        ans += q.pop()
        nq += 1
    n += 1

print(ans)


Measured memory_bytes: 103732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const double EPS = 1e-10;
typedef pair<int, int> P;
int A[200000];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	bool one = 1;
	for (int i = 1; i < N; i++) {
		if (A[i] <= A[i - 1]) {
			one = 0;
			break;
		}
	}
	if (one) {
		cout << 1 << endl;
		return 0;
	}
	int l = 1, r = 1 << 30;
	while ((r - l) > 1) {
		int m = (l + r) / 2;
		map<int, int> mp;
		bool ok = 1;
		for (int i = 1; i < N; i++) {
			if (A[i - 1] < A[i]) continue;
			auto itr = mp.lower_bound(A[i]);
			mp.erase(itr, mp.end());
			int j = A[i] - 1;
			while (j >= 0) {
				if (mp.find(j) != mp.end() && mp[j] == m - 1) {
					j--;
					continue;
				}
				mp[j]++;
				itr = mp.upper_bound(j);
				mp.erase(itr, mp.end());
				break;
			}
			if (j < 0 || mp[j] >= m) {
				ok = 0;
				break;
			}
		}
		if (ok) r = m;
		else l = m;
	}
	cout << r << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n;
    cin >> n;
    deque<long long> q;
    for (int i = 0;i < n;i++){
        long long a;
        cin >> a;
        if (i % 2 == 0){
            q.push_back(a);
        }
        else {
            q.push_front(a);
        }
    }

    if (n % 2 == 0){
        while(!q.empty()){
            cout << q.front() << " ";
            q.pop_front();
        }
    }
    else {
        while(!q.empty()){
            cout << q.back() << " ";
            q.pop_back();
        }
    }
    cout << endl;
}

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

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

  int ans;
  c - v >=  0 ? ans = c-v : ans =  0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  if(x < 4){
    cout << 1 << endl;
    return 0;
  }
  int ans = 0;
  for(int i = 2; i * i <= x; i++){
    int b = i;
    for(;;){
      b *= i;
      if(b > x){
        b /= i;
        ans = max(ans, b);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int y = sc.nextInt();
    boolean bl = false;
    int f = 0;
    int s = 0;
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n - i; j++){
        if(i * 10000 + j * 5000 + (n - i - j) * 1000 == y){
          bl = true;
          f = i;
          s = j;
          break;
        }
      }
      if(bl){
        break;
      }
    }
    if(bl){
      System.out.println("" + f + " " + s + " " + (n - f - s));
    }else{
      System.out.println("-1 -1 -1");
    }
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
class dice
{
public:
    dice()
    {

    }
    int n[6];
    int l[6][6];
    void set(int n0,int n1,int n2,int n3,int n4,int n5)
    {
        n[0] = n0;
        n[1] = n1;
        n[2] = n2;
        n[3] = n3;
        n[4] = n4;
        n[5] = n5;
        l[0][1] = 2;l[0][2] = 4;l[0][3] = 1;l[0][4] = 3;
        l[1][0] = 3;l[1][2] = 0;l[1][3] = 5;l[1][5] = 2;
        l[2][0] = 1;l[2][1] = 5;l[2][4] = 0;l[2][5] = 4;
        l[3][0] = 4;l[3][1] = 0;l[3][4] = 5;l[3][5] = 1;
        l[4][0] = 2;l[4][2] = 5;l[4][3] = 0;l[4][5] = 3;
        l[5][1] = 3;l[5][2] = 1;l[5][3] = 4;l[5][4] = 2;
    }
    int get(int i)
    {
        return n[i];
    }
    int rot(char c)
    {
        int t[6];
        for(int i = 0;i < 6;i++)
        {
            t[i] = n[i];
        }
        switch(c)
        {
        case 'N':
            n[0] = t[1];
            n[1] = t[5];
            n[5] = t[4];
            n[4] = t[0];
            break;
        case 'S':
            n[0] = t[4];
            n[1] = t[0];
            n[5] = t[1];
            n[4] = t[5];
            break;
        case 'E':
            n[0] = t[3];
            n[3] = t[5];
            n[5] = t[2];
            n[2] = t[0];
            break;
        case 'W':
            n[0] = t[2];
            n[3] = t[0];
            n[5] = t[3];
            n[2] = t[5];
            break;
        default:
            break;
        }
    }
    int getLink(int t,int f)
    {
        int nt,nf;
        for(int i = 0;i < 6;i++)
        {
            if(n[i] == t)
            {
                nt = i;
            }
        }
        for(int i = 0;i < 6;i++)
        {
            if(n[i] == f)
            {
                nf = i;
            }
        }
        return n[l[nt][nf]];
    }
};

int main()
{
    int n[6];
    for(int i= 0;i < 6;i++)
    {
        cin >> n[i];
    }
    dice d;
    d.set(n[0],n[1],n[2],n[3],n[4],n[5]);
    int s;
    cin >> s;
    for(int i = 0;i < s;i++)
    {
        int t,f;
        cin >> t >> f;
        cout << d.getLink(t,f) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dp[102][102],p[102];
const int INF=1000100010;
int main(){
    int n,l,r;
    cin>>n;
    rep(i,n){
        cin>>l>>r;
        if(i!=n-1) p[i]=l;
        else p[i]=l,p[i+1]=r;
    }
    FOR(i,1,n+1)FOR(j,1,n+1){
        if(i!=j)dp[i][j]=INF;
        else dp[i][j]=0;
    }
    FOR(i,1,n+1)FOR(l,1,n-i+1)FOR(r,l+1,i+l+1){
        dp[l][i+l]=min(dp[l][i+l],dp[l][r-1]+dp[r][i+l]+p[l-1]*p[r-1]*p[l+i]);
    }
    cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 3152
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define eps 1e-9
#define mp make_pair

char s[1000],s2[1000];
int len;

int main () {
	scanf("%s",s);
	len=strlen(s);
	FOR(i,0,len) {
		s2[i]=s[len-i-1];	
		//printf("%d %c %c\n",i,s[len-i],s2[i]);
	}
	FOR(i,0,len) {
		if (s[i]!=s2[i]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;	
}

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

int main(){

    int a,b;
    cin>>a>>b;

    if(abs(a-b)%2==0){
        cout<<max(a,b)-abs(a-b)/2<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
// #include <bits/stdc++.h>
#define req(i,k) for(int i = 0; i < k; i++)
using namespace std;


int main(void) {
    int n;
   cin >> n;
  vector<long long> a(n);
  req(i,n) {
      cin >> a.at(i);
  }
  long long sum = 0;
  long long total = 0;
  long long mi = 1e12;
  long long k;
    for(int j = n - 1; j > 0; j--) {
        sum += a.at(j);
    }
  for(int i = 0; i < n; i++) {
        total += a.at(i);
      if (total == sum) {
          cout << 0;
          return 0;
      } else if (total > sum) {
          k = total - sum;
      } else {
          k = sum - total;
      }
      mi = min(mi, k);
      if(i < n-1) {
          sum -= a.at(i+1);
      }

  }
cout << mi;
    return 0;
}

Measured memory_bytes: 1792
import static java.lang.Math.log10;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); 
        
       int sum = 0 ;
        for(int i = 1 ; i<=n ; i++){
            
          
           double j =0;
           j = (int)log10(i)+1;
           
            if(j%2==1){
                sum++;
            }
        }
            
         /*   int count =0;
            while(i!=0){
                i=i/10;
                count++;
            }
            if(count%2==1){
                sum++ ;
            }
        }*/
        System.out.println(sum);
          
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(void) {
	int n,m; cin >> n >> m;
	vi a(m); rep(i,m) cin >> a[i];
	vector<bool> brkd(n+1,false);
	rep(i,m) brkd[a[i]] = true;
	vector<mint> p(n+1,0);
	p[0] = 1;
	rep2(i,1,n+1){
		if(i-1>=0&&(!brkd[i-1])) p[i] = p[i]+p[i-1];
		if(i-2>=0&&(!brkd[i-2])) p[i] = p[i]+p[i-2];
	}
	cout << p[n].x << endl;
}




Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
 
#define long long long int
 
using namespace std;
 
// @author: pashka
const long MOD = 998244353;
 
long pw(int x) {
    long res = 1;
    long a = 2;
    while (x > 0) {
        if (x & 1) {
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        x /= 2;
    }
    return res;
}
 
void add(int &a, int b) {
    a += b;
    a %= MOD;
//    cout << "!!! " << b << "\n";
}
 
vector<int> f;
 
void init(int n) {
    f.assign(n + 1, 0);
}
 
long sum(int r) { // exclusive
    if (r == 0)
        return 0;
    r--;
    long result = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1)
        result += f[r];
    return result;
}
 
void inc(int i) {
    for (; i < f.size(); i = (i | (i + 1)))
        f[i]++;
}
 
int main() {
    ios::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector<pair<int, int>> p(n);
    for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
 
    int res = 0;
    for (int i = 0; i < n; i++) {
        add(res, pw(n));
        add(res, -pw(i));
        add(res, -pw(n - 1 - i));
        add(res, -pw(i));
        add(res, -pw(n - 1 - i));
    }
 
    sort(p.begin(), p.end());
    int last = -2000000000;
    int c = 0;
    for (int i = 0; i < n; i++) {
        if (p[i].first != last) {
            last = p[i].first;
            c++;
        }
        p[i].first = c;
    }
    for (int i = 0; i < n; i++) {
        swap(p[i].first, p[i].second);
    }
    for (int q = 0; q < 2; q++) {
        for (int i = 0; i < n; i++) {
            p[i].first = n - 1 - p[i].first;
        }
        sort(p.begin(), p.end());
 
        init(n + 1);
        for (int i = 0; i < n; i++) {
//            cout << p[i].first << " " << p[i].second << "\n";
            int x = sum(p[i].second);
            int y = i - x;
//            cout << " " << x << " " << y << "\n";
            add(res, pw(x));
            add(res, pw(y));
            inc(p[i].second);
        }
    }
 
    res -= n;
    while (res < 0) res += MOD;
    cout << res << "\n";
 
    return 0;
}

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

class Main{
  public static void main(String[] args) {
  Scanner scan = new Scanner(System.in);

double r = scan.nextDouble();
double x = Math.PI;

System.out.printf("%.5f %5f\n",r * r * x,r * 2 * x);
  }
}

Measured memory_bytes: 28236
/**
  @date Time-stamp: <2019-04-29 08:29:07 tagashira>
  @file c.cpp
  @brief https://atcoder.jp/contests/abc125/tasks/abc125_c
**/

#include <algorithm>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

uint gcd(uint a, uint b) {
  if (b == 0) {
    return a;
  }

  return gcd(b, a % b);
}

uint multi_gcd(vector<uint> a) {
  if (a.size() == 2) {
    return gcd(a[0], a[1]);
  } else {
    vector<uint> tmp(a.begin() + 1, a.end());
    return gcd(a[0], multi_gcd(tmp));
  }
}

int main(int argc, char* argv[]) {
  uint N;
  cin >> N;
  vector<uint> A(0, N);
  uint tmpA;
  uint i;

  for (i = 0; i < N; i++) {
    cin >> tmpA;
    A.push_back(tmpA);
  }

  // gcd test
  // cout << gcd(1071, 1029) << "\n"; //21
  // mluti gcd test
  // chrono::system_clock::time_point start, end;
  // cout << multi_gcd({4, 6, 8}) << "\n"; //2
  // start = chrono::system_clock::now();
  // for (i = 0; i < 100; i++) {
  //   multi_gcd({4, 6, 8});
  // }
  // end         = chrono::system_clock::now();
  // double time = static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
  // printf("gcd time %lf[ms]\n", time / 100);

  // 累積 GCD (左と右両方)
  vector<uint> left(N + 1, 0), right(N + 1, 0);
  for (i = 0; i < N; ++i) {
    left[i + 1] = gcd(A[i], left[i]);
  }
  for (i = N - 1; i > 0; --i) {
    right[i] = gcd(A[i], right[i + 1]);
  }

  // 集計
  vector<uint> M;
  for (i = 0; i < N; ++i) {
    // 左側
    uint l = left[i];

    // 右側
    uint r = right[i + 1];

    M.push_back(gcd(l, r));
  }
  cout << *max_element(M.begin(), M.end()) << endl;

  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef vector<int> vi;

typedef vector<double> vd;
typedef vector<vd> mat;
double eps=1e-9;
int MAX_H=252;
vd solve(mat a,vd b){
	int H=a.size(),W=a[0].size();
	bool used[MAX_H]={};
	rep(j,W){
		int i=0;
		while(i<H&&(used[i]||abs(a[i][j])<eps)) i++;
		if(i==H) continue;
		used[i]=1;
//		rep(x,H) rep(y,W) printf("a[%d][%d]=%lf\n",x,y,a[x][y]);
		double t=a[i][j];
		rep(k,W) a[i][k]/=t;
		b[i]/=t;
		rep(k,H){
			if(k==i) continue;
			double c=-a[k][j]/a[i][j];
			rep(l,W) a[k][l]+=a[i][l]*c;
			b[k]+=b[i]*c;
		}
	}
	return b;
}

int H,W,I;
string s[5],t[5];
vi brd[252];
map<vi,int> ibrd;
void dfs(int h,int w,vector<int> vc){
	if(h==H){
		brd[I]=vc;
		ibrd[vc]=I;
		I++;
		return;
	}
	rep(i,w+1){
		vector<int> nvc=vc;
		nvc.pb(i);
		dfs(h+1,i,nvc);
	}
}
void init(){
	I=0;
	ibrd.clear();
}
vector<string> paint(vector<string> a,int x,int y,char c){
	rep(i,x+1) rep(j,y+1) a[i][j]=c;
	return a;
}
int main(){
	while(true){
		cin>>H>>W;
		int X=H*W*2;
		if(H==0) break;
		rep(i,H) cin>>s[i];
		rep(i,H) cin>>t[i];
		init();
		dfs(0,W,vector<int>());
		mat M;
		vd con;
		rep(i,I){
			vd eq(I);
			double co=0;
			if(i==0){
				eq[i]=1;
				M.pb(eq);
				con.pb(co);
				continue;
			}
			eq[i]=-1;
			vi v=brd[i];
			vector<string> a(H,string(W,'a'));
			rep(x,H) rep(y,W) a[x][y]=t[x][y];
			rep(x,H) rep(y,v[x]) a[x][y]='*';
			rep(x,H) rep(y,W) rep(z,2){
				char c='B';
				if(z==1) c='W';
				vector<string> b=paint(a,x,y,c);
				vector<int> nv;
				rep(j,H){
					int k=W-1;
					while(k>=0&&b[j][k]==t[j][k]) k--;
					nv.pb(k+1);
				}
				for(int j=H-1;j>0;j--) chmax(nv[j-1],nv[j]);
				int ni=ibrd[nv];
				eq[ni]+=1.0/X;
				co-=(double)(x+1)*(y+1)/X;
			}
			M.pb(eq);
			con.pb(co);
		}
		vd ans=solve(M,con);
		vector<int> fv;
		rep(j,H){
			int k=W-1;
			while(k>=0&&s[j][k]==t[j][k]) k--;
			fv.pb(k+1);
		}
		for(int j=H-1;j>0;j--) chmax(fv[j-1],fv[j]);
		int id=ibrd[fv];
		printf("%.12f\n",ans[id]);
	}
}

Measured memory_bytes: 4048
import java.util.Scanner;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
		
    String S = sc.next();
    String li[] = S.split("");
    
    int i = 0;
    int count = 0;
    int N = li.length;
    while(i<N-i){
      if(!li[i].equals(li[N-1-i])){
        count++;
      }
      i++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int n;
    cin>>n;
    set<string> Keihin;
    rep(i,n){
        string s;
        cin>>s;
        Keihin.insert(s);
    }
    cout<<Keihin.size()<<endl;
}

Measured memory_bytes: 19180
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <deque>
using namespace std;
typedef long long ll;

struct Sushi
{
	ll pos;
	ll nut;
};

const int maxn = 100005;
int N;
ll C;
Sushi A[maxn], B[maxn];
ll pfxA[maxn], pfxB[maxn];
ll maxA[maxn];
ll maxA2[maxn];

int main()
{
	//ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("input.in","r",stdin);
	cin >> N >> C;
	for (int i = 1; i <= N; i++) {
		ll xi, vi; cin >> xi >> vi;
		A[i] = {xi,vi};
		B[i] = {xi,vi};
	}
	B[N+1] = {C,0};
	for (int i = 1; i <= N; i++) {
		pfxA[i] = pfxA[i-1] + A[i].nut;
		pfxB[N-i+1] = pfxB[N-i+2] + B[N-i+1].nut;
	}
	//calculate max A
	for (int i = 1; i <= N; i++) {
		maxA[i] = max(maxA[i-1],pfxA[i]-A[i].pos);
		maxA2[i] = max(maxA2[i-1],pfxA[i]-2*A[i].pos);
		//cout << maxA[i] << '\n';
	}
	//calculate in O(n) maximum
	ll ans = 0;
	for (int j = N+1; j > 0; j--) {
		//cout << pfxB[j] << ' ' << (C - B[j].pos) << '\n';
		ll T = maxA[j-1] + pfxB[j] - 2*(C - B[j].pos);
		ans = max(ans,T);
		ll T2 = maxA2[j-1] + pfxB[j] - (C-B[j].pos);
		ans = max(ans,T2);

	}
	//output ans
	cout << ans << '\n';
	
	
	
	
	return 0;
}

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

using namespace std;

typedef long long ll;

set<string> st;

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

	string S;
	cin >> S;

	st.insert("KIHBR");
	st.insert("AKIHBR");
	st.insert("KIHABR");
	st.insert("AKIHABR");
	st.insert("KIHBAR");
	st.insert("AKIHBAR");
	st.insert("KIHABAR");
	st.insert("AKIHABAR");
	st.insert("KIHBRA");
	st.insert("AKIHBRA");
	st.insert("KIHABRA");
	st.insert("AKIHABRA");
	st.insert("KIHBARA");
	st.insert("AKIHBARA");
	st.insert("KIHABARA");
	st.insert("AKIHABARA");

	if(st.count(S) == 1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

}


Measured memory_bytes: 256
# N = int(input())
import heapq

X, Y, A, B, C = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = sorted(p, reverse=True)[:X]
q = sorted(q, reverse=True)[:Y]
heapq.heapify(p)
heapq.heapify(q)
r_asc = sorted(r, reverse=True)

for r in r_asc:
    p_min = heapq.heappop(p)
    q_min = heapq.heappop(q)
    if p_min > q_min and r > q_min:
        heapq.heappush(q, r)
        heapq.heappush(p, p_min)
    elif q_min >= p_min and r > p_min:
        heapq.heappush(p, r)
        heapq.heappush(q, q_min)
    else:
        heapq.heappush(q, q_min)
        heapq.heappush(p, p_min)
        break
print(sum(p) + sum(q))



Measured memory_bytes: 122064
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;
const int N = 2e5+5;
vector<int> adj[N];
int vis[N];

void dfs(ll u,ll &res)
{
    if(vis[u]) return;
    vis[u]++;
    res++;
    for(auto k:adj[u]) dfs(k,res);
}
int main()
{
    FAST
    ll n;cin>>n;
    ll m;cin>>m;
    f(i,0,m)
    {
        ll u,v;cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    ll ans=0;
    f(i,1,n+1)
    {
        if(!vis[i])
        {
            ll res = 0;
            dfs(i,res);
            ans=max(ans,res);
        }
    }
    cout<<ans<<endl;

}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl;

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}


int main() {
  string s;
  cin >> s;

  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
    p("Bad");
  } else {
    p("Good");
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int N;
int A[100010][3];
int dp[100010][3];

int main() {
  cin >> N;
  rep(i, 0, N) rep(j, 0, 3) cin >> A[i][j];

  rep(i, 0, 3) dp[0][i] = A[0][i];
  rep(i, 1, N) rep(lst, 0, 3) {
    rep(nxt, 0, 3) if (lst != nxt) chmax(dp[i][nxt], dp[i-1][lst] + A[i][nxt]);
  }

  int res = 0;
  rep(i, 0, 3) chmax(res, dp[N-1][i]);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2560