akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <map>
using namespace std;

int ms[15][15];
int n;

void init(){
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i == n / 2 && j == n / 2 + 1) ms[i][j] = 1;
      else ms[i][j] = -1;
    }
  }
}

pair<int, int> checkNext(pair<int, int> now){
  int nx = now.first, ny = now.second;
  if(nx < n && nx >= 0 && ny < n && ny >= 0 && ms[nx][ny] == -1) return now;
  else if(nx >= n) return checkNext(pair<int, int>(0, ny));
  else if(ny >= n) return checkNext(pair<int, int>(nx, 0));
  else if(nx < 0) return checkNext(pair<int, int>(n - 1, ny));
  else if(ny < 0) return checkNext(pair<int, int>(nx, n - 1));
  else if(ms[nx][ny] != -1) return checkNext(pair<int, int>(nx - 1, ny + 1));
}

void printMs(){
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      printf("%4d", ms[j][i]);
    }
    printf("\n");
  }
}

int main(void){
  while(cin >> n && n != 0){
    init();
    pair<int, int> now = pair<int, int>(n/2, n/2 + 1);
    for(int i = 2; i <= n * n; i++){
      pair<int, int> next = checkNext(pair<int, int>(now.first + 1, now.second + 1));
      ms[next.first][next.second] = i;
      now = next;
    }
    printMs();
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5] ) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T> vector<vector<T>> make_vector_2d(int n, int m, T initialValue) {
    auto r = vector<vector<T>>(n);
    for (int i = 0; i < n; i++) r[i] = vector<T>(m,initialValue);
    return r;
}
template <typename T> vector<vector<vector<T>>> make_vector_3d(int n, int m, int l, T initialValue) {
    auto r = vector<vector<vector<T>>>(n);
    for (int i = 0; i < n; i++) {
        r[i] = vector<vector<T>>(m);
        for (int j = 0; j < m; j++) r[i][j] = vector<T>(l, initialValue);
    }
    return r;
}

int main() {

    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];
    std::sort(p.begin(), p.end());
    std::sort(q.begin(), q.end());
    std::sort(r.begin(), r.end());
    p.push_back(LLONG_MAX);
    q.push_back(LLONG_MAX);

    int ip = a - x;
    int iq = b - y;
    int ir = c;
    while (true) {
        if (ir == 0) break;
        if (p[ip] < q[iq]) {
            if (p[ip] < r[ir - 1]) {
                ip++;
                ir--;
            }
            else {
                break;
            }
        }
        else {
            if (q[iq] < r[ir - 1]) {
                iq++;
                ir--;
            }
            else {
                break;
            }
        }
    }
    ll sum = 0ll;
    for (int i = ip; i < a; i++) sum += p[i];
    for (int i = iq; i < b; i++) sum += q[i];
    for (int i = ir; i < c; i++) sum += r[i];

    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 3328
from math import factorial

n = int(input())
f = factorial(n)

mod = 10 ** 9 + 7

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n ** 0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

ans = 1
for p in primes(n):
    temp = 1
    while f % p == 0:
        temp += 1
        f //= p
    ans = (ans * temp) % mod
print(ans)

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

void Push(int* s, int x){
	int top;
	s[0]++;
	top=s[0];

	s[top]=x;
}
void Pop(int* s){
	s[0]--;
}
int Top(int* s){
	int top=s[0];
	return s[top];
}

int main(){
	char in[1000][20];
	int s[1000];
	s[0]=0;

	int i=0,ans=0,tmp,a,b;
	while(1){
		if(scanf("%s",&in[i])!=1)break;

		if(in[i][0]=='+'){
			a=Top(s);	Pop(s);
			b=Top(s);	Pop(s);

			Push(s,b+a);
			//printf("%d+%d\n",a,b);
		}else if(in[i][0]=='-'){
			a=Top(s);	Pop(s);
			b=Top(s);	Pop(s);

			Push(s,b-a);
			//printf("%d-%d\n",a,b);
		}else if(in[i][0]=='*'){
			a=Top(s);	Pop(s);
			b=Top(s);	Pop(s);

			Push(s,b*a);
			//printf("%d*%d\n",a,b);
		}else{
			tmp=atoi(in[i]);
			Push(s,tmp);
		}
		i++;
	}

	printf("%d\n",Top(s));
	return 0;
}



