akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!
num = int(raw_input())
num_li = list(map(int,raw_input().split()))
li = []
t  = -1
answer = 0
for i in range (num):
    if t != num_li[i]:
        li.append(1)
        t = num_li[i]
    else:
        li[-1] += 1
        t = num_li[i]
for i in li:
    answer += i//2
print answer

Measured memory_bytes: 2568
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
a = Is()
m = 1
for e in a:
    m = m*e
m -= 1
f = 0
for e in a:
    f += m%e
print(f)


Measured memory_bytes: 3692
def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        if V[i] - C[i] > 0:
            ans += V[i] - C[i]
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d;
  e=c/b;
  if(c%b!=0)
    e+=1;
  f=a/d;
  if(a%d!=0)
    f+=1;
  if(e<=f)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	map<int,int> cnt;
	int ans=0,s=0;
	cnt[0]=1;
	REP(i,n){
		s+=read();
		ans+=cnt[s];
		cnt[s]++;
	}
	print(ans);
}


Measured memory_bytes: 12800
using System;
class Program
{
	static void Main()
	{
	string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
	int a = int.Parse(input[0]);
	int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);
    int ok = 0;
      int aa = 0;
      for(int i = 0; i < 105; i++)
      {
        aa += a;
        if(aa % b == c)ok++;
      }
	//出力
	Console.WriteLine((ok >= 1) ? "YES" : "NO");
	}
}

Measured memory_bytes: 11092
def i():
	return int(input())
def i2():
	return map(str,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

from decimal import Decimal
a,b = i2()
c = Decimal(a)
d = Decimal(b)
print(int(c*d))

Measured memory_bytes: 10024
N,c = open(0).read().split()
N = int(N)
white_right = 0
red = 0
red_left = 0
for x in c:
    if x == 'R':
        red_left += 1
    else:
        break
c_altered = c[red_left:]
l = len(c_altered)
for x in c_altered:
    if x == 'R':
        red += 1
        white_right = 0
    else:
        white_right += 1
c_altered = c_altered[:l-white_right]
l = len(c_altered)
ans1 = red
ans2 = c_altered[:red].count('W')
print(min(ans1,ans2))

Measured memory_bytes: 9552
s = input()
ct = {i : 0 for i in set(s)}
ct[s[0]] += 1
ct[s[1]] += 1
if ct[s[1]] == 2:
    print(1, 2)
else:
    flg = False
    for i, _s in enumerate(s[2:], 2):
        ct[_s] += 1
        if ct[_s] > 1:
            flg = True
            break
        else:
            ct[s[i-2]] -= 1
    if flg:
        print(i-1, i+1)
    else:
        print("-1 -1")

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const int MAX_N = 212345;
int A[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();

  map<int, ll> c;
  REP(i, N) ++c[A[i]];

  ll tot = 0;
  for (auto p : c) {
    tot += p.second * (p.second - 1) / 2;
  }
  REP(i, N) {
    ll m = c[A[i]];
    ll ans = tot;
    ans -= m * (m-1) / 2;
    ans += (m-1) * (m-2) / 2;
    printf("%lld\n", ans);
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 10240
t = input()
# count = 0

# if t[0] == 'D' or t[0] == '?':
#     count += 1

# for i in range(1, len(t)):
#     if t[i] == '?':
#         if t[i - 1] == 'P':
#             t[i] = 'D'
#         elif t[i + 1]
#         else:
#             t[i] = 'P'

# print(''.join(t))

print(t.replace('?', 'D'))


Measured memory_bytes: 9396
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)
using namespace std;

#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

const int MAX_X = 101'000;
// 二乗を計算する。
int sq(int x) { return x * x; }
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> X(N);
  REP(i, N) {
    cin >> X[i];
  }
  vector<int> box(M);
  vector<int> box2(MAX_X);
  vector<int> used(M);
  REP(i, N) {
    box[X[i] % M]++;
    box2[X[i]]++;
  }
  used[0] = box[0];
  SREP(1, i, (M + 1) / 2) {
    used[M - i] = used[i] = min(box[i], box[M - i]);
  }
  if (M % 2 == 0) {
    int idx = M / 2;
    used[idx] = box[idx];
  }
  int count = 0;
  count += used[0] / 2;
  SREP(1, i, (M + 1) / 2) {
    count += used[i];
  }
  if (M % 2 == 0) {
    int idx = M / 2;
    count += used[idx] / 2;
  }
  vector<int> rest(M);
  REP(i, M) {
    rest[i] = box[i] - used[i];
  }
  vector<int> pair_count(M);
  REP(i, MAX_X) {
    int m = i % M;
    pair_count[m] += box2[i] / 2;
  }
  REP(i, M) {
    count += min(pair_count[i], rest[i] / 2);
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 2560
import java.util.*;

public class Main {
	static boolean f;
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		char[] s_char = s.toCharArray();
		
		if(s_char[2]==s_char[3]) {
			if(s_char[4]==s_char[5])
				f = true;
		}
		
		if(f)
			System.out.println("Yes");
		else
			System.out.println("No");
		
	}
}


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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if (A + B + C >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
}


Measured memory_bytes: 256
using System;
using static System.Math;
 
class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    
    int max = Max(a + b, (Max(a - b, a * b)));
    Console.WriteLine("{0}", max);
  }
}   

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

