akhauriyash/Code-Regression huggingface dataset:
# D - Prediction and Restriction
N,K = map(int,input().split())
score = list(map(int,input().split()))
T = input()

# dp[i][j]: i回目のじゃんけんで j を出したときの最大の合計点数
# グー: 0, チョキ: 1, パー: 2
dp = [[0]*3 for _ in range(N+1)]

def judge(a,b):
    # パーで勝つとき
    if a == 'r' and b == 2:
        return score[2]
    # グーで勝つとき
    elif a == 's' and b == 0:
        return score[0]
    # チョキで勝つとき
    elif a == 'p' and b == 1:
        return score[1]
    return 0
    
# i 回目のじゃんけん
for i in range(1,N+1):
    # i回目のじゃんけんで j を出したとき
    for j in range(3):
        # i-K 回目のじゃんけんで k を出したとき
        for k in range(3):
            # i = K 回以上のとき
            if i > K:
                # K 回前と同じ手を出したらスルー
                if j == k:
                    continue
            # i < K 回のとき
            else:
                # 勝ち続けるのが最適
                dp[i][j] = judge(T[i-1],j)
                continue
            # K 回前に k を出したときの得点に、j を出して得た得点を加点
            dp[i][j] = max(dp[i][j],dp[i-K][k] + judge(T[i-1],j))

ans = 0
for a in dp[-K:]:
    ans += max(a)
print(ans)

Measured memory_bytes: 28912
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll              long long
#define pi              pair<int,int>
#define pll             pair<ll,ll>
#define pb              push_back
#define F               first
#define S               second
#define vi              vector<int>
#define vll             vector<ll>
#define endl            '\n'
#define all(v)          (v).begin(),(v).end()
#define MP(a,b)         make_pair(a,b)
#define debug(x)        cerr<< #x << " : " << x << endl;
#define debugp(p)       cerr<< #p << " : " << "(" << (p).first << "," << (p).second << ")\n";
#define debugv(v)       cerr<< #v << " : " << "["; for(int i = 0; i < (v).size(); i++) cerr << v[i] << " "; cerr<<"]\n";
#define debugs(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<*itr << " "; cerr << "]\n";
#define debugm(m)       cerr<< #m << " : [ "; for(auto itr = m.begin(); itr != m.end(); itr++) cerr <<"(" << itr->first << "," << itr->second << ") "; cerr << "]\n";

/* ordered set: 
tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
member functions :
1. order_of_key(k) : number of elements strictly lesser than k
2. find_by_order(k) : k-th element in the set
*/

inline ll modexp(ll x, ll ex , ll md) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}

const int inf = 1e9 + 7;

