akhauriyash/Code-Regression huggingface dataset:
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



#include<bits/stdc++.h>
using namespace std;


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}




#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

//gp_hash_table<long long, int, custom_hash> cnt;

const int mx = 1e5+123;
int a[mx];

int main()
{
    optimize();

    map < ll, int > cnt;

    int n;
    cin >> n;
    for ( int i = 1; i <= n; i++ ) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    int ans = 0;
    for ( int i = 1; i <= n; i++ ) {
        if ( cnt[a[i]] >= a[i] ) ans += ( cnt[a[i]] - a[i] );
        else ans += cnt[a[i]];
        cnt[a[i]] = 0;
    }

    cout << ans << endl;



    return 0;
}


















Measured memory_bytes: 6656
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,k = iim()
P = iil()
Psum = []
tmp = 0
for i in P:
    tmp += i
    Psum.append(tmp)

ans = Psum[k-1]
for i in range(1,n-k+1):
    ans = max(ans,Psum[i+k-1]-Psum[i-1])

print((ans+k)/2)

Measured memory_bytes: 24804
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M,ans=0;
    cin >> N >> M;
    vector<int> v(2*M);//辺の格納
    for(int i=0;i < 2*M;i++){
        cin >> v.at(i);
    }
    vector<int> u(N);
    for(int i=0;i < N;i++){
        u.at(i) = i+1;
    }//昇順に頂点を格納
    
    do{
        int count=0;
        for(int i=0;i < N-1;i++){
            for(int j=0;j < 2*M-1;j+=2){
                if(u.at(i)==v.at(j) && u.at(i+1)==v.at(j+1)){
                    count++;
                }
                else if(u.at(i)==v.at(j+1) && u.at(i+1)==v.at(j)){
                    count++;
                }//頂点をつなぐ辺があるか
            }
        }
        if(count == N-1 && u.at(0)==1){
            ans++;
        }//すべての辺があったらその順列の進み方は可能
    }while(next_permutation(u.begin(),u.end()));
    cout << ans << endl;
}

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

long long dp[60][60][2510];

int main() {
	int A, i, j, k, N, x[60];
	long long C;
	scanf("%d%d", &N, &A);
	for (i=0;i<N;i++) scanf("%d", &x[i]);

	dp[0][0][0] = 1;
	for (k=1;k<2510;k++) dp[0][0][k] = 0;
	for (i=0;i<N;i++) {
		for (j=0;j<=i+1;j++) {
			for (k=0;k<2510;k++) {
				if (k < x[i]) dp[i+1][j][k] = dp[i][j][k];
				else if (k >= x[i] && j >= 1) dp[i+1][j][k] = dp[i][j][k] + dp[i][j-1][k-x[i]];
				else dp[i+1][j][k] = 0;
			}
		}
	}

	C = 0;
	for (k=1;k<=N;k++) C += dp[N][k][k*A];
	printf("%lld\n", C);
	return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ll n,a,b,c,sola,solb,solc,ta,tb,tc;

    cin >> n;

    cin >> a >> b >> c;
    sola = a;
    solb = b;
    solc = c;

    for (ll i=1; i<n; i++) {
        cin >> a >> b >> c;
        ta = max(a+solb, a+solc);
        tb = max(b+sola, b+solc);
        tc = max(c+sola, c+solb);
        sola = ta;
        solb = tb;
        solc = tc;
    }

    cout << max(sola, max(solb, solc)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  char n[200], m[200];
  scanf("%s%s", n, m);
  
  int a = strlen(n);
  int b = strlen(m);
  
  if(a > b) printf("GREATER\n");
  else if(a < b) printf("LESS\n");
  else{
    for(int i = 0; i < a; i++){
      if(n[i] > m[i]){
        printf("GREATER\n");
        break;
      }
      else if(n[i] < m[i]){
        printf("LESS\n");
        break;
      }
      else if(i == a - 1){
        printf("EQUAL\n");
      }
    }
  }
  
  return 0;
}
                       

Measured memory_bytes: 128
n = int(input())
a = map(int, input().split())
t1 = []
t2 = []
for i in a:
    if i % 2 == 0:
        t1.append(i)
        if i % 3 == 0 or i % 5 == 0:
            t2.append(i)
if t1 == t2:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
object Main {

	def main(arg:Array[String]) = {
        var n = scala.io.StdIn.readLine().toInt;
		var list = scala.io.StdIn.readLine().split(" ").map(_.toInt);
  		list.reverse;
        
        val max = list.max;
        val diff = list.filter(_ != max).map(x => math.max(math.abs(max / 2 - x), math.abs((max + 1) / 2 - x))).sorted.head;
        val ans = list.filter(_ != max).filter(x => (diff == math.abs(max / 2 - x)) || (diff == math.abs((max + 1) / 2 - x))).head;
        println(max + " " + ans);
	}

}


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

int main(){
    long cnt = 0;
    while(1){
        long n;
        cin >> n;
        if(n == 0){
            return 0;
        }else{
            cnt++;
            cout << "Case " << cnt << ": " << n << endl;
        }
    }
}


Measured memory_bytes: 3084
a, b, c, x, y = map(int, input().split())
ans = 0
maxxy = max(x,y)
minxy = min(x,y)
abcost = a * minxy + b * minxy
ccost = c * minxy * 2
ans += min(abcost, ccost)
amari = maxxy - minxy
if x > y:
    acost = a * amari
    ccost = c * amari * 2
    ans += min(acost, ccost)
elif x < y:
    bcost = b * amari
    ccost = c * amari * 2
    ans += min(bcost, ccost)

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define ll long long int
#define ld long double
#define fo(i, n) for(ll i = 0; i<n; i++)
#define Fo(i, a, n) for(ll i = a; i<n; i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define pi pair<int, int>
#define pl pair<ll, ll>
#define u_m unordered_map
#define u_s unordered_set
#define p_q priority_queue
using namespace std;
void fast() {ios::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);}
const int N = 1e5+2;
bool dp[N];
void print(vl arr){
    fo(i, arr.size())
        cout<<arr[i]<<" ";
    cout<<endl;
}
void solve()
{
    int n, k;
    cin>>n>>k;
    vector<int> arr(n);
    for(int i = 0; i<n; i++)
        cin>>arr[i];
    for(int i = 0; i<=k; i++)
    {
        for(int x:arr)
        {
            if(i>=x && !dp[i-x])
                dp[i] = 1;
        }
    }
    cout<<(dp[k]?"First":"Second")<<endl;
}
int main()
{
    fast(); 
    int t;
    //scanf("%d", &t);
    //while(t--)
		solve();	
    return 0;
}


