akhauriyash/Code-Regression huggingface dataset:
N = int(input())
W = []
for i in range(N):
    W.append(input())


count = 0


#重複判定


for i in range(1, N):
    if W[i][0] != W[i - 1][-1]:
        count += 1
        break

W.sort()
for i in range(N - 1):
    if W[i] == W[i + 1]:
        count += 1
        break

if count != 0:
    print("No")

else:
    print("Yes")


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a*b%2==0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 3676
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    vector<pair<PL, PL>> p(n);
    REP(i,n){
        int w = in(), s = in(), v = in();
        p[i] = make_pair(PL(w + s, v), PL(w, s));
    }
    sort(ALL(p));
    VL w(n), s(n), v(n);
    REP(i,n){
        v[i] = p[i].first.second;
        w[i] = p[i].second.first;
        s[i] = p[i].second.second;
    }

    int m = 2e4 + 10;
    VL dp(m, -1e18);
    dp[0] = 0;
    REP(i,n){
        FORR(j,s[i],0){
            dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
        }
    }
    ll ans = 0;
    REP(i,m) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import Control.Applicative
import Control.Monad
import Data.List

f :: String -> String
f []     = []
f (x:xs) = x : x : f xs

main :: IO ()
main = do
    [h, w] <- fmap read . words <$> getLine :: IO [Int]
    xss <- replicateM h getLine
    let xss' = transpose . fmap f $ transpose xss
    putStrLn $ unlines xss'

Measured memory_bytes: 2428
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            System.out.println(s.replace(",", " "));
        }
    }
}


Measured memory_bytes: 21204
a=int(input())
b=int(input())
c=int(input())
x=int(input())

ans=0
i=0
j=0
while(i<=a and i*500<=x):
    while(j<=b and (i*500 + j*100) <=x):
        rest=x-i*500-j*100
        if(rest%50==0):
            k=rest//50
            if(0<=k and k<=c):
#                print(i,j,k)
                ans+=1
        j+=1
    i+=1
    j=0
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		for (int i=0; i<n; i++) {
			int L = 0;
			int R = 0;
			boolean F = true;
			for (int j=0; j<10; j++) {
				int ball = sc.nextInt();
				if (ball > L) {L = ball;}
				else if (ball > R) {R = ball;}
				else {F = false;}
			}
			out.println(F?"YES":"NO");
		}
	}
}


Measured memory_bytes: 26060
import java.util.Scanner;

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

        sc.close();

        for (int i = n; i > 0; i--) {
            int sqrt = (int) Math.sqrt(i);
            int pow = (int) Math.pow(sqrt, 2);
            if (i == pow) {
                System.out.println(i);
                return;
            }
        }
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<pair<char, ll>> RLE(const string &S) {
    ll cnt = 0;
    vector<pair<char, ll>> res;
    for (ll i = 0; i < (ll) S.size(); i++) {
        cnt++;
        if (i == (ll) S.size() - 1) {
            res.emplace_back(S[i], cnt);
            break;
        }
        if (S[i] != S[i + 1]) {
            res.emplace_back(S[i], cnt);
            cnt = 0;
        }
    }
    return res;
}