Measured memory_bytes: 2700
import java.util.*;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        long[/* placed */][/* num */][] dp = new long[2][4][n+1];
        if(n % 2 >= 0) {
            //dp[1][ind(1, 1)][2] = a[1];
            dp[0][0][1] = dp[0][3][1] = dp[1][0][1] = dp[1][3][1] = Long.MIN_VALUE;
            dp[0][1][1] = dp[0][2][1] = dp[1][1][1] = dp[1][2][1] = Long.MIN_VALUE;
            dp[1][ind(0, 1)][1] = a[0];
            dp[0][ind(0, 0)][1] = 0;
            for(int i=1; i<n; i++) {
                int n1 = i / 2;
                int n2 = i / 2 + 1;
                dp[0][0][i] = dp[0][3][i] = dp[1][0][i] = dp[1][3][i] = Long.MIN_VALUE;
                dp[0][ind(i, n1)][i + 1] = Math.max(dp[0][ind(i - 1, n1)][i], dp[1][ind(i - 1, n1)][i]);
                dp[1][ind(i, n1)][i + 1] = dp[0][ind(i - 1, n1 - 1)][i] + a[i];
                dp[0][ind(i, n2)][i + 1] = Math.max(dp[0][ind(i-1, n2)][i], dp[1][ind(i - 1, n2)][i]);
                dp[1][ind(i, n2)][i + 1] = dp[0][ind(i - 1, n2 - 1)][i] + a[i];
            }
        }

        long res = Math.max(dp[0][ind(n-1, n/2)][n], dp[1][ind(n-1, n/2)][n]);

        System.out.println(res);
    }
    static int ind(int i, int num) {
        return (num - (i / 2) + 1);
    }

}

Measured memory_bytes: 64756
N,M=map(int,input().split())
ListA=list(map(int,input().split()))
LIstC2=[]
book1={}
for i in range(M):
    B,C=map(int,input().split())
    if C in book1.keys():
        book1[C]+=B
    else:
        book1[C]=B
for i in range(N):
    if ListA[i] in book1.keys():
        book1[ListA[i]]+=1
    else:
        book1[ListA[i]]=1
ListC2=sorted(list(book1.keys()))
i=len(ListC2)-1
amount=0
point=0
while 0<=i:
    if amount+book1[ListC2[i]]<=N:
        point+=book1[ListC2[i]]*ListC2[i]
        amount+=book1[ListC2[i]]
        i-=1
    else:
        point+=(N-amount)*ListC2[i]
        break
print(point)

Measured memory_bytes: 33316
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
#define vecmin(A) *min_element(A.begin(), A.end())
#define vecmax(A) *max_element(A.begin(), A.end())
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> vv;

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

int main(){
  int n,k;
  cin >> n >> k;
  vec x(n);
  rep(i,n) cin >> x[i];
  vec d(n-k+1);
  rep(i,n-k+1){
    d[i] = abs(x[i+k-1] - x[i]);
    d[i] += min(abs(x[i+k-1]),abs(x[i]));
  }
  cout << vecmin(d) << endl;
}

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

x, y = map(int, input().split())

grp1 = [1,3,5,7,8,10,12]
grp2 = [4,6,9,11]
grp3 = [2]

if x in grp1 and y in grp1 or x in grp2 and y in grp2 or x in grp3 and y in grp3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int inf=0x3f3f3f3f;
using namespace std;
long double a,sum;
int n;
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		sum+=(1/a);
	}
	cout<<1/sum<<endl;
	return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
//const ll MOD = 924844033;
const ld PI = 3.141592653589793;
const int maxn = 600001;
const int MOD = 1e9 + 7;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll dp[101][4][4];

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");

    auto solve = [](int _) {
        int n;
        cin >> n;
        string s1;
        cin >> s1;
        string s2;
        cin >> s2;
        if (s1[0] == s2[0]) {
            for (int i = 0; i < 3; ++i) {
                dp[1][i][i] = 1;
            }
        } else {
            for (int i = 0; i < 3; ++i) {
                for (int j = 0; j < 3; ++j) {
                    if (i != j) dp[1][i][j] = 1;
                }
            }
        }
        auto cmp = [](char fi, char se, int fi1, int se1) {
            if (fi != se) {
                return fi1 != se1;
            }
            return fi1 == se1;
        };
        for (int i = 1; i < n; ++i) {
            for (int a = 0; a < 3; ++a) {
                for (int b = 0; b < 3; ++b) {
                    for (int x = 0; x < 3; ++x) {
                        for (int z = 0; z < 3; ++z) {
                            bool ok = cmp(s1[i], s2[i], x, z) && cmp(s1[i - 1], s1[i], a, x) &&
                                      cmp(s2[i - 1], s2[i], b, z);
                            if (ok) {
                                dp[i + 1][x][z] += dp[i][a][b];
                                dp[i + 1][x][z] %= MOD;
                            }
                        }
                    }
                }
            }
        }
        ll ans = 0;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                ans += dp[n][i][j];
                ans %= MOD;
            }
        }
        cout<<ans;
    };


    fast_io();
    cout.precision(9);
    cout << fixed;

    solve(1);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define vv vector
#define pp pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
typedef pair<ll, ll> pll;
typedef vv<ll> vll;
typedef vv<pll> vpll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//adds two more functions to set
//(1)*(set.find_by_order(k))[kth element in the sorted set]
//(2)set.order_of_key(k)[count of elements strictly less than k]
#define LG(args...)                               \
	{                                             \
		string _s = #args;                        \
		replace(_s.begin(), _s.end(), ',', ' ');  \
		stringstream _ss(_s);                     \
		err(istream_iterator<string>(_ss), args); \
		cerr << endl;                             \
	}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "(" << *it << ":" << a << ") ";
	err(++it, args...);
}
//:::::::::::::::::::::::::::::::::::::::::::::
const ll INF = 9e18;
const ll MOD = 1e9 + 7;
// #define dbg