int main() {
    string N;
    cin >> N;
    string ans = "No";
    for (int i=0; i<3; i++) {
        if (N[i] == '7') {
            ans = "Yes";
            continue;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
S = input()

min_753 = 100000000
for i in range(len(S) - 2):
    num = int(S[i] + S[i+1] + S[i+2])
    abs_753 = abs(num - 753)
    if abs_753 < min_753:
        min_753 = abs_753
print(min_753)


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

void solve() {
    std::string s, t;
    std::cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < (int)s.length(); ++i) {
        ans += (s[i] != t[i]);
    }

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

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

    solve();

    return 0;
}


Measured memory_bytes: 3732
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
//using namespace __gnu_pbds;
//using namespace __gnu_cxx;


using ll = long long;

//#define int ll

using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;



const int N = 2e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 6e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


//template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


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

int s, w;
main() {
  file("threesum");
  ios;
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (1) {
    c -= b;
    if (c <= 0) return !(cout << "Yes");
    a -= d;
    if (a <= 0) return !(cout << "No");
  }
  return 0;
}
/**

*/


Measured memory_bytes: 3640
n = int(input())
w = list(input() for i in range(n))
check = 0
if all(w[i][-1] == w[i+1][0] for i in range(n-1)):
  if len(w) == len(list(set(w))):
    check = 1
    
if check ==1:
  print("Yes")
else:
  print("No")

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

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var a = Console.ReadLine();
		Console.WriteLine(a[0] >= 'A' && a[0] <= 'Z' ? "A" : "a");
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if(a==b){
        cout << "Draw" << endl;
        return 0;
    }
    if(a<b){
        if(a!=1){
            cout << "Bob" << endl;
            return 0;
        }else{
            cout << "Alice" << endl;
            return 0;
        }
    }
    if(b<a){
        if(b!=1){
            cout << "Alice" << endl;
            return 0;
        }else{
            cout << "Bob" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 384
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+9;

void raushan_kumar(){

    /////////////////variables///////////////
    int d=0,e=0,f=0,g=0;
    double f1=0.0,f2=0.0,f3=0.0;
    int flag=0,ans=0,res=0,cnt=0,sum=0;
    /////////////////////////////////////////
    
    int n;cin>>n;
    set<string> s;
    fo0(i,n){
    	string str;cin>>str;
    	s.insert(str);
    }
    cout<<s.size();
    
}

int32_t main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fast;int t=1;
    //cin>>t;
    while(t--){
        raushan_kumar();
    }

}

Measured memory_bytes: 19220
#include <iostream>
using namespace std;
int main() {
char c;
cin >> c;
char *s = "aiueo";
bool a = false;
for (int i = 0; i < 5; ++i) if (c == s[i]) {
a = true;
}
if (!a) cout << "consonant" << endl;
else cout << "vowel" << endl;
}

Measured memory_bytes: 256
/***********************************************
#
#      Filename: b.cpp
#
#        Author: Comsyl - ylsong15@fudan.edu.cn
#   Description: ---
#        Create: 2017-05-06 21:24:02
***********************************************/
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
typedef pair<int, int> pii;
using namespace std;

int main()
{
    int N, M;
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;

    int u, v;
    unordered_map<int, unordered_set<int>> s;
    for (int i = 1; i <= N; ++ i) 
        s[i] = unordered_set<int>();

    for (int i = 0; i < M; ++ i) {
        cin >> u >> v;
        if (s[u].find(v) != s[u].end()) {
            s[u].erase(v);
            s[v].erase(u);
            continue;
        }
        s[u].insert(v);
        s[v].insert(u);
    }
    bool res = true;
    while (true) {
        bool has = false;
        for (auto it = s.begin(); it != s.end(); ) {
            int u = it->first;
            if (s[u].empty()) {
                it = s.erase(it);
                continue;
            }
            if (s[u].size() == 1) {
                res = false;
                break;
            }
            has = true;
            auto iter1 = s[u].begin();
            auto iter2 = iter1; advance(iter2, 1);
            int nu = * iter1;
            int nv = * iter2;
            s[u].erase(iter1);
            s[nu].erase(u);

            s[u].erase(iter2);
            s[nv].erase(u);
            if (s[nu].find(nv) != s[nu].end()) {
                s[nu].erase(nv);
                s[nv].erase(nu);
            } else {
                s[nu].insert(nv);
                s[nv].insert(nu);
            }
            ++ it;
        }
        if (!has) break;
        if (!res) break;
    }
    if (res) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 19236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner scanner = new Scanner(System.in);
		final int counter = scanner.nextInt();
		final int loop = scanner.nextInt();
		scanner.nextLine();
		final String line = scanner.nextLine();
		final int[][] index = new int[loop][2];
		final int[] array = new int[counter];
		
		for(int i = 0;i<loop;i++) {
			index[i][0] = scanner.nextInt();
			index[i][1] = scanner.nextInt();
		}

		for (int i = 1; i < counter; i++) {
			array[i] = array[i - 1];
			if (line.charAt(i) == 'C' && line.charAt(i - 1) == 'A') {
				array[i]++;
			}
		}

		for (int i = 0; i < loop; i++) {
			final int begin = index[i][0];
			final int end = index[i][1];
			System.out.println(array[end - 1] - array[begin - 1]);
		}

		scanner.close();
	}

}

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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int ans = 1;
  
  for(int i=0; i<N; i++){
    int cnt = 1;
    int jump = 0;
   for(int j=i+1; j<N; j++){
    if(vec.at(i) == vec.at(j)){
      cnt++;
      jump++;
     }
    else if(vec.at(i)+1 == vec.at(j) || vec.at(i)+2 == vec.at(j)){
     cnt++;
    }
    else{
     ans = max(ans,cnt);
     i += jump;
     break;
    }
    if(j == N-1){
     ans = max(ans,cnt);
     i += jump;
     break;
    }
   }
  } 
  cout << ans << endl;     
 }

Measured memory_bytes: 640
from collections import deque
n,m = map(int,input().split())

path = []
net = [[] for _ in range(n+1)]
for _ in range(m):
    a,b = map(int,input().split())

    net[a].append(b)
    net[b].append(a)

a = [-1] * (n+1)
d = deque()
d.append(1)
while d:
    u = d.popleft()
    for child in net[u]:
        if a[child] != -1:continue
        a[child] = u
        d.append(child)
a = a[2:]
for z in a:
    if z == -1:
        print("No")
        exit()
print("Yes")
for z in a:
    print(z)



Measured memory_bytes: 94604
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  printf("%d %d %d\n", c, a, b);
  return(0);
}


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