Measured memory_bytes: 384
import itertools
import copy
from collections import deque
import heapq
n = int(input())
a = list(map(int,input().split()))
a.sort()
a = a[::-1]
p = a[0]
c = 1
ans = 0
cnt = 0
for i in range(n-1):
    ans += p
    if c == 0:
        c += 1
    else:
        c = 0
        cnt += 1
        p = a[cnt]
    #print(ans,p)
print(ans)

Measured memory_bytes: 32696
#include<stdio.h>

int main() {
  double X = 0;
  char yes[] = "Yes";
  char no[] = "No";
  char *mes;


  scanf("%lf", &X);
  if( X >= 30 ) mes = yes;
  else mes = no;  
  printf("%s", mes);
  return 0;
}

Measured memory_bytes: 2184
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

struct Point {
    double x;
    double y;
};

static double cos_60;
static double sin_60;

static void init_sin_cos(void){
    cos_60 = cos(M_PI / 3.0);
    sin_60 = sin(M_PI / 3.0);
    
    return;
}
       

static void GetPos(const struct Point* p1, const struct Point* p2, struct Point* s, struct Point* t, struct Point* u) {
      /* y = a (x - x1) + y1,  a = (y2 - y1) / (x2 - x1) */
    double a = (p2->y - p1->y) / ( p2->x - p1->x);

    s->x = (p2->x - p1->x) / 3.0 + p1->x;
    s->y = a * (s->x - p1->x) + p1->y;

    t->x = (p2->x - p1->x) * 2.0 / 3.0 + p1->x;
    t->y = a * (t->x - p1->x) + p1->y;

    u->x = (t->x - s->x) * cos_60 - (t->y - s->y) * sin_60 + s->x;
    u->y = (t->x - s->x) * sin_60 + (t->y - s->y) * cos_60 + s->y;
    
    return;
}


static void Kock(int n, const struct Point* p1, const struct Point* p2) {
    struct Point s, t, u;

    if ( n == 0 ) {
        return;
    }

    GetPos(p1, p2, &s, &t, &u);

    Kock( n - 1, p1, &s);
    printf("%lf %lf\n", s.x, s.y);
    Kock( n - 1, &s, &u);
    printf("%lf %lf\n", u.x, u.y);    
    Kock( n - 1, &u, &t);
    printf("%lf %lf\n", t.x, t.y);    
    Kock( n - 1, &t, p2);

    return;
}


int main(void) {
    int n;
    struct Point p1 = { .x = 0, .y = 0};
    struct Point p2 = { .x = 100, .y = 0};

    init_sin_cos();

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

    printf("%lf %lf\n", p1.x, p1.y);
    Kock(n, &p1, &p2);
    printf("%lf %lf\n", p2.x, p2.y);

    return 0;
}
        



Measured memory_bytes: 2072
#include <stdio.h>
#include <stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int n, a[100] = {0};
    int apt=0, bpt=0;

    scanf("%d", &n);
    for(int i=0; i<n; i++){ scanf("%d", &a[i]); }
    qsort( a, n, sizeof(int), compare_int );
    
    for(int i=0; i<n; i++){
        if( i%2==0 ){ apt += a[n-1-i]; }
        else        { bpt += a[n-1-i]; }
    }
    printf("%d\n", apt-bpt);

    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <regex>
using namespace std;

int N;

int main() {
    cin >> N;
    
    for (size_t i = 0; i < N; i++)
    {
        cout << "ACL";
    }
    cout << endl;
    
    
    return 0;
}

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

