akhauriyash/Code-Regression huggingface dataset:
import java.util.*; 
   
public class Main{ 
   
    int n; 
    int[][] c; 
    char[] per; 
    boolean[] used; 
    int goal,ans; 
    int[] v;
   
    void solve(){ 
        Scanner sc = new Scanner(System.in); 
   
        n = sc.nextInt(); 
        c = new int[n][n]; 
        for(int i=0; i<n; i++){ 
            for(int j=0; j<n; j++){ 
                int cc = sc.nextInt(); 
                c[i][j] = cc; 
                c[j][i] = cc; 
            } 
        }

        v = new int[8765433];
        Arrays.fill(v,-1);
        dijkstra();
 
        int max = 0;
        for(int i=0; i<v.length; i++) max = Math.max(max,v[i]);
   
        System.out.println(max); 
    } 
   
    void dijkstra(){ 
        //permutation,cost 
        PriorityQueue<int[]>  
            q = new PriorityQueue<int[]>(n, new Comparator<int[]>(){ 
                    public int compare(int[] a, int[] b){ 
                        return a[1] - b[1]; 
                    } 
                }); 
   
        String sss = "";
        for(int i=1; i<=n; i++) sss += Integer.toString(i);
        q.add(new int[]{Integer.parseInt(sss),0}); 
 
        while(q.size()>0){ 
            int[] pp = q.poll(); 
            int perm = pp[0]; 
            int cost = pp[1]; 
   
            if(v[perm/10]!=-1) continue; 
            v[perm/10] = cost; 
   
            char[] permm = Integer.toString(perm).toCharArray(); 
   
            for(int i=0; i<n; i++){ 
                for(int j=i+1; j<n; j++){ 
                    char tmp = permm[i]; 
                    permm[i] = permm[j]; 
                    permm[j] = tmp; 
                    q.add(new int[]{Integer.parseInt(new String(permm)), cost+c[i][j]}); 
                    tmp = permm[i]; 
                    permm[i] = permm[j]; 
                    permm[j] = tmp; 
                }    
            } 
        } 
    } 
   
    public static void main(String[] args){ 
        new Main().solve(); 
    } 
} 

Measured memory_bytes: 130212
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+50;
int n;
int a[maxn];
int cnt;
bool flag=false;
void dfs(int x,int step)
{
    if(a[x]==2)
    {
        flag=true;
        cnt=step+1;
        return ;
    }
    if(step>n)
    {
        flag=false;
        return;
    }
    int pos=a[x];
    dfs(pos,step+1);
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dfs(1,0);
    if(flag)
        cout << cnt << endl;
    else
        cout << -1 <<endl;
    //cout << "Hello world!" << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

//0609
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), l[] = new int[m], r[] = new int[n];
        for (int i = 0; i < m; i++)
            l[i] = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int s = 0;
            for (int j = 0; j < n; j++) {
                if (sc.nextInt() == l[i]) {
                    r[j]++;
                    s++;
                }
            }
            r[l[i] - 1] += n - s;
        }
        for (int i : r)
            System.out.println(i);
    }
}



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