void Main() {
    // 考察
    // S1=0の時2K-1箇所潰す
    // S1=1の時2K箇所潰す

    ll N, K; cin >> N >> K;
    string S; cin >> S;

    int max_len = 1;
    int last = N-1, num_zero = (S.back() == '0');
    for(int first = N-2; 0 <= first; first--){
        if(S[first] == '1'|| (S[first] == '0' && S[first+1] == '0')) {
            max_len = max(max_len,last - first +1);
        } else {
            ++num_zero;
            while(K < num_zero) {
                while (S[last]=='1')--last;
                while (S[last]=='0')--last;
                --num_zero;
            }
            max_len = max(max_len,last - first +1);
        }
    }
    cout << max_len << endl;
}

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


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 20;
ll a[maxn][maxn];
ll c[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll n, m, x;
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
        }
    }
    ll inf = 1LL << 63 - 1;
    ll ans = inf;
    ll num = 1LL << n;
    for (int i = 0; i < num; i++)
    {
        ll cur = i;
        vector<ll> b(m);
        ll cnt = 0;
        for (int j = 0; j < n; j++)
        {
            int id = cur >> j;
            if (id & 1)
            {
                cnt += c[j];
                //DBG(cnt);
                for (int k = 0; k < m; k++)
                {
                    b[k] += a[j][k];
                }
            }
        }
        int flag = 0;
        for (int t = 0; t < m; t++)
        {
            if (b[t] < x)
            {
                flag = 1;
                break;
            }
        }
        if (!flag)
        {
            ans = min(ans, cnt);
            //DBG(ans);
        }
    }
    if (ans == inf)
        cout << -1 << "\n";
    else
        cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string s,t;
  cin >> s;
  cin >> t;
  int p=s.size();
  int q=t.size();
  int dp[p+10][q+10];

  for(int i=0;i<=p;i++){
    for(int j=0;j<=q;j++){
      dp[i][j]=0;
    }
  }

  for(int i=0;i<p;i++){
    for(int j=0;j<q;j++){
      if(s[i]==t[j]){
        dp[i+1][j+1]=dp[i][j]+1;
      }else{
        dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
      }
    }
  }
  vector<char> ans;
  while(p>0 && q>0){
    if(s[p-1]==t[q-1]){
      ans.push_back(s[p-1]);
      p--,q--;
    }else{
      if(dp[p-1][q]>dp[p][q-1]){
        p--;
      }else{
        q--;
      }
    }
  }
  reverse(ans.begin(),ans.end());
  for(int i=0;i<ans.size();i++){
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 35584
module Main (main) where

import Data.Functor ((<$>))
import Control.Monad.Trans.State

showCase :: Show a => a -> State Int String
showCase x = state $ \n -> ("Case " ++ show n ++ ": " ++ show x, n+1)

main :: IO ()
main = do
  xs <- takeWhile (/=0) . map read . words <$> getContents :: IO [Int]
  mapM_ putStrLn $ evalState (mapM showCase xs) 1



Measured memory_bytes: 4936
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
s = input().split()
t = [int(p) for p in s]

N = t[0]
K = t[1]

#p = int(N/K)
#a = N - p * K
#a = Decimal(N % K)
#b = Decimal(K - a)
a = N % K
b = K - a

#print('N:{}, K:{}, p:{}, a:{}, b:{}'.format(N,K,p,a,b))
print(min(a,b))
# 1000000000000000000

Measured memory_bytes: 9752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a / gcd(a, b) * b; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s,front;
    int q,state = 1;//state == 1//通常
    cin>>s>>q;
    rep(i,q){
        int t,f;
        char c;
        cin>>t;
        if(t == 1){
            state *= -1;
        }
        else{
            cin>>f>>c;
            if(f == 2)f = -1;//最後尾
            if(f * state > 0){//先頭に追加
                front = c + front;
            }
            else{
                s += c;
            }
        }
    }
    s = front + s;
    if(state > 0)cout<<s<<endl;
    else {
        reverse(all(s));
        cout<<s<<endl;
    }

    return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 998244353
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF INT_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}


vl f;
vl invf;
ll MAXVAL = 2*(1e5)+100;
void init(){
	f.resize(MAXVAL, 1);
	invf.resize(MAXVAL, 1);
	forne(i, MAXVAL-1) f[i] = (f[i-1]*i)%MOD;
	forne(i, MAXVAL-1) invf[i] = modinv(f[i]);
}

ll ncr(ll n, ll r){
	return invf[n-r] * ( f[n] * invf[r] % MOD ) % MOD;
}

void solve(){
	ll n, m, k;
	cin>>n>>m>>k;
	ll answer = 0;
	forn(i, k+1){
		ll factor = (m*modpow(m-1, n-i-1))%MOD;
		answer = answer + (factor*ncr(n-1, i))%MOD;
		answer %= MOD;
	}
	cout<<answer<<endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
    init();
	int t=1;
	while(t--)
		solve();
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();
            var count = 0;

            for (var i = 0; i < 3; i++)
                if (S[i] == T[i]) count++;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
n = int(input())
l = list(map(int,input().split()))
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
           # print(l[i],l[j],l[k])
            if (l[i] != l[j] and l[j] != l[k] and l[i] != l[k]) and max(l[i],l[j],l[k]) < ((l[i] + l[j] + l[k]) - max(l[i],l[j],l[k])):
                #print(l[i],l[j],l[k])
                ans += 1
print(ans)

Measured memory_bytes: 9224
def resolve():
    import sys
    import bisect
    input = sys.stdin.readline
    n = int(input())
    ans = dict()
    need_sort = True
    sorted_keys = None
    for _ in range(n):
        q, key, *x = input().split()
        if q == "0":
            if key in ans:
                ans[key] = x[0]
            else:
                ans[key] = x[0]
                need_sort = True
        elif q == "1":
            if key in ans:
                print(ans[key])
            else:
                print(0)
        elif q == "2":
            ans[key] = "0"
        else:
            if sorted_keys is None:
                sorted_keys = sorted(ans.keys())
            if need_sort:
                sorted_keys = sorted(ans.keys())
                need_sort = False
            l, r = key, x[0]
            fr = bisect.bisect_left(sorted_keys, l)
            to = bisect.bisect_right(sorted_keys, r)
            for i in range(fr, to):
                if ans[sorted_keys[i]] != "0":
                    print(sorted_keys[i], ans[sorted_keys[i]])


resolve()



Measured memory_bytes: 42696
class Main{
  public static void main(String[]z){
    Scanner x=new Scanner(System.in);
    String s=x.nextLine();
    while(x.hasNext()){
      s=x.nextLine();
      if(s.matches(">'(=+)#\\1~"))System.out.println("A");
      else if(s.matches(">\\^(Q=)+~~"))System.out.println("B");
      else System.out.println("NA");
    }
  }
}

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

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

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  int mid = 0;
  rep(i,n) {
    if( i ) printf(" ");
    if( i <= (int)(n/2) ) printf("0");
    else                  printf("%d",m);
  } puts("");
  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);