int main() {
  long k,s,ans=0;
  cin >> k >> s;
  for(int x=0;x<=k;x++) {
    for(int y=0;y<=k;y++) {
      if(x+y<=s&&x+y+k>=s) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18

T = sys.stdin.buffer.readline().decode().rstrip()
P = sys.stdin.buffer.readline().decode().rstrip()

MASK30 = (1 << 30) - 1
MASK31 = (1 << 31) - 1
MOD = (1 << 61) - 1
MASK61 = MOD


def Mul(a, b):
    au = a >> 31
    ad = a & MASK31
    bu = b >> 31
    bd = b & MASK31
    mid = ad * bu + au * bd
    midu = mid >> 30
    midd = mid & MASK30
    return au * bu * 2 + midu + (midd << 31) + ad * bd


# mod 2^61-1を計算する関数
def CalcMod(x):
    xu = x >> 61
    xd = x & MASK61
    res = xu + xd
    if res >= MOD:
        res -= MOD
    return res


class RollingHash:
    # Verify: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_14_B
    def __init__(self, seq, base=10 ** 9 + 7):
        """
        :param str|typing.Sequence[int] seq:
        :param int base:
        :param int mod:
        """
        if isinstance(seq, str):
            self._seq = seq = list(map(ord, seq))
        else:
            self._seq = seq

        hashes = [0] * (len(seq) + 1)
        power = [1] * (len(seq) + 1)
        for i, c in enumerate(seq):
            hashes[i + 1] = CalcMod(Mul(hashes[i], base) + c)
            power[i + 1] = CalcMod(Mul(power[i], base))
        self._hashes = hashes
        self._power = power

    def get(self, L, r):
        """
        [L, r) のハッシュ値を取得します
        :param int L:
        :param int r:
        """
        if L >= r:
            return 0
        return (self._hashes[r]  - self._hashes[L] * self._power[r - L]) % MOD


t_rh = RollingHash(T)
p_rh = RollingHash(P)

obj = p_rh.get(0, len(P))
r = len(P)
l = 0
while r <= len(T):
    if t_rh.get(l, r) == obj:
        print(l)
    r += 1
    l += 1


# S = 'ababa'
# rh = RollingHash(S)
# for l in range(len(S)):
#     for r in range(l + 1, len(S) + 1):
#         print(S[l:r], l, r, rh.get(l, r))
#
# print(t_rh._hashes)



Measured memory_bytes: 111608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y;long long total;
    cin>>n>>y;
    if(y%1000!=0){
        cout<<"-1 -1 -1"<<endl;
        return 0;
    }
    y/=1000;
    //a:一万、b:五千、n-a-b:千
    for(int a=0;a<=n;a++)
    {
        for(int b=0;b<=n-a;b++)
        {
            total=a*10+b*5+(n-a-b);
            if(total==y&&a+b<=n)
            {
                cout<<a<<' '<<b<<' '<<n-a-b<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
//import java.util.Map;
//import java.util.HashMap;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] map = {"Sunny", "Cloudy", "Rainy"};
    
 	String s = sc.next();

    int i = 0;
    for ( i = 0; i < map.length; i++) {
      if (map[i].equals(s)) {
        break;
      }
    }
    
    String result = "";
    if (i < map.length) {
      result = map[ (i+1) % map.length ];
    }
     
    System.out.println(result);
  }
}



Measured memory_bytes: 26812
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    
    int sum = 0;
    //initial: leader is west
    for(int i=1; i<N; i++) if(S[i] == 'E') sum++; 
    int ans = sum;
    
    
    for(int i=0; i<N-1; i++){
        if(S[i] == 'W')sum++;
        if(S[i+1] == 'E') sum--;
        if(ans > sum)ans = sum;
    } 
    
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double ld;
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pair<int,int>>
#define pb push_back
#define pf push_front
#define mp map<ll,ll>
#define INF 1000000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}
/**********************************************************************
***********************************************************************
*********************ACTUAL CODE BEGINS HERE***************************/
int main()
{   
    fast;
    int x;
    cin>>x;
    cout<<(x^1);
    return 0;
}

Measured memory_bytes: 3576
N,M = map(int,input().split())
G = {}
for i in range(M):
    P,Y = map(int,input().split())
    if P not in G:
        G[P]=[]
    G[P].append((i+1,Y))
C = []
for P in G:
    G[P] = sorted(G[P],key=lambda x:x[1])
    a = len(str(P))
    x = "0"*(6-a)+str(P)
    for i in range(len(G[P])):
        b = len(str(i+1))
        y = x+"0"*(6-b)+str(i+1)
        C.append((G[P][i][0],y))
C = sorted(C,key=lambda x:x[0])
for c in C:
    print(c[1])

Measured memory_bytes: 53120
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(ll &x){
	x=0;static char ch;static bool flag;flag = false;
	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)     
int main(){
    ll n,a,b,c,d;read(n);read(a);read(b);read(c);read(d);
    if(n == 1){
		if(a != b)puts("NO");
		else puts("YES");
    }else{
		-- n;
		for(ll i = 0, j;i <= n;++i){
			j = n - i;
			ll x = i*c, y = i * d;
			ll X = j*c + b - a, Y = j*d + b - a;
			if(y < X) continue;
			if(Y < x) continue;
			puts("YES");
			return 0;
		}puts("NO");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n,d;
    cin >> n >> d;
    cout << (n+(2*d+1)-1)/(2*d+1) <<endl;
    return 0;


}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);

	string s;
	cin >> s;

	int n=s.size()-1,prev;
	ll ans=0;
	ll tmp;
	for(int i=0;i<(1<<n);i++){
		prev=0;
//		printf("--------%d--------\n",i);
		for(int j=0;j<n;j++){
			if((i>>j) & 1){
				
				ans += stoll(s.substr(prev,j+1-prev));
				
//				printf("prev:%d  j:%d\n",prev,j);
//				printf("%dから%d個    %d\n",prev,j+1-prev,atoi(s.substr(prev,j+1-prev).c_str()));
				prev=j+1;
			}
		}
//		printf("%d(%c)から%d(%c)まで\n",prev,s[prev],n,s[n]);
//		printf("last  %dから%d個    %d\n",prev,n+1-prev,atoi(s.substr(prev,n+1-prev).c_str()));
		
		ans += stoll(s.substr(prev,n+1-prev));
	}
	cout << ans << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    long a[n];
    long sum = 0;
    std::unordered_map<long, long> mp;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        sum += a[i];
        mp[sum]++;
    }
    long count = 0;
    long x;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        x = itr->second;
        if(itr->first == 0){
            count += (x * (x+1) / 2);
        } else {
            count += (x * (x-1) / 2);
        }
    }
    std::cout << count << std::endl;
}

Measured memory_bytes: 10056
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
  Scanner sc=new Scanner(System.in);
  int t=sc.nextInt();
    int a=t/500;
    int b=((t-500*a)/5)*5;
  System.out.println(1000*a+b);
  }
}

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