int main() {
    std::string S;
    std::cin >> S;

    int ans[2] = {0, 0};
    for (int i = 0; i < S.length(); ++i) {
        int c = S[i] - '0';
        for (int j = 0; j < 2; ++j) {
            ans[j] += (c != (i + j) % 2);
        }
    }

    std::cout << std::min(ans[0], ans[1]) << std::endl;
    return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846
#ifdef LOCAL
#include <sys/types.h>
#include <sys/timeb.h>
#include <intrin.h> 
#include <thread>
#else
#include <sys/time.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

const int N = 100005;
int a[N];
LL s[N];
LL s_oe[N];

int main(){
	int n, q;
	scanf("%d%d", &n, &q);
	REP(i, n) scanf("%d", &a[i]);
	s[0] = 0;
	REP(i, n)s[i+1] = s[i] + a[i];
	REP(i, n)s_oe[i+2] = s_oe[i] + a[i];
	REP(i, q) {
		int x;
		scanf("%d", &x);
		int l = 0;
		int r = 1000000005;
		while (r - l > 1) {
			int mid = (l + r) / 2;
			auto l_idx = lower_bound(a, a + n, x - mid) - a;
			auto r_idx = upper_bound(a, a + n, x + mid) - a;
			if (r_idx - l_idx + 1 < n - r_idx) {
				l = mid;
			}
			else {
				r = mid;
			}
		}
		auto l_idx = lower_bound(a, a + n, x - l) - a;
		auto r_idx = upper_bound(a, a + n, x + l) - a;
		if (r_idx - l_idx + 1 < n - r_idx)l++;
		l_idx = lower_bound(a, a + n, x - l) - a;
		r_idx = upper_bound(a, a + n, x + l) - a;
		int c = r_idx - l_idx;
		int d = n - r_idx;
		if (c > d) {
			r_idx--;
			c--;
			d++;
		}
		LL ret = s[n] - s[r_idx];
		if (c == d)ret += s_oe[l_idx+1];
		else ret += s_oe[l_idx];
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3712
using System;
using System.Linq;
 
class prog{
  static void Main(){
    
    int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
    
    Console.WriteLine(input[0] % 2 != 0&&input[1] % 2 != 0 ? "Odd" : "Even");
    
  }
}

Measured memory_bytes: 11220
#include<iostream>
#include<vector>
#include<set>
#include<utility>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cinttypes>
#include<stack>
using namespace std;

typedef long long ll;


#define ceil(a,b)  ( !(a%b) ? a/b : a/b+1 )
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define endl '\n' 
#define debug(a) cin>>#a>>a;
//vector<ll> primes{ }

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

int main(){
    vector<int> a{ 1,3,5,7,8,10,12 };
    vector<int> b { 4,6,9,11 };
    int x,y;
    cin>>x>>y;
    if( (find(all(a),x) != a.end() && find(all(a),y) != a.end()) || ( find(all(b),x) != b.end() && find(all(b),y) != b.end()) ){
        cout<<"Yes";
    } else{
        cout<<"No";
    }
    cout<<endl;

}


Measured memory_bytes: 3592
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <limits>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

double dis[1002][1002];
int preve[1002];
bool f[1002];

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

int main() {
	int xs, ys, xt, yt, n;
	cin >> xs >> ys >> xt >> yt >> n;
	LL x[1002], y[1002], r[1002];
	REP(i,1,n+1) cin >> x[i] >> y[i] >> r[i];
	x[0] = xs; y[0] = ys; r[0]= 0;
	x[n+1] = xt; y[n+1] = yt; r[n+1]= 0;
	REP(i,0,n+2) REP(j,i,n+2) {
		if (i == j) dis[i][j] = 0;
		else {
			dis[i][j] = dis[j][i] = max(0.0, sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j])) - r[i] - r[j]);
			//cout << dis[i][j] << " " << sqrt(sqr(x[i]-x[j])+sqr(y[i]-y[j])) << endl;
		}
	}
	//int ans[1002];
	vector<double> d(n+2);
	REP(i,0,n+2) {
		preve[i] = -1;
		f[i] = false;
		if (i) d[i] = std::numeric_limits<double>::max();
		else d[i] = 0;
	}
	while (true) {
		bool b = false;
		REP(i,0,n+2) {
			if (!(f[i])) {
				b = true;
				break;
			}
		}
		if (!b) break;
		double mindis = std::numeric_limits<double>::max();
		REP(i,0,n+2) {
			if (!(f[i])) mindis = min(mindis, d[i]);
		}
		int index = -1;
		REP(i,0,n+2) {
			if (!(f[i]) && mindis == d[i]) { index = i; break;}
		}
		f[index] = true;
		REP(i,0,n+2) {
			if (f[i]) continue;
			if (d[i] > d[index] + dis[index][i]) {
				d[i] = d[index] + dis[index][i];
				preve[i] = index;
			}	
		}
	}
	//cout << d[n+1] << endl;
	//REP(i,0,n+2) printf("%.9lf\n", d[i]);
	printf("%.10lf\n", d[n+1]);
	
	return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

using namespace std;


int main(){
	int n,count=0,t,min,min_index,tmp,left_node,right_node,dist;
	scanf("%d",&n);
	int distance[n][n],P[n];

	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)distance[i][k]=10000001;
		P[i]=0;
	}
	distance[0][0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		for(int k=0;k<tmp;k++){
			scanf("%d %d",&right_node,&dist);
			distance[left_node][right_node] = dist;
		}
	}

	while(count<n-1){

		min=10000001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&distance[0][i]<min){
				min_index = i;
				min = distance[0][i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=0;i<n;i++){
			if(distance[0][i] > distance[0][t]+distance[t][i]){
				distance[0][i]=distance[0][t]+distance[t][i];
			}
		}
	}

	for(int i=0;i<n;i++){
		printf("%d %d\n",i,distance[0][i]);
	}

    return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