void solve(){
    int n , k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort (all (p));
    ll sum = 0;
    int i = 0;
    while (k--){
        sum += p[i++];
    }
    cout << sum << endl;
}
int main(){
    ios :: sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr);
    
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    #ifdef LOCAL
    cerr << "Time elapsed\t: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";       
    #endif
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
#define coa cout << ans << endl
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


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

    int ans = 0;
    for(int i = a; i <= b; i++){
        string s = to_string(i);
        auto iter0 = s.begin();
        auto iter9 = s.rbegin();
        if(*iter0 == *iter9 && *(iter0 + 1) == *(iter9 + 1)) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3668
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

#define ll0 (long long)0

int main()
{
	long long a,b,k;
	cin >> a >> b >> k;
	cout << max(ll0,a-k) << " " << max(ll0,b-max(ll0,k-a)) << endl;




}


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

m = sum(W)
for i in range(N):
  s1 = sum(W[0:i])
  s2 = sum(W[i:])
  if m > abs(s1-s2):
    m = abs(s1-s2)
print(m)

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const ll INF = 1001001001001;
const int MOD = 1000000007;

int main(){
    ll A, B;
    cin >> A >> B;

    if (A > B) swap(A, B);

    vector<ll> v;
    for (int i = 1; (ll)i * i <= A; ++i) {
        if (A % i != 0) continue;
        if (B % i == 0) v.emplace_back(i);
        ll j = A / i;
        if (i != j && B % j == 0) v.emplace_back(j);
    }

    auto f = [&](ll x){
        if (x == 1) return true;
        for (int i = 2; (ll)i * i <= x; ++i) {
            if (x % i == 0) return false;
        }
        return true;
    };

    int ans = 0;
    for (auto &i : v) {
        if (f(i)) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3732
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long X[114514];
long long justX[114514];

int main() {
    int N,K;cin >> N >> K;
    for(int i = 0;i<114514;i++)X[i] = 0;
    //gcd{A}がXの倍数になるようなAの選び方は(K/i)^N通り
    for(int i = K;i>0;i--){
        int A = K/i;
        X[i] = mod_pow(A,N);
        //2*X,3*X…の通りを引いていく
        int times = 2;
        while(times*i <= K){
            X[i] -= X[times*i];
            X[i] %= MOD;
            times++;
        }
    }
    
    long long ans = 0;
    for(long long i = 1;i<=K;i++){
        ans += (i*X[i])%MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 4548
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
typedef long long ll;
using namespace std;

int main() {
    int n, k, ans = 0;
    cin >> n >> k;
    vector<int>x(n);
    for(int i = 0; i < n; i++) cin >> x[i];
    for(int i = 0; i < n; i++) ans += min(2 * x[i], 2 * (k-x[i]));
    cout << ans << endl;
}

Measured memory_bytes: 256
#coding utf-8
N,K=map(int,input().split())
S=input()
LRf=-1
RLf=-1
ans=0
for i in range(N-1):
  if S[i:i+2]=="LL" or S[i:i+2]=="RR":
    ans+=1

for i in range(N-1):
  if K==0:
    break
  if S[i:i+2]=="LR" and RLf==-1:
    LRf=i
  elif S[i:i+2]=="RL" and LRf>=0:
    LRf=-1
    ans+=2
    K-=1
  elif S[i:i+2]=="RL" and LRf==-1:
    RLf=i
  elif S[i:i+2]=="LR" and RLf>=0:
    RLf=-1
    ans+=2
    K-=1
  if i==N-2:
    if RLf>=0 or LRf>=0:
      ans +=1
      K-=1

print(ans)    

Measured memory_bytes: 3316
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
#include <memory>
#include <time.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXIST2(s,e) (find(ALL(s),(e))!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

int main(){
	int n,k,s;
	while(cin>>n>>k>>s,n|k|s){
		int ans=0;
		REP(mask,1<<n){
			int bits=0;
			int sum=0;
			REP(i,n){
				if((mask>>i)&1){
					bits++;
					sum+=i+1;
				}
			}
			if(bits==k&&sum==s){
				ans++;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
  int H, W;
  char c[N][N];
  int a[N][N] = {0};

  cin >> H >> W;

  rep(i,H){
    rep(j,W){
      cin >> c[i+1][j+1];
    }
  }  

  rep(i,H){
    rep(j,W){
      if(c[i+1][j+1] == '#'){
        rep(p,3){
          rep(q,3){
            a[(i+1)-(p-1)][(j+1)-(q-1)] += 1;
          }
        }        
      }
    }
  }
  
  rep(i,H){
    rep(j,W){
      if(c[i+1][j+1] != '#'){
        cout << a[i+1][j+1];          
      }
      else{
        cout << '#';          
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
bool same( string s)
{
    int n=s.length();
    for(int i=1;i<n;i++)
        if (s[i]!= s[0])
            return false;

        return true;
}
 int main()
 {
     string s;
     cin>>s;
     if (same(s)){
     cout<<"No"<<endl;
     }
     else
        cout<<"Yes"<<endl;
     return 0;
 }





Measured memory_bytes: 256
N = int(input())
res_list = []
for i in range(N//4+1):
    for j in  range(N//7 + 1):
        if i*4 + j * 7 <=N:
            res_list.append(i*4 + j * 7)
if N in res_list:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int main(int argc, char const* argv[])
{
  string S;
  cin >> S;
  int64_t zeros = 0, ones = 0;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == '0') {
      zeros++;
    } else {
      ones++;
    }
  }
  printf("%ld\n", min(zeros, ones)*2);

  return 0;
}


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

const int MAX_=1000000;
map<int,bool> is_mon_sat_prime;
vector<int> mon_sat_prime;
vector<int> mon_sat_number;

void sieve(){
	for(auto it=mon_sat_number.begin(); it!=mon_sat_number.end(); ++it){
		is_mon_sat_prime[*it]=true;
	}
	is_mon_sat_prime[1]=false;
	for(auto it=mon_sat_number.begin(); it!=mon_sat_number.end(); ++it){
		if(it==mon_sat_number.begin()) ++it;
		if(is_mon_sat_prime[*it]){
			mon_sat_prime.push_back((*it));
			for(auto it_=mon_sat_number.begin(); (*it_)*(*it)<MAX_; ++it_){
				if(it_==mon_sat_number.begin()) ++it_;
				is_mon_sat_prime[(*it_)*(*it)]=false;
			}
		}
	}
}

void init(){
	for(int i=0; 6+i<MAX_ ; i+=7){
		mon_sat_number.push_back(6+i);
		mon_sat_number.push_back(1+i);
	}
	sort(mon_sat_number.begin(),mon_sat_number.end());
	sieve();
}

void solve(int n){
	vector<int> ans;
	int tmp=n;
	for(auto it=mon_sat_prime.begin(); (*it)<=n; ++it){
		if(n%(*it)==0){
			ans.push_back(*it);
		}
	}
	sort(ans.begin(),ans.end());
	cout << tmp << ": ";
	for(auto it=ans.begin(); it!=ans.end(); ++it){
		cout << *it;
		if(++it==ans.end()){
			cout << endl;
		} else {
			cout << ' ';
		}
		--it;
	}
}

int main(){
	init();
	int N;
	while(cin >> N&&N!=1){
		solve(N);
	}
	return 0;
}

Measured memory_bytes: 20180
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  
  //スペース区切り　input[0] が tmp[0], input[1],...
	tmp = input[0].split(" ");
  
  //この時点では全部文字列（数値に変換しないといけない）

	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
    var ab = a*b;
	//出力
    if(ab%2 == 0){
      
      console.log('%s', 'Even');
    }else{
      console.log('%s', 'Odd'); 
    }
	
  
  //%は符号付き10進数, %sは文字列
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){
    int n, m;
    cin >> n >> m;
    V<int> a(m), b(m);
    V<V<int>> c(m, V<int>(n));
    rep(i,m) {
        cin >> a[i] >> b[i];
        rep(j,b[i]) {
            int d;
            cin >> d;
            c[i][d-1] = 1;
        }
    }

    V<V<int>> dp(m+1, V<int>(1<<n));
    rep(i,m+1)rep(j,(1<<n)) dp[i][j] = inf;
    dp[0][0] = 0;
    rep(i,m) {
        rep(j,(1<<n)) {
            int bit = j;
            rep(k,n) if(c[i][k]) bit |= (1<<k);
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][bit], dp[i][j] + a[i]);
        }
    }
    int ans = inf;
    Rep(i,m) {
        chmin(ans, dp[i][(1<<n)-1]);
    }
    if(ans == inf) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 19260
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MAX_N = 1000000;

bool prime[MAX_N];
VI primes;
bool isprime(int x){
  if(x < MAX_N) return prime[x];

  int sq = sqrt(x) + 1;
  for(int i=0;primes[i]<=sq;++i)
	if(x % primes[i] == 0) return false;
  return true;
}

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

  fill(prime, prime+MAX_N, true);
  for(int i=2;i<MAX_N;++i)
	if(prime[i]){
	  primes.PB(i);
	  for(int j=i+i;j<MAX_N;j+=i)
		prime[j] = false;
	}

  int N; cin >> N;
  int ans = 0;
  REP(i,N){
	int x; cin >> x;
	if(isprime(x)) ++ans;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2604
n = int(input())
P = input().split()
count = 0
for i in range(n):
  P[i] = int(P[i])

for i in range(1,n-1):
  _ = [P[i-1],P[i],P[i+1]]
  _.sort()
  if P[i] == _[1]:
    count +=1

print(count)


Measured memory_bytes: 2940
<?php
  $n = trim(fgets(STDIN));
  $a = explode(" ",trim(fgets(STDIN)));
  $count = 0;
  $num = [];
  for($i=0; $i<$n; $i++) $num[] = $i+1;
  $j=0;
  for ($i=0; $i<$n; $i++){
    if($a[$i] == $num[$j]) {
      $j++;
      $count++;
    }
  }
  if ($count > 0)echo count($a)-$count."\n";
  else echo "-1\n";

Measured memory_bytes: 29164
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoderSolve.Tool;

namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();
            int N = int.Parse(Console.ReadLine());
            long M = 0;
            List<Tuple<int, int>> ans = new List<Tuple<int, int>>();

            if (N % 2 != 0)
            {
                for(var i = 1; i <= N-1; i++)
                {
                    M++;
                    ans.Add(new Tuple<int, int>(N, i));
                }
                N--;
            }
            for (var i = 1; i <= N; i++)
            {
                for (var j = 1; j <= N; j++)
                {
                    if (i < j && j != i && j != N - i + 1)  
                    {
                        M++;
                        ans.Add(new Tuple<int, int>(i, j));
                    }
                }
            }

            Console.WriteLine(M);
            foreach(var e in ans)
            {
                Console.WriteLine($"{e.Item1} {e.Item2}");
            }


            //Console.Out.Flush();
        }

        

    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for(var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }

    struct Pair<T> : IComparable<Pair<T>> where T : IComparable<T>
    {
        public T variable;
        public int index;

        public Pair(T val, int i)
        {
            variable = val;
            index = i;
        }

        public int CompareTo(Pair<T> otherPair)
        {
            return variable.CompareTo(otherPair.variable);
        }

        public int CompareIndex(Pair<T> otherPair)
        {
            return index.CompareTo(otherPair.index);
        }
    }



}






Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

constexpr int C = 1000000007;
  
int main()
{ 
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
  
  unsigned H, W;
  std::cin >> H >> W; 
  vector<vector<char>> arr(H, vector<char>(W));
  vector<vector<int>> dp(H, vector<int>(W, 0));
    
  for (auto& h : arr)
  {   
    for (auto& w : h)
    { 
      std::cin >> w;
    } 
  } 
    
  for (size_t j = W; j > 0; --j)
  {   
    if (arr[H-1][j-1] == '#') break;
    dp[H-1][j-1] = 1;
  }
  
  for (size_t i = H-1; i > 0; --i)
  {
    for (size_t j = W; j > 0; --j)
    {
      size_t a = i-1, b = j-1;
      if (arr[a][b] == '#') continue;
      if (b+1 == W)
      {
        dp[a][b] = dp[a+1][b];
      }
      else
      {
        dp[a][b] = (dp[a+1][b] + dp[a][b+1]) % C;
      }
    }
  }

  std::cout << dp[0][0];

  return 0;
}

Measured memory_bytes: 7168
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M);
  for(int i=0; i<M; i++){
    cin >> X[i];
  }
  if(N >= M){
    cout << 0 << endl;
    return 0;
  }
  sort(X.begin(),X.end());
  vector<int> sa;
  int ans = 0;
  for(int i=0; i<M-1; i++){
    sa.push_back(X[i+1]-X[i]);
    ans += X[i+1] - X[i];
  }
  sort(sa.begin(),sa.end(),greater<int>());
  for(int i=0; i<N-1; i++){
    ans -= sa[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//


signed main()
{
  ios();
  int N,M;
  cin >> N;
  cin >> M;
  vector<pair<int,int>> v(M);
  for(int i=0;i<M;i++){
    cin >> v[i].first >> v[i].second;
  }
  sort(ALL(v),[](auto a, auto b){ return a.second < b.second;});
  int x = v[0].second-1;
  int cnt = 1;
  rep(i,M-1)
  {
    if(x >= v[i+1].first)
    {
      continue;
    }
    cnt ++ ;
    x = v[i+1].second -1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
#define mod 1000000007
typedef long long ll;
ll fact[200010];

ll exp(ll a, ll b) {
  ll ans = 1;
  while(b) {
    if(b & 1) ans *= a;
    a *= a, b >>= 1, ans %= mod, a %= mod;
  }
  return ans;
}

ll cmb(ll a, ll b) {
  return (fact[a] * ((exp(fact[b], mod - 2) * exp(fact[a - b], mod - 2)) % mod)) % mod;
}

int main(void) {
  ll i, j, h, w, a, b, ans = 0;
  scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
  fact[0] = fact[1] = 1;
  for(i = 2; i <= h + w; ++i) fact[i] = (fact[i - 1] * i) % mod;
  for(i = b; i < w; ++i) ans += cmb(i + (h - a - 1), i) * cmb(a - 1 + (w - i - 1), a - 1), ans %= mod;
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1664
#include <algorithm>
#include <chrono>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vi2;
typedef vector<vi2> vi3;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vll> vll2;
typedef vector<vll2> vll3;
typedef vector<bool> vb;

#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)
#define repeat(n) for (int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define vec vector
#define loop(a) for (auto &x : a)
#define all(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back

template <typename T>
void debug0(const T &value) {
    cerr << value << endl;
}

template <typename T, typename... Args>
void debug0(const T &value, const Args &... args) {
    cerr << value << ' ';
    debug0(args...);
}

#ifdef LOCAL
#define debug(...) debug0(__VA_ARGS__)
#else
#define debug(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int n;
    cin >> n;
    vi2 adj(n);
    rep(i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    ll f1 = 0;
    ll ans = 0;
    repi(L, n - 1, 0) {
        ll f2 = f1 + (n - L);
        loop(adj[L]) {
            if (L < x) {
                f2 -= n - x;
            }
        }
        f1 = f2;
        debug("L", L, "f1", f1);
        ans += f1;
    }
    cout << ans << el;
}


Measured memory_bytes: 15108
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) v.begin(),v.end()

const int MOD = 1000000007;
const int MAX = 5100000;
ll gcd(ll a, ll b) {
    return (b==0) ? a : gcd(b, a%b);
}

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
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] % MOD) % MOD;
}

// 以下から
const int MAX_N = 100000;
struct Edge {
    int to;
    int id;
};

const int D = 80 * 160 + 10;
const int D2 = D*2;
typedef bitset<D2> bs;
int a[100][100];
bs dp[90][90];



const int N = 20;
int h;
int w;
vector<vector<char>> maze(N, vector<char>(N,'#'));

const int MAX_WH = 21;
int d[MAX_WH][MAX_WH];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
const int INF = 100000;
int bfs(int x, int y) {
    queue<P> que;
    rep(i,MAX_WH) {
        rep(j,MAX_WH) {
            d[j][i] = INF;
        }
    }
    que.push(P(x,y));
    d[x][y] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        for (int i=0; i< 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[nx][ny] != '#' && d[nx][ny] == INF) {
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    int mx = 0;
    rep(i,h) rep(j,w) {
            if (d[j][i] == INF) continue;
            mx = max(mx, d[j][i]);
        }
    return mx;
}

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}
void dfs(){

}
const int MX = 100000;
vector<int> G[MX];
int main(){
    int a,b; cin >> a >> b;
    stringstream ss1;
    stringstream ss2;
    rep(i,b) {
        ss1 << a;
    }
    rep(i,a) {
        ss2 << b;
    }
    string ans = ss1.str() < ss2.str() ? ss1.str() : ss2.str();
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(p[i]!=i+1) count++;
    }
    if(count<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
void Main(){
    string S;cin>>S;
    int left=0,right=S.size()-1;
    while(true){
        if(S[left]=='A') break;
        left++;
    }
    while(true){
        if(S[right]=='Z') break;
        right--;
    }
    cout<<right-left+1<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 640
/*
 * main.c
 *
 *  Created on: 2019/07/21
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int M = 0, D = 0;
	int i = 0, j = 0, ans = 0;
	scanf("%d %d", &M, &D);
	for (i = 2; i <= M; i++) {
		for (j = 20; j <= D; j++) {
			if ((j%10) < 2) {
				continue;
			}
			if (i == (j/10) * (j%10)) {
				//printf("%d %d\n",i, j);
				ans++;
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

typedef long long ll;

const int N=100500;
int OO=0x3f3f3f3f;
ll linf=1e15;

vector<int>adj[N];
int mem[N];
bool vis[N];

int solve(int idx)
{
    vis[idx]=true;
    if(mem[idx]!=-1)
        return mem[idx];
        int mx=0;
    for(int i=0;i<adj[idx].size();++i)
    {
        mx=max(mx,solve(adj[idx][i])+1);
    }
    return mem[idx]=mx;
}

int main() {

    int n,m,u,v;
    cin>>n>>m;
    for(int i=0;i<=n;++i)
        mem[i]=-1;
    while(m--)
    {
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    int mx=0;
    for(int i=0;i<n;++i)
    {
        if(!vis[i])
        {
            mx=max(mx,solve(i));
        }
    }
    cout<<mx;
    /*mx=0;
    for(int i=0;i<n;++i)
    {
        mx=max(mx,mem[i]);
    }
    cout<<mx;*/

	return 0;
}


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


int main(){
	string input;
	cin >> input;
	string hint;
	cin >> hint;
	bool ok = false;
	int latest = -1;
	if(input.size() < hint.size()){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for(int j=0;j<=input.size()-hint.size();j++){
		for(int i=0;i<hint.size();i++){
			if(input[j+i] == '?'){
				ok = true;
			}else if(input[j+i] == hint[i]){
				ok = true;
			}else{
				ok = false;
				break;
			}
		}
		if(ok){
			latest = j;
		}
	}
	if(latest == -1){
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for(int i=0;i<input.size();i++){
		if(i != latest){
			if(input[i] == '?'){
				cout << "a";
			}else{
				cout << input[i];
			}
		}else{
			for(int j=0;j<hint.size();j++){
				cout << hint[j];
			}
			i += hint.size()-1;
		}
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

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

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


signed main(){
    int n,k;cin>>n>>k;
    ll a[n];
    rep(i,n) cin>>a[i];
    long double b[n];
    rep(i,n)b[i]=log(a[i]);
    long double s=0;
    rep(i,k){
        s+=b[i];
    }

    for(int i=k;i<n;i++){
        long double ps=s;
        s-=b[i-k];
        s+=b[i];
        if(s>ps) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#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 FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};



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

  ll h,n;
  cin>>h>>n;
  vll a(n),b(n);
  REP(i,n)cin>>a[i]>>b[i];

//  vector<pair<ld,pll>> p(n);
//  REP(i,n){
//    p[i].FI = a[i]*1.0/b[i];
//    p[i].SE.FI=a[i];
//    p[i].SE.SE=b[i];
//  }


  ll dp[h+1];
  REP(i,h+1)dp[i]=LLINF;
  dp[0] = 0;

  REP(i,n){
    REP(j,h+1){
      if(dp[j]==LLINF)
        continue;

      ll k = j+a[i];
      if(k>h)
        k=h;
      dp[k] = min(dp[k], dp[j]+b[i]);
    }
  }

  cout << dp[h] << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <regex>
#define FOR(i, s, e) for (ll i = ll(s); i < ll(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
#define mkpr make_pair
#define EPR(msg) cerr << msg << endl;
#define AST(exp, msg) if(!exp){EPR(msg)} assert(exp);
#define TAST(exp, msg) if(!exp){EPR(msg)} while(!exp){}
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vc = vector<char>; using vvc = vector<vc>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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

  const ll HMAX = 10, WMAX = 1000;
  ll H, W, K; cin>>H>>W>>K;
  vs S(H); REP(i,H) cin>>S[i];

  // H 行の行間の H-1 ラインを切るか切らないかのパターン
  const ll HPTN = 1LL<<(H-1);
  ll ans = LINF;

  REP(ptn, HPTN) {
    vl hgp;  // 水平方向にわけたグループに含まれる 1 の数
    vl i2g(H, 0);  // i 行目は g グループに属する
    
    REP(i, H) {
      i2g[i] = hgp.size();
      if ((1LL<<i) & ptn) { // i 行目の下を切るなら
        hgp.push_back(0);
      }
    }
    hgp.push_back(0);  // 最後の行の下は切ると考える

    const ll GSZ = hgp.size();
    AST(i2g[0] == 0, "最初の行は最初のグループに属する");    
    AST(i2g[H-1] == GSZ-1, "最後の行は最後のグループに属する");
    
    ll hcut = GSZ-1;

    // 行を水平グループに分けたグリッドを求めておく
    vvl gd(GSZ, vl(W, 0));
    REP(i,H) {
      REP(j,W) {
        ll g = i2g[i];
        gd[g][j] += S[i][j] - '0';
      }
    }

    auto can_add = [&](const vl hgp, const int J) {
      vl gp = hgp;
      REP(g, GSZ) gp[g] += gd[g][J];
      REP(g, GSZ) {
        if (gp[g]>K) return false;
      }
      return true;
    };

    // j 列目を各グループに加算してみる
    ll vcut = 0;
    bool ok = true;
    REP(j, W) {
      if (can_add(hgp, j)) {
        REP(g, GSZ) hgp[g] += gd[g][j];
      } else {
        // リセット
        vcut++;
        hgp = vl(GSZ, 0);
        if (can_add(hgp, j)) {
          REP(g, GSZ) hgp[g] += gd[g][j];
        } else {
          ok = false;
          break;
        }
      }
      if (!ok) break;
    }
    if (!ok) vcut = LINF;

    ans = min(ans, hcut+vcut);
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
int main(void)
{
	int B[2];
	int sum;
	cin >> B[0] >> B[1];
	for (int i = 0; i < 2; i++)
	{
		if (B[0] >= B[1])
		{
			sum += B[0];
			B[0]--;
		}
		else
		{
			sum += B[1];
			B[1]--;
		}
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps DBL_EPSILON
#define moder 10007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
string s;
signed main(){
	cin>>s;
	int ans=0;
	int cnt=0;
	rep(i,s.size()){
		if(s[i]=='W'){
			ans+=i-cnt;
			cnt++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

n = int(input())
e = [[int(i) for i in input().split()] for i in range(n)] 
for i in e:
    a = max(i)
    i.remove(a)
    if a*a == i[0]*i[0]+ i[1]*i[1]:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 7880
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define mp map<int,int>
#define vi vector<int>
#define M INT_MAX
#define MI INT_MIN
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
int main()
{
	ll x,y;
	cin>>x>>y;
	if(x%y==0)
	{
		cout<<"0"<<endl;
	}
	else if(x>y)
	{
		ll d=(x/y);
		ll K=(d+1)*y-x;
		cout<<K<<endl;
	}
	else
	{
	ll diff=abs(x-y);
	ll sec=abs(diff-y);
	cout<<min(diff,sec)<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>
#include <string>

int main() {
  size_t n;
  char buf[128];
  scanf("%zu %s", &n, buf);
  std::string s = buf;

  size_t res = 0;
  for (size_t i = 1; i < n; ++i) {
    std::string s0 = s.substr(0, i);
    std::string s1 = s.substr(i);
    std::set<char> t0(s0.begin(), s0.end());
    std::set<char> t1(s1.begin(), s1.end());
    size_t cur = 0;
    for (auto c: t0)
      if (t1.count(c)) ++cur;
    res = std::max(res, cur);
  }
  printf("%zu\n", res);
}


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


bool isKainbun(string str){
    string s=str;
    reverse(str.begin(),str.end());

    for(int i=0;i<s.size();i++){
        if(s[i]!=str[i])return false;
    }
    return true;
}

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

    int n=s.size();
    string b=s.substr(0,n/2);
    string c=s.substr(((n+3)/2)-1,n-1);
    bool logic=isKainbun(s)&&isKainbun(b)&&isKainbun(c);

    cout<<(logic?"Yes":"No")<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

string card[4][13];
int main() {
  string hoge = "23456789TJQKA";
  map<char, int> ten;
  REP(i,13)ten[hoge[i]]=i;
  char trump;
  while(cin>>trump, trump!='#') {
    REP(i,4) REP(j,13)
      cin >> card[i][j];
    int ew = 0, ns = 0;
    int win = 0;
    REP(i,13) {
      int ma = -1;
      int led = card[win][i][1];
      REP(j,4) {
        int score = ten[card[j][i][0]];
        if (card[j][i][1]==trump) score += 100;
        if (card[j][i][1]==led) score += 50;
        if (score > ma) {
          ma = score;
          win = j;
        }
      }
      // cout << ma << " " << win << endl;
      if (win==0||win==2) ns++;
      else ew++;
    }
    if (ew > ns) cout << "EW" << " " << ew-6 << endl;
    else cout << "NS" << " " << ns-6 << endl;
  }
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    int N; cin >> N;
    vector<string> VS(N);
    for (int i = 0; i < N; i++) {
        cin >> VS[i];
    }

    vector<vector<int>> VV(N);
    for (int i = 0; i < N; i++) {
        vector<int> cnt(26);
        for (int j = 0; j < VS[i].size(); j++) {
            int idx = VS[i][j] - 'a';
            cnt[idx]++;
        }
        VV[i] = cnt;
    }
    sort(VV.begin(), VV.end());
    
    VV.push_back({0});
    long long cnt = 1;
    long long ans = 0;
    for (int i = 1; i < VV.size(); i++) {
        if (VV[i] == VV[i-1]) {
            cnt++;
        } else {
            ans += cnt*(cnt-1)/2;
            cnt = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 20224
/*トポロジカルソート*/
#include<iostream>
#include<vector>
#include<queue>

using Graph = std::vector<std::vector<size_t>>;

int main(){
    
    size_t v, e;
    std::cin >> v >> e;

    Graph g(v);
    std::vector<size_t> in(v, 0);

    for(size_t i = 0; i < e; i++){
        size_t s, t;
        std::cin >> s >> t;

        g.at(s).emplace_back(t);
        in.at(t)++;
    }

    std::queue<size_t> set;

    for(size_t i = 0; i < in.size(); i++){
        if(in.at(i) == 0) set.emplace(i);
    }

    std::vector<size_t> ans;

    while(!set.empty()){
        auto vertex = set.front(); set.pop();
        ans.emplace_back(vertex);

        for(const auto& e : g.at(vertex)){
            in.at(e)--;
            if(in.at(e) == 0) set.emplace(e);
        }
    }

    for(const auto& e : ans){
        std::cout << e << std::endl;
    }
    
    return 0;
}

/*
for(size_t i = 0; i < v; i++){
    std::cout << "in size: " << in.at(i) << ", out vertex: ";
    for(size_t j = 0; j < g.at(i).size(); j++){
        std::cout << g.at(i).at(j) << ", ";
    }std::cout << std::endl;
}
*/



Measured memory_bytes: 4040
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<cmath>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<stdio.h>
#include<queue>
using namespace std;
int main()
{
  string s;
  cin>>s;
  s[3]='8';
  cout<<s<<endl;
  system("pause");
  return 0;
}


Measured memory_bytes: 504
#include<stdio.h>
#include<string.h>
int main(void){
   int n;
   scanf("%d",&n);
   while(n--){
      char a[1000],b[1000],c[1000];
      int j,len;

      for(j=0;j<81;j++){
         a[j]=0;
         b[j]=0;
         c[j]='0';
      }
      scanf("%s%s",a,b);
      len=strlen(a);
      if(len<strlen(b))
         len=strlen(b);
      if(len>80){
         printf("overflow\n");
         continue;
      }
      /*for(j=0;j<len+1;j++){
         c[j]='0';9999999999999999999999999999999999999999999999999999999999999999999999999999999
      }*/
      for(j=0;j<strlen(a);j++){
         c[j]=a[strlen(a)-j-1];
      }
      for(j=0;j<strlen(b);j++){
         c[j]+=b[strlen(b)-j-1]-'0';
      }
      for(j=0;j<len;j++){
         if(c[j]>=58){
            if(j==len-1){
               c[j+1]='0';
               len++;
            }
            c[j]-=10;
            c[j+1]+=1;
         };
      }
      if(len>80){
         printf("overflow\n");
         continue;
      }
      else{
         for(j=len-1;j>=0;j--){
            printf("%c",c[j]);
         }
         puts("");
      }
   }
   return 0;
}

//9999999999999999999999999999999999999999999999999999999999999999999999999999999

Measured memory_bytes: 1012
def main():
    N, Q = (int(i) for i in input().split())
    S = input()
    C = [0] * (len(S) + 1)
    for i in range(1, len(S)):
        C[i+1] = C[i] + (1 if S[i] == "C" and S[i-1] == "A" else 0)

    for q in range(Q):
        le, ri = (int(i) for i in input().split())
        print(C[ri] - C[le])


if __name__ == '__main__':
    main()


Measured memory_bytes: 52668
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let (a, b) = get!(i64, i64);
    if  a > 9 || a < 1 || b > 9 || b < 1 {
        println!("-1");
        process::exit(0);
    }
    println!("{}", a*b);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long a = input.nextLong();
		long b = input.nextLong();
		long c = input.nextLong();
		long LS = 4*a*b;
		long RS = c-a-b; //Don't square pre-emptively
		System.out.println(LS<RS*RS&&RS>0?"Yes":"No");
		//Second component of if statement due to following counter:
		/*a=2,b=3,c=0 (Expected No, says yes due to negatives->Positive from squaring)
		 * */
	}
}

Measured memory_bytes: 22996