int main(){
	fastio;
	string s;
	cin>>s;
	for(auto& i: s){
		if(i == '?')
			i='D';
	}
	cout<<s;
}	

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

#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    print(ceil(float(N)/2));
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<vector<ll>> Graph;
struct Node {ll v,d,p,l,r;};
typedef vector<Node> Tree;
struct Point {ll x,y;};
struct Vector {ll x,y;};
typedef pair<Point,Point> Edge;
Vector operator-(Point a,Point b) {
  Vector vec;
  vec.x=a.x-b.x; vec.y=a.y-b.y;
  return vec;
}
ll operator*(Vector &a,Vector &b) {return a.x*b.x+a.y*b.y;}
bool onLine(Point a,Point b,Point c) {
  if(a.x==b.x&&b.x==c.x) return true;
  if(a.y==b.y&&b.y==c.y) return true;
  Vector v1=a-b,v2=c-b;
  if((v1*v1)*(v2*v2)==(v1*v2)*(v1*v2)) return true;
  return false;
}
bool operator<(Point a,Point b) {
  if(a.x<b.x) return true;
  if(a.x>b.x) return false;
  return a.y<b.y;
}
bool operator==(Point a,Point b) {return a.x==b.x&&a.y==b.y;}
bool operator==(Edge a,Edge b) {return a.first==b.first&&a.second==b.second;}

namespace std {
  template<>
  struct hash<Edge> {
    size_t operator()(const Edge e) const{
      return hash<ll>()(e.first.x)^hash<ll>()(e.first.y)^hash<ll>()(e.second.x)^hash<ll>()(e.second.y);
    }
  };
}

void print(Edge a){
  printf("(%lld,%lld),(%lld,%lld)\n",a.first.x,a.first.y,a.second.x,a.second.y);
}
const ll MOD = 998244353;

ll pw(ll a){
  ll ret=1;
  REP(i,a) ret=ret*2%MOD;
  return ret;
}

ll mod(ll a){
  return ((a%MOD)+MOD)%MOD;
}

int main(){
  ll N; cin>>N;
  vector<Point> P(N); REP(i,N) cin>>P[i].x>>P[i].y;
  UM<Edge,ll> um;
  REP(i,N) FOR(j,i+1,N) {
    Edge edge={P[i],P[j]};
    if(!(edge.first<edge.second)) swap(edge.first,edge.second);
    ll cnt=2;
    REP(k,N) {
      if(k==i||k==j) continue;
      if(onLine(P[i],P[j],P[k])) {
        if(P[k]<edge.first) edge.first=P[k];
        if(edge.second<P[k]) edge.second=P[k];
        cnt++;
      }
    }
    um[edge]=cnt;
  }

  ll sum=0;
  for(auto i:um) {sum+=pw(i.second)-(1+i.second); sum%=MOD;}
  cout<<mod(pw(N)-sum-N-1)<<endl;

}


Measured memory_bytes: 1792
s = input()
first = int(s[:2])
last = int(s[2:])

def is_month(m):
    return m > 0 and m <= 12

if is_month(first) and not is_month(last):
    print('MMYY')
elif not is_month(first) and is_month(last):
    print('YYMM')
elif not is_month(first) and not is_month(last):
    print('NA')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3060
if __name__ == "__main__":
 
    n = int(input())
    a_list = input().split()
    b_list = input().split()
    c_list = input().split()
    
    points = 0
    for i, a in enumerate(a_list):
        points += int(b_list[int(a) - 1])
        if i >= 1 and int(a_list[i]) == int(a_list[i - 1]) + 1:
            points += int(c_list[int(a_list[i - 1]) - 1])
    
    print('{0}'.format(points))

Measured memory_bytes: 3064
#include <stdio.h>

#define MAX_SIZE 100

int main(void)
{
    int n,i,j,tmp;
    int a[MAX_SIZE];
    int sorted[MAX_SIZE];
    int point_alice, point_bob;

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

    //sort
    for(i=0; i<(n-1); i++){
        for(j=(n-1); j>i; j--){
            if(a[j-1]<a[j]){
                tmp = a[j-1];
                a[j-1]=a[j];
                a[j]=tmp;
            }
        }
    }

    for(i=0; i<n; i++){
        //Aliceのターンでゲットするポイント計算
        if(i%2 == 0){
            point_alice += a[i];
        }
        //Bobのターンで取得するポイント計算
        else{
            point_bob += a[i];
        }
    }

    printf("%d\n", point_alice-point_bob);
}

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

using namespace std;

int main(){

        int height,width;

        while(true){
                cin >> height >> width;
                if(height == 0 && width == 0)break;

                for(int i = 1; i <= height; i++){
                        for(int j = 1; j <= width; j++){
                                if((i % 2) != 0){
                                        if((j % 2) != 0)
                                                cout << "#";
                                        else
                                                cout << ".";
                                }
                                else{
                                        if((j % 2) != 0)
                                                cout << ".";
                                        else 
                                                cout << "#";
                                }
                        }
                        cout << "\n";
                }
                cout << "\n";
        }

        return 0;
}