long long solve(const string &S) {
    int N = S.size();
    vector<long long> val(2019, 0);
    long long fac = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        long long add = S[N-1-i] - '0';
        cur = (cur + fac * add) % 2019;
        fac = (fac * 10) % 2019;
        val[cur]++;
    }
    long long res = 0;
    for (int i = 0; i < val.size(); ++i) {
        res += val[i] * (val[i] - 1) / 2;
    }
    return res;
}

int main() {
    string S;
    cin >> S;
    cout << solve(S) << endl;
}


Measured memory_bytes: 3652
import random

D = int(input())
C = list(map(int, input().split()))  # (26,)
S = [list(map(int, input().split())) for _ in range(D)]  # (365, 26)


class Scorer:

    def __init__(self, c, s):
        self.n_cty = len(c)
        self.c = c  # (26,)
        self.s = s  # (365, 26)
        self.elapsed_time = [0] * self.n_cty

        self.score = 0

    def step(self, d, cty):
        elapsed_time = self.elapsed_time[:]

        for cty_ in range(self.n_cty):
            if cty_ == cty:
                elapsed_time[cty_] = 0
            else:
                elapsed_time[cty_] += 1

        cur_score = self.s[d][cty]
        for cty_ in range(len(elapsed_time)):
            cur_score -= self.c[cty_] * elapsed_time[cty_]

        score = self.score + cur_score
        return score

    def update(self, d, cty):
        elapsed_time = self.elapsed_time[:]

        for cty_ in range(self.n_cty):
            if cty_ == cty:
                elapsed_time[cty_] = 0
            else:
                elapsed_time[cty_] += 1

        cur_score = self.s[d][cty]
        for cty_ in range(len(elapsed_time)):
            cur_score -= self.c[cty_] * elapsed_time[cty_]

        score = self.score + cur_score

        # update
        self.elapsed_time = elapsed_time
        self.score = score

        return score


# greedy
T = []
scorer = Scorer(C, S)
for d in range(D):
    best_cty = -1
    best_score = -float('inf')
    for cty in range(26):
        cur_score = scorer.step(d, cty)
        if best_score < cur_score:
            best_cty = cty
            best_score = cur_score
    scorer.update(d, best_cty)
    T.append(best_cty)

N_REPLACE = 5
N_ITER = 100
EPS = 0.5
ATT = 0.95

# best_score = -1
# for _ in range(N_ITER):
#     scorer = Scorer(C, S)
#     T_ = T[:]
#
#     # replace N elements
#     for i in range(N_REPLACE):
#         T_[random.randint(0, D - 1)] = random.randint(0, 25)
#
#     for d in range(D):
#         cty = T_[d]
#         scorer.update(d, cty)
#
#     if best_score <= scorer.score:
#         best_score = scorer.score
#         T = T_
#     elif random.random() < EPS:
#         best_score = scorer.score
#         T = T_
#
#     EPS *= ATT

for t in T:
    print(t + 1)


Measured memory_bytes: 78440
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
  int a;
  cin>>a;
  cout<<a+pow(a,2)+pow(a,3);
  return 0;
}


Measured memory_bytes: 4132
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();
	String t = sc.next();
	int min = Integer.MAX_VALUE;
	int count = 0;
	for (int i=0; i<=s.length()-t.length(); i++) {
	    String sis = s.substring(i,i+t.length());
	    count = 0;
	    for (int j=0; j<t.length(); j++) {
		if (sis.charAt(j) != t.charAt(j)) {
		    count++;
		}
	    }
	    if (count < min) {
		min = count;
	    }
	}
	System.out.print(min);
    }
}


Measured memory_bytes: 36648
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	set<int> ans;
	int a, b, k;
	cin >> a >> b >> k;
	repn(i, a, min(b + 1, (a + k))) ans.insert(i);
	repn(i, max(a, (b - k + 1)), b + 1) ans.insert(i);
	for(int x : ans) cout << x << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int f[9]={0,1,2,4,8,16,32,64,128};
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=9;i++)
	if(f[i]>n)
	{
		cout<<f[i-1]<<endl;
		break;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int N, K, S;
	cin >> N >> K >> S;
	for (int i = 0; i < K; i++) {
		if (i != 0) cout << " ";
		cout << S;
	}
	for (int i = K; i < N; i++) {
		cout << " ";
		if (S == 1) cout << 2;
		else cout << S - 1;
	}
	cout << endl;
}

Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int Max = 200000;