bool used[N];

vector<int> g[N];

int deg[N];

map<pair<int, int>, int> xx, w;

int cnt[N];

void solve(){
	int n, m;
	cin >> n >> m;
	rep(i, n){
		string s;
		cin >> s;
		cout << s << endl << s << endl;
	}

}	

 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 27520
#include <stdio.h>

int main()
{
    int inputA, inputB, inputC;

    scanf("%d %d %d", &inputA, &inputB, &inputC);

    // Checks if all numbers have the same or different value
    if ((inputA == inputB && inputB == inputC) || (inputA != inputB && inputB != inputC && inputA != inputC))
    {
        printf("No \n");
    }
    else
    {
        printf("Yes \n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

unsigned long S(unsigned long N) {
  unsigned long ret=0;
  for (unsigned long n=N; n>0; n/=10)
    ret += n%10;
  return ret;
}

static unsigned long const Ninit = 1000000000000000;

int main() {
  double min = double(Ninit)/double(S(Ninit));
  std::vector<unsigned long> Nums(1000);

  for (unsigned long i=Ninit; i>=1000; i/=10) {
    for (unsigned long j=i; j>i/10; j-=i/1000) {
      unsigned long const n = j-1;
      double const s = double(n)/double(S(n));

      if (s<=min) {
        min = s;
        Nums.push_back(n);
      }
    }
  }

  for (unsigned long n=99; n>10; n-=10) {
    double const s = double(n)/double(S(n));

    if (s<=min) {
      min = s;
      Nums.push_back(n);
    }
  }

  for (unsigned long n=9; n>0; n-=1) {
    double const s = double(n)/double(S(n));

    if (s<=min) {
      min = s;
      Nums.push_back(n);
    }
  }

  size_t k;
  std::cin >> k;

  for (auto i=Nums.crbegin();
       std::distance(Nums.crbegin(), i) < k;
       std::advance(i, 1))
    std::cout << *i << std::endl;

  return 0;
}


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

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,P; cin >> N >> P;
    string S; cin >> S;
    reverse(all(S));
    ll b = 1;
    vector<int> A(N+1);
    if (P==2) {
        ll ans = 0;
        rep(i,N) {
            int k = S[i] - '0';
            if (k%2==0) {
                ans += N-i;
            }
        }
        cout << ans << ln;
        return 0;
    }
    if (P==5) {
        ll ans = 0;
        rep(i,N) {
            int k = S[i] - '0';
            if (k%5==0) {
                ans += N-i;
            }
        }
        cout << ans << ln;
        return 0;
    }
    rep(i,N) {
        int k = S[i] - '0';
        k = k*b%P;
        A[i+1] = k;
        b = b*10%P;
    }
    map<int, ll> dic;
    dic[0] = 1;
    rep(i,N) {
        A[i+1] += A[i];
        A[i+1] %= P;
        dic[A[i+1]]++;
    }
    ll ans = 0;
    for (auto i : dic) {
        ans += i.second*(i.second-1)/2;
    }
    cout << ans << ln;
    
}

Measured memory_bytes: 1812
#include <iostream>

using namespace std;

int main() {
    int D, G;
    cin >> D >> G;

    int i, p[D], c[D], j;
    for(i=0; i<D; i++) {
        cin >> p[i] >> c[i];
    }

    int bit, pro_num, min_num=1001;
    long long int score;
    for(bit=0; bit<(1<<D); bit++) {
        score = 0;
        pro_num = 0;
        for(i=0; i<D; i++) {
            if(bit & (1<<i)) {
                score += c[i];
                score += p[i]*(i+1)*100;
                pro_num += p[i];
            }
        }
        if(score>=G) {
            if(min_num>pro_num) {
                min_num = pro_num;
            }
        } else {
            for(i=D-1; i>=0; i--) {
                if(bit & (1<<i)) {
                    continue;
                } else {
                    for(j=1; j<p[i]; j++) {
                        score += (i+1)*100;
                        pro_num += 1;
                        if(score>=G) {
                            if(min_num>pro_num) {
                                min_num = pro_num;
                            }
                            break;
                        }
                    }
                }
            }
        }
    }

    cout << min_num << endl;

    return 0;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	fmt.Println(train(n, a))
}

func train(n int, a []int) int {
	for c, p := 1, 1; c <= len(a); c++ {
		p = a[p-1]
		if p == 2 {
			return c
		}
	}
	return -1
}


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

const int MAX = 510000;
const int p = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

ll mod(ll val, ll m) {
  ll res = val % m;
  if (res < 0) res += m;
  return res;
}

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % p;
    inv[i] = p - inv[p%i] * (p / i) % p;
    finv[i] = finv[i - 1] * inv[i] % p;
  }
}

