akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mxn 10000002
ll bigmod(ll a,ll p,ll m)
{
    if(p==0)
        return 1%m;
    if(p%2!=0)
    {
        return (a*(bigmod(a,p-1,m)))%m;
    }
    else
    {
        ll x=(bigmod(a,p/2,m))%m;
        return (x*x)%m;
    }
}
ll pre[mxn];
bool vis[mxn];
ll res[mxn];
void solve()
{
    int sq=sqrt(mxn);
    for(int j=4; j<=mxn; j+=2)
    {
        ll cnt=0;
        vis[j]=1;
        while(pre[j]%2==0)
        {
            pre[j]/=2LL;
            cnt++;
        }
        res[j] *= (cnt+1LL);
    }
    for(ll i=3; i<=sq; i+=2)
    {
        if(vis[i]==0)
        {
            for(int j=(i*i); j<=mxn; j+=i)
            {
                ll cnt=0;
                vis[j]=1;
                while(pre[j]%i==0)
                {
                    pre[j]/=i;
                    cnt++;
                }
                res[j] *= (cnt+1LL);
            }
        }
    }
    ll tot=0;
    for(ll j=1; j<=mxn; j++)
    {
        if(pre[j]!=1)
        {
            res[j] *=2LL;
        }
        res[j]=tot+(res[j]*j);
        tot=res[j];
    }
}
int main()
{
    for(ll i=1; i<=mxn; i++)
    {
        res[i]=1LL;
        pre[i]=i;
    }
    solve();
    ll n;
    while(cin>>n)
    {
        cout<<res[n]<<endl;
    }
    return 0;
}


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