int main(){
  int A[Max], n, i;
  int maxv, minv;

  cin >> n;
  for(i = 0; i < n; i++) {
    cin >> A[i];
  }

  maxv = A[1] - A[0];
  minv = A[0];

  for(i = 1; i < n; i++) {
    maxv = (maxv > (A[i] - minv))?maxv:(A[i] - minv);
    minv = (minv < A[i])?minv:A[i];
  }

  cout<<maxv<<endl;

  return 0;

}



Measured memory_bytes: 3844
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

    private static List<Integer> permList = new ArrayList<>();

    private static void permutation(int n, Set<Integer> set, int num) {
        if (String.valueOf(num).length() >= n) {
            permList.add(num);
            return;
        }
        for (int i = 1; i <= n; i++) {
            if (set.contains(i)) {
                continue;
            }
            set.add(i);
            permutation(n, set, num * 10 + i);
            set.remove(i);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] q = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            q[i] = sc.nextInt();
        }

        int pnum = 0;
        int qnum = 0;
        for (int i = 0; i < n; i++) {
            pnum += p[i] * Math.pow(10, n - i - 1);
            qnum += q[i] * Math.pow(10, n - i - 1);
        }

        permutation(n, new HashSet<>(), 0);
        int a = 0;
        int b = 0;
        for (int i = 0; i < permList.size(); i++) {
            if (pnum == permList.get(i)) {
                a = i;
            }
            if (qnum == permList.get(i)) {
                b = i;
            }
        }
        System.out.println(Math.abs(a - b));
    }

}


Measured memory_bytes: 39792
from operator import itemgetter
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    a_,b_=map(int,input().split())
    a.append(a_)
    b.append(b_)
ab=sorted([(a[i],b[i]) for i in range(m)],  key=itemgetter(1))  
removed=-1
ans=0

for i,j in ab:
    if i>removed:
        ans+=1
        removed=j-1
print(ans)

Measured memory_bytes: 20564
import math

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
  
a = list(range(1, n+1))
b = list(range(1, n+1))
nump = 1
numq = 1

for i in range(n):
  nump += a.index(p[i]) * math.factorial(n-(i+1))
  a.remove(p[i])

for i in range(n):
  numq += b.index(q[i]) * math.factorial(n-(i+1))
  b.remove(q[i])

print(abs(nump - numq))

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    vector<int> dist(n,inf);
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    rep(i,n){
        if(a[i]==0){
            dist[i]=-inf;
            pq.emplace(-inf,i);
        }
    }
    while(pq.size()){
        auto p = pq.top();pq.pop();
        int d = p.first, cur = p.second;
        if(dist[cur]<d)continue;
        for(int nxt = cur-1;nxt<=cur+1;nxt+=2){
            if(nxt<0||nxt>=n)continue;
            int nd = d + 1;
            if(a[nxt]<0)nd = max(nd,a[nxt]);
            if(dist[nxt]>nd){
                dist[nxt]=nd;
                pq.emplace(nd,nxt);
            }
        }
    }
    ll ans=0;
    rep(i,n){
        if(a[i]>0&&dist[i]<=0)ans+=min(a[i],-dist[i]);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4632
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, M = sc.nextInt()

    val prefectures = Array.fill(N+1)(
      new scala.collection.mutable.ArrayBuffer[Int]())
    val result = new Array[String](M)
    val year = new Array[Int](M)

    (0 until M) foreach { i =>
      val p = sc.nextInt()
      year(i) = sc.nextInt()
      prefectures(p).append(i)
    }

    @inline val format = (n: Long) => "%012d".format(n)

    (1 to N). foreach { p =>
      val prefecture = prefectures(p).sortBy(i => year(i))
      val l = prefecture.size
      var i = 1
      while (i <= l) {
        val city = prefecture(i-1)
        result(city) = format(p * 1000000L + i)
        i += 1
      }
    }

    println(result.mkString("\n"))

  }

}


Measured memory_bytes: 134052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, k;
  cin >> n >> k;
  vl p(n);
  rep(i,n){
    cin >> p[i];
  }
  sort(all(p));
  ll ans = 0;
  rep(i,k){
    ans += p[i];
  }
  print(ans);
}