ll com(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % p) % p;
}

int main() {
  COMinit();
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(), a.end());
  ll maxx = 0, minx = 0;
  rep(i,0,n-k+1) {
    minx += com(n-i-1,k-1) * a[i];
    minx %= p;
  }
  rep(i,k-1,n) {
    maxx += com(i,k-1) * a[i];
    maxx %= p;
  }
  ll ans = mod(maxx - minx, p);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 15844
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

#define MOD 1e9+7

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    ll m = MOD;
    int n;
    cin >> n;
    vector<ll> a, rui;
    rui.push_back(0);
    rep(i, n){
        ll x;
        cin >> x;
        a.push_back(x);
        rui.push_back(x+rui[i]);
    }

    ll sum=0;
    rep(i, n-1){
        sum = (sum + (a[i] * ((rui[n] - rui[i+1]) % m)) % m) % m;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6644
#include<bits/stdc++.h>
#define X first
#define Y second
#define N 200005
using namespace std;
vector<int>vec[N];
int T[N<<2],b[N],sum[N],New[N];
int ql,qr,n,i,k,ans,m,Zero;
void build(int x,int l,int r){
	T[x]=-1e9;if (l==r) return;
  int mid=(l+r)>>1;
  build(x<<1,l,mid);
  build(x<<1|1,mid+1,r);
}
int Query(int x,int l,int r){
	if (ql<=l&&r<=qr) return T[x];
	int mid=(l+r)>>1,ret=-1e9;
	if (ql<=mid) ret=max(ret,Query(x<<1,l,mid));
	if (qr>mid)  ret=max(ret,Query(x<<1|1,mid+1,r));
	return ret;
}
void Update(int x,int l,int r,int pos,int val){
	if (l==r) {T[x]=max(T[x],val);return;}
	int mid=(l+r)>>1;
	if (pos<=mid) Update(x<<1,l,mid,pos,val);
	         else Update(x<<1|1,mid+1,r,pos,val);
	T[x]=max(T[x<<1],T[x<<1|1]);
}
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) 
	  scanf("%d",&b[i]),sum[i]=sum[i-1]+b[i];
	scanf("%d",&m);
	for (i=1;i<=m;i++)
	  scanf("%d%d",&ql,&qr),vec[ql].push_back(qr);
	build(1,0,n); 
	Update(1,0,n,0,0-sum[0]);
	for (i=1;i<=n;i++){
		ql=qr=i-1;Zero=Query(1,0,n)+sum[i-1]+(b[i]==0);
		for (k=0;k<vec[i].size();k++){
			ql=i-1;qr=vec[i][k];
			New[k]=sum[vec[i][k]]+Query(1,0,n);
		}
		Update(1,0,n,i,Zero-sum[i]);
		for (k=0;k<vec[i].size();k++)
		  Update(1,0,n,vec[i][k],New[k]-sum[vec[i][k]]);
	}
	ql=qr=n;ans=Query(1,0,n)+sum[n];
	printf("%d\n",n-ans);
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    ll N,goukei = 0;
    cin >> N;

    vector<ll>L(N);

    for(ll i = 0;i < N;i++)
        cin >> L.at(i);

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

    for(ll i = 0;i < N - 2;i++){
        for(ll j = i + 1;j < N -1;j++){
            const ll k = lower_bound(ALL(L),L.at(i)+L.at(j))-L.begin();
            ll d = k - j -1;
            goukei += d;
        }
    }

    cout << goukei << endl;
}

Measured memory_bytes: 3656
n=int(input())
lst=list(map(int,input().split()))
aa=sum(lst) % (10**9+7)
# print(sum(lst) % (10**9+7) )
new_lst=[]
temp_1=aa
for i in range(n-1):
    temp_1-=lst[i]
    new_lst.append(temp_1)