int day(int y, int m, int d) {
  int ans = 0;
  for (int i=1; i<y; i++) {
    if (i%3 == 0) {
      ans += 200;
    } else {
      ans += 195;
    }
  }
  bool dai = (y%3 == 0);
  for (int i=1; i<m; i++) {
    if (dai || i%2 != 0) {
      ans += 20;
    } else {
      ans += 19;
    }
  }
  ans += d;
  return ans;
}

int main() {
  int n;
  scanf("%d", &n);
  int C = day(1000,1,1);
  for (int i=0; i<n; i++) {
    int y, m, d;
    scanf("%d%d%d", &y, &m, &d);
    int D = day(y, m, d);
    printf("%d\n", C-D);
  }
}

Measured memory_bytes: 1172
def bigger?(s,t)
  return s>=t ? 1 : 0
end

w,h,n=gets.split.map &:to_i
pt=[nil,0,w,0,h]

n.times do
  a=gets.split.map &:to_i
  a[2]%2==1&&pt[a[2]]<a[a[2]/3]&&pt[a[2]]=a[a[2]/3]
  a[2]%2==0&&pt[a[2]]>a[a[2]/3]&&pt[a[2]]=a[a[2]/3]
end

puts (pt[2]-pt[1])*(pt[4]-pt[3])*bigger?(pt[2],pt[1])*bigger?(pt[4],pt[3])


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
using namespace std;
 
template<class T>bool chmax(T& a, const T& b) { return (a < b) ? (a = b, 1) : 0; }
template<class T>bool chmin(T& a, const T& b) { return (a > b) ? (a = b, 1) : 0; }
 
using ull=unsigned long long;
const ull B1=1000000003LL;
const ull B2=1000000009LL;
 
const int limit=200010;
ull P1[limit],P2[limit];
 
 
vector<int> tree[100010];
map<ull,int> num;
int sub[100010];
 
int dmax=0;
 
ull dfs(int v,int p){
	ull cur=0;
	for(auto &v2:tree[v]){
		if(v2==p) continue;
		cur+=dfs(v2,v);
	}
 
	//sort(begin(ary),end(ary));
	//for(auto &it:ary) cur=cur*P1[2*get<1>(it)]+get<0>(it);
 
	cur=cur*B1+1;
	//sub[v]+=1;
 
	num[cur]++;	
	return cur;
}
 
int main(void){
	P1[0]=1LL,P2[0]=1LL;
	for(int i=1;i<limit;++i) P1[i]=P1[i-1]*B1,P2[i]=P2[i-1]*B2;
 
 
	int n;
	cin >> n;
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		a--,b--;
		tree[a].push_back(b);
	}
 
	dfs(0,-1);
 
	ull ans=0LL;
	for(auto &it:num){
		//cout << it.second << endl;
		ull cur=it.second;
		ans+=cur*(cur-1)/2LL;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 24196
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	int n,q;
	cin>>n;
	map<ll,int>cnt;
	ll sum = 0;
	for(int i=0;i<n;i++){
		ll a;
		cin>>a;
		cnt[a]++;
		sum+=a;
	}
    cin>>q;
    while(q--)
    {
		ll b,c;
		cin>>b>>c;
		if(cnt.find(b) == cnt.end()){cout<<sum<<'\n';continue;}
	    sum-=b*cnt[b];
	    sum+=c*cnt[b];
	    cnt[c]+=cnt[b];
	    cnt.erase(b);
	    cout<<sum<<'\n';
	}
	
	
}