Measured memory_bytes: 3624
class UnionFind:

    def __init__(self, n):
        # parent[x] < 0 means x is root and abs(parent[x]) == size[x]
        self.parent, self.depth = [-1] * n, [0] * n

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        if self.isSame(x, y):
            return
        x, y = self.find(x), self.find(y)

        if self.depth[x] > self.depth[y]:
            self.parent[x] += self.parent[y]
            self.parent[y] = x
        else:
            self.parent[y] += self.parent[x]
            self.parent[x] = y
            if self.depth[x] == self.depth[y]:
                self.depth[y] += 1

    def size(self, x):
        return - self.parent[self.find(x)]


N, M, K = map(int, input().split())
Friend, Block = {i: [] for i in range(N)}, {i: [] for i in range(N)}
union = UnionFind(N)
for _ in range(M):
    A, B = map(int, input().split())
    union.unite(A - 1, B - 1)
    Friend[A - 1].append(B - 1)
    Friend[B - 1].append(A - 1)
for _ in range(K):
    C, D = map(int, input().split())
    Block[C - 1].append(D - 1)
    Block[D - 1].append(C - 1)

ans = []
for i in range(N):
    nBlock = 0
    for b in Block[i]:
        if union.isSame(i, b):
            nBlock += 1
    ans.append(str(union.size(i) - 1 - len(Friend[i]) - nBlock))
print(' '.join(ans))


Measured memory_bytes: 128084
// #includes {{{
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cmath>
using namespace std;
// }}}
// pre-written code {{{
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair
//#define PB push_back
#define CLEAR(c,d) memset((c),(d),sizeof(c))
#define TO_STRING(VariableName) # VariableName
//#define DB(c) cout<<TO_STRING(c)<<"="<<(c)<<endl

#define EXIST(e,s) ((s).find(e)!=(s).end())
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizeof(a))
#define pb push_back

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;
//{{{ io
struct IO{ }io;//dummy
#define endl "\n"
IO& operator>>(IO &io,int &n){scanf("%d",&n);return io;}
IO& operator>>(IO &io,unsigned int &n){scanf("%u",&n);return io;}
IO& operator>>(IO &io,long long &n){scanf("%lld",&n);return io;}
IO& operator>>(IO &io,unsigned long long &n){scanf("%llu",&n);return io;}
IO& operator>>(IO &io,double &n){scanf("%lf",&n);return io;}
IO& operator>>(IO &io,long double &n){scanf("%Lf",&n);return io;}
IO& operator>>(IO &io,char *c){scanf("%s",c);return io;}
IO& operator>>(IO &io,string &s){
    char c;s.clear();
    while(isspace(c=getc(stdin))){if(c==-1)return io;}
    do{
        s.push_back(c);
    }while(!isspace(c=getc(stdin)));
    if(c!=-1)ungetc(c,stdin);
    return io;
}
IO& operator<<(IO &io,const int &n){printf("%d",n);return io;}
IO& operator<<(IO &io,const unsigned int &n){printf("%u",n);return io;}
IO& operator<<(IO &io,const long long &n){printf("%lld",n);return io;}
IO& operator<<(IO &io,const unsigned long long &n){printf("%llu",n);return io;}
IO& operator<<(IO &io,const double &n){printf("%lf",n);return io;}
IO& operator<<(IO &io,const long double &n){printf("%Lf",n);return io;}
IO& operator<<(IO &io,const char c[]){printf("%s",c);return io;}
IO& operator<<(IO &io,const string &s){
    REP(i,s.size())putc(s[i],stdout);
}
//}}}
// }}}
string t[] = {"dream","dreamer","erase","eraser"};
string S;

int dp[100000];