# print(new_lst)

tem=0
for i in range(n-1):
    tem+=(lst[i] )*new_lst[i]
        # print(tem)
print(tem % (10**9 +7))

Measured memory_bytes: 101936
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (Isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar();
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define debug(x) cout << #x << " = " << x << endl;
#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

const int maxn = 2e5 + 30;
int n;
int a[maxn], b[maxn];
int cmp(int x, int y) {
	return x > y;
}
int main() {
	n = ri();
	for (int i = 1; i <= n; i++) {
		a[i] = ri();
	}
	for (int j = 1; j <= n; j++) {
		b[j] = ri();
	}
	sort(b + 1, b + 1 + n, cmp);
	int ok = 0, begin = n + 1, end = 1;
	for (int i = 1; i <= n; i++) {
		if (a[i] == b[i]) {
			ok = 1;
			begin = min(begin, i);
			end = max(end, i);
		}
	}
	if (ok == 0) {
		puts("Yes");
		for (int i = 1; i<= n; i++) {
			printf("%d ", b[i]);
		}
		return 0;
	}
	if (begin - 1 + (n - end) < (end - begin + 1)) {
		puts("No");
		return 0;
	}
	int delta = end - begin + 1;
	int pos = begin;
	for (int i = 1; i < begin; i++) {
		if (b[i] == b[pos] || a[i] == b[pos]) continue;
		swap(b[i], b[pos]); delta--;
		pos++;
		if (delta == 0) break;
	}
	if (delta ==0) {
		puts("Yes"); 
		for (int i = 1; i<= n; i++) {
			printf("%d ", b[i]);
		}
		return 0;
	}
	for (int i = end + 1; i <= n; i++) {
		if (b[i] == b[pos] || a[i] == b[pos]) continue;
		swap(b[i], b[pos]);
		pos++, delta--;
		if (delta == 0) break;
	}
	if (delta) {
		cout << "No" << endl; return 0;
	}
	puts("Yes"); 
	for (int i = 1; i<= n; i++) {
		printf("%d ", b[i]);
	}
	return 0;
}


Measured memory_bytes: 5324
# Sol : (n1 + n2)/2
# Ex : 
# Q : 16 - x = 2 - x
# => 16 + x = 2 + x
# => 16 + 2 = 2x
# => 18/2 = x
# => 9 = x
a = list(map(int, input().split()))
if ((a[0] + a[1]) // 2) * 2 != a[0] + a[1]:
    print("IMPOSSIBLE")
else:
    print(((a[0] + a[1]) // 2))

Measured memory_bytes: 2940
#include <iostream>
#include "string.h"
#include <algorithm>
#include <vector>
#include <stdio.h>
#include "math.h"
#include <queue>
using namespace std;

double abs(double x) {
    if (x < 0.0) return -x;
    return x;
}

int main() {

    int n;
    cin >> n;
    int t, a;
    cin>>t>>a;
    vector<int> v;

    for (int i=0; i<n; i++) {
        int x;
        cin>>x;
        v.push_back(x);
    }

    int best = 0;
    for (int i=0; i<n; i++) {
        if (abs(t - v[best]*0.006 - a) > abs(t - v[i]*0.006 - a)) {
            best = i;
        }
    }

    cout << best + 1 << endl;

    return 0;
}

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

int main()
{
	long n;
	cin >> n;
	long count =0;
	count += (n / 11) * 2;
	long t = n % 11;
	if(1 <= t &&t <= 6)
		count++;
	else if(7 <= t)
		count+=2;
  	else
      	;
	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.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 lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#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>;
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 PS(int x) {
  int a=1;
  repl(i,0,x) {
    a*=10;
  }
  return a;
}
int main() {
  string S;
  cin >> S;
  int keta=0;
  rep(i,S.size()) {
      keta +=(S.at(i)-'0');
  }
 
int Tot=0;
  rep(i,S.size()) {
Tot +=(S.at(i)-'0')*PS(S.size()-1-i);
  }
if(Tot%keta==0) {
cout<< "Yes"<< endl;
}
else {
cout <<"No" << endl;
}
}


Measured memory_bytes: 256
from collections import Counter, defaultdict, deque

S = input().rstrip()
N = len(S)


def isPalindrome(s):
    return s == s[::-1]


if (
    isPalindrome(S)
    and isPalindrome(S[: (N - 1) // 2])
    and isPalindrome(S[-1 + (N + 3) // 2 :])
):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include <iostream>
#include <limits>
#include <tuple>
#include <vector>

using namespace std;

int main() {
  int n, t_limit;
  cin >> n >> t_limit;
  
  vector<tuple<int, int>> routes;
  for (int i = 0; i < n; ++i) {
    int c, t;
    cin >> c >> t;
    tuple<int, int> tmp_tie = tie(c, t);
    routes.push_back(tmp_tie);
  }
  
  int smallest = numeric_limits<int>::max();
  for (int i = 0; i < n; ++i) {
    int c, t;
    tie(c, t) = routes[i];
    
    if (t <= t_limit && c < smallest) {
      smallest = c;
    }
  }
  
  if (smallest == numeric_limits<int>::max()) {
    cout << "TLE\n";
    return 0;
  }
  
  cout << smallest << "\n";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define chkmin(x, y) (x = min(x, y))
const int L = 200010;
long long dp[L][5], a[L];
int n;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
//	function<void(int,int) > dfs = [&](int x, int y)
//	{
//		
//	};
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = dp[0][4] = 0;
	for (int i = 1; i <= n; ++i)
	{
        long long cur = dp[i - 1][0];
		dp[i][0] = dp[i - 1][0] + a[i];
		dp[i][1] = chkmin(cur, dp[i - 1][1]) + (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][2] = chkmin(cur, dp[i - 1][2]) + ((a[i] + 1) & 1);
		dp[i][3] = chkmin(cur, dp[i - 1][3]) + (a[i] == 0 ? 2 : (a[i] & 1));
		dp[i][4] = chkmin(cur, dp[i - 1][4]) + a[i];
	}
	long long ans = (LL)1e18;
	for (int i = 0; i <= 4; ++i)
		ans = min(ans, dp[n][i]);
	cout << ans;
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <cmath>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;
typedef long long ll;

int N, P, A[50];

ll combination(ll n, ll r) {
  static ll comb[51][51];
  ll &ret = comb[n][r];
  if(ret != 0) return ret;
  if(n == 0 || r == 0) return ret = 1;
  if(n == r) return ret = 1;
  if(r == 1) return ret = n;
  return ret = combination(n - 1, r - 1) + combination(n - 1, r);
}

int main(void) {
  cin >> N >> P;
  REP(i, 0, N) cin >> A[i];

  ll cnt[2] = { 0, 0 };
  REP(i, 0, N) cnt[A[i] % 2]++;

  ll ans = 0;
  for(int i = 1; i <= cnt[1]; i += 2) ans += combination(cnt[1], i);
  ans *= pow(2, cnt[0]);
  if(P == 0) ans = pow(2, N) - ans;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Here your code !
#coding: utf-8

def Is_riku(coo):
    a = coo[0]
    b = coo[1]
    if 0 <= a < l[1] and 0 <= b < l[0] and \
    map_list[a][b] == 1:
        return True
    else:
        return False

while True:
    l = map(int, raw_input().split())
    if l == [0,0]:
        break
    else:
        coo_done = []
        map_list = []
        for i in range(l[1]):
            row = map(int,raw_input().split())

            map_list.append(row)
            for k in range(l[0]):
                coo_done.append((i,k))

        stack = []
        arrived = []
        count = 0

    while coo_done:
        coo = coo_done.pop()
        if Is_riku(coo):
            stack.append(coo)
            arrived.append(coo)
            while stack:
                coo = stack.pop()
                coo_a = (coo[0], coo[1] + 1)
                coo_b = (coo[0], coo[1] - 1)
                coo_c = (coo[0] + 1, coo[1])
                coo_d = (coo[0] - 1, coo[1])
                coo_e = (coo[0] + 1, coo[1] + 1)
                coo_f = (coo[0] + 1, coo[1] - 1)
                coo_g = (coo[0] - 1, coo[1] + 1)
                coo_h = (coo[0] - 1, coo[1] - 1)
                coo_l = [coo_a, coo_b, coo_c, coo_d, coo_e, coo_f, coo_g, coo_h]
                for c in coo_l:
                    if Is_riku(c) and c not in arrived:
                        stack.append(c)
                        arrived.append(c)
                        if c in coo_done:
                            coo_done.remove(c)
            count = count + 1

    print count
            

Measured memory_bytes: 6620
n = int(input())
dollar = [int(input()) for i in range(n)]
m = dollar[0]
max = dollar[1] - m

for i in range(1, n):
    if dollar[i] - m > max:
        max = dollar[i] - m
    if dollar[i] < m:
        m = dollar[i]
print(max)


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

int main() {
  string str;
  cin >> str;
  int l = str.length();
  int ret = 0;
  char pre = str[0];
  for (int i = 0; i < l; i++) {
    if (pre != str[i]) {
      ret++;
    }
    pre = str[i];
  }
  cout << ret << endl;
}


Measured memory_bytes: 512
S = input()
ans = "Yes"
for i in range(len(S)):
    if i%2 == 0:
        if S[i] not in ["R", "U", "D"]:
            ans = "No"
    else:
        if S[i] not in ["L", "U", "D"]:
            ans = "No"
print(ans)

Measured memory_bytes: 38256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int V[100000];
long long C;
long long X[100000];
long long dp1x[100001];
long long dp1y[100001];
long long dp2x[100001];
long long dp2y[100001];
int main(){
  int i;
  long long s;
  long long res = 0;
  rd(N);
  rd(C);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(X[Lj4PdHRW]);
      rd(V[Lj4PdHRW]);
    }
  }
  s = 0;
  for(i=(0);i<(N);i++){
    s += V[i];
    dp1x[i+1] =max_L(dp1x[i], s - X[i]);
    dp2x[i+1] =max_L(dp2x[i], s - 2*X[i]);
  }
  s = 0;
  for(i=(0);i<(N);i++){
    s += V[N-1-i];
    dp1y[i+1] =max_L(dp1y[i], s - (C-X[N-1-i]));
    dp2y[i+1] =max_L(dp2y[i], s - 2*(C-X[N-1-i]));
  }
  for(i=(0);i<(N+1);i++){
    chmax(res, dp1x[i] + dp2y[N-i]);
  }
  for(i=(0);i<(N+1);i++){
    chmax(res, dp1y[i] + dp2x[N-i]);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// int N, V[1d5]; ll C, X[1d5];
// ll dp1x[100001], dp1y[100001], dp2x[100001], dp2y[100001];
// {
//   ll s, res = 0;
//   rd(N,C,(X,V)(N));
// 
//   s = 0;
//   rep(i,N){
//     s += V[i];
//     dp1x[i+1] = max(dp1x[i], s - X[i]);
//     dp2x[i+1] = max(dp2x[i], s - 2X[i]);
//   }
// 
//   s = 0;
//   rep(i,N){
//     s += V[N-1-i];
//     dp1y[i+1] = max(dp1y[i], s - (C-X[N-1-i]));
//     dp2y[i+1] = max(dp2y[i], s - 2(C-X[N-1-i]));
//   }
// 
//   rep(i,N+1) res >?= dp1x[i] + dp2y[N-i];
//   rep(i,N+1) res >?= dp1y[i] + dp2x[N-i];
//   wt(res);
// }


Measured memory_bytes: 4480
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (w, h, x, y) = (v[0], v[1], v[2], v[3]);
    let mut flag = 0;
    if x * 2 == w && y * 2 == h {
        flag = 1;
    }
    println!("{} {}", (w * h) as f64 / 2.0, flag);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn n int
#define ll long long 
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define globalbool 2000000
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	int A[n][3];
	in(n)
		inj(3)
			cin>>A[i][j];
	int dp[n][3]={0};
	dp[0][0]=A[0][0];dp[0][1]=A[0][1];dp[0][2]=A[0][2];
	for(int i=1;i<n;i++)
	{
		int choice=0;
		inj(3)
		{
			if(j!=choice)
				dp[i][choice]=max(dp[i][choice],A[i][choice]+dp[i-1][j]);
		}
		choice=1;
		inj(3)
		{
			if(j!=choice)
				dp[i][choice]=max(dp[i][choice],A[i][choice]+dp[i-1][j]);
		}
		choice=2;
		inj(3)
		{
			if(j!=choice)
				dp[i][choice]=max(dp[i][choice],A[i][choice]+dp[i-1][j]);
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

antenna= []
for i in range(5):
    antenna.append(int(input()))
k = int(input())

reach = True

for i in range(5):
    for j in range(5):
        if antenna[i]-antenna[j] > k:
            reach = False

if reach == True:
    print("Yay!")
else:
    print(":(")
    

Measured memory_bytes: 2940
import sys

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))


n=II()
A=LI()
B=LI()
C=LI()

ans = 0
before = -1

for i in range(n):
    ans+=B[A[i]-1]
    if before == A[i] - 1:
        ans+=C[A[i-1]-1]
    before = A[i]
print(ans)

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

using namespace std;
using ll = long long;

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    
    if (s == "ABC")
        cout << "ARC";
    else
       cout << "ABC";
}

Measured memory_bytes: 3648
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include<bits/stdc++.h>
using namespace std;

#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test int t;cin>>t;while(t--)
#define X first
#define Y second
#define pb push_back
#define all(s) s.begin(),s.end()

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

const int MOD = 1e9+7;

ll n,W;
ll w[100],v[100];

ll recur(int r, int idx, vector<vector<ll>> &dp){
    if(r<=0) return 0;
    if(idx==n) return 1e11;
    if(dp[idx][r]!=-1) return dp[idx][r];

    dp[idx][r] = min(recur(r,idx+1,dp),recur(r-v[idx],idx+1,dp)+w[idx]);
    return dp[idx][r];
}

void solve(){
    cin >> n >> W;
    ll sum = 0;
    for(int i=0;i<n;i++){
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(sum+1,-1));

    ll ans = 0;
    for(int i=sum;i>=0;i--){
        if(recur(i,0,dp)<=W){
            ans = i;
            break;
        }
    }
    cout << ans;

}

int main(){
    FIN;   
    // test
    solve();
}

Measured memory_bytes: 80256
#include <iostream>
#include <vector>
#include <numeric>
 
using namespace std;
 
int main(){
    while(true){
        // N, M, P ?????\???
        int n, m, p;
        cin >> n >> m >> p;
 
        // 0 0 0 ????????????
        if(n == 0 && m == 0 && p == 0)
            return 0;
 
        //x ?????\???
        vector<int> x(n);
        for(auto &a:x)
            cin >> a;
 
        // ????????????????????????
        if(x[m - 1] == 0){
            cout << 0 << endl;
            continue;
        }
 
        //????テつィ??????????
        int sum = accumulate(x.begin(), x.end(), 0) * 100;
        //?????????????????????
        double total = sum * (100 - p) / 100;
        //????????????
        int money = total / x[m - 1];
 
        cout << money << endl;
    }
 
    return 0;
}

Measured memory_bytes: 3044
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 19:43:38 2020

@author: liang
"""

N = int(input())
H = [int(x) for x in input().split()]

ans = 0
count = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        count = 0
    if ans < count:
        ans = count
print(ans)

Measured memory_bytes: 19852
s = input() # all
t = input() # substring

def calc_length(str1, str2):
    length = 0
    for i in range(len(str1)):
        if str1[i] != str2[i]:
            length += 1
    return length

min_length = len(t)
for i in range(len(s)- len(t) + 1):
    l = calc_length(s[i:i+len(t)], t)
    if l < min_length:
        min_length = l

print(min_length)


Measured memory_bytes: 9124
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, startA, startB, endA, endB;
	string str;
	cin >> n >> startA >> startB >> endA >> endB;
	cin >> str;

	string result = "Yes";

	if (endB < endA) {
		int point = str.find("...", startB - 2);
		if (point == -1 || point > endB - 2)
			result = "No";
	}

	int point = str.find("##", startA);
	if (point != -1 && (point < endA || point < endB))
		result = "No";

	cout << result << endl;
	/*
		endA < endBなら
	*/
}


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()
#define dump(v) (cerr << #v << ": " << v << endl)
#define cerr                                                                   \
  if (true)                                                                    \
  cerr

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long N, vector<long long> a) {
  ll all = 0;
  ll ans = 1LL << 50;

  vll aa(N, 0);
  REP(i, N) {
    aa[i] = a[i];
    if (i != 0)
      aa[i] += aa[i - 1];
  }

  all = aa[N - 1];

  FOR(i, 0, N - 1) { ans = min(ans, abs(all - 2LL * aa[i])); }

  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long N;
  cin >> N;
  vector<long long> a(N - 1 + 1);
  for (int i = 0; i <= N - 1; i++) {
    cin >> a[i];
  }
  solve(N, a);
  return 0;
}


Measured memory_bytes: 4992
import re

def BubbleSort(C, N, A):
    for i in range(0,N,1):
        for j in range(N-1, i, -1):
            #print(str(N)+' '+str(i)+' '+str(j))
            if C[j] < C[j-1]:
                C[j],C[j-1] = C[j-1],C[j]
                A[j],A[j-1] = A[j-1],A[j]
            #print(A)
    return A

def SelectionSort(C, N, A):
    for i in range(0,N,1):
        minj = i
        for j in range(i,N,1):
            #print(str(N)+' '+str(i)+' '+str(j))
            if C[j] < C[minj]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
        A[i], A[minj] = A[minj], A[i]
        #print(A)
    return A

if __name__ == '__main__':
    #print(list(range(0,5,1)))
    N = int(input())
    A = input()
    C = list(map(int,re.sub(r'\D', ' ', A).split()))
    CC = list(re.sub(r'[^A-Z]', ' ', A).split())
    A = A.split()

    BSA = BubbleSort(C[:],N,A[:])
    print(' '.join(BSA))
    print('Stable')
    SSA = SelectionSort(C[:],N,A[:])
    print(' '.join(SSA))
    print('Stable' if (BSA == SSA) else 'Not stable')
    








Measured memory_bytes: 6548