int main(){
  long N;
  cin >> N;
  long z;
  cin >>z;
  long min1=z;
  long counter=1;
  for(int i=1; i<N; i++){
    long x;
    cin >> x;
    if(x<=min1)counter++;
    min1 = min(x, min1);
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <tuple>
#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>

using namespace std;

//conversion
//------------------------------------------
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();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
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);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

class MCM_Solver
{
private:
    vector<tuple<LL, LL>> dims;
    vector<VL> dp;

public:
    LL solve_dp();
    MCM_Solver(vector<tuple<LL, LL>> dims, size_t n) : dims(dims), dp(n, VL(n, LONG_MAX))
    {
        REP(i, n)
        {
            dp[i][i] = 0;
        }
    }
};

LL MCM_Solver::solve_dp()
{
    int n = dp.size();
    FOR(l, 2, n + 1)
    {
        FOR(i, 0, (n - l + 1))
        {
            int j = i + l - 1;
            LL ans = LONG_MAX;
            FOR(k, i, j)
            {
                ans = min(
                    ans,
                    dp[i][k] + dp[k + 1][j] + get<0>(dims[i]) * get<0>(dims[k + 1]) * get<1>(dims[j]));
            }
            dp[i][j] = ans;
            // cout << i << ", " << j << ", " << dp[i][j] << endl;
        }
    }

    return dp[0][n - 1];
}

int main()
{
    // cout << LONG_MAX << endl;

    int n;
    cin >> n;
    vector<tuple<LL, LL>> dims;
    REP(i, n)
    {
        int nn, m;
        cin >> nn >> m;

        dims.push_back(make_tuple(nn, m));
    }

    LL ans = MCM_Solver(dims, n).solve_dp();

    cout << ans << endl;
}


Measured memory_bytes: 3224
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut xm = read::<isize>();
    xm.sort();
    let mut cost = Vec::new();
    for i in 0..m - 1 {
        cost.push((xm[i] - xm[i + 1]).abs() as usize);
    }

    cost.sort();

    for _ in 0..n - 1 { cost.pop(); }
    println!("{}", cost.into_iter().sum::<usize>());
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 8444
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#define ff first
#define ss second
#define M 1000000007
typedef long long int ll;
using namespace std;
ll power(ll a,ll b){
    ll ans = 1;
    while(b>0){
        if(b%2!=0){
            ans = ((ans)*(a));
        }
        a = ((a)*(a));
        b=b/2;
    }
    return ans;
}
ll add(ll a,ll b){
    ll temp = (a%M + b%M)%M;
    if(temp>M){
        temp=temp-M;
    }
    return temp;
}
vector <vector <ll>> mul(const vector <vector <ll>> &a,const vector <vector <ll>> &b){
    ll n = a.size();
    vector <vector <ll>> res(n,vector <ll> (n,0));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            for(ll k=0;k<n;k++){
                res[i][j]+=((a[i][k]%M)*(b[k][j]%M))%M;
                while(res[i][j]>M){
                    res[i][j]=res[i][j]%M;
                }
            }
        }
    }
    return res;
}
vector <vector <ll>> power(vector <vector <ll>> &a,ll k){
    ll n = a.size();
    vector <vector <ll>> res(n,vector <ll> (n,0));
    for(ll i=0;i<n;i++){
        res[i][i]=1;
    }
    while(k){
        if(k%2){
            res = mul(res,a);
        }
        a = mul(a,a);
        k=k/2;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector <vector <ll>> a(n,vector <ll> (n));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    vector <vector <ll>> res=power(a,k);
    ll ans = 0;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            ans=add(ans,res[i][j]);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
# Problem B - Popular Vote

# input
N, M = map(int, input().split())
A_list = list(map(int, input().split()))

# initialization
A_list = sorted(A_list, reverse=True)
is_ok = True
test_limit = sum(A_list) / (4*M)

# check
test_list = A_list[:M]
for t in test_list:
    if t<test_limit:
        is_ok = False
        break

# output
if is_ok:
    print("Yes")
else:
    print("No")


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

def main():
    N = int(input())
    v = list(map(int, input().split()))
    v.sort()

    ans = v[0]
    for x in v[1:]:
        ans = (ans + x) / 2

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
n = int(input())
cnt_t=0
cnt_h=0
for i in range(n):
    a,b=input().split()
    if a>b:
        cnt_t+=3
    elif a<b:
        cnt_h+=3
    else:
        cnt_t+=1
        cnt_h+=1
print(cnt_t,cnt_h)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , ll >
#define F first
#define S second
#define int long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/*
310 304 317 489 225 131 160 195 197 199 220 203 239 269
407 226 411 415 422 482 520 521 221 222 223 224*/
const int N=3e5+3;


int32_t main(){
	ll n,z;
	cin >> n >> z;
	string s,k="";
	cin >> s;
	for (int i=0;i<z-1;i++){
        k+=s[i];
	}
	k+=s[z-1]-('A'-'a');
	for (int i=z;i<n;i++){
        k+=s[i];
	}
	cout << k;
	return 0;
}



















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

int binarySearch(int a[], int key, int n)
{
    int left = 0;
    int right = n;
    while(left < right){
        int mid = (left + right) / 2;
        if(a[mid] == key){
            return mid;
        }
        else if(key < a[mid]){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    return -1;
}

int main()
{
    int cnt = 0;
    int n;
    cin >> n;
    int S[n];
    for(int i = 0; i < n; i++){
        cin >> S[i];
    }
    
    int q;
    cin >> q;
    int T[q];
    for(int i = 0; i < q; i++){
        cin >> T[i];
    }
    for(int i = 0; i < q; i++){
        if((binarySearch(S, T[i], n)) != -1)
            cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3684
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=1; i<=n; i++)

int main(){
    int r,c;
    cin >> r >> c;
    vector<vector<int>> vv(r+2,vector<int>(c+2,0));
    rep(i,r){
        rep(j,c){
            cin >> vv[i][j];
        }
    }
    
    rep(i,r){
        rep(j,c){
            vv[i][c+1]+=vv[i][j];
        }
    }
    rep(j,c+1){
        rep(i,r){
            vv[r+1][j]+=vv[i][j];
        }        
    }
    
    rep(i,r+1){
        rep(j,c){
            cout << vv[i][j] << " ";    
        } 
        cout << vv[i][c+1];
        cout << endl;
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    if(s.size()==1){
        cout<<s<<endl;
        return 0;
    }

    // int sloop = 1;
    // REP(i,s.size()-2){
    //     sloop = sloop<<1;
    //     sloop |= 1;
    // }
    int sloop = pow(2,s.size()-1)-1;

    ll ans = 0;
    FOR(i,0,sloop+1){
        int prevbit = 0;
        ll temp = 0;
        FOR(j,0,s.size()-1){
            temp *= 10;
            temp += s[j]-'0';
            bool flg = i & 1<<j;
            if(flg){
                ans += temp;
                temp = 0;
            }
        }
        temp *= 10;
        temp += s[s.size()-1]-'0';
        ans += temp;
        temp = 0;
    }

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

Measured memory_bytes: 384
N = int(input())
childs = [[] for _ in range(N)]
parent = [-1 for _ in range(N)]
for _ in range(N):
    i, l, r = map(int, input().split())
    childs[i].extend([l, r])
    for child in [l, r]:
        if child != -1:
            parent[child] = i

preorder = []
inorder = []
postorder = []


def dfs(cur):
    preorder.append(cur)
    [left, right] = childs[cur]
    if left != -1:
        dfs(left)
    inorder.append(cur)
    if right != -1:
        dfs(right)
    postorder.append(cur)


root = 0
while root < N:
    if parent[root] == -1:
        break
    else:
        root += 1
dfs(root)


print('Preorder')
print(' ' + ' '.join(map(str, preorder)))
print('Inorder')
print(' ' + ' '.join(map(str, inorder)))
print('Postorder')
print(' ' + ' '.join(map(str, postorder)))



Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define endl '\n'
const ll mod = 998244353;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,w;
    cin>>n>>w;
    pair<ll,ll> p[n];
    for(int i=0;i<n;i++){
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+n);
    ll dp[n][w+1];
    for(int i=0;i<n;i++)
        for(int j=0;j<=w;j++)
            dp[i][j] = 0;
    for(int i=1;i<=w;i++){
        if(i>=p[0].first)
            dp[0][i] = p[0].second;
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<=w;j++){
            if(p[i].first>j){
                dp[i][j] = dp[i-1][j];
                continue;
            }
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-p[i].first]+p[i].second);
        }
    }
    cout<<dp[n-1][w]<<endl;
}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string a,b,c; cin>>a>>b>>c;
	cout<<(char)toupper(a.front())<<(char)toupper(b.front())<<(char)toupper(c.front())<<endl;
	return 0;
}


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

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        IEnumerable<int> ch = Enumerable.Repeat(int.MaxValue, 26);
        for (int i = 0; i < n; i++)
        {
            int[] p = new int[26];
            foreach (var c in Console.ReadLine())
            {
                p[c - 'a']++;
            }
            ch = ch.Zip(p, (x, y) => Math.Min(x, y));
        }
        string res = "";
        int[] ccc = ch.ToArray();
        for (int i = 0; i < 26; i++)
        {
            res += new string(char.ConvertFromUtf32('a' + i)[0], ccc[i]);
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
#include <stdbool.h>
#include <string.h>

int main(void)
{
    int n, m, i, j, sum;

    scanf("%d%d", &n, &m);

    int a[n][m];
    int b[m];

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            getchar();
            scanf("%d", &a[i][j]);
        }
    }

    for (int j = 0; j < m; ++j)
    {
        getchar();
        scanf("%d", &b[j]);
    }

    for (int i = 0; i < n; ++i)
    {
        sum = 0;
        for (int j = 0; j < m; ++j)
        {
            sum += a[i][j]*b[j];
        }
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 2740
N = int(input())

nums = list(map(int, input().split(' ')))

abs_sum = 0
count = 0
min_value = abs(nums[0])
for i in range(N):
  abs_sum += abs(nums[i])
  if nums[i] < 0:
    count += 1
  if abs(nums[i]) < min_value:
    min_value = abs(nums[i])

if count % 2 == 1:
  print(abs_sum - 2*min_value)
else:
  print(abs_sum)

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

int N, C, K;
int T[1000010];

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

    for (int i = 0; i < N; i++)
    {
        scanf("%d", &T[i]);
    }

    sort(T, T + N);

    int cnt = 0;
    for (int i = 0; i < N;)
    {
        cnt++;

        int start = i;
        while (i < N && T[i] - T[start] <= K && i - start < C)
        {
            i++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 640
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

def calc():
    c = Counter(A)
    if N % 2 == 0:
        for i, v in c.items():
            if i % 2 == 0:
                return 0
            if v != 2:
                return 0
    else:
        for i, v in c.items():
            if i % 2 == 1:
                return 0
            if i == 0 and v == 1:
                continue
            if v != 2:
                return 0
    return pow(2, N//2, 10**9+7)

print(calc())        



Measured memory_bytes: 55404
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>
#include <unordered_set>

int main()
{
    std::string s;
    uint64_t K;
     
    std::cin >> s >> K;

    uint64_t len = 0;
    for (int i = 0; i < s.size(); ++i) {
        char c = s[i];
        if (c == '1') {
            len += 1;
            if (K == len) {
                std::cout << c << std::endl;
                return 0;
            }
        } else {
            std::cout << c << std::endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MKP 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())
 
const int INF = 999999;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll MOD = 1000000007;

int dp[505][505];
int N,M,Q;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    REP(i,M){
        int l,r;
        cin >> l >> r;
        dp[l][r]++;
    }
    for(int i = N; i >= 1; i--){
        for(int j = 1; j <= N; j++){
            dp[i][j] += (dp[i+1][j] + dp[i][j - 1] - dp[i+1][j - 1]);
        }
    }

    REP(i,Q){
        int l,r;
        cin >> l >> r;
        cout << dp[l][r] << endl;
    }

    return 0;
}

Measured memory_bytes: 1920
from math import gcd
k = int(input())
gcdl = [[0 for i in range(k + 1)]for i in range(k+1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcdl[i][j] = gcd(i, j)
s = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for l in range(1, k + 1):
            s += gcdl[i][gcdl[j][l]]

print(s)


Measured memory_bytes: 68284
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b)cout<<(n-2)*(b-a)+1<<endl;
    else
    cout<<0<<endl; 
 } 

Measured memory_bytes: 256
import bisect
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n-2):
     for j in range(i + 1,n-1):
          ans += bisect.bisect_left(l,l[i] + l[j]) - j - 1
print(ans)

Measured memory_bytes: 3188
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto a = readln.split.to!(int[]);
    auto b = readln.split.to!(int[]);

    // dp(s, x) = (sに含まれるカードを左からソートした状態で詰めて最後がxになるときの最小操作回数)
    auto dp = new int[][](1 << N, 51);
    fillAll(dp, inf);
    dp[0][0] = 0;

    foreach (s ; 0 .. 1 << N) {
        foreach (x ; 0 .. 51) {
            if (dp[s][x] == inf) continue;
            int p = 0;
            int i = s.popcnt;

            foreach (j ; 0 .. N) if (!(s & 1 << j)) {
                int pos = p + i;
                p++;

                int y = abs(j - i) % 2 == 0 ? a[j] : b[j];

                debug {
                    writefln("pos: %s, y: %s", pos, y);
                }

                if (y >= x) {
                    chmin(dp[s | 1 << j][y],
                        dp[s][x] + abs(pos - i));
                }
            }
        }
    }

    debug {
        writefln("%(%s\n%)", dp);
    }

    int ans = inf;
    foreach (x ; 0 .. 51) {
        chmin(ans, dp[(1 << N) - 1][x]);
    }

    ans = ans < inf ? ans : -1;

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 76028
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
    string orig, mod;
    cin >> orig;
    cin >> mod;

    if(equal(begin(orig), end(orig), begin(mod))){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    
    return 0;
}


Measured memory_bytes: 3608
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [n,k] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  xs <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ length $ filter (>= k) xs


Measured memory_bytes: 1788
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int Dfs(int v, const vvi& E, vi& C)
{
    for (auto u: E[v]) {
        if (C[u] == -1) {
            C[u] = 1 - C[v];
            if (!Dfs(u, E, C)) return false;
        }
        else if (C[u] != 1 - C[v]) return false;
    }
    return true;
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vvi E(N);
    for (int m = 0; m < M; ++m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    vi C(N, -1);
    C[0] = 0;
    if (Dfs(0, E, C)) {
        int k = 0;
        for (int n = 0; n < N; ++n) {
            if (C[n] == 0) ++k;
        }
        cout << (ll)k*(N-k) - M << '\n';
    } else {
        cout << (ll)N*(N-1)/2 - M << '\n';
    }
    
    return 0;
}


Measured memory_bytes: 6656
N = int(input())
A = list(map(int,input().split()))
cnt=0
for i in range(N-1):
    minj=i
    for j in range(i,N):
        if A[j]<A[minj]:
            minj=j
    if minj != i:
        A[i],A[minj]=A[minj],A[i]
        cnt += 1
[print(A[x],end=' ') for x in range(N-1)];print(A[N-1]);print(cnt)


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
using namespace std;
const int N=2e5+3, INF=1e9;
int n, a[N], cnt[N], ans;
int choose(int x)
{
    return x*(x-1)/2;
}
signed main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(int i = 1; i <= n; i++)
    {
        ans+=choose(cnt[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        cout << ans - choose(cnt[a[i]]) + choose(cnt[a[i]]-1) << endl;
    }
}

Measured memory_bytes: 4736
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            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();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, k) = get!(usize, usize);
    let ab = get!(usize, usize ; n);

    let mut array = BTreeMap::new();

    for &(a, b) in &ab {
        *array.entry(a).or_insert(0) += b;
    }

    let mut rest = k;
    for (&n, &c) in array.iter() {
        if c >= rest {
            println!("{}", n);
            return;
        }
        rest -= c;
    }
}


Measured memory_bytes: 6396
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int n; cin >> n;
    ll a[n], b[n];
    rep(i,n) cin >> a[i] >> b[i];

    ll ans = 0;
    for (int i = n - 1; i >= 0; --i) {
        a[i] += ans;
        if (a[i] % b[i] == 0) continue;
        ans += b[i] - a[i] % b[i];
    }
    out(ans);


    return 0;
}









Measured memory_bytes: 1792
use std::io;
use std::cmp::Ordering;

fn main(){

    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Failed to read line");

    let v : Vec<&str> = input.split('/').collect();

    let y : i32 = v[0].parse().unwrap();
    let m : i32 = v[1].parse().unwrap();

    match y.cmp(&2019){
        Ordering::Less => println!("Heisei"),
        Ordering::Equal => match m.cmp(&04){
            Ordering::Less => println!("Heisei"),
            Ordering::Equal => println!("Heisei"),
            Ordering::Greater => println!("TBD"),
        },
        Ordering::Greater => println!("TBD"),
    }

}

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

int main() {
  int x,y; cin >> x >> y;
  if ( x == 2 && y == 2 ) cout << "Yes" << endl;
  else if ( (x == 4 || x == 6 || x == 9 || x == 11) &&
	    ( y == 4 || y == 6 || y == 9 || y == 11)) cout << "Yes" << endl;
  else if ( (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10
	     || x == 12) &&
	     (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10
	      || y == 12)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=2e5+10,inf=0x3f3f3f3f,mod=1e9+7;
int idx[maxn],idx_cnt,a[maxn],b[maxn],N,dp[maxn];
inline void add(int &x,int y){
	x+=y;
	x=(x>=mod?x-mod:x);
}
struct szsz{
	int c[maxn];
	inline int lowbit(int x){
		return x&(-x);
	}
	int sum(int x){
		int res=0;
		while(x){
			add(res,c[x]);
			x-=lowbit(x);
		}
		return res;
	}
	void Add(int x,int y){
		while(x<=idx_cnt){
			add(c[x],y);
			x+=lowbit(x);
		}
	}
}bit;
struct point{
	int x,y;
	bool operator <(const point &rhs) const{
		return x<rhs.x || (x==rhs.x && y<rhs.y);
	}
	bool operator ==(const point &rhs) const{
		return x==rhs.x && y==rhs.y;
	}
}A[maxn];
int main(){
	int n=read(),m=read();
	REP(i,1,n) a[i]=read();
	REP(i,1,m) b[i]=read();
	REP(i,1,n){
		int u=lower_bound(b+1,b+m+1,a[i])-b;
		if(b[u]==a[i] || u==1 || u==m+1) continue;
		A[++N]=(point){a[i]-b[u-1],b[u]-a[i]};
		idx[++idx_cnt]=a[i]-b[u-1];
		idx[++idx_cnt]=b[u]-a[i];
	}
	idx[++idx_cnt]=0;
	idx[++idx_cnt]=inf;
	sort(idx+1,idx+idx_cnt+1);
	idx_cnt=unique(idx+1,idx+idx_cnt+1)-idx-1;
	REP(i,1,N){
		A[i].x=lower_bound(idx+1,idx+idx_cnt+1,A[i].x)-idx;
		A[i].y=lower_bound(idx+1,idx+idx_cnt+1,A[i].y)-idx;
	}
	sort(A+1,A+N+1);
	N=unique(A+1,A+N+1)-A-1;
	bit.Add(1,1);
	for(int i=1,j;i<=N;i=j+1){
		j=i;
		while(j<N && A[j+1].x==A[i].x) ++j;
		REP(k,i,j){
			dp[k]=bit.sum(A[k].y-1);
		}
		REP(k,i,j) bit.Add(A[k].y,dp[k]);
	}
	printf("%d\n",bit.sum(idx_cnt));
	return 0;
}


Measured memory_bytes: 4608
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            return consoleReader.Int / 3;
        }

        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    public class ConsoleReader
    {
        private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = ReadLineSplit();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader : IEnumerable<ConsoleReader>
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }
            public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator();
            System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();

            public IEnumerable<string> String => this.Select(cr => cr.String);
            public IEnumerable<int> Int => this.Select(cr => cr.Int);
            public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1);
            public IEnumerable<long> Long => this.Select(cr => cr.Long);
            public IEnumerable<double> Double => this.Select(cr => cr.Double);
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
    #endregion
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	int n,m;
	cin>>n>>m;
	cout<<n+m/2<<endl;

	return 0;
}


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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

// -------------------------------------------------------------------
// sort 1 2 3 4

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vec a(1);

    int x;
    rep (i, n) {
        cin >> x;
        a.pb((x + a[i]) % m);
    }

    map<int, int> mp;
    repall (i, a)
        mp[i]++;

    int ans = 0;
    repall (e, mp) {
        x = e.second;
        ans += x * (x - 1) / 2;
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define int ll
#define Endl endl

int UF[114514];
void UFinit(int n){
    for(int i=0;i<=n;i++){
        UF[i]=i;
    }
}
int UFroot(int k){
    if(UF[k]==k){
        return k;
    }else{
        UF[k]=UFroot(UF[k]);
        return UF[k];
    }
}
int UFsame(int P,int Q){
    if(UFroot(P)==UFroot(Q)){
        return true;
    }else{
        return false;
    }
}
void UFunite(int P,int Q){
    int p=UFroot(P);
    int q=UFroot(Q);
    if(p==q)return;
    if(p>q)swap(p,q);
    UF[q]=p;
}


signed main(void){
    int N,M;
    int X[114514],Y[114514],Z[114514];
    cin >> N >> M;
    REP(i,M){
        cin >> X[i] >> Y[i] >> Z[i];
        X[i]--;Y[i]--;
    }
    UFinit(N);
    REP(i,M){
        UFunite(X[i],Y[i]);
    }
    int Ans=0;
    REP(i,N){
        if(UF[i]==i){
            Ans++;
        }
    }
    cout << Ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll cd = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll N;
    cin >> N;
    vel A(N);
    rep(i, N) {
        cin >> A.at(i);
    }
    ll c4 = 0, c2 = 0, co = 0;
    rep(i, N) {
        if(A.at(i) % 4 == 0) {
            c4++;
        }
        else if(A.at(i) % 2 == 0) {
            c2++;
        }
        else {
            co++;
        }
    }
    if (c2 == 0) {
        if (co < c4 + 2) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        if (co < c4 +1) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

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

int main() {
  int x; cin>>x;
  if(x<4){cout<<x;}
  else{
    for(int i=2; i<=x/2; i++){
      if(x%i==0){x++;i=1;}
      if(i==x/2&&x%i!=0){cout<<x;break;}
    }
  }
}

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

int main() {
  int A, B, i, x1, x2, x3, x4, x5, n;
  n = 0;
  cin >> A >> B;
  for (i = A; i <= B; i++){
    x1 = i / 10000;
    x2 = (i - x1 * 10000) / 1000;
    x3 = (i - x1 * 10000 - x2 * 1000) / 100;
    x4 = (i - x1 * 10000 - x2 * 1000 - x3 * 100) / 10;
    x5 = i - x1 * 10000 - x2 * 1000 - x3 * 100 - x4 * 10;
    int m;
    if (x1 == x5 && x2 == x4){
      m = 1;
    }
    else {
      m = 0;
    }
    n += m;
  }
  cout << n <<endl;
}


Measured memory_bytes: 256
n=int(input())
ns=list(map(int,input().split()))
ans=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if(ns[j]<ns[minj]):
            minj=j
    if i!=minj:
        ans+=1
        k=ns[i]
        ns[i]=ns[minj]
        ns[minj]=k
 
for i in range(n):
    if(i!=n-1):
        print(ns[i],end=' ')
print(ns[n-1])
print(ans)



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
  cin>>N>>K;
  vector<bool>dp(K+1);
  vector<int>a(N);
  for(int i=0;i<N;i++)
    cin>>a.at(i);
  for(int i=0;i<a.at(0);i++)
    dp[i]=false;
  for(int i=0;i<N;i++)
    dp[a.at(i)]=true;
  set<int>S;
  for(int i=0;i<N;i++)
    S.insert(a.at(i));
  for(int i=a.at(0)+1;i<=K;i++)
    if(!S.count(i)){
    bool x=false;
      for(int j=0;j<N;j++){
      if(0<=i-a.at(j)){
       if(!dp[i-a.at(j)]){x=true; break;}
      
      }
      }
         dp[i]=x;
    
    }if(dp[K])
      cout<<"First"<<endl;
  else
    cout<<"Second"<<endl;
    
    
    
  
   return 0;
}

Measured memory_bytes: 256
//import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.HashSet;

public class Main {
    static int[][] map;
    static boolean[][] visited;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int w, h;
        while (true) {
            String[] wh = br.readLine().split(" ");
            w = Integer.parseInt(wh[0]);
            h = Integer.parseInt(wh[1]);
            if (w == 0 && h == 0) break;
            map = new int[h+2][w+2];
            visited = new boolean[h+2][w+2];
            int count = 0;
            
            for (int i = 0; i < h; i++) {
                String[] line = br.readLine().split(" ");
                for (int j = 0; j < w; j++) {
                    map[i+1][j+1] = Integer.parseInt(line[j]);
                }
            }
            
            for (int k = 0; k < h; k++) {
                for (int l = 0; l < w; l++) {
                    if (map[k+1][l+1] == 1 && !visited[k+1][l+1]) {
                        dfs(k+1, l+1);
                        count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
    public static void dfs(int raw, int column) {
        int[] df = {-1, 0, 1};
        for (int raw_df: df) {
            for (int column_df: df) {
                if (raw_df==0 && column_df==0) continue;
                if (map[raw-raw_df][column-column_df] == 0 || visited[raw-raw_df][column-column_df]) {
                    continue;
                }
                else {
                    visited[raw-raw_df][column-column_df] = true;
                    dfs(raw-raw_df, column-column_df);
                }
            }
        }
    }
}



Measured memory_bytes: 29012
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

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

int main()
{
    int a1,a2,a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3>=22)
    {
        cout<<"bust"<<endl;
    }
    else
    {
        cout<<"win"<<endl;
    }
    
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int cnt = 0;
    int index = 1;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i] != index) cnt++;
        else index++;
    }
    if(cnt == n) cnt = -1;
    cout << cnt << endl;
}

Measured memory_bytes: 4024
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// a^n mod 
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;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	cin>>n>>a>>b>>c;
/*
	memset(b, '\0', sizeof(b));
初期化*/
/*
	len = strlen(s);
文字列長さ*/
/*
	string s;
	s.size()
*/
/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("YES");
	else puts("NO");
*/

int main(){
	int n, w[110];
	int ans=P;
	memset(w, '\0', sizeof(w));
	cin>>n;
	rep(i, n){
		cin>>w[i];
	}
	int wa=0;
	rep(i, n){
		wa=wa+w[i];
	}
	int sub;
	for(int i=0;i<n;i++){
		sub=0;

		rep(j, i){
			sub=sub+w[j];
	
		}
		ans=min(ans, ze(sub,wa-sub));
	}




/*	long long int as[N], bs[N], cnm[N];
	memset(as, '\0', sizeof(as));
	memset(bs, '\0', sizeof(bs));
	memset(cnm, '\0', sizeof(cnm));
	as[0]=1;
	bs[0]=1;
	cnm[0]=1;
	long long int invab=modinv(a+b,P);//inva+b
	long long int inva=mt(invab, a,P);
	long long int invb=mt(invab, b,P);
	rep(i, N){
		if(i>0){
			as[i]=mt(as[i-1],inva,P);
			bs[i]=mt(bs[i-1],invb,P);
			cnm[i]=mt(mt(cnm[i-1],modinv(i,P),P),n+i,P);

		}
	}
	long long int kari;
	rep(i, n){
		kari=cnm[i];
		kari=mt(kari,(mt(as[n],bs[i],P)+mt(as[i],bs[n],P))%P,P);
		kari=mt(kari,n+i,P);
		ans=(ans+kari)%P;
	}
	ans=mt(mt(ans,100,P),modinv(a+b,P),P);
*/
	cout<<ans<<endl;


}

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

int main()
{
	string ver[4] = {"AC", "WA", "TLE", "RE"};
	int ar[4] = {};

	int n;
	cin >> n;

	string s;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;

		for (int j = 0; j < 4; ++j)
			if (ver[j] == s)
				ar[j]++;
	}

	for (int i = 0; i < 4; ++i)
		cout << ver[i] << " x " << ar[i] << '\n';
	return 0;
}

Measured memory_bytes: 3596
from collections import defaultdict
N,M = map(int,input().split())
d1 = defaultdict(lambda:False)
d2 = defaultdict(lambda:0)
for i in range(M):
    p,s = input().split()
    if s == 'WA':
        if not d1[p]:
            d2[p] += 1
    else:
        if not d1[p]:           
            d1[p] = True
ans = [0,0]
for p in d1:
    if d1[p]:
        ans[0] += 1
        ans[1] += d2[p]
print(*ans)

Measured memory_bytes: 27220
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int main() {
	char S[10];
	cin >> S;
	bool A = false;
	for (int i = 1; i <= 3; i++) {
		A = A || S[i - 1] == S[i];
	}
	if (A) cout << "Bad";
	else cout << "Good";
	return 0;
}

Measured memory_bytes: 256