akhauriyash/Code-Regression huggingface dataset:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for i in range(N)]
dic = defaultdict(int)
for s in S:
    if s[0] in "MARCH":
        dic[s[0]] += 1

march = list("MARCH")
L = list(combinations(march, 3))
ans = 0
for l in L:
    tmp = 1
    for y in l:
        tmp *= dic[y]
    ans += tmp
print(ans)



Measured memory_bytes: 11840
n = gets.to_i
sum = 0

1.upto(n) do |k|
  #k.step(n, k) do |i|
  #  sum += i
  #end
  # ↑は等差数列になるので・・・
  sum += (k + n - n % k) * (n / k) / 2
end

p sum

Measured memory_bytes: 14248
N, M ,Q = map(int,input().split())

Rq = [list(map(int,input().split())) for _ in range(Q)]

ary = [1 for _ in range(N)]
ans = 0
while True:
  #print(ary)
  pt = 0
  for j in range(Q):
    rq = Rq[j]
    if ary[rq[1]-1]-ary[rq[0]-1] == rq[2]:
      pt += rq[3]
  ans = max(ans,pt)
  
  if ary[0] == M:
    break
  
  #次の配列へ
  for i in range(-1, -N-1, -1):
    if ary[i] < M:
      ary[i] += 1
      tmp = ary[i]
      for l in range(i+1, 0):
        ary[l] = tmp
      break
      
print(ans)


Measured memory_bytes: 74012
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int,int> P;
typedef long long ll;
const ll mod=1000000007;