Measured memory_bytes: 1120
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    string S;
    cin >> N >> K >> S;
    S[K - 1] += 'a' - 'A';
    cout << S << "\n";
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long long a[4];
    for(int i=0;i<4;i++)cin >> a[i];
    long long ans=max(max(a[0]*a[3],a[1]*a[3]),max(a[0]*a[2],a[1]*a[2]));
    cout << ans;
}

Measured memory_bytes: 3192
while True:
    num = list(map(int,input().split()))
    if(num[0] == 0 and num[0] == 0): break
    else:
        flag = False
        for i in range(num[0]):
            str = ""
            if(i % 2 == 0):flag = True
            else: flag = False
            for j in range(num[1]):
                if(flag):
                    str = str + "#" 
                    flag = False
                else:
                    str = str + "."
                    flag = True
            print(str)
        print("")


Measured memory_bytes: 5612
N, Ma, Mb = map(int, input().split())
ABC = [tuple(map(int, input().split())) for _ in range(N)]
ABC.sort(key=lambda x: x[2])

dp = [[(0, 0, [-1])]]

for p in range(1, N * 100 + 1):
    tmp = []
    for i, (a, b, c) in enumerate(ABC):
        if p - c >= 0:
            for ta, tb, ti in dp[p - c]:
                if ti[-1] < i:
                    if (a + ta) * Mb == (b + tb) * Ma:
                        print(p)
                        exit()
                    tmp.append((a + ta, b + tb, ti + [i]))
    dp.append(tmp)

print("-1")


Measured memory_bytes: 3188
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    int n;
    while(cin >> n && n + 1)
    {
        vint v;
        
        do {
            v.push_back(n % 4);
        } while (n /= 4);
        
        rep(i, v.size())
            cout << v[v.size() - i - 1];
        cout << endl;
    }
}

Measured memory_bytes: 0
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if b-a<=k and c-a<=k and d-a<=k and e-a<=k:
    if c-b<=k and d-b<=k and e-b<=k:
        if d-c<=k and e-c<=k:
            if e-d<=k:
                print("Yay!")
            else:
                print(":(")
        else:
            print(":(")
    else:
        print(":(")
else:
    print(":(")


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