static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];


void dijkstra(){
  priority_queue<pair<int, int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int, int> f = PQ.top(); PQ.pop();
    int u = f.second;

    color[u] = BLACK;

    if(d[u] < f.first * (-1))continue;

    for(int j = 0;j < adj[u].size(); j++){
      int v = adj[u][j].first;
      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][j].second){
	d[v] = d[u] + adj[u][j].second;

	PQ.push(make_pair(d[v] * (-1), v));
	color[v] = GRAY;
      }
    }
  }

  for(int i = 0;i < n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main(){
  int k, u, v, c;

  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for(int j = 0;j < k; j++){
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}



Measured memory_bytes: 8080
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 300010
#define LL long long
#define INF 1e16
int n,m,a[MAXN],st[MAXN],r;
LL f[MAXN],g[MAXN],h[MAXN],ans[MAXN],sum[MAXN],tmp[MAXN],t[MAXN];
double K(int x,int y)
{
	return (t[x]-t[y]+1LL*x*(x-1)/2-1LL*y*(y-1)/2+sum[x]-sum[y])*1.0/(x-y);
}
void DP()
{
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	st[r=1]=0;
	for(int i=1;i<=n;i++)
	{
		while(r>1&&K(st[r],st[r-1])<=i) r--;
		int j=st[r];
		t[i]=max(t[i-1],t[j]+1LL*(i-j)*(i-j+1)/2+sum[j]-sum[i]);
		while(r>1&&K(st[r],st[r-1])<K(i,st[r])) r--;
		st[++r]=i;
	}
}
void Solve(int L,int R)
{
	if(L==R)
	{
		h[L]=max(h[L],g[R+1]+f[L-1]+1-a[L]);
		return;
	}
	int mid=(L+R)/2;
	st[r=1]=L-1;
	for(int i=L;i<mid;i++)
	{
		while(r>1&&K(st[r],st[r-1])<K(i,st[r])) r--;
		st[++r]=i;
	}
	for(int i=mid;i<=R;i++)
	{
		while(r>1&&K(st[r],st[r-1])<=i) r--;
		int j=st[r];
		tmp[i]=t[j]+1LL*(i-j)*(i-j+1)/2+sum[j]-sum[i]+g[i+1];
	}
	for(int i=R-1;i>=mid;i--) tmp[i]=max(tmp[i],tmp[i+1]);
	for(int i=mid;i<=R;i++) h[i]=max(h[i],tmp[i]);
	Solve(L,mid);
	Solve(mid+1,R);
}
void Pre()
{
	DP();
	for(int i=1;i<=n;i++)
		f[i]=t[i];
	for(int i=1;i<=n/2;i++)
		swap(a[i],a[n-i+1]);
	DP();
	for(int i=1;i<=n;i++)
	{
		g[i]=t[n-i+1];
		ans[i]=-INF;
	}
	for(int i=1;i<=n/2;i++)
		swap(a[i],a[n-i+1]);
	for(int i=1;i<=n;i++)
	{
		t[i]=f[i];
		sum[i]=sum[i-1]+a[i];
		h[i]=-INF;
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	Pre();
	Solve(1,n);
	for(int i=1;i<=n;i++)
		ans[i]=max(ans[i],h[i]);
	for(int i=1;i<=n;i++) swap(g[i],f[i]);
	for(int i=1;i<=n/2;i++)
	{
		swap(a[i],a[n-i+1]);
		swap(f[i],f[n-i+1]);
		swap(g[i],g[n-i+1]);
	}
	for(int i=1;i<=n;i++)
	{
		t[i]=f[i];
		sum[i]=sum[i-1]+a[i];
		h[i]=-INF;
	}
	Solve(1,n);
	for(int i=1;i<=n;i++)
		ans[i]=max(ans[i],h[n-i+1]);
	for(int i=1;i<=n/2;i++)
	{
        swap(f[i],f[n-i+1]);
        swap(g[i],g[n-i+1]);
        swap(a[i],a[n-i+1]);
    }
    for(int i=1;i<=n;i++)
    	swap(f[i],g[i]);
    scanf("%d",&m);
    while(m--)
    {
    	int x,y;
    	scanf("%d%d",&x,&y);
    	printf("%lld\n",max(f[x-1]+g[x+1],ans[x]+a[x]-y));
	}
}

Measured memory_bytes: 21248
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,m,a=0,b=0;
  cin>>n>>m;
  long long int A[n+1],B[n+1];
  memset(A,0,sizeof A);memset(B,0,sizeof B);
  while(m--){
    long long int p;
    string s;
    cin>>p>>s;
    if(!A[p] && s=="AC") A[p]=1;
    else if(!A[p] && s=="WA") B[p]+=1;
  }
  for(long long int i=1;i<=n;i++) {
  	a+=A[i];
    if(!A[i] && B[i]) b+=0;
    else if(A[i] && B[i]) b+=B[i];
  }
  cout<<a<<" "<<b;
}

  

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

unordered_map<uint64_t, uint64_t> memo;

uint64_t _getCeilNum(uint64_t n, int divNum){
  uint64_t ans = (n + divNum - 1) / divNum;
  if (ans < 0) return -ans;
  return ans;
}

uint64_t _getFloorNum(uint64_t n, int divNum){
  uint64_t ans = n / divNum;
  if (ans < 0) return -ans;
  return ans;
}

uint64_t walk(uint64_t n, uint64_t A, uint64_t B, uint64_t C, uint64_t D) {
    if (n == 0) return 0;
    if (n == 1) return D;
    if (memo.find(n) != memo.end()) {
        return memo[n];
    }
    
    uint64_t result = min({
      D * (_getCeilNum(n, 5) * 5 - n) + C + walk(_getCeilNum(n, 5), A, B, C, D),
      D * (n - _getFloorNum(n, 5) * 5) + C + walk(_getFloorNum(n, 5), A, B, C, D),
      D * (_getCeilNum(n, 3) * 3 - n) + B + walk(_getCeilNum(n, 3), A, B, C, D),
      D * (n - _getFloorNum(n, 3) * 3) + B + walk(_getFloorNum(n, 3), A, B, C, D),
      D * (_getCeilNum(n, 2) * 2 - n) + A + walk(_getCeilNum(n, 2), A, B, C, D),
      D * (n - _getFloorNum(n, 2) * 2) + A + walk(_getFloorNum(n, 2), A, B, C, D),
      D * n
      });

    memo[n] = result;
    return result;
}

int main() {
    int T;
    cin >> T;
    vector<vector<uint64_t>> testCaseList(T, vector<uint64_t>(5));
    for (int i = 0; i < T; ++i) {
        cin >> testCaseList.at(i).at(0) >> testCaseList.at(i).at(1) >>
            testCaseList.at(i).at(2) >> testCaseList.at(i).at(3) >>
            testCaseList.at(i).at(4);
    }

    for (auto testCase : testCaseList) {
        memo.clear();
        cout << walk(testCase.at(0), testCase.at(1), testCase.at(2),
                     testCase.at(3), testCase.at(4))
             << endl;
        ;
    }
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n)  for(int i=0;i<n;i++)
#define per(i,n)  for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
using namespace std;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string str;
    bool check = true;
    int Q,Case,F1;
    deque<char> letters, letters1;
    char letter;
    cin >> str >> Q;
    for (auto i : str) letters.push_back(i);
    rep(i,Q){
        cin >> Case;
        if (Case == 1){
            check = !check;
        }
        else {
            if (check){
                cin >> F1 >> letter;
                if (F1 == 1) letters.push_front(letter);
                else letters.push_back(letter);
            }
            
            else{
                cin >> F1 >> letter;
                if (F1 == 1) letters.push_back(letter);
                else letters.push_front(letter);
            }
            }
        }
    str.clear();
    if(check) for (auto i : letters) str += i;
    else {
        
    for (auto i : letters) letters1.push_front(i);
    for (auto i : letters1) str += i;
        
    }
        
    cout << str;
    return 0;
    }


Measured memory_bytes: 1424
#include<iostream>


#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
int n,k;
int ans=0;
int main(){
    cin>>n>>k;
    while(n>0){
        n/=k;
        ans++;
    }
    puts(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

signed main(){

	string s, ans;

	cin >> s;

	for (int i = 0; i < s.length(); i++){
		char c = s[i];

		if (c == '0' || c == '1')
			ans.insert(ans.end(), c);
		else
			if (ans.length()>0)
				ans.erase(ans.end() - 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using Vi = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust"<<endl;
    }
    else{
        cout<<"win"<<endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    long long ans = 0;
    bool distinct = false;
    int bmin = 1<<30;
    while (n--) {
        int a, b; cin >> a >> b;
        ans += a;
        if (a > b) bmin = min(bmin, b);
    }
    cout << (bmin < 1<<30 ? ans-bmin : 0) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n;
long long dp[20][100009];
string s;

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow((b*b) % 13, e >> 1)) % 13 : 1;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> s;
	n = s.length();
	reverse(s.begin(), s.end());
	if (s[0] == '?') {
		for (int i = 0; i < 10; i++) {
			dp[i][0] = 1;
		}
	}
	else {
		dp[s[0] - '0'][0] = 1;
	}
	for (int i = 1; i < n; i++) {
		if (s[i] == '?') {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 13; k++) {
					long long tmp = quickpow(10, i);
					tmp = tmp * j;
					tmp = tmp % 13;
					tmp = tmp + k;
					tmp = tmp % 13;
					dp[tmp][i] += dp[k][i - 1];
					dp[tmp][i] = dp[tmp][i] % MOD;
				}
			}
		}
		else {
			for (int k = 0; k < 13; k++) {
				long long tmp = quickpow(10, i);
				tmp = tmp * (s[i] - '0');
				tmp = tmp % 13;
				tmp = tmp + k;
				tmp = tmp % 13;
				dp[tmp][i] = dp[k][i - 1];
				dp[tmp][i] = dp[tmp][i] % MOD;
			}
		}
	}
	cout << dp[5][n - 1] << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 10704
// [[ABC134C] Exception Handling] https://www.luogu.com.cn/problem/AT4843
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  int rcnt = 0, bcnt = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R')
      rcnt++;
    else
      bcnt++;
  }

  cout << (rcnt > bcnt ? "Yes\n" : "No\n") << endl;
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	if (s.size() == 26u) {
		string t(s);
		if (!next_permutation(t.begin(), t.end())) {
		cout << -1 << endl;
		return 0;
		}
		while (t.substr(0, t.size() - 1) > s) t.pop_back();
		cout << t << endl;
	}
	else {
		for (int i = 0; i < 26; i++) {
			int f = 0;
			for (char c : s) if (c - 'a' == i) f = 1;
			if (f) continue;
			cout << s << char('a' + i) << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    vector<ll> a(n+1);
    for(ll i = 1; i <= n; i++){
        ll b; cin >> b;
        a[i] = b;
    }
    vector<vector<ll>> ans(h+1, vector<ll>(w+1, 0));
    vector<p> b;
    for(ll i = 1; i <= h; i++){
        for(ll j = 1; j <= w; j++){
            if(i%2!=0) b.push_back(p(i, j));
            else b.push_back(p(i, w-j+1));
        }
    }
    ll s = 1;
    ll count = 0;
    for(ll i = 0; i < b.size(); i++){
        ans[b[i].first][b[i].second] = s;
        count++;
        if(count==a[s]){
            count = 0; s++;
        }
    }
    for(ll i = 1; i <= h; i++){
        for(ll j = 1; j <= w; j++){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>

int main(void){
	int N;
	int A;
	int i,j;

	scanf("%d",&N);
	int max=0,sec=0, mn;

	for(i=0; i<N; i++){
		scanf("%d",&A);
		if(A>sec){
			if(A>max){ sec = max;  max = A; mn=i; }else{ sec = A; }
		}
	}

	for(i=0; i<N; i++){
		if(i==mn) printf("%d\n",sec );
		else printf("%d\n",max );
	}
}

Measured memory_bytes: 1536
//have fun
#include <bits/stdc++.h>
using namespace std;
#define mod 		998244353
#define ll 		long long
#define mp 		make_pair
#define pb 		push_back
#define forn(i,n) 	for(int i=0;i<n;i++)
#define for1(i,n) 	for(int i=1;i<n;i++)
#define ford(i,n) 	for(int i=n-1;i>=0;i--)
#define vi 		vector<int>
#define vl 		vector<ll>
#define pii 		pair<int,int>
#define pll 		pair<ll,ll>
#define vpi 		vector<pair<int,int> >
#define vpl		vector<pair<ll,ll> >
#define vvi 		vector<vector<int> >
#define vvl 		vector<vector<ll> >
#define ull 		unsigned long long
#define IOS 		ios_base::sync_with_stdio(false);
#define PI 		3.1415926535897932384626
#define ff 		first
#define ss 		second
#define char2Int(c) 	(c-'0')
#define FOREACH(i,t) 	for (auto i=t.begin(); i!=t.end(); i++)
#define clr(a,x) 	memset(a,x,sizeof(a)) //set elements of array to some value
#define all(x)		(x).begin(),(x).end()//cout<<"Case #"<<zzz<<": ";
void solve()
{
    int x,y;cin>>x>>y;
    if(y>4*x||y<2*x){cout<<"No"<<endl;return;}
    while(x>0&&y>2*x)
    {
        y-=4;--x;
    }
    if(2*x==y){cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
    return;
}
int main()
{
    IOS;cin.tie(NULL);
    int zz=1;
    for(int zzz=1;zzz<=zz;zzz++)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3636
n, m = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
a.sort!.reverse!

priority_queue = []
priority_queue << a.shift / 2

(m-1).times do
  if a == []
    a = priority_queue
    priority_queue = []
    priority_queue << a.shift / 2
  elsif a[0] > priority_queue[0]
    priority_queue << a.shift / 2
  else
    priority_queue << priority_queue.shift / 2
  end
end

sum = 0
sum += a.inject(:+) if !a.empty?
sum += priority_queue.inject(:+) if !priority_queue.empty?
print sum


Measured memory_bytes: 13944
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



s = S()
x, y = LI()
components = [len(i) for i in s.split('T')]
initial_x = components[0]
components = components[1:]
y_component = [j for j in components[::2] if j]
x_component = [j for j in components[1::2] if j]
x_len = len(x_component)
y_len = len(y_component)
x_D = defaultdict(int)
y_D = defaultdict(int)


x_D[initial_x] = 1
for i in range(x_len):
    nxt_x_D = defaultdict(int)
    for pos in x_D.keys():
        nxt_x_D[pos + x_component[i]] = nxt_x_D[pos - x_component[i]] = 1
    x_D = nxt_x_D


y_D[0] = 1
for i in range(y_len):
    nxt_y_D = defaultdict(int)
    for pos in y_D.keys():
        nxt_y_D[pos + y_component[i]] = nxt_y_D[pos - y_component[i]] = 1
    y_D = nxt_y_D



if x_D[x] and y_D[y]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 76892
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define vec vector<long long int>
#define fi first
#define se second
#define pb push_back
void dfs(vector<vector<int>> &x, vector<int> &visited, int k, int &count)
{
    if (visited[k] == 1)
    {
        return;
    }

    visited[k] = 1;
    for (int i = 0; i < x[k].size(); i++)
    {
        if (visited[x[k][i]] == 0)
        {
            count++;
            dfs(x, visited, x[k][i], count);
        }
    }
}
int dfsu(vector<vector<int>> &x, vector<int> &visited, int k)
{
    int mi = 0;
    int count = 0;
    dfs(x, visited, k, count);
    mi = max(mi, count);
    for (int i = 0; i < visited.size(); i++)
    {
        count = 0;
        if (visited[i] == 0)
        {
            dfs(x, visited, i, count);
            mi = max(mi, count);
        }
    }
    return mi;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> x(n + 1);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        x[a].pb(b);
        x[b].pb(a);
    }
    vector<int> vis(n + 1, 0);
    int ma = dfsu(x, vis, 1);
    cout << ma + 1;
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    vector<ll> L;
    L.push_back(A[0]);

    FOR(i, 1, N){
        ll a = A[i];
        if(L.back()<a){
            L.push_back(a);
        }else{
            auto it = lower_bound(ALL(L), a);
            *it = a;
        }
    }

    ll ans = L.size();
    p(ans);
    
    return 0;
}


Measured memory_bytes: 4436
import sys
sys.setrecursionlimit(10000000)
MOD = 998244353

def main():
    N = int(input())
    D = [int(c) for c in input().split()]

    if D[0] != 0:
        print(0)
        sys.exit()

    for i in range(1, N):
        if D[i] >= N or D[i] == 0:
            print(0)
            sys.exit()

    dist_nums = {}
    for i in range(N):
        if dist_nums.get(D[i]) is None:
            dist_nums[D[i]] = 1
        else:
            dist_nums[D[i]] += 1

    ans = 1
    num = 1
    dist_nums = sorted(dist_nums.items(), key=lambda x: x[0]) # [(0, 1), (1, 2), (2, 1)]
    for i in range(1, len(dist_nums)):
        if dist_nums[i][0] == i:
            ans *= dist_nums[i - 1][1] ** dist_nums[i][1]
            num += dist_nums[i][1]
        else:
            break

    if num != N:
        print(0)
    else:
        print(ans % MOD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 21020
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include<unordered_set>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

bool lis[40][40];
string s[40], t[40];
signed main(void)
{
	int h, w, n;
	cin >> h >> w >> n;
	REP(i, h) cin >> s[i];

	//(i, j)??¨(i, j+1)?????\?????????
	REP(i, h) REP(j, w-1) {
		if(s[i][j] == '.' && s[i][j+1] == '.') continue;
		//cout << i << " " << j << endl;
		REP(k, h) t[k] = s[k];
		//cout << i << " " << j << endl;
		//REP(k, h) cout << t[k] << endl;
		swap(t[i][j], t[i][j+1]);
		//????????????
		REP(k, w) REP(l, h)	{
			bool ra = false;
			for(int l2=h-1; l2>=1; --l2) {
				//cout << k << " " << l2 << endl;
				if(t[l2][k] == '.') ra = true;
				if(ra) {t[l2][k] = t[l2-1][k]; t[l2-1][k] = '.';}
			}
		}
		while(true) {
			//?¨?????????§n??\???????????§?????¨??????????¶????
			REP(k, h) REP(l, w) lis[k][l] = false;
			REP(k, h) {
				int c = 1;
				FOR(l, 1, w) {
					if(t[k][l] == t[k][l-1] && t[k][l] != '.') c++;
					else {
						if(c >= n) REP(l2, c) lis[k][l-l2-1] = true;
						c = 1;
					}
				}
				if(c >= n) REP(l2, c) lis[k][w-l2-1] = true;
			}
			//???????????§n??\???????????§?????¨??????????¶????
			REP(l, w) {
				int c = 1;
				FOR(k, 1, h) {
					if(t[k][l] == t[k-1][l] && t[k][l] != '.') c++;
					else {
						if(c >= n) REP(l2, c) lis[k-l2-1][l] = true;
						c = 1;
					}
				}
				if(c >= n) REP(l2, c) lis[h-l2-1][l] = true;
			}
			//cout << "y:" << i << " x:" << j << endl;
			//lis???true?????¨??????????¶???? ???????????°break
			bool flag = false;
			REP(k, h) {
				REP(l, w) {
					//cout << (lis[k][l]?"o ":"x ");
					if(lis[k][l]) {
						flag = true;
						t[k][l] = '.';
					}
				}
				//cout << endl;
			}
			//cout << "b" << endl;
			/*REP(k, h) {
				REP(l, w) {
					cout << t[k][l] << " ";
				}
				cout << endl;
			}*/
			if(!flag) {
				//??¨??¨'.'????¢??????????????????????Yes?????? return 0;
				bool f2 = true;
				REP(k, h) REP(l, w) {
					if(t[k][l] != '.') f2 = false;
				}
				//cout << "a" << endl;
				if(f2) {cout << "YES" << endl; return 0;}
				break;
			}
			//????????????
			REP(k, w) REP(l, h)	{
				bool ra = false;
				for(int l2=h-1; l2>=1; --l2) {
					//cout << k << " " << l2 << endl;
					if(t[l2][k] == '.') ra = true;
					if(ra) {t[l2][k] = t[l2-1][k]; t[l2-1][k] = '.';}
				}
			}
			//cout << endl;
			//if(i == 2 && j == 2) REP(k, h) cout << t[k] << endl;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;

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

    ll n,x,m;
    cin>>n>>x>>m;
    map<ll,pair<int,int>> mp;
    vector<ll> c_sum;
    ll a=x,cnt=1;
    c_sum.emplace_back(0);
    c_sum.emplace_back(a);
    while(++mp[a].first<=1){
        mp[a].second=cnt;
        cnt++;
        a%=m;
        a*=a;
        a%=m;
        c_sum.emplace_back(c_sum.back()+a);
    }
    ll t=(cnt-1)-(mp[a].second-1),v=c_sum[cnt-1]-c_sum[mp[a].second-1];
    ll ans=((n-(mp[a].second-1))/t)*v;
    ll b=x;
    for(ll i=1;i<mp[a].second;i++){
        ans+=b;
        b%=m;
        b*=b;
        b%=m;
    }
    n-=mp[a].second-1;
    n%=t;
    for(ll i=1;i<=n;i++){
        ans+=a;
        a%=m;
        a*=a;
        a%=m;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6664
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <sstream>
#include <string>
using namespace std;

int main(){
	string s;
	while(getline(cin, s)){
		stack<double> st;
		stringstream ss(s);
		string t;	
		double a, b;
		
		while(ss >> t){
			
			if(t == "+"){
				a=st.top();
				st.pop();
				b=st.top();
				st.pop();
				st.push(b+a);
			}
			else if(t == "-"){
				a=st.top();
				st.pop();
				b=st.top();
				st.pop();
				st.push(b-a);
			}
			else if(t == "*"){
				a=st.top();
				st.pop();
				b=st.top();
				st.pop();
				st.push(b*a);				
			}
			else if(t == "/"){
				a=st.top();
				st.pop();
				b=st.top();
				st.pop();
				st.push(b/a);			
			}
			else st.push(atof(t.c_str()));
	
		}
	
		printf("%lf\n", st.top());
		st.pop();
	}
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if(a > b or (n == 1 and a != b)){printf("0\n");return 0;}
	int mx = a+(n-1)*b, mn = b+(n-1)*a;
	printf("%lld\n", mx-mn+1);
	return 0;
}







Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s>>t;
	int n1=s.length(),n2=t.length(),ans=n1;
	for(int i=0;i+n2-1<n1;i++){
		int c=0;
		for(int j=i;j<i+n2;j++){
			c+=(s[j]!=t[j-i]);
		}
		ans=min(c,ans);
	}
	cout<<ans;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int cnt[19][19];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    LL ans = 0;
    for(cin >> N; N; N -= 1){
        long double A;
        cin >> A;
        LL X = A * 1000000000 + .5;
        int u = 0, v = 0;
        for(; X % 2 == 0 and u < 18; X /= 2) u += 1;
        for(; X % 5 == 0 and v < 18; X /= 5) v += 1;
        for(int i = 18 - u; i <= 18; i += 1)
            for(int j = 18 - v; j <= 18; j += 1)
                ans += cnt[i][j];
        cnt[u][v] += 1;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3740
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_set>
#include<unordered_map>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod;
#define N 2010
ll f[N][N];
ll n,m,s[N],t[N];
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++)cin>>s[i];
  for(int i=1;i<=m;i++)cin>>t[i];
  for(int i=0;i<N;i++)f[i][0]=f[0][i]=0;
  f[0][0]=1;
  for(int i=0;i<=n;i++)for(int j=0;j<=m;j++){
    if(i==0&&j==0)continue;
    ll res=0;
    if(i)mad(res,f[i-1][j]);
    if(j)mad(res,f[i][j-1]);
    if(i>0&&j>0){
      mad(res,mod-f[i-1][j-1]);
      if(s[i]==t[j])mad(res,f[i-1][j-1]);
    }
    f[i][j]=res;
  }
  /*
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      cout<<f[i][j]<<" ";
    }
    cout<<endl;
  }*/
  cout<<f[n][m]<<endl;
  return 0;
}


Measured memory_bytes: 31744