main(){
  int n;cin>>n;
  vector<vector<int>> d(n,vector<int>(2));
  rep(i,n) cin>>d[i][0]>>d[i][1];
  bool ans=false;
  for(int i=0;i<n-2;i++){
    if(d[i][0]==d[i][1]){
      if(d[i+1][0]==d[i+1][1]){
        if(d[i+2][0]==d[i+2][1]){
          ans=true;
        }
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let inp:Vec<_> = s.trim().split(' ').collect();
    let a = inp[0].to_string().chars().collect::<Vec<char>>();
    let b = inp[1].to_string().chars().collect::<Vec<char>>();
    let c = inp[2].to_string().chars().collect::<Vec<char>>();
    let au: Vec<_> = a[0].to_uppercase().collect();
    let bu: Vec<_> = b[0].to_uppercase().collect();
    let cu: Vec<_> = c[0].to_uppercase().collect();
    println!("{}{}{}", au[0], bu[0], cu[0]);
}


Measured memory_bytes: 4352
N = int(input())
L = [int(x) for x in input().split()]

print(' '.join(map(str, L)))

for i in range(1, N):
    v = L[i]
    j = i - 1
    while j >= 0 and L[j] > v:
        L[j + 1] = L[j]
        j -= 1
    L[j + 1] = v
    print(' '.join(map(str, L)))


Measured memory_bytes: 5604
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    ll n, ans = 0;
    scanf("%lld", &n);
    vector<ll> a(n), b(n), c(n);
    for (ll i = 0; i < n; ++i) scanf("%lld", a.begin() + i);
    for (ll i = 0; i < n; ++i) scanf("%lld", b.begin() + i);
    for (ll i = 0; i < n; ++i) scanf("%lld", c.begin() + i);
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    for (ll i = 0; i < n; ++i) ans += (lower_bound(a.begin(), a.end(), b.at(i)) - a.begin()) * (c.end() - upper_bound(c.begin(), c.end(), b.at(i)));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

solve :: Int -> Int -> [Int] -> Int
solve n start xs = foldl1' gcd $ map op xs
  where op x = abs(x - start)

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

main = do
  cont <- B.getContents
  let n : start : xs = bsReadInts cont
  putStrLn $ show $ solve n start xs


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long
#define pb                      push_back
#define rep(i,a,b,c)            for(ll i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(ll i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
#define mp                      make_pair
#define vpll                    vector<pair<ll,ll> >
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define ln                      cout<<"\n";
#define endl                    "\n"
#define test                    ll T;cin>>T;while(T--)
#define isvowel(a)              (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define show(w,size)            for(ll i=0;i<size;i++) cout<<w[i]<<" ";
#define prll(a)                 cout<<a<<"\n";
#define mset(dp,no)             memset(dp,no,sizeof(dp))
#define input(a,n)              rep(i,0,n-1,1) cin>>a[i];
#define countbit                __builtin_popcount                                           //Number of setbits in decimal notation
#define lb(v,cur)               lower_bound(all(v),cur)-v.begin()
#define ub(v,cur)               upper_bound(all(v),cur)-v.begin()
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
long long pows(long long a, long long b) {
  long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll powm(ll x,ll y,ll m=MOD){x=x%m;ll res=1;while(y){if(y&1)res=res*x;res%=m;y=y>>1;x=x*x;x%=m;}return res;}
ll modInverse(ll a, ll m=MOD){if(m == 1)return 0;ll m0=m,y=0,x=1;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0) x+=m0;return x;}
int main()
{
fastIO
ll n,m,i,j,k,x,y,z,t,e,f,p,q,g,l,r,w,h,count1=0,prod=1,a,b,c,d,index,x1,x2,y1,y2,diff,ans=0,sum=0,sum1=0,sum2=0,flag=0,flag1=0,flag2=0;
string s1,s2;
ld rad;
cin>>rad;
ld pi=3.14159265359;
ld cir=2*pi*rad;
cout<<fixed<<setprecision(7)<<cir;
}


Measured memory_bytes: 3792
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = [1 for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        ans[b-1] = 0
    elif h[a-1] < h[b-1]:
        ans[a-1] = 0
    else:
       ans[a-1] = 0
       ans[b-1] = 0
cnt = 0
for i in range(n):
    if ans[i] == 0:
        cnt += 1
print(n-cnt)

Measured memory_bytes: 20128
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

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

  vector<int> h(N);
  vector<int> c(N + 2, -1);
  rep(i, N) { cin >> h[i]; }

  c[0] = 0;
  for (int i = 0; i < N - 1; ++i) {
    c[i + 1] = c[i + 1] == -1 ? c[i] + abs(h[i] - h[i + 1])
                              : min(c[i + 1], c[i] + abs(h[i] - h[i + 1]));
    c[i + 2] = c[i + 2] == -1 ? c[i] + abs(h[i] - h[i + 2])
                              : min(c[i + 2], c[i] + abs(h[i] - h[i + 1]));
  }

  cout << c[N - 1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <fstream>
class Bit {
	std::vector<int> vec;
public:
	Bit(const int size) : vec(size, 0) {};
	int operator[](int position) const {
		int result = 0;
		while (position >= 0) {
			result += vec[position];
			position -= ~position & (position + 1);
		}
		return result;
	}
	void increment(int position) {
		while (position < vec.size()) {
			vec[position]++;
			position += ~position & (position + 1);
		}
	}
};
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<int> permutation(n); for (auto& p : permutation) std::cin >> p;
	if (n == k) {
		bool can_sort = true;
		for (auto i = 1; i < n; ++i) {
			if (permutation[i - 1] > permutation[i]) {
				if (can_sort) {
					can_sort = false;
				}
				else {
					std::cout << "No\n";
					return 0;
				}
			}
		}
		std::cout << "Yes\n";
	}
	else if (k % 2 == 0) {
		std::cout << "Yes\n";
	}
	else {
		Bit bit(n);
		long long int swap_count = 0;
		for (auto i = 0; i < n; ++i) {
			const auto p = permutation[i];
			swap_count += i - bit[p - 1];
			bit.increment(p - 1);
		}
		if (swap_count % 2 == 0) {
			std::cout << "Yes\n";
		}
		else {
			std::cout << "No\n";
		}
	}
}




Measured memory_bytes: 3608
hotel = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

z = int(input())

for x in range(z):
    a, b, c, d = map(int, input().split())
    hotel[a - 1][b - 1][c - 1] = hotel[a - 1][b - 1][c - 1] + d

for i, ridge in enumerate(hotel):
    for j, floor in enumerate(ridge):
        for k, room in enumerate(floor):
            print(f" {room}", end="")
        print()
    if i != 3:
        print("####################")



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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

using Int = long long;

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

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

signed main()
{
    Int A, B;
    cin >> A >> B;

    cout << lcm(A, B) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool d[100009],b[100009];
int i,j,n,k,a[100009];
bool dp(int x){
    if(x==0) return 0;
    if(b[x]) return d[x];
    b[x]=1;
    for(int i=0;i<n&&d[x]!=1;i++)
        if(x-a[i]>=0) d[x]=1-dp(x-a[i]);
    return d[x];
}
int main()
{
    cin>>n>>k;
    for(i=0;i<n;i++) cin>>a[i];
    if(dp(k)) cout<<"First";
    else cout<<"Second";
    return 0;
}


Measured memory_bytes: 5120
#!/usr/bin/env python3
import sys
# Maze by warshall_floyd
# ワーシャルフロイド法


def solve(H, W, a):
    # print(a)
    inf = H*W**2
    d = [[inf]*(H*W) for _ in range(H*W)]
    for h in range(H):
        for w in range(W):
            if (a[h][w] == "0"):
                d[h*W+w][h*W+w] = 0
                if (w+1<W)and(a[h][w+1] == "0"):
                    d[h*W+w][h*W+w+1] = 1
                if (h+1<H)and(a[h+1][w] == "0"):
                    d[h*W+w][(h+1)*W+w] = 1
                if (w-1>=0)and(a[h][w-1] == "0"):
                    d[h*W+w][h*W+w-1] = 1
                if (h-1>=0)and(a[h-1][w] == "0"):
                    d[h*W+w][(h-1)*W+w] = 1
                
    # print(*d, sep='\n')

    for k in range(H*W):  # via k [k//W][k% W]
        for st in range(H*W):  # start from st
            for ed in range(H*W):  # go to ed
                d[st][ed] = min(d[st][ed], d[st][k]+d[k][ed])

    # print(*d, sep="\n")

    print(max(*map(lambda x: max([_ if _ != inf else 0 for _ in x ]), d)))
    return

if __name__ == '__main__':
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int

    a = [[_ for _ in next(tokens).replace(".","0").replace("#","1")] for _ in range(H)]  # type: "List[int]"
    solve(H, W, a)


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

int main(void){
  int n, m, a, b;
  cin >> n >> m;
  bool ma[n][n];
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      ma[i][j] = false;
  for(int i = 0; i  < m; i++){
    cin >> a >> b;
    ma[a - 1][b - 1] = true;
    ma[b - 1][a - 1] = true;
  }
  int p[n];
  int ans = 0;
  for(int i = 0; i < n; i++) p[i] = i;
  do{
    bool flag = true;
    for(int i = 0; i < n - 1; i++){
      if(p[0] != 0) flag = false;
      if(!ma[p[i]][p[i + 1]]) flag = false;
    }
    if(flag) ans++;
  }while(next_permutation(p, p + n));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = (N % 1000) ? 1000 - N % 1000 : 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
#n,q = [int(i) for i in readline().split()]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
 
MOD = 10**9+7
def dfs(v,p): #p: parent of v
    b = w = 1
    for c in g[v]:
        if c == p: continue
        bb, ww = dfs(c,v)
        b *= ww
        b %= MOD        
        w *= bb+ww
        w %= MOD
    return b,w

print(sum(dfs(0,-1))%MOD)
 

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

int main() {
    int N; cin >> N;
    string prev;
    set<string> c;
    for (int i = 0; i < N; i++)
    {
        string s; cin >> s;
        if(c.count(s)!=0){
            cout << "No" << endl;
            return 0;
        }
        c.insert(s);
        if(i!=0){
            if(prev[prev.size()-1] != s[0]){
                cout << "No" << endl;
                return 0;
            }
        }
        prev = s;
    }
    cout << "Yes" << endl;
    
}

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

int main() {
  char s[3];
  cin >> s;
  int c;
  if (s[0] == 'o') ++c;
  if (s[1] == 'o') ++c;
  if (s[2] == 'o') ++c;
  cout << 700 + c*100 << endl;
  return 0;
}


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

int solve(string S)
{
    long long Ssize = S.size();
    long long sum = 0;
    if (Ssize == 1)
    {
        int ss = S[0] - '0';
        cout << ss << endl;
        return 0;
    }

    for (long long bit = 0; bit < (1 << (Ssize - 1)); bit++)
    {
        string num = "";
        for (long long i = 0; i < Ssize; i++)
        {
            num += S[i];
            if (bit & (1 << i)) //0:nasi 1:+
            {
                sum += stoll(num);
                num = "";
            }
        }
        sum += stoll(num);
    }

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

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))
N, M = inpl()
AB = [None]*N
for i in range(N):
    AB[i] = inpl()
AB.sort(key=lambda x: -x[0])
q = []
ans = 0
for m in range(1,M+1):
    while len(AB) > 0 and AB[-1][0] <= m:
        ab = AB.pop()
        heapq.heappush(q,-ab[1])
    if len(q) > 0:
        ans += -heapq.heappop(q)
print(ans)

Measured memory_bytes: 68828
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;

#define MAX_N 200005
vector<int> G[MAX_N];
int f[MAX_N];
int BipartiteGraph(){
    rep(i,MAX_N)f[i] = -1;
    queue<int> que;
    que.push(0);
    f[0] = 0;
    int flag = 0;
    while(que.size() > 0){
        int x = que.front();
        que.pop();
        rep(i,G[x].size()){
            if(f[G[x][i]] == -1){
                f[G[x][i]] = (f[x] + 1) % 2;
                que.push(G[x][i]);
            }else{
                if(f[G[x][i]] == f[x]){
                    flag = 1;
                    break;
                }
            }
        }
        if(flag == 1)break;
    }
    if(flag == 1) return -1;
    int res = 0;
    rep(i,MAX_N){
        if(f[i] == 0)res++;
    }
    return res;
}

int main() {
    ll n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll count = BipartiteGraph();
    ll ans = 0;
    if(count == -1){
        ans = n * (n - 1) / 2 - m;
    }else{
        ans = count * (n - count) - m;
    }

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


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

int main()
{
    int n, len;
    cin >> n;
    string msg, srv;
    while (cin >> srv >> msg, n--) {
        len = msg.size();
        for (int i = srv.size() - 1; i >= 0; --i) {
            if (srv[i] == 'J') {
                rotate(msg.begin(), msg.end() - 1, msg.end());
            } else if (srv[i] == 'C') {
                rotate(msg.begin(), msg.begin() + 1, msg.end());
            } else if (srv[i] == 'E') {
                if (len % 2)
                    msg = msg.substr(len / 2 + 1) + msg[len / 2] + msg.substr(0, len / 2);
                else
                    msg = msg.substr(len / 2) + msg.substr(0, len / 2);
            } else if (srv[i] == 'A') {
                reverse(msg.begin(), msg.end());
            } else if (srv[i] == 'P') {
                for (int j = 0; j < len; ++j) {
                    if (msg[j] >= '0' && msg[j] <= '9')
                        msg[j] = (msg[j] - '0' + 9) % 10 + '0';
                }
            } else {
                for (int j = 0; j < len; ++j) {
                    if (msg[j] >= '0' && msg[j] <= '9')
                        msg[j] = (msg[j] - '0' + 1) % 10 + '0';
                }
            }
        }
        cout << msg << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string s;
    int k;
    cin>>k;
    cin>>s;
    if(s.size()<=k){
        cout<<s<<endl;
    }
    else{
        rep(i,0,k)cout<<s[i];
        cout<<"..."<<endl;
    }

    return 0;
}




Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int solve(){
    cin>>n;
    cout<<(n/500)*1000+((n%500)/5)*5;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <cstring>
using namespace std;
int main(){
    int n,A;
    scanf("%d%d",&n,&A);
    if (n - (n/500) * 500 <= A) 
    {
        printf("Yes\n");
    }else 
    {
        printf("No\n");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  if(n == 1){
    cout << 0;
    return 0;
  }
  vector<long long> a(n);  
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    a.at(i) -= (i+1);
  }
  sort(a.begin(),a.end());
  int b = a.at((n -1)/2);
  long long ans = 0;
  for(int i = 0; i < n; i++)
    ans += abs(a.at(i) - b);
  
  cout << ans;
}


Measured memory_bytes: 4824
#include <stdio.h>
#include <math.h>
main(){
float D,d,a,b,x,y;
while(scanf("%f%f%f%f%f",&D,&a,&b,&x,&y),D){
d=hypot(a,b);if(a*x+b*y>0)d=2-d;fabs(a*y-b*x)>1e-7||D<d?puts("impossible"):printf("%.8f\n",d);}
}

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

const int LIM = 400, dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int h, w;
string s[LIM];
bool visited[LIM][LIM];
ll ans, bk, wt;

void dfs(int sy, int sx) {
    visited[sy][sx] = true;
    if (s[sy][sx] == '.') wt++; else bk++;
    
    rep(i, 4) {
        int ny = sy + dy[i], nx = sx + dx[i];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w || visited[ny][nx]) continue;
        if (s[sy][sx] != s[ny][nx]) dfs(ny, nx);
    }
}

int main() {
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    rep(i, h) {
        rep(j, w) {
            if (s[i][j] == '#') {
                bk = wt = 0;
                dfs(i, j);
                ans += bk * wt;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20608
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	// 入力
	int N;
	cin >> N;
	
	if (N / 10 == 9 || N % 10 == 9) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b;
  for (int i = 0; i < a; i++){
    int x;
    cin >> x;
    if (b-x < x){
      c += 2*(b-x);
    }
    else {
      c += 2*x;
    }
  }
  cout << c << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  double prob = 0;
  for (int i = 1; i <= N; i++) {
    int total = i;
    double half = 1.0/N;
    while (total < K) {
      total *= 2;
      half /= 2;
    }
    prob += half;
  }
  printf("%.12f\n",prob);
}

Measured memory_bytes: 256
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#include "/home/shahraaz/bin/debug.h"
#else
#define db(...)
#define pc(...)
#endif

#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 1e6 + 5, MOD = 1000000007;

int dp[2][NAX];
class Solution
{
private:
public:
    Solution() {}
    ~Solution() {}
    void solveCase()
    {
        string str;
        cin >> str;
        int n = str.size();
        dp[1][n + 1] = MOD;
        dp[0][n + 1] = 0;
        for (int i = n; i > 0; i--)
        {
            int d = str[i - 1] - '0';
            dp[0][i] = d + dp[0][i + 1];
            dp[1][i] = 10 - d + dp[0][i + 1];
            if (d + 1 < 10)
            {
                dp[0][i] = min(dp[0][i], d + 1 + dp[1][i + 1]);
                dp[1][i] = min(dp[1][i], 10 - (d + 1) + dp[1][i + 1]);
            }
            else
                dp[1][i] = min(dp[1][i], dp[1][i + 1]);
        }
        cout << min(dp[0][1], dp[1][1] + 1) << '\n';
    }
};

int32_t main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    Solution mySolver;
    for (int i = 1; i <= t; ++i)
    {
        mySolver.solveCase();
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}

Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int n,num[200010];
int main()
{
	scanf("%d",&n);
	memset(num,0,sizeof(num));
	for(int i=2,fa;i<=n;++i) {
		scanf("%d",&fa);
		num[fa]++;
	}
	for(int i=1;i<=n;++i) printf("%d\n",num[i]);
	return 0;
}

Measured memory_bytes: 4608
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n, m;
    cin >> n >> m;
    int k[m];
    vector<vector<int>> s(m);

    int ans = 0;

    rep(i, m) {
        cin >> k[i];
        rep(j, k[i]) {
            int s_temp;
            cin >> s_temp;
            s[i].push_back(s_temp);
        }
    }
    int p[m];
    rep(i, m) { cin >> p[i]; }

    vector<bool> judge(n);
    rep(i, pow(2, n)) {
        rep(j, n) {
            if (i & (int)pow(2, j)) {
                judge[j] = true;
            } else {
                judge[j] = false;
            }
        }

        bool flag = true;
        rep(i, m) {
            int num = 0;
            for (int &here : s[i]) {
                num += judge[here - 1];
            }

            if (num % 2 == p[i]) {
            } else {
                flag = false;
            }
        }

        if (flag) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int bitCount(uint bits) {
  int cnt = 0;
  while(bits!=0){
    ++cnt;
    bits&=bits-1;
  }
  return cnt;
}
int main(){
  int n;
  cin>>n;
  vector<vector<int>> board(n,vector<int>(n));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      board[i][j]=-1;
    }
  }
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    for(int j=0;j<a;j++){
      int x,y;
      cin>>x>>y;
      x--;
      board[i][x]=y;
    }
  }
  int ans=0;
  for(int i=0;i<(1<<n);i++){
    vector<int> d(n);
    for(int j=0;j<n;j++){
      if(i&(1<<j))d[j]=1;
    }
    bool ok=true;
    for(int j=0;j<n;j++){
      if(d[j]){
        for(int k=0;k<n;k++){
          if(board[j][k]==-1)continue;
          if(board[j][k]!=d[k])ok=false;
        }
      }
    }
    if(ok){
      ans=max(ans,bitCount(i));
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3572
// AOJ 2034 Autocorrelation Function
// 2018.3.27 bal4u

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

#define EPS 1e-6
#define EQ(a,b)  (fabs((a)-(b))<EPS)

// バッファ入力から整数値を得る
char buf[50], *p;
int in()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = 10*n + (*p++ & 0xf);
		n = -n;
	} else while (*p >= '0') n = 10*n + (*p++ & 0xf);
	p++;
	return n;
}

double tbl[205]; int sz;
int n; double r;
int x[102], y[102]; double k[102];

double ff(double xx)
{
	int i;
	if (xx <= x[0] || x[n-1] <= xx) return 0.0;
	for (i = 0; !(x[i] <= xx && xx < x[i+1]); i++);
	return k[i]*(xx - x[i]) + y[i];
}

#define f(x) (ff(x)*ff(x+r))

int cmp(double *a, double *b) {
	if (EQ(*a, *b)) return 0;
	if (*a <= *b) return -1; return 1;
}

int uniq(double *a, int n)
{
	int i, j;
	
	for (i = 0, j = 1; j < n; j++) {
		while (j < n && EQ(a[j], a[i])) j++;
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int main()
{
	int i;
	double a, b, c, fa, fb, fc, ans;

	while (fgets(p=buf, 50, stdin) && *p != '0') {
		sscanf(p, "%d%lf", &n, &r);
		sz = 0;	for (i = 0; i < n; i++) {
			fgets(p=buf, 50, stdin);
			tbl[sz++] = x[i] = in(), y[i] = in();
			tbl[sz++] = x[i] - r;
			if (i > 0) k[i-1] = ((double)(y[i]-y[i-1]))/(x[i]-x[i-1]);
		}
		k[n-1] = 0;
		qsort(tbl, sz, sizeof(tbl[0]), cmp);
		sz = uniq(tbl, sz) - 1;

		ans = 0;
		a = tbl[0], fa = f(a);
		for (i = 0; i < sz; i++) {
			b = tbl[i+1], c = 0.5*(a+b);
			fb = f(b), fc = f(c);
			ans += (fa + 4*fc + fb)*(b-a)/6;
			a = b, fa = fb;
        }
		printf("%.8lf\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2036
n = input()

if int(n[-1]) == 2 or int(n[-1]) == 4 or int(n[-1]) == 5 or int(n[-1]) == 7 or int(n[-1]) == 9:
    print('hon')
elif int(n[-1]) == 0 or int(n[-1]) == 1 or int(n[-1]) == 6 or int(n[-1]) == 8:
    print('pon')
else:
    print('bon')

Measured memory_bytes: 61672
#include<bits/stdc++.h>
#define INF 9003372036854775807LL
#define mod 1000000007
#define fixed fixed<<setprecision(12)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii=pair<int, int > ;
lol a[300010];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  lol n,m,k,r,x,y,z;
  cin >>n>>m>>x;
  lol ans=0;
  m--;
  for(int i=0;i<n;i++){
    cin >>r;
    ans+=m/r+1;
  }
  cout <<ans+x<<'\n';
  return (0);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Big Integers - Remainder of Big Integers
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_2_E&lang=jp

"""
import sys


def main(args):
    A, B = map(int, input().split())
    print(A % B)


if __name__ == '__main__':
    main(sys.argv[1:])



Measured memory_bytes: 5620
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	s := sc.Text()
	l := len(s)
	r := make([]rune, l)
	for i, c := range s {
		r[l-i-1] = c
	}
	fmt.Println(string(r))
}



Measured memory_bytes: 1064
#include <stdio.h>

int main() {
	int n;
	scanf(" %d", &n);
	if (n==1) {
		printf("Hello World\n");
	}
	else {
		int a, b;
		scanf("%d %d", &a, &b);
		printf("%d\n", a+b);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void){
	while(true){
		int x,y;
		cin >> x >> y;
		if(x == 0 && y == 0){
			break;
		}
		if(x < y){
			cout << x << " " << y << endl;
		} else {
			cout << y << " " << x << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
 
int main(){
  int W,H,x,y,r,a;
  a = 0;
  
  cin >> W >> H >> x >> y >> r;
  if (x-r<0 or x+r>W){
      a = a + 1;
  }
  if (y-r<0 or y+r>H){
      a = a + 1;
  }
  if (a == 0){
      cout << "Yes" << endl;
  } else {
      cout << "No" << endl;
  }
  
      
  
      

  return 0;		 
}
		   


Measured memory_bytes: 3068
#include<stdio.h>

int main(){
    int n,a=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        if(((0<i)&&(i<10))||((99<i)&&(i<1000))||((9999<i)&&(i<100000))){
            a++;
        }
    }
    printf("%d\n",a);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}


int main() {
    int h,w;cin>>h>>w;
    vector<string> s(h+2);
    string edge;
    for(auto i = 0;i<w+2;i++) edge+=".";
    s[0] = edge;
    rep(i,h) {
        string temp;
        temp+=".";
        string temp2;cin>>temp2;
        temp+=temp2;
        temp+=".";
        s[i+1] = temp;
        //        cout<<temp << endl;;
    }
    s[h+1] = edge;
    
    vector<string> out(h);
    rep(i,h)out[i].resize(w);
    
    for(auto i = 1;i<h+1;i++){
        for(auto j = 1;j<w+1;j++){
            if (s[i][j]=='#') {out[i-1][j-1] = '#';continue;};
            int count = 0;
            
            count += (s[i+1][j] == '#');
            count += (s[i-1][j] == '#');
            count += (s[i][j+1] == '#');
            count += (s[i][j-1] == '#');
            count += (s[i+1][j+1] == '#');
            count += (s[i+1][j-1] == '#');
            count += (s[i-1][j+1] == '#');
            count += (s[i-1][j-1] == '#');
            out[i-1][j-1] = count+'0';
            
        }
    }
    rep(i,h) cout<<out[i]<<endl;
    
    
    return 0;
}







Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
	int i=0,j,k,count=0,s=0;
	char list[200][200];

	while(scanf("%s",list[i])!=EOF){
		i++;
		if(i==1) break;
	}

	for (k = strlen(list[0])-1; k>1; k--)
	{
		s=0;
		if(k%2==0)
		{
			for(j=0;j<k/2;j++){
				if(list[0][j]!=list[0][j+k/2]) s=1; 
			}
			if(s==0) break;
		}
	}

	printf("%d\n",k);


}

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

using namespace std;

int S_a[100001];
int S_b[100001];
int T_a[100001];
int T_b[100001];

int main(){
    string S, T;
    cin >> S;
    cin >> T;
    int q;
    cin >> q;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'A'){
            S_a[i+1] = S_a[i]+1;
            S_b[i+1] = S_b[i];
        }
        if(S[i] == 'B'){
            S_a[i+1] = S_a[i];
            S_b[i+1] = S_b[i]+1;
        }
    }
    for(int i = 0; i < T.size(); i++){
        if(T[i] == 'A'){
            T_a[i+1] = T_a[i]+1;
            T_b[i+1] = T_b[i];
        }
        if(T[i] == 'B'){
            T_a[i+1] = T_a[i];
            T_b[i+1] = T_b[i]+1;
        }
    }
    for(int i = 0; i < q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int diff_S = (S_a[b] - S_a[a-1]) - (S_b[b] - S_b[a-1]);
        //cout << (S_a[b] - S_a[a-1]) << ' ' << (S_b[b] - S_b[a-1]) << endl;
        diff_S = (diff_S%3 + 3)%3;
        int diff_T = (T_a[d] - T_a[c-1]) - (T_b[d] - T_b[c-1]);
        diff_T = (diff_T%3 + 3)%3;
        //cout << (T_a[d] - T_a[c-1]) << ' ' << (T_b[d] - T_b[c-1]) << endl;
        if(diff_S == diff_T) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

Measured memory_bytes: 2432
from itertools import combinations


n = int(input())
s = input()
ans = 0
for i in range(1000):
    num = '{:0=3}'.format(i)
    inds = 0
    indnum = 0
    while inds < len(s) and indnum < 3:
        if s[inds] == num[indnum]:
            indnum += 1
        inds += 1
    if indnum == 3:
        ans += 1
print(ans)


Measured memory_bytes: 41052
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  bool dp[80][80][12800];
  for(int i = 0;i < 80;i++)for(int j = 0;j < 80;j++)for(int k = 0;k < 12800;k++)dp[i][j][k]  = false;
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  vector<vector<int>> b(h,vector<int>(w));
  for(int i = 0;i < h;i++)for(int j = 0;j < w;j++)cin >> a[i][j];
  for(int i = 0;i < h;i++)for(int j = 0;j < w;j++)cin >> b[i][j];
  dp[0][0][abs(a[0][0] - b[0][0])] = true;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      //cout << i << " " << j << endl;
      for(int k = 0;k < 12800;k++){
        if(dp[i][j][k]){
          //if(i == 1 && j == 0)cout << k << endl;
          if(i + 1 < h){
            dp[i + 1][j][k + abs(a[i + 1][j] - b[i + 1][j])] = true;
            dp[i + 1][j][abs(k - abs(a[i + 1][j] - b[i + 1][j]))] = true;
          }
          if(j + 1 < w){
            dp[i][j + 1][k + abs(a[i][j + 1] - b[i][j + 1])] = true;
            dp[i][j + 1][abs(k - abs(a[i][j + 1] - b[i][j + 1]))] = true;
          }
        }
      }
            //  cout << i << " " << j << endl;
    }
  }
  //cout  <<"!"<< endl;
  for(int i = 0;i < 12800;i++){
    if(dp[h - 1][w - 1][i]){
      cout << i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_W=300,MAX_H=300,INF=1e8;
int H,W;
typedef pair<int,int> P;
P coi[MAX_H*MAX_W],coi2[MAX_H*MAX_W],rotcoi[MAX_H*MAX_W];
char temp[MAX_H+8][MAX_W+8+1];
int psm[MAX_H+8][MAX_W+8+1];
int main(){
	cin>>H>>W;
	int N=0;
	ll ans=0;
	REP(i,H){
		string s;
		cin>>s;
		REP(j,W){
			if (s[j]=='#'){
				coi[N++]=P(i,j);
			}
		}
	}
	REP(par,2){
		int N2=0;
		REP(i,N){
			if ((coi[i].first+coi[i].second)%2==0){
				coi2[N2]=P((coi[i].first+coi[i].second)/2,(-coi[i].first+coi[i].second)/2);
				N2++;
			}
		}
		REP(rot,4){
			REP(i,MAX_H+8){
				REP(j,MAX_W+8){
					temp[i][j]='.';
				}
			}
			REP(i,N2){
				rotcoi[i]=coi2[i];
			}
			{
				int mih=INF,miw=INF;
				REP(i,N2){
					mih=min(rotcoi[i].first,mih);
					miw=min(rotcoi[i].second,miw);
				}
				REP(i,N2){
					rotcoi[i].first-=mih;
					rotcoi[i].second-=miw;
				}
			}
			REP(i,N2){
				temp[rotcoi[i].first][rotcoi[i].second]='#';
			}
			memset(psm,0,sizeof(psm));
			REP(h,MAX_H+8){
				REP(w,MAX_W+8){
					psm[h][w+1]=psm[h][w];
					if (temp[h][w]=='#'){
						psm[h][w+1]=psm[h][w]+1;
					}
				}
			}
			FOR(wid,2,MAX_W+8+1){
				REP(h,MAX_H+8-wid+1){
					REP(w,MAX_W+8-wid+1){
						if (temp[h][w]=='#' && temp[h][w+wid-1]=='#'){
							ans+=psm[h+wid-1][w+wid-1]-psm[h+wid-1][w];
						}
					}
				}
			}
			REP(i,N2){
				swap(coi2[i].first,coi2[i].second);
				coi2[i].second*=-1;
			}
		}
		REP(i,N){
			coi[i].first++;
		}
	}
	cout<<ans<<endl;
				
		
	return 0;
}

Measured memory_bytes: 2176
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	cnt := make(map[string]int)
	for i := 0; i < N; i++ {
		cnt[nextLine()]++
	}
	fmt.Println("AC x", cnt["AC"])
	fmt.Println("WA x", cnt["WA"])
	fmt.Println("TLE x", cnt["TLE"])
	fmt.Println("RE x", cnt["RE"])
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}

// ここから拝借
// https://shoman.hatenablog.com/entry/2020/02/25/185456
// Stackは[]intのエイリアス
type Stack []int

// Push adds an element
func (s *Stack) Push(v int) {
	*s = append(*s, v)
}

// Pop removes the top element and return it
func (s *Stack) Pop() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	v := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return v, nil
}

// Peek returns the top value
func (s *Stack) Peek() (int, error) {
	if s.Empty() {
		return 0, fmt.Errorf("stack is empty")
	}

	return (*s)[len(*s)-1], nil
}

// Size returns the length of stack
func (s *Stack) Size() int {
	return len(*s)
}

// Empty returns true when stack is empty
func (s *Stack) Empty() bool {
	return s.Size() == 0
}

// NewStack generates stack
func NewStack() *Stack {
	s := new(Stack)
	return s
}


Measured memory_bytes: 2512