int main(){
    ll h,w;
    cin >> h >> w;
    string str[50];
    ll a[8]={1,0,-1,0,1,-1,1,-1};
    ll b[8]={0,1,0,-1,1,1,-1,-1};
    rep(i,h) cin >> str[i];
    
    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(str[i][j]=='#') continue;
            
            ll count=0;
            
            for(ll k=0;k<8;k++){
                ll c=i+a[k];
                ll d=j+b[k];
                if(c<0||h<=c) continue;
                if(d<0||w<=d) continue;
                if(str[c][d]=='#') count++;
            }
            
            str[i][j]=count+'0';
        }
    }
    
    rep(i,h) cout << str[i] << endl;

    return 0;
}










Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int str[3][50],a,b,c,x,cnt,i,j,k;
    scanf("%d%d%d%d",&a,&b,&c,&x);
    for(i=0;i<=a;i++){
        str[0][i]=i;
    }
    for(i=0;i<=b;i++){
        str[1][i]=i;
    }
    for(i=0;i<=c;i++){
        str[2][i]=i;
    }
    for(i=0;i<=a;i++){
        for(j=0;j<=b;j++){
            for(k=0;k<=c;k++){
                if(x==((str[0][i]*500)+(str[1][j]*100)+(str[2][k]*50)))
                    cnt++;
            }
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define lld long double
#define MOD 1000000007
#define CAP 100000001
#define inf 1000000000000000000LL
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(v) v.size()
#define all(v)    v.begin(),v.end()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll power(ll x,ll y, ll md=MOD){ll res = 1;x%=md;while(y>0){if(y&1)res = (res*x)%md;x = (x*x)%md;y = y>>1;}return res%md;}
#define dbg(x) cout <<#x<<":"<<x<<endl;
ll max1(ll a, ll b, ll c=-inf, ll d=-inf) {ll mx1=(a>b)?a:b, mx2=(c>d)?c:d; return ((mx1>mx2)?mx1:mx2);}
#define int ll


signed main() {
	fast;
	
	ll n,k;
	cin>>n>>k;
	ll lef=n-k;
	if(k>1) cout<<lef;
	else cout<<0;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
enum vision_rank{
	RANK_A = 0,
	RANK_B,
	RANK_C,
	RANK_D,
	MAX_RANK
};
int main()
{
	int l_num[MAX_RANK] = {0,};
	int r_num[MAX_RANK] = {0,};

	while(true)
	{
		double left, right;
		cin >> left >> right;
		if( cin.eof() ) break;

		if( left >= 1.1 ){
			++l_num[ RANK_A ];
		}else if( left >= 0.6 ){
			++l_num[ RANK_B ];
		}else if( left >= 0.2 ){
			++l_num[ RANK_C ];
		}else{
			++l_num[ RANK_D ];
		}

		if( right >= 1.1 ){
			++r_num[ RANK_A ];
		}else if( right >= 0.6 ){
			++r_num[ RANK_B ];
		}else if( right >= 0.2 ){
			++r_num[ RANK_C ];
		}else{
			++r_num[ RANK_D ];
		}
	}
	for(int i = RANK_A; i < MAX_RANK; ++i){
		cout << l_num[ i ] << ' ' << r_num[ i ] << '\n';
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define pb push_back
typedef long double ld;
typedef vector<ll> vll;
typedef vector<pair<ll,ll>> vpl;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const ll mod = 1e9+7;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll n;cin >> n;
        ll ans =1;
        vll pf(n+3,1);
        for(ll i=2;i<=n;i++){
            for(ll j=i; j<=n ; j+=i){
                    pf[j]++;
            }
        }

        repA(i,2,n){
            // cout << pf[i] << ' ';
            ans += i*pf[i];
        }
        // cout << endl;
        cout << ans << endl;
    }
}


Measured memory_bytes: 81328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define P pair<ll,ll>
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main(){
	int a,b; cin >> a >> b;
	cout << lcm((ll)a,b) << endl;
}

Measured memory_bytes: 256
from copy import deepcopy

def getval():
    n,ma,mb = map(int,input().split())
    p = [list(map(int,input().split())) for i in range(n)]
    return n,ma,mb,p 

def main(n,ma,mb,p):
    dp = [[[-1 for i in range(401)] for i in range(401)]]
    dp[0][0][0] = 0
    for i in range(n):
        temp = deepcopy(dp[-1])
        temp[0][0] = 0
        cur = p[i]
        prev = dp[-1]
        for a in range(401):
            for b in range(401):
                if cur[0]>a or cur[1]>b:
                    continue
                if prev[a-cur[0]][b-cur[1]]==-1:
                    continue
                elif prev[a][b]==-1:
                    temp[a][b] = prev[a-cur[0]][b-cur[1]] + cur[2]
                    #print(i,a,b,temp[a][b],prev[a-cur[0]][b-cur[1]])
                else:
                    temp[a][b] = min(prev[a][b], prev[a-cur[0]][b-cur[1]] + cur[2])
        dp.append(temp)
    ans = -1
    for i in range(1,401):
        if i*ma>400 or i*mb>400:
            break
        if dp[n][i*ma][i*mb]!=-1:
            if ans==-1:
                ans = dp[n][i*ma][i*mb]
            else:
                ans = min(ans,dp[n][i*ma][i*mb])
    print(ans)
    #print(dp[n])

if __name__=="__main__":
    n,ma,mb,p = getval()
    main(n,ma,mb,p)


Measured memory_bytes: 131016
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int lastd(int x){
    return x%10;
}
int firstd(int x){
    while(x>=10)x/=10;
    return x;
}
int pw(int x){
    int res=1;
    while(x--)res*=x;
    return res;
}
int bit(int x){
    int res=0;
    while(x)x/=10,res++;
    return res;
}
int n,ans,cnt,dp[20][20];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        int l=lastd(i),f=firstd(i);
        dp[l][f]++;
    }
    for(int i=0;i<=9;i++)
        for(int j=0;j<=9;j++)
            ans+=dp[i][j]*dp[j][i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=100000+9,mod=1000000000+7;
ll cnt[N],fres[N];
void go(ll n){

   for(ll i=1;i*i<=n;i++){

       if(n%i==0){
         cnt[i]++;
         if(n/i!=i) cnt[n/i]++;
       }

   }
}
ll power(ll b,ll p){

   if(p==0) return 1;
   if((p&(1ll))){
     return b%mod*power((b*b)%mod,p/2)%mod;
   }
   else{
    return  power((b*b)%mod,p/2);
   }
}
int main(){
    GO();
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=k;i++){
        go(i);
    }
    ll ans=0;
    for(ll i=k;i>=1;i--){
        fres[i]=power(cnt[i],n);
         for(ll j=i*2;j<=k;j+=i){
            fres[i]=((fres[i]-fres[j])+mod)%mod;
         }
         ans+= (1ll*fres[i]*i)%mod;
         if(ans>=mod) ans-=mod;

    }
    cout<<ans<<"\n";
}



















Measured memory_bytes: 5108
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define mp make_pair
#define pb push_back
using namespace std; 
typedef long long ll; 
int cnt[200005]; 
int main()
{
	// freopen("ARC086-C.in", "r", stdin); 
	int n, k; 
	scanf("%d%d", &n, &k); 
	for (int i = 0; i < n; i++)
	{
		int x; 
		scanf("%d", &x); 
		cnt[x]++; 
	}
	sort(cnt, cnt + n + 1, greater<int>()); 
	for (int i = 0; i < k; i++)
		n -= cnt[i]; 
	printf("%d\n", n);
	return 0; 
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (int) 1e9+7
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define vi vector<int>
ll xpow(ll a, ll b)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
	{
		ll k = xpow(a, b / 2);
		return k * k;
	}
	if (b % 2 != 0)
		return a * xpow(a, b - 1);
}
int main()
{

#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out1.txt", "w", stdout);
#endif
	fio;
	string s, t;
	cin >> s >> t;
	int si = s.size();
	int flag = 0;
	for (int i = 0; i < si; i++)
	{
		if (s[i] == t[i])
			continue;
		else
		{
			flag = 1;
			break;
		}
	}
	if (flag == 1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>

long long f(long long n, long long x)
{
    if(n>=0)
        return n/x + 1;
    else if(n==-1)
        return 0;
}

int main()
{
    // std::cout << std::fixed << std::setprecision(5);
    int h, w; std::cin >> h >> w;
    char c[h][w];
    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            std::cin >> c[i][j];
        }
    }

    for(int i=0; i<h; i++)
    {
        for(int j=0; j<w; j++)
        {
            std::cout << c[i][j] << ((j==w-1)?"\n":"");
        }
        for(int j=0; j<w; j++)
        {
            std::cout << c[i][j] << ((j==w-1)?"\n":"");
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<utility>
using namespace std;
vector<int>par;
int root(int v) {
  if (v == par[v]) return v;
  return par[v] = root(par[v]);
}
bool unit(int a, int b) {
  a = root(a);
  b = root(b);
  if (a == b) return false;
  par[b] = a;
  return true;
}
int main () {
  int N;
  cin >> N;
  par.resize(N);
  for (int i = 0; i < N; i ++) par[i] = i;
  vector<tuple<int, int, int>>X(N);
  vector<tuple<int, int, int>>Y(N);
  for (int i = 0; i < N; i ++) {
    int x, y;
    cin >> x >> y;
    X[i] = make_tuple(x, y, i);
    Y[i] = make_tuple(y, x, i);
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  vector<tuple<int, int, int>>roa(2 * N - 2);
  for (int i = 0; i < N - 1; i ++) {
    roa[i] = make_tuple(get<0>(X[i + 1]) - get<0>(X[i]),
                        get<2>(X[i]), get<2>(X[i + 1]));
  }
  for (int i = 0; i < N - 1; i ++) {
    int j = i + N - 1;
    roa[j] = make_tuple(get<0>(Y[i + 1]) - get<0>(Y[i]),
                        get<2>(Y[i]), get<2>(Y[i + 1]));
  }
  long long ans = 0;
  sort(roa.begin(), roa.end());
  for (int i = 0; i < N * 2 - 2; i ++) {
    bool kj = unit(get<1>(roa[i]), get<2>(roa[i]));
    if (kj) ans += (long long)get<0>(roa[i]);
  }
  cout << ans << endl;
}


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

n = int(raw_input())
p = [0 for i in range(n+2)]
for i in range(1, n+1):
    a, b = map(int, raw_input().split())
    p[i] = a
p[n+1] = b

M = [[0 for i in range(n+1)] for j in range(n+1)]
for d in range(1, n+1):
    for i in range(1, n-d+1):
        j = i+d
        msf = M[i][i] + M[i+1][j] + p[i]*p[i+1]*p[j+1]
        for k in range(i, j):
            msf = min(msf, M[i][k] + M[k+1][j] + p[i]*p[k+1]*p[j+1])
        M[i][j] = msf
print M[1][n]

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

int main(){
  string S;
  cin>>S;
  int ans=0;
  int temp1=0,temp2=0;

  while(1){
    //cout<<temp1<<" "<<temp2<<endl;

    if(temp1==S.length()-1-temp2){
      break;
    }
    if(temp1+1==S.length()-1-temp2){
      if(S.at(temp1)==S.at(S.length()-1-temp2)){
        break;
      }
      if(S.at(temp1)=='x'||S.at(S.length()-1-temp2)=='x'){
        ans++;
        break;
      }
      if(S.at(temp1)!=S.at(S.length()-1-temp2))
      cout<<-1<<endl;
      return 0;
    }

    if(S.at(temp1)==S.at(S.length()-1-temp2)){
      temp1++;
      temp2++;
      continue;  
    }
    if(S.at(temp1)!=S.at(S.length()-1-temp2)){
      if(S.at(temp1)=='x'){
        ans++;
        temp1++;
        continue;
      }
      if(S.at(S.length()-1-temp2)=='x'){
        ans++;
        temp2++;
        continue;
      }      
    }
    cout<<-1<<endl;
    return 0;
  }
  cout<<ans<<endl;
  return 0;
}

    

Measured memory_bytes: 512
// AOJ DSL_3_B The Smallest Window II
// 2018.5.6 bal4u@uu

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define MAX_N 100003
int a[MAX_N], f[MAX_N];

int main()
{
	int N, K, i, j, s, t, ans;

	N = in(), K = in();
	if (N < K) { puts("0"); return 0; }
	for (i = 0; i < N; i++) a[i] = in();

	s = 0, i = j = 0;
	while (s < K && j < N) {
		t = a[j++];
		if (t <= K) { if (f[t] == 0) s++; f[t]++; }
	}
	if (s < K) { puts("0"); return 0; }
	while ((t = a[i]) > K || f[t] > 1) { i++; if (t <= K) f[t]--; }
	ans = j-i;

	while (j < N) {
		if ((t = a[j++]) <= K) f[t]++;
		while ((t = a[i]) > K || f[t] > 1) { i++; if (t <= K) f[t]--; }
		if (j-i < ans) ans = j-i;
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = unsigned long long;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
lint A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
vl a;
map<lint, lint> mp;
// string s;

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

	cin >> N;
    a.assign(N, 0);
    rep(i, N) {
        cin >> a[i];
        mp[a[i]]++;
    }

    lint sum = 0;
    for (auto i : mp) {
        sum += i.second * (i.second-1) / 2;
    }

    rep(i, N) {
        lint ans = sum;
        if (mp[a[i]] > 1) ans -= (mp[a[i]] * (mp[a[i]]-1)) / 2;
        if (mp[a[i]] > 1) ans += ((mp[a[i]]-1) * (mp[a[i]]-2)) / 2;
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    // cout<<t.substr(0,s.length());
    if(s==t.substr(0,s.length())&&t.length()==s.length()+1)
    cout<<"Yes";
    else
    cout<<"No";
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int A, B;
  cin >> A >> B;
  if(B == 1) cout << 0;
  else if((B - 1) % (A - 1) > 0) cout << (B - 1)  / (A - 1) + 1;
   
  else cout << (B - 1)  / (A - 1);
 return 0; 
}

Measured memory_bytes: 256
<?php
# 整数の入力
fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $d);

echo calc($a, $b, $c, $d) ;
function calc($a, $b, $c, $d) {
  if($b <= $c) return 0;
  if($d <= $a) return 0;

  if($a <= $c && $b <= $d) return ($b - $c);
  if($a <= $c && $d <= $b) return ($d - $c);
  if($c <= $a && $d <= $b) return ($d - $a);
  if($c <= $a && $b <= $d) return ($b - $a);
  
  return -1;
}

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

#define LL long long

/*void print(vector<int>a,vector<int>b){
    system("cls");
    for(int x :a)cout<<x<<" ";
    cout<<endl;
    for(int x :b)cout<<x<<" ";
    cout<<endl;
    Sleep(1500);
}*/

int main(){
    LL n;
    cin>>n;
    LL c=0;
    vector<LL>monsters(n+1);
    vector<LL>heros(n);
    for(LL i=0;i<=n;i++){
        cin>>monsters[i];
    }
    for(LL i=0;i<n;i++){
        cin>>heros[i];
    }
    for(LL i=0;i<n;i++){
        if(heros[i]<monsters[i]){
            c+=heros[i];
            monsters[i]-=heros[i];
            heros[i]=0;
            //print(monsters,heros);
        }
        else if(heros[i]==monsters[i]){
            c+=monsters[i];
            monsters[i]=0;
            heros[i]=0;
            //print(monsters,heros);
        }
        else{
            c+=monsters[i];
            heros[i]-=monsters[i];
            monsters[i]=0;
            //print(monsters,heros);
            if(heros[i]<monsters[i+1]){
                c+=heros[i];
                monsters[i+1]-=heros[i];
                heros[i]=0;
                //print(monsters,heros);
            }
            else if(heros[i]==monsters[i+1]){
                c+=monsters[i+1];
                monsters[i+1]=0;
                heros[i]=0;
                //print(monsters,heros);
            }
            else{
                c+=monsters[i+1];
                heros[i]-=monsters[i+1];
                monsters[i+1]=0;
                //print(monsters,heros);
            }
        }
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <cctype>
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

string lower(const string& s) {
  string out;
  out.reserve(s.size());
  for (size_t i = 0; i < s.size(); ++i) {
    out += static_cast<char>(tolower(s[i]));
  }
  return out;
}

int main() {
  string w, s;
  cin >> w;
  w = lower(w);

  size_t n = 0;
  while (getline(cin, s)) {
    if (s == "END_OF_TEXT") {
      break;
    }
    istringstream is(s);
    string b;
    while (is >> b) {
      if (w == lower(b)) {
        ++n;
      }
    }
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll dp[200010];
vector<ll> col[200010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll C[N];
    REP(i, 0, N) {
        cin >> C[i];
    }
    vector<ll> CC;
    CC.push_back(C[0]);
    REP(i, 1, N) {
        if (C[i] != C[i - 1]) {
            CC.push_back(C[i]);
        }
    }
    ll len = CC.size();
    ll ind[len];
    REP(i, 0, len) {
        col[CC[i]].push_back(i);
        ind[i] = col[CC[i]].size() - 1;
    }
    fill(dp, dp + 200010, 0);
    dp[0] = 1;
    REP(i, 0, len) {
        ll id = ind[i];
        dp[i + 1] = modadd(dp[i + 1], dp[i]);
        if (id != col[CC[i]].size() - 1) {
            ll num = col[CC[i]][id + 1];
            dp[num] = modadd(dp[num], dp[i]);
        }
        // REP(j, id, col[CC[i]].size()) {
        //     ll num = col[CC[i]][j];
        //     dp[num + 1] = modadd(dp[num + 1], dp[i]);
        // }
    }
    cout << dp[len] << endl;
}


Measured memory_bytes: 17392
from collections import Counter
def check():
  H, W = map(int, input().split())
  S = [input() for _ in range(H)]
  s = ''.join(S)
  c = Counter(s)
  d = Counter(c.values())
  two = 0
  one = 0
  for k,v in d.items():
    if k%4==2 or k%4==3:
      two += 2*v
    if k%2==1:
      one += v
  if H%2==0 and W%2==0:
    if two>0 or one>0:
        return 'No'
  elif H%2==1 and W%2==1:
    if two>(H+W-2) or one>1:
      return 'No'
  elif H%2==1:
    if two>W or one>0:
      return 'No'
  elif W%2==1:
    if two>H or one>0:
      return 'No'
  return 'Yes'
print(check())

Measured memory_bytes: 9404
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int n, m;
    cin>>n>>m;
    vector<int>X(n+1, 0), Y(m+1, 0);
    cin>>X[0]>>Y[0];
    for(int i=1; i<=n; i++)cin>>X[i];
    for(int i=1; i<=m; i++)cin>>Y[i];
    sort(all(X));
    sort(all(Y));
    cout<<(X.back()<Y[0]?"No War":"War");
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;


int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

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

	if (a + b + c >= 22) cout << "bust" << endl;
	else cout << "win" << endl;

	return 0;
}


Measured memory_bytes: 3648
N = int(input())
S = list(input())
E = S[1:].count('E')
W = 0
mi = E+W
for i in range(1,N):
    if S[i] == 'E':E -= 1
    if S[i-1] == 'W':W+=1
    if E+W <= mi:mi = E+W
print(mi)
        

Measured memory_bytes: 13660
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    string s; cin >> s;
    bool flag = true;
    rep(i, s.size()){
        if(i%2==1){
            if(s[i]=='L'||s[i]=='U'||s[i]=='D');
            else flag=false;
        }
        if(i%2!=1){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D');
            else flag = false;
        }
    }
    printf(flag ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    double L;
    cin >> L;
    printf("%lf\n",L*L*L/3.0/3.0/3.0);
    //cout << L*L*L/3.0/3.0/3.0 <<endl;

    return 0;
}

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

int main(){
    int n, k, ans=0; cin >> n >> k;
    vector<int> num, idx(200000, -1);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(idx[a-1]>=0) num[idx[a-1]]++;
        else{
            idx[a-1] = num.size(); num.push_back(1);
        }
    }
    sort(num.begin(), num.end());
    for(int i = 0; i < int(num.size()) - k; i++){
        ans += num[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2168
s = input()
if len(s)==2 and s[0]==s[1]:
  print(1,2)
  exit()
for i in range(len(s)-2):
  if s[i]==s[i+1]:
    print(i+1,i+3)
    exit()
  elif s[i]==s[i+2]:
    print(i+1,i+3)
    exit()
else:
  print(-1,-1)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll Color = 31;
ll d[Color][Color] = {};
static const ll MAX = 501;
ll lis[MAX][MAX] = {};
ll nummodc[3][Color] = {};

int main() {
   

    ll n,c;
    cin >> n >> c;
    for (ll i=1;i<=c;i++){
        for (ll j=1;j<=c;j++){
            cin >> d[i][j];
        }
    }
    for (ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            cin >> lis[i][j];
            nummodc[(i+j)%3][lis[i][j]]++;
        }
    }

    ll minv;
    ll ansi = 1;
    ll ansj = 2;
    ll ansk = 3;
    for (int i=1;i<=c;i++){
        for (int j=1;j<=c;j++){
            if(i==j){
                continue;
            }
            for (int k=1;k<=c;k++){
                if(i==k or j==k){
                    continue;
                }
                ll tmp = 0;
                ll des[3];
                des[0] = i;
                des[1] = j;
                des[2] = k;
                for (int p=0;p<3;p++){
                    for(int q=1;q<=c;q++){
                        tmp += nummodc[p][q] * d[q][des[p]];
//                        if(i==3 and j==1 and k==2)
//                        cout << nummodc[p][q] << " " << d[q][i] << endl;
                    }
                }
                if(i==1 and j==2 and k==3){
                    minv = tmp;
                }else{
                    if(minv > tmp){
                        ansi = i;
                        ansj = j;
                        ansk = k;
                        minv = tmp;
                    }
                }

            }
        }
    }
//    cout << ansi << " " << ansj << " " << ansk << endl;
    cout << minv << endl;
}




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

int main(){
    int n; cin >> n;
    
    double k = (-1+sqrt(1+8*n))/2.0;
    
    if(k==(int)k){
        rep(i,k)cout << i+1 << endl;
    }
    else{
        int p = (int)k + 1;
        int t = p*(p+1)/2;
        int s = t-n;
        
        for(int i=1; i<=p; i++){
            if(i==s)continue;
            cout << i << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256