Measured memory_bytes: 7572
#include<bits/stdc++.h>
using namespace std;
int n,a[200000];
int main(){
	cin>>n;
	for(int i=0;i<n;++i) cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;++i){
		if(a[i]==a[i+1]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

Measured memory_bytes: 1024
n=int(input())
mod=10**9+7

dp=[1 for _ in range(n+1)]

for i in range(n+1):
  if i<3:
    dp[i]=0
  else:
    di=dp[i]
    for j in range(3,i):
      if i-j>=3:
        di+=dp[i-j]
    dp[i]=di
print(dp[n]%mod)

Measured memory_bytes: 68296
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1000000000000 ;
const ll mod=1000003 ;

int main(){
  int n;
  cin >> n;
  int a[n],b[n],c[n];
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n)cin >> c[i];
  ll ans=0;
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  rep(i,n){
    ll x=lower_bound(a,a+n,b[i])-a;
    ll y=upper_bound(c,c+n,b[i])-c;
    ans+=x*(n-y);
  }
  cout << ans << endl;
return 0;}


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

using namespace std;

long long n;
vector<int> v;

int main() {
	scanf("%lld", &n);
	for (int i = 0; n; i++) {
		v.push_back(abs(n) % 2);
		if (abs(n) % 2) {
			if (i & 1)
				n++;
			else
				n--;
		}
		n /= 2;
	}
	reverse(v.begin(), v.end());
	if (v.empty()) v.push_back(0);
	for (int i : v)
		printf("%d", i);
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(),(a).end()
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
	ios_base::sync_with_stdio(false);

	int n,k;
	cin >> n >> k;

	vector<int>stone(n);
	for(int& i:stone) cin >> i;

	vector<bool>dp(k+1,false);

	for(int i=1;i<=k;i++){
		for(int num:stone){
			if(i >= num and dp[i-num] == false )
				dp[i] = true;
		}
	}

	cout << (dp[k]?"First":"Second") << endl;

	return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(A==B && A!=C && B!=C || A==C && A!=B && C!=B || B==C && C!=A && B!=A ){
		printf("Yes");
	}
	else printf("No");
	return 0;
}

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

int main() {
    vector<string> S = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s;
    cin >> s;
    for (int i=0; i<7; i++) {
        if (s==S.at(i)) cout << 7-i;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
const lli INF = 1e9+7;
int main(){
    lli n,m;
    cin >> n>>m;
    lli sumProfit = 0;
    vector < pair <lli,lli> >  v(n);
    for(int i =0;i<n;i++){
        lli x,y;
        cin >> x >> y;
        v[i].first = x;
        v[i].second=y;
        sumProfit+=y;
    }
    vector < lli > dp(sumProfit+1,INF);
    dp[0]=0;
    for(int i =0;i<n;i++){
        for(int j = sumProfit;j>=1;j--){
            if(j-v[i].second>=0)
                dp[j] = min(dp[j],dp[j-v[i].second]+v[i].first);
        }
    }
    for(int i =dp.size()-1;i>=0;i--){
        if(dp[i]<=m){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cstdlib>
#include <stack>
#include <random>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;

ll binpow(ll a, ll n)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
        {
            res = res * a % MOD;
            n--;
        }
        else
        {
            a = a * a % MOD;
            n /= 2;
        }
    }
    return res;
}
ll fact[300300], invFact[300300];
ll cnk(ll n, ll k)
{
    return (fact[n] * invFact[k] % MOD) * invFact[n - k] % MOD;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    fact[0] = 1;
    invFact[0] = 1;
    for (int i = 1; i < 300300; i++)
    {
        fact[i] = fact[i - 1] * i % MOD;
        invFact[i] = binpow(fact[i], MOD - 2);
    }
    ll ans = 0;
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    for (ll x = 0; x * a <= k && x <= n; x++)
    {
        if ((k - a * x) % b)
            continue;
        ll y = (k - a * x) / b;
        if (y <= n)
            ans = (ans + cnk(n, x) * cnk(n, y)) % MOD;
    }
    cout << ans << "\n";
    return 0;
}






Measured memory_bytes: 4992
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class ATriangle {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int S;
        cin >> S;

        int m = 1000000000;
        int x2 = (S + m - 1) / m;
        int y2 = m * x2 - S;
        cout << 0 << " " << 0 << " ";
        cout << 1 << " " << m << " ";
        cout << x2 << " " << y2 << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    ATriangle solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
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; }
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_w = 0; sum_w <= W; ++sum_w) {

            // i 番目の品物を選ぶ場合
            if (sum_w - weight[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
            }

            // i 番目の品物を選ばない場合
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }

    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 81740
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 12:29:30 2020

@author: shinba
"""

a,b = map(int,input().split())

if a % 3 == 0:
    print("Possible")
elif b % 3 == 0:
    print("Possible")
elif (a+b) % 3 == 0:
    print("Possible")
else:
    print("Impossible")


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

struct pen
{
	int d, c, t;
};

vector<int> graph[100005];

struct query
{
	int v, d, c;
};

query qry[100005];
int rem_dist[100005];
int color[100005];

void bfs(int qidx)
{
	int v = qry[qidx].v;
	int d = qry[qidx].d;
	int c = qry[qidx].c;

	if (rem_dist[v] >= d) return;

	queue<pair<int, int>> que;
	if (rem_dist[v] == -1) color[v] = c;
	rem_dist[v] = d;
	que.emplace(v, d);

	while (que.empty() == false)
	{
		int vv, dd;
		tie(vv, dd) = que.front();
		que.pop();

		if (dd == 0) continue;

		for (int nxt : graph[vv])
		{
			if (rem_dist[nxt] >= dd - 1) continue;
			if (rem_dist[nxt] == -1) color[nxt] = c;
			rem_dist[nxt] = dd - 1;
			que.emplace(nxt, dd - 1);
		}
	}
}

int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	for (int i = 1; i <= n; i++) rem_dist[i] = -1;

	int q;
	scanf("%d", &q);

	for (int i = 0; i < q; i++)
	{
		int v, d, c;
		scanf("%d%d%d", &v, &d, &c);
		qry[i] = {v, d, c};
	}

	for (int i = q - 1; i >= 0; i--)
	{
		bfs(i);
	}

	for (int i = 1; i <= n; i++) printf("%d\n", color[i]);
}


Measured memory_bytes: 8912
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N, X;
	in >> N >> X;
	std::vector<LL>L(N);
	rep(i, N) in >> L[i];

	LL D = 0, ans = 1;
	rep(i, N)
	{
		D += L[i];
		if (D <= X) ++ans;
	}
	out << ans << std::endl;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		BigDecimal a = sc.nextBigDecimal();
		BigDecimal b= sc.nextBigDecimal();
		BigDecimal c = b.multiply(a);
		long d = c.longValue();
		System.out.println(d);
		
		

	}

}


Measured memory_bytes: 37404
from collections import deque
v, e  = map(int, input().split())

Edg = [[] for _ in range(v)]
inDeg = [0 for _ in range(v)]
Done = [0 for _ in range(v)]
for _ in range(e):
    s,t = map(int, input().split( ))
    Edg[s].append(t)
    inDeg[t] += 1

Q= deque()

ans = []
for u in range(v):
    if not inDeg[u]:
        Q.append(u)

while Q:
    u = Q.popleft()
    ans.append(u)
    for t in Edg[u]:
        inDeg[t] -= 1
        if inDeg[t] == 0 and not Done[t]:
            Q.append(t)
            Done[t] = 1

    
for i in ans:
    print(i)


Measured memory_bytes: 9120
# -*- coding: utf-8-*-
strs = []
n,k = map(int,input().split())
hates = list(input().split())

give = n

while(True):
  stri = str(give)
  hantei = True
  for hate in hates:
    if hate in stri:
      hantei = False
      break;
  if hantei:
    print(give)
    break;
  else:
    give = give + 1


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

int main(){
  int N, N_1, N_10, N_100, N_1000;
  cin >> N;
  N_1 = N % 10;
  N -= N_1;
  N /= 10;
  N_10 = N % 10;
  N -= N_10;
  N /= 10;
  N_100 = N % 10;
  N -= N_10;
  N /= 10;
  N_1000 = N % 10;

  int count = 0;
  if(N_1000 == N_100){
    if(N_100 == N_10){
      cout << "Yes" << endl;
      count++;
    }
  }
  else{
    if(N_100 == N_10){
      if(N_10 == N_1){
        cout << "Yes" << endl;
        count++;
      }
    }
  }

  if(count == 0){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int x = in.nextInt();

		int cnt = 1;
		int sum = 0;
		for ( int i = 0; i < n; i++ ) {			
			sum += in.nextInt();
			if ( x < sum ) break;			
			cnt++;
		}

		System.out.println(cnt);
		in.close();
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3

def pow(N,R,mod):
    ans = 1
    i = 0
    while((R>>i)>0):
        if (R>>i)&1:
            ans *= N
            ans %= mod
        N = (N*N)%mod
        i += 1
    return ans%mod


def main():
    N,K = map(int,input().split())
    li = [0 for _ in range(K)]

    mod = 10**9+7
    ans = 0
    for i in range(K,0,-1):
        mm = K//i
        mm = pow(mm,N,mod)

        for j in range(2,(K//i)+1):
            mm -= li[i*j-1]    
        li[i-1] = mm


        ans += (i*mm)%mod
        ans %= mod

    print(ans)

if __name__ == '__main__':
    main()

    



Measured memory_bytes: 11272
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
using namespace std;

typedef long long ll;

int main() {
  int N; ll K; cin >> N >> K;
  vector<ll>A(N);
  ll dp[55][2];
  memset(dp,-1,sizeof(dp));
  for ( int i = 0; i < N; i++ ) cin >> A[i];
  dp[0][0] = 0;
  for ( int d = 0; d < 50; d++ ) {
    ll mask = 1LL<<(50-d-1);

    int num = 0;
    for ( int i = 0; i < N; i++ ) if ( A[i] & mask ) num++;
    ll cost0 = mask*num;
    ll cost1 = mask*(N-num);
    if ( dp[d][0] != -1 ) {
      if ( K & mask ) dp[d+1][0] = max(dp[d+1][0],dp[d][0]+cost1);
      else dp[d+1][0] = max(dp[d+1][0],dp[d][0]+cost0);
    }

    if ( dp[d][0] != -1 ) {
      if ( K & mask ) dp[d+1][1] = max(dp[d+1][1],dp[d][0]+cost0);
    }

    if ( dp[d][1] != -1 ) {
      dp[d+1][1] = max(dp[d+1][1],dp[d][1]+max(cost1,cost0));
    }
  }
  cout << max(dp[50][0],dp[50][1]) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<set>
#include<cstdio>
#include<cassert>

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

using namespace std;


int main()
{
  set<string> used;

  bool fst = true;
  string AI = "",ME = "a";
  used.insert("a");
  rep(i,50)
    {
      if(fst)
	{
	  cout << "?" << ME << endl;
	}
      else 
	{
	  cout << "?" <<  AI[AI.size()-1];
	  if(i < 26)cout << (char)('a'+i);
	  else      cout << (char)('a'+i%26) << 'a';
	  cout << "a\n";
	}   
      // fflush(stdout);
      fst = false;

      cin >> AI;

      if(used.find(AI) != used.end())
	{
	  cout << "!OUT" << endl;
	  return 0;
	}
      if(AI[0] != 'a')
	{
	  cout << "!OUT" << endl;
	  return 0;
	}

      used.insert(AI);

    }
  assert(false);
  return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h> 
#define Re register
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define edge(i, u) for (Re int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define pb push_back
#define F first
#define S second
#define ll long long
#define inf 10000000000007
#define mp std::make_pair
#define lowbit(x) (x & -x)
#define eps 1e-4
#define itset std::set<node>::iterator
#define lb lower_bound
#define N 55
#define ls (k << 1)
#define rs (k << 1 | 1)
#define M 260
int q, ans, n, x[3];
char s[N];
const int dig[3] = {3, 5, 7};
inline int abs (int x) {return x < 0 ? -x : x;}
inline void search (ll now)
{
    if (now > n) return;
    if (x[0] && x[1] && x[2])
        ++ans;
    fo (i, 0, 2)
    {
        ++x[i];
        search(now * 10 + dig[i]);
        --x[i];
    }
}
int main ()
{
    scanf("%d", &n);
    search(0);
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

int main()
{
    int x;
    cin>>x;
    if(x>=400&&x<=599){
        cout<<8<<endl;
    }
    else if(x>=600&&x<=799){
        cout<<7<<endl;
    }
    else if(x>=800&&x<=999){
        cout<<6<<endl;
    }
    else if(x>=1000&&x<=1199){
        cout<<5<<endl;
    }
    else if(x>=1200&&x<=1399){
        cout<<4;
    }
    else if(x>=1400&&x<=1599){
        cout<<3;
    }
    else if(x>=1600&&x<=1799){
        cout<<2;
    }
    else cout<<1;
}


Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(1000000)

h, w = map(int, input().split())
s = [input() for _ in range(h)]
t = [[None]*w for _ in range(h)]

def dfs(i,j,color): # i,jの色がcolorと同じなら0, colorと異なるなら連結成分でまだカウントされていない要素を数えてその白黒の数を返す
    if not(0<=i<h and 0<=j<w): return 0,0 # i,jが意味をなさないとき
    if s[i][j]==color: return 0,0 # i,jの色がcolorと同じとき
    if t[i][j]: return 0,0 # すでにカウントしたi,jであったとき
    
    t[i][j]=True
    #c = s[i][j]
    wh, bl=0,0
    if s[i][j]=='#':
        bl+=1
    else:
        wh+=1
    

    tmp1,tmp2=dfs(i+1,j,s[i][j])
    wh,bl=wh+tmp1,bl+tmp2

    tmp1,tmp2=dfs(i-1,j,s[i][j])
    wh,bl=wh+tmp1,bl+tmp2
            
    tmp1,tmp2=dfs(i,j-1,s[i][j])
    wh,bl=wh+tmp1,bl+tmp2

    tmp1,tmp2=dfs(i,j+1,s[i][j])
    wh,bl=wh+tmp1,bl+tmp2

    return wh,bl

    # tmp1, tmp2 = dfs(i-1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i+1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i,j-1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp1

    # tmp1, tmp2 = dfs(i,j+1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # return bl,wh

ans = 0
for i in range(h):
    for j in range(w):
        a,b = dfs(i,j,'!')
        ans += a*b
print(ans)
    

Measured memory_bytes: 138728
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

int main(void)
{
    int k;
    string s;

    cin >> k >> s;
    if(s.size() <= k)
        cout << s << endl;
    else
        cout << s.substr(0, k) << "..." << endl;

    return 0;
}


Measured memory_bytes: 3628
n,m =map(int,input().split())
d = [list(map(int,input().split())) for i in range(n)]
d.sort()
i = 0
cnt = 0
while m>0:
  if m-d[i][1] >= 0:
    cnt += d[i][0]*d[i][1]
    m -= d[i][1]
    i += 1
  else:
    cnt += d[i][0]*m
    m = 0
    i += 1
    
print(cnt)


Measured memory_bytes: 27756
def e_change_a_little_bit(MOD=10**9 + 7):
    N = int(input())
    C = [int(i) for i in input().split()]

    C.sort(reverse=True)
    ans = 0
    for i in range(N):
        ans += C[i] * (i + 1 + 1)
    ans *= 4**(N - 1)
    return ans % MOD

print(e_change_a_little_bit())

Measured memory_bytes: 26804
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  int X, N;
  cin >> X >> N;
  vector<int> p;
  int P;
  rep(i, 0, N - 1) {
    cin >> P;
    p.push_back(P);
  }

  vector<int> absList;
  map<int, vector<int>> Map;
  rep(i, 0, N - 1) {
    absList.push_back(abs(X - p[i]));
    Map[abs(X - p[i])].push_back(p[i]);
  }

  int idx = 0;
  for (auto m : Map) {
    // cout << m.first << ": ";
    // for (auto v : m.second) {
    //   cout << v << " ";
    // }
    // cout << endl;

    if (idx == 0) {
      if (m.first != 0) {
        cout << X << endl;
        return 0;
      }
    } else {
      if (m.first == idx) {
        if (m.second.size() == 1) {
          if (m.second[0] == X - idx) {
            cout << X + idx << endl;
            return 0;
          } else {
            cout << X - idx << endl;
            return 0;
          }
        }
      } else {
        cout << X - idx << endl;
        return 0;
      }
    }
    idx++;
  }
  cout << X - idx << endl;
  return 0;
}


Measured memory_bytes: 3636
class Dice
  def initialize(side)
    @side = side;
  end
  
  def get_top
    return @side[@top];
  end
  
  def get_top
    return @side[0]
  end
  
  def move_s
    @side[0], @side[1], @side[5], @side[4] = @side[4], @side[0], @side[1], @side[5];
  end
  
  def move_n
    @side[0], @side[1], @side[5], @side[4] = @side[1], @side[5], @side[4], @side[0];
  end
  
  def move_e
    @side[0], @side[2], @side[5], @side[3] = @side[3], @side[0], @side[2], @side[5];
  end
  
  def move_w
    @side[0], @side[2], @side[5], @side[3] = @side[2], @side[5], @side[3], @side[0];
  end
end

dice = Dice.new(gets.split(" ").map(&:to_i));
a = gets.chomp.split("");

for s in a do
  if s == "S" then
    dice.move_s;
  elsif s == "N" then
    dice.move_n;
  elsif s == "E" then
    dice.move_e;
  elsif s == "W" then
    dice.move_w;
  end
end

puts dice.get_top;

Measured memory_bytes: 8724
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
// #include <boost/multiprecision/cpp_int.hpp> 

#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define pp pair<int,int>
#define ppl pair<ll,ll>
#define bigint boost::multiprecision::cpp_int
#define finp ios_base::sync_with_stdio(0);cin.tie(0);
#define bc __builtin_popcountll
#define afor(i,a,b) for(int i=a;i<=b;++i)
#define bfor(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vpp vector<pp>
#define vll vector<ll>

using namespace std;
using namespace __gnu_pbds;

char putnb[20];
void putn(ll n) {if(!n)pc('0');if(n<0)pc('-'),n=0-n;int pi=0;while(n)putnb[pi++]=(n%10)+'0',n/=10;while(pi)pc(putnb[--pi]);}
void sci(int *x) {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x = (int)((((*x)<<1) + ((*x)<<3)) + c - 48);}
void scll(ll *x)  {register char c = gc();*x = 0;for(; (c<48)||(c>57);c = gc());for(; (c>47)&&(c<58);c = gc())*x =  (ll)((((*x)<<1) + ((*x)<<3)) + c - 48);}
ll fp(ll a,ll b,ll c) {if(b==0)return 1%c; if(b==1)return a%c; ll ret=fp(a,b/2,c); ret=(ret*ret)%c; if(b&1)ret=(ret*a)%c; return ret;}

const ll mod=1e9 +7;
const ll mod2=1999999973;
const ll inf=1e18;
const int infs=1e9 + 1000;
const int N=100000;
const long double PI = acos(-1);

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main()
{
  finp;
	ll x;
	cin>>x;
	ll ans = 2*(x/11);
	if(x%11)
	{
		if(x%11 <= 6)ans++;
		else ans+=2;
	}  
	cout<<ans;
return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
using i8 = std::int_fast8_t;
using u8 = std::uint_fast8_t;
using i16 = std::int_fast16_t;
using u16 = std::uint_fast16_t;
using i32 = std::int_fast32_t;
using u32 = std::uint_fast32_t;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;
inline void fast_io() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
template <class T>
inline void in(T &now) {
    std::cin >> now;
}
template <class T, class... Args>
void in(T &head, Args &... tail) {
    in(head);
    in(tail...);
}
template <class T>
inline void out(T now) {
    std::cout << now;
}
template <class T, class... Args>
void out(T head, Args... tail) {
    out(head);
    out(tail...);
}
template <class T>
inline void up(T &a, const T &b) noexcept {
    if (a < b) {
        a = b;
    }
}
template <class T, class... Args>
void up(T &a, const T &head, const Args &... tail) noexcept {
    up(a, head);
    up(a, tail...);
}
template <class T>
inline void down(T &a, const T &b) noexcept {
    if (b < a) {
        a = b;
    }
}
template <class T, class... Args>
void down(T &a, const T &head, const Args &... tail) noexcept {
    down(a, head);
    down(a, tail...);
}
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char *argv[]) {
    fast_io();

    i64 n, r;
    in(n, r);
    if (n >= 10) {
        out(r);
    } else {
        out(r + (100 * (10 - n)));
    }

    return 0;
}


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = input[0];
            int D = input[1];

            int ans = 0;
            if (N % (2 * D + 1) == 0)
            {
                ans = N / (2 * D + 1);
            }
            else
            {
                ans = N / (2 * D + 1) + 1;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int n, d; scanf("%d%d", &n, &d);
	d = d*2+1;
	printf("%d\n", (n+d-1)/d);
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b;
    char ans[5];
    ans[0] = 'E';
    ans[1] = 'v';
    ans[2] = 'e';
    ans[3] = 'n';
    ans[4] = '\0';
    scanf("%d%d", &a, &b);
    if (a % 2 == 1)
    {
        if (b % 2 == 1)
        {
            ans[0] = 'O';
            ans[1] = 'd';
            ans[2] = 'd';
            ans[3] = '\0';
        }
    }
    printf("%s", ans);
    fflush(stdout);
    return 0;
}

Measured memory_bytes: 128