int main(){
	memset(dp,0,sizeof(dp));
	dp[0] = 1;
	cin>>S;
	REP(i,S.size()){
		if(!dp[i])continue;
		REP(j,4){
			if(i+t[j].size()>S.size())continue;
			if(S.substr(i,t[j].size())==t[j])dp[i+t[j].size()]=1;
		}
	}
	cout<<(dp[S.size()]?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
    double l;
	cin >> l;
	double ans = (l / 3)*(l / 3)*(l / 3);
	printf("%.10lf", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>
 
using namespace std;
 
#define MAX 21
#define EPS 1e-9
#define INF 1e9

struct Point{
  double x, y;
  Point(double x = 0,double y = 0) : x(x), y(y) {}
}; 

int N;
Point h, d, crystal[MAX];
 
double dist(Point a, Point b){
  return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}

bool ok;

void rec(int S, int v, double total_dist){
  if(ok) return;

  if(S == (1 << N) - 1){
    ok = true;
    return;
  }
  for(int u = 0 ; u < N ; u++){
    if(!(S >> u & 1)){
      if(total_dist + dist(crystal[v],crystal[u]) >= dist(d, crystal[u])){
	return;
      }
    }
  }
  for(int u = 0 ; u < N ; u++){
    if(!(S >> u & 1) && !ok){
      rec(S | 1 << u, u, total_dist + dist(crystal[v],crystal[u]));
    }
  }
}

bool solve(){
  for(int i = 0 ; i < N ; i++){
    ok = false;
    rec(0, i, dist(h, crystal[i]));
    if(ok){
      return true;
    }
  }  

  return false;
}
 
int main(){
  while(cin >> N >> h.x >> h.y >> d.x >> d.y, (N + h.x + h.y + d.x + d.y)){
    for(int i = 0 ; i < N ; i++){
      cin >> crystal[i].x >> crystal[i].y;
    }
    cout << (solve() ? "YES" : "NO") << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1220
def solve():
    A,B,C,X,Y = map(int, input().split())
    ret = 0
    max_pizza = max(X,Y)
    min_pizza = min(X,Y)
    if A+B >= 2*C:
        ret += min_pizza*2*C
    else:
        ret += min_pizza*(A+B)
        
    max_price = B if X < Y else A
    if max_price <= 2*C:
        ret += (max_pizza - min_pizza)*max_price
    else:
        ret += 2*C*(max_pizza - min_pizza)
    
    print(ret)
    
solve()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h) {
        cin >> c[i];
    }
    int ans = 0;
    for (int bh = 0; bh < (1<<h); bh++)
    {
        for (int bw = 0; bw < (1<<w); bw++)
        {
            int cnt = 0;
            rep(i,h) {
                rep(j,w) {
                    // 塗らないマスが黒なら
                    if ( ((bh & (1<<i)) == 0) && ((bw & (1<<j)) == 0)) {
                        if (c[i][j] == '#') cnt++;
                    }
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>

using namespace std;

int N, A, B, C;
vector<int> l;

int minimum = 99999;

void calc(vector<int> v) {
    int a = 0, b = 0, c = 0, dupe = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == 0) {
            if (a != 0) dupe += 10;
            a += l[i];
        }
        if (v[i] == 1) {
            if (b != 0) dupe += 10;
            b += l[i];
        }
        if (v[i] == 2) {
            if (c != 0) dupe += 10;
            c += l[i];
        }
    }
    const int sum = abs(a - A) + abs(b - B) + abs(c - C) + dupe;
    if (a == 0 || b == 0 || c == 0) return;
    if (sum < minimum) {
        minimum = sum;
    }
    
    return;
}

void dfs(int cur, vector<int> v) {
    if (cur == N) {
        calc(v);
        return;
    }
    for (int i = 0; i < 4; i++) {
        v[cur] = i;
        dfs(cur + 1, v);
    }
    return;
}

int main() {
    cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        l.push_back(tmp);
    }
    dfs(0, vector<int>(N));

	cout << minimum << endl;

    return 0;
}

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

#define N_MAX 100
#define M_MAX 1000
#define INF 10000000
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

typedef unsigned long long ull;

int d[M_MAX];
int n, m;

int i, j, k;

int e[M_MAX][2];

void deb(){
	return;
}

void solve(){
	return;
}

int main (void) {
	char x;
	scanf("%c\n", &x);
	switch (x) {
	case 'a':
	case 'i':
	case 'u':
	case 'e':
	case 'o':
		puts("vowel");
		break;
	default:
		puts("consonant");
	}

	solve();
	return 0;
}




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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define en '\n'
#define fs first
#define sd second

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (auto& el : a) {
        cin >> el;
        --el;
    }
    vector<bool> u(n, false);
    ll s = 0;
    ll res = 0;
    while(!u[s] and k){
        --k;
        u[s] = true;
        s = a[s];
    }

    if(k == 0){
        res = s;
    }else{
        u.assign(n, false);
        ll r = 0;
        while(!u[s] and k){
            --k;
            ++r;
            u[s] = true;
            s = a[s];
        }
        if(k  == 0){
            res = s;
        }else{
            k %= r;
            while(k){
                --k;
                s = a[s];
            }
            res = s;
        }
    }
    cout << res+1 << en;
}

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

bool debug = false;

int main() {
  std::string s;
  int n;
  std::cin >> s >> n;
  if (debug) std::cout << s << std::endl;

  std::string cmd, p;
  int a, b;
  for (int i = 0; i < n; i++) {
    std::cin >> cmd >> a >> b;
    if (debug) std::cout << cmd << " " << a << ',' << b << ": ";
    if (cmd == "print") {
      std::cout << s.substr(a, b-a+1) << std::endl;
    } else if (cmd == "reverse") {
      std::string t;
      t = s.substr(0, a);
      for (int i = b; i >= a; i--)
        t.push_back(s[i]);
      t += s.substr(b + 1, s.size());
      s = t;
      if (debug) std::cout << s << std::endl;
    } else if (cmd == "replace") {
      std::cin >> p;
      s.replace(a, b-a+1, p);
      if (debug) std::cout << s << std::endl;
    }
  }
}



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

#ifdef moskupols
    #define debug(...) fprintf(stderr, __VA_ARGS__)
    #define cdebug(...) cerr << __VA_ARGS__
#else
    #define debug(...) do {} while (false)
    #define cdebug(...) do {} while (false)
#endif

#define timestamp(x) debug("["#x"]: %.3f\n", (double)clock() / CLOCKS_PER_SEC)

#define hot(x) (x)
#define sweet(value) (value)
#define faceless

#define WHOLE(v) (v).begin(),(v).end()
#define RWHOLE(v) (v).rbegin(),(v).rend()
#define UNIQUE(v) (v).erase(unique(WHOLE(v)),(v).end())

typedef long long i64;
typedef unsigned long long ui64;
typedef long double TReal;

using namespace std;

class TSolver {
public:
    int n;
    vector<int> a;

    explicit TSolver(std::istream& in) {
        in >> n;
        a.resize(n);
        for (int i = 0; i < n; ++i) {
            in >> a[i];
        }
    }

    void Solve() {
    }

    void PrintAnswer(std::ostream& out) {
        auto it = max_element(WHOLE(a));
        auto fst = *it;
        iter_swap(a.begin(), it);
        int sec = *min_element(a.begin() + 1, a.end(), [&](int a, int b) { return max(a, fst - a) < max(b, fst - b); });
        out << fst << ' ' << sec << '\n';
    }
};

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

    {
        auto solver = std::make_shared<TSolver>(std::cin);
        solver->Solve();
        solver->PrintAnswer(std::cout);
    }

    timestamp(end);
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b>>c;
	if((10*b+c)%4==0){cout<<"YES";}
	else{cout<<"NO";}




	cout<<endl;
} 


Measured memory_bytes: 256
def main():
    def factorization(n):
        arr = []
        tmp = n
        for i in range(2, int(-(-tmp**0.5//1))):
            if tmp%i == 0:
                cnt = 0
                while tmp%i == 0:
                    cnt += 1
                    tmp //= i
                arr.append([i, cnt])
        if tmp != 1:
            arr.append([tmp, 1])
        if tmp == []:
            arr.append([n, 1])
        return arr
    n = int(input())
    fn = factorization(n)
    x = [fn[i][1] for i in range(len(fn))]
    b = 1
    res = 0
    for i in x:
        while b <= i:
            i -= b
            b += 1
            res += 1
        b = 1
    print(res)   

if __name__ == '__main__':
    main()

Measured memory_bytes: 9420
fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt()}
    val A = readLine()!!.split(" ").map { it.toLong() }.sorted().toLongArray()
    val BC = Array(M){ readLine()!!.split(" ").map { it.toLong() }}.sortedBy { -it[1] }

    var sum = 0.toLong()
    var cursor = 0
    BC.forEach {
        if(cursor<N) {
            for (i in 0 until it[0].toInt()) {
                if (cursor+i>=N) break
                sum += Math.max(A[cursor+i], it[1])
            }
            cursor+=it[0].toInt()
        }
        
    }
    for (i in cursor until N){
        sum+=A[i]
    }
    println(sum)


}

Measured memory_bytes: 105996
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int A, B;
    cin >> A >> B;

    if (B % A == 0) {
        cout << A + B << endl;
    } else {
        cout << B - A << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }

int N;
int A[200010];

map<int, int> _map;

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];

	for (int i = 0; i < N; i++)
	{
		_map[A[i] + (i + 1)]++;
	}

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += _map[(i + 1) - A[i]];
	}

	cout << ans << endl;
}




Measured memory_bytes: 27668
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;
int main()
{

	ll a, b = 0, c = 0, d = 0;
	ll l;
	char C[1000][1000] = {};
	long double x[1001] = {}, y[1001] = {}, xhensa[1001] = {}, yhensa[1001] = {}, xave, yave, xkyobun[1001] = {}, ykyobun[1001] = {}, xykyobun[1001] = {}, xkyo = 0, ykyo = 0, xykyo = 0;
	string s, t;
	ll n, h[100001], w[100001];
	string z[101];
	cin >> a;
	cin >> t;

	for (int i = 0; i < a-1; i++)
	{
		cin >> s;
		if (t[t.length() - 1] == s[0])
		{
			c = 0;
			for (int j = 0; j < b; j++)
			{
				if (z[j]==s)
				{
					cout << "No" << endl;
					return 0;
				}
				/*for (int k = 0; k < s.length(); k++)
				{
					if (z[j][k] != s[k])
					{
						break;
					}
					if (k == s.length() - 1)
					{
						cout << "No" << endl;
						return 0;

					}

				}*/
			}
		}
		else
		{
			cout << "No" << endl;
			return 0;
		}
		b++;
		//strcpy(t, s);
		z[i] = t;
		t = s;
	}
	cout << "Yes" << endl;


	//cout << sum << endl;
	//cout <<  endl;

	return 0;
}

//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};



void solve(){
    string s;
    cin>>s;
    if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> c(n), s(n), f(n);
  REP(i,n-1){
    cin >> c[i] >> s[i] >> f[i];
  }
  REP(i,n){
    int t=0;
    FOR(j,i,n-1){
      if(t<s[j]) t = s[j];
      else if(t%f[j]==0) ;
      else t = t+f[j]-(t%f[j]);
      t += c[j];
    }
    cout << t << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>

using namespace std;

class town
{
	public:
	char nowtown;
	int Ttown,Ftown;
	
	void intown(char n,int t,int f)
	{
		nowtown = n;
		Ttown = t;
		Ftown = f;
	};
};
//A-0,X-1,Y-2,Z-3,W-4,B-5
int main()
{
	char in[101];
	int now,i;
	town P[6];
	P[0].intown('A',2,1);
	P[1].intown('X',3,-1);
	P[2].intown('Y',-1,1);
	P[3].intown('Z',5,4);
	P[4].intown('W',2,5);
	P[5].intown('B',1,2);
	
	while(scanf("%s",in) && in[0] != '#'){
		now = 0;
		for(i = 0;in[i] != '\0'; i++){
			if(in[i] == '0'){
				now = P[now].Ftown;
			}
			else{
				now = P[now].Ttown;
			}
			if(now < 0){
				break;
			}
		}
		if(now == 5)
			printf("Yes\n");
		else
			printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 1108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long N, long long x, std::vector<long long> a)
{
    vector<ll> b(N);
    copy(a.begin(), a.end(), b.begin());
    ll cost1 = 0, cost2 = 0;
    if (x < a[0])
    {
        cost1 += a[0] - x;
        a[0] = x;
    }
    for (int i = 1; i < N; i++)
    {

        ll one = a[i - 1];
        ll two = a[i];

        if (one + two <= x)
        {
            continue;
        }
        else
        {
            cost1 += (one + two - x);
            a[i] = x - one;
        }
    }
    cout << cost1 << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long x;
    scanf("%lld", &x);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &a[i]);
    }
    solve(N, x, std::move(a));
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <array>
#include <algorithm>

int main()
{
    std::array<std::string, 3> weather = {"Sunny", "Cloudy", "Rainy"};

    std::string buf;
    std::cin >> buf;
    std::size_t idx = ((std::find(weather.begin(), weather.end(), buf) - weather.begin()) + 1) % 3;
    std::cout << weather[idx] << std::endl;

    return 0;
}

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

int main () {
  int A, B;
  cin >> A >> B;
  
  if (A==B) {
    cout << "Draw" << endl;
  }
  else if (A==1) {
    cout << "Alice" << endl;
  }
  else if (B==1) {
    cout << "Bob" << endl;
  }
  else if (A>=B) {
    cout << "Alice" << endl;
  }
  else if (A<=B) {
    cout << "Bob" << endl;
  }
}

Measured memory_bytes: 256