akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  int N;
  cin >> N;
  ll a[100];
  for (auto i = 0; i < N; ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  bool ok = false;
  while (!ok) {
    ok = true;
    for (auto i = 0; i < N; ++i) {
      if (a[i] <= N-1) {
        continue;
      } else {
        ok = false;
        break;
      }
    }
    if (!ok) {
      ll S = 0;
      for (auto i = 0; i < N; ++i) {
        S += a[i]/N;
      }
      for (auto i = 0; i < N; ++i) {
        a[i] = a[i] - N * (a[i]/N) + S - a[i]/N;
      }
      ans += S;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int cal(string s, char key){
  int i = 0;
  bool ok = true;
  while(true){
    // cout << s << endl;
    int m = s.size();
    ok = true;
    REP(i,m){
      if(s[i] != key){
	ok = false;
	break;
      }
    }
    if(ok)break;
    ////////////////
    string t = s.substr(0,m - 1);
    for(int j = 1; j < m - 1; j ++){
      if(t[j] == key) t[j - 1] = key;
    }
    s = t;
    i ++;
  }
  return i;
}
int main()
{
  string s; cin >> s;
  int n = s.size();
  int ans = 100;
  set<char> mp;
  REP(i,n){
    mp.insert(s[i]);
  }
  REPvec(itr, mp){
    // cout << *itr << endl;
    ans = min(ans, cal(s,*itr));
  }
  // REP(i,n){
  //   
  // }
  cout << ans << endl;
}


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

using i64 = int64_t;

struct Event{
    int event, tm, x;
    bool operator<(const Event &rhs)const{
        if(tm == rhs.tm)return event < rhs.event;
        return tm < rhs.tm;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    vector<Event> v;
    for(int i=0;i<n;++i){
        int s, t, x;
        cin >> s >> t >> x;
        v.push_back({1, s-x, x});
        v.push_back({-1, t-x, x});
    }

    sort(v.begin(), v.end());
    set<int> st;
    int idx = 0;
    for(int i=0;i<q;++i){
        int d;
        cin >> d;
        while(idx < (int)v.size() && d >= v[idx].tm){
            if(v[idx].event == 1){
                st.insert(v[idx].x);
            }else{
                st.erase(v[idx].x);
            }
            idx++;
        }
        if(st.empty())cout << -1;
        else cout << *(st.begin());
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 16236
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
#include <functional>																							   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;	
const int mod = 1e9+7;																							   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra																													   																				   list<int>::iterator it;																								   
																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS//////////////////////////////////////////////////////




///////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	string s;
	cin >> s;
	
	vector<int> cnt(2, 0);
	for(int i = 0; i < s.size(); i++){
		cnt[s[i] - '0']++;
	}
	
	int ans = min(cnt[0], cnt[1]) * 2;
	cout << ans << endl;
	
						
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
long int max(long int a, long int b){
	return a>b?a:b;
}
int main(){
	long int n, w, w_ar[100], v_ar[100], i, j, dp[101][100001] = {0};
	scanf("%ld%ld", &n, &w);
	for(i=0;i<n;i++){
		scanf("%ld%ld", &w_ar[i], &v_ar[i]);
	}

	for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			if(i==0||j==0)
				dp[i][j] = 0;
			else if(j>=w_ar[i-1])
				dp[i][j] = max(v_ar[i-1]+dp[i-1][j-w_ar[i-1]], dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	printf("%ld", dp[n][w]);
	return 0;
}

Measured memory_bytes: 80612
#!/usr/bin/env python3
import sys

MOD = 998244353  # type: int

def comb(n, k):
    if k > n:
        return 0
    k = min(k, n - k)
    ret = 1
    for i in range(k):
        ret *= n - i
        ret //= i + 1
    return ret

def solve(S: str):
    n = len(S)
    b_total = 0
    b_counts = []
    for c in S:
        b_total += ord(c) - ord('0')
        b_counts.append(b_total)
    dp = [[0] * (b_total + 1) for _ in range(2 * n + 1)]
    dp[0][0] = 1
    for i in range(n):
        for j in range(min(i + 1, b_total + 1)):
            if b_counts[i] >= j + 1:
                dp[i + 1][j + 1] += dp[i][j]
            if (i + 1) * 2 - b_counts[i] >= (i + 1) - j:
                dp[i + 1][j] += dp[i][j]
    #    print(dp[i])
    #print(dp[n])
    comb = [0] * (n + 1)
    comb[0] = 1
    for i in range(n):
        comb[i + 1] = comb[i] * (n - i) // (i + 1)
    ret = 0
    for b, val in enumerate(dp[n]):
        #ret += val * comb(n, b_total - b)
        if b_total - b >= 0 and b_total - b <= n:
            ret += val * comb[b_total - b]
    print(ret % MOD)
    return

    ##dp[0][0] = 1
    ##for i in range(2 * n):
    ##    for j in range(min(i + 1, b_total + 1)):
    ##        b_max = b_counts[i] if i < n else b_total
    ##        r_max = (i + 1) * 2 - b_max if i < n else 2 * n - b_total
    ##        if b_max >= j + 1:
    ##            dp[i + 1][j + 1] += dp[i][j]
    ##        if r_max >= (i + 1) - j:
    ##            dp[i + 1][j] += dp[i][j]
    ##ret = sum(dp[2 * n])
    ##print(ret % MOD)
    ##return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = str(next(tokens))
    solve(S)

if __name__ == '__main__':
    main()


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int d,n;
    Scd2(d,n);

    int k = 1;
    Rep(i,d){
        k *= 100;
    }

    if( n == 100 ){
        n = 101;
    }

    printf ("%d\n", k * n);

    return 0;
}



Measured memory_bytes: 256
import sys
input=sys.stdin.readline
def main():
    r,c,k=map(int,input().split())
    v=[0] * (c * r)
    for _ in range(k):
        ri,ci,a=map(int,input().split())
        v[(ri-1)*c + (ci-1)]=a
    dp= [0] * (c * r * 4)
    #print(dp)
    x = c * r
    if v[0]>0: dp[x] = v[0]

    for i in range(r):
        for j in range(c):
            idx = i*c+j
            idx2 = (i-1)*c + j
            idx3 = i*c + j-1
            if i>0:
                dp[x + idx] = max(dp[x + idx], dp[idx2]+v[idx])
                dp[idx] = max(dp[idx],dp[idx2])
                dp[x + idx]=max(dp[x + idx],dp[x + idx2]+v[idx])
                dp[idx]=max(dp[idx],dp[x + idx2])
                dp[x + idx]=max(dp[x + idx],dp[2*x + idx2]+v[idx])
                dp[idx]=max(dp[idx],dp[2*x + idx2])
                dp[x + idx]=max(dp[x + idx],dp[3*x + idx2]+v[idx])
                dp[idx]=max(dp[idx],dp[3*x + idx2])
            if j>0:
                dp[x + idx]=max(dp[x + idx],dp[idx3]+v[idx])
                dp[2*x + idx]=max(dp[2*x + idx],dp[x + idx3]+v[idx])
                dp[3*x + idx]=max(dp[3*x + idx],dp[2*x + idx3]+v[idx])
                dp[idx]=max(dp[idx],dp[idx3])
                dp[x + idx]=max(dp[x + idx],dp[x + idx3])
                dp[2*x + idx]=max(dp[2*x + idx],dp[2*x + idx3])
                dp[3*x + idx]=max(dp[3*x + idx],dp[3*x + idx3])

    #print(dp)
    ans=0
    for i in range(4): ans=max(dp[i*x + (r-1)*c + (c-1)],ans)
    return print(ans)

if __name__=="__main__":
    main()



Measured memory_bytes: 427044
#include<stdio.h>
int main(){
	int i,n,c[5][14],m,j;
	char d;
	scanf("%d",&n);
	for(i=1;i<5;i++){
		for(j=1;j<14;j++){
			c[i][j]=0;
		}
	}
	for(i=0;i<n;i++){
		scanf(" %c %d",&d,&m);
		if(d=='S'){
			c[1][m]=m;
		}else if(d=='H'){
			c[2][m]=m;
		}else if(d=='C'){
			c[3][m]=m;
		}else if(d=='D'){
			c[4][m]=m;
		}	
	}
	for(i=1;i<5;i++){
		for(j=1;j<14;j++){
			if(i==1 && c[i][j]==0){
				printf("S %d\n",j);
			}else if(i==2 && c[i][j]==0){
				printf("H %d\n",j);
			}else if(i==3 && c[i][j]==0){
				printf("C %d\n",j);
			}else if(i==4 && c[i][j]==0){
				printf("D %d\n",j);
			}
		}
	}
}


Measured memory_bytes: 2704
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX = 111;
int N;
vector<int> b;
vector<int> ans;

int main(void) {
    cin >> N;
    b.resize(N);
    REP(i, N) cin >> b[i];

    REP(cnt, N) {
        VI cand;
        REP(i, b.size()) {
            if (i + 1 == b[i] && i <= N - cnt - 1) {
                cand.EB(i);
            }
        }
        if (cand.empty()) {
            cout << -1 << endl;
            return 0;
        }
        ans.EB(cand.back());
        b.erase(begin(b) + cand.back());
    }
    RREP(i, ans.size()) cout << ans[i] + 1 << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	static long N,M;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
			 N = sc.nextInt();
			 M= sc.nextInt();
		  sc.close();

		  long ans = 0 ;
		  ans = Math.abs((N-2)*(M-2));

		  System.out.println(ans);
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
    int x, a;
    cin >> x >> a;
    if (x < a)
        printf("0\n");
    else
        printf("10\n");
}

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;

signed main(){
    
    
    int n,m;
    cin >> n >> m;

    if(m == 1){
        cout << 1 << endl;
        return 0;
    }

    vector<pair<int,int>> x;
    int M =m;
    for(int i = 2; i*i <= M ;i++){
        if(M%i == 0){
            x.pb(MP(i,0));
            while(M%i == 0){
                x[x.size()-1].se ++;
                M /= i;
            }
        }
    }
    if(M != 1){
        x.pb(MP(M,1));
    }

    set<int> s;
    for(int i = 0;i < x.size(); i++){
        if(i == 0){
            s.insert(1);
            int q = x[i].fi;
            REP(j,x[i].se){
                s.insert(q);
                q *= x[i].fi;
            }
        }else{
            set<int> cop(s);
            int q = x[i].fi ;

            REP(j,x[i].se){
                for(auto l:cop){
                    if(q*l <= m) s.insert(q*l);
                }
                q *= x[i].fi;
            }
        }
    }

    // for(auto i:s) cerr << i << " ";
    // cerr << endl << endl;;
    // for(auto i:x) cerr << i.fi << " " << i.se << " " <<endl;


    for(auto i:s){
        if(m % i == 0 && i >= n){
            cout << m/i << endl;
            return 0;
        }
    }

    return 0;
}
//g++ -std=c++14 code1.cpp


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            int N = sc.nextInt();
            if (N == 0) break;
            String[] codes = new String[N];
            for (int i = 0; i < N; i++) {
                codes[i] = code(sc.next());
            }
            int ans= -1;
            for (int i = 1; i <= 50 ; i++) {
                HashSet<String> set = new HashSet<>();
                for (int j = 0; j < N; j++) {
                    set.add(codes[j].substring(0, Math.min(i, codes[j].length())));
                }
                if (set.size() == N) {
                    ans = i;
                    break;
                }
            }
            System.out.println(ans);
        }

    }

    static String code(String name) {
        String ret = "" + name.charAt(0);
        for (int i = 1; i < name.length(); i++) {
            if ("aiueo".indexOf(name.charAt(i - 1)) >= 0) ret += name.charAt(i);
        }
        return ret;
    }


}

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

int main()
{
  string s;
  cin >> s;
  
  int n = s.size();
  for(int i = 0; i < n; i++){
    if( (i % 2 == 1) && (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') ){
      cout << "No" << endl;
      return 0;
    }else if( (i % 2 == 0) && (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') ){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl; 
      
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#define print(n) std::cout << n << std::endl
#define print_no_indention(n) std::cout << n
using namespace std;


int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if((b - a) == (c - b))print("YES");
    else print("NO");
}

Measured memory_bytes: 256
# 入力の取得(1行目。数値)
i = list(map(int, input().split()))

# 変数セット
# 1.配列[値=初期の点数-★正解数(解説より)★、個数=人数]
points = [i[1]- i[2]] * (i[0] )
# 2.正解数(引数の数)
correntCount = i[2]

# 正解数ループ
for i in range(correntCount):
    correcter = int(input()) - 1    
    #正解者に1加算
    points[correcter] += 1

# 値が0以下の参加者は敗退(No)、1以上なら勝ち抜け(Yes)
for point in points:
    if point <= 0:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 6700
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int X[20][20];
int main(void) {
    int N,D;
    cin>>N>>D;

    for(int i = 1;i <= N;i++) {
        for(int j = 1;j <= D;j++) {
            cin>>X[i][j];
        }
    }

    int ans = 0;
    for(int i = 1;i <= N;i++) {
        for(int j = i+1;j <= N;j++) {
            int dist = 0;
            for(int d = 1;d <= D;d++) {
                dist += (X[i][d] - X[j][d])*(X[i][d] - X[j][d]);
            }
            for(int k = 1;k*k<=dist;k++)
                if(k*k == dist)
                    ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}


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

int main(){
	int a,b,c;cin>>a>>b>>c;
	if((a==b&&b!=c)||(a==c&&c!=b)||(b==c&&a!=b)){
		cout<<"Yes"<<endl;
	} else{
		cout<<"No"<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    int count=0;
    cin>>n;
    vector<char> a(n);
    vector<char> b(n);
    vector<char> c(n);
    for (int i=0;i<n;i++){
        cin>>a.at(i);
    }
    for (int i=0;i<n;i++){
        cin>>b.at(i);
    }
    for (int i=0;i<n;i++){
        cin>>c.at(i);
    }
    for (int i=0;i<n;i++){
        if (a.at(i)==b.at(i)){
            if (a.at(i)!=c.at(i))
            count+=1;
        }
        else{
            if(c.at(i)==a.at(i) || c.at(i)==b.at(i)){
                count+=1;
            }
            else{
                count+=2;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int x ;
	cin >> x ; 
	int mx = 0 ;
	auto chk = [&](int X){
		if (X < 2 or (X > 2 and ~X & 1)) return false;
		for(int i = 3 ; i*i<=X ; i+=2){
			if(X%i==0) return false;
		}
		return true;
	};
	for(int i = x ; ;++i){
		if(chk(i)){
			cout << i << endl ;
			return ;
		}
	}
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


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

using namespace std;
#define int long long
const int N = 2e3 + 3;
int dp[N][N], p[N], A[N];

bool cmp(int i, int j) {return A[i] > A[j];}
int32_t main() {
    int n, ans = 0; cin >> n;
    for (int i = 1; i <= n; i++) cin >> A[i], p[i] = i;
    sort(p + 1, p + n + 1, cmp);
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j + i <= n; j++) {
            if (i) dp[i][j] = max(dp[i][j], dp[i - 1][j] + A[p[i + j]] * abs(p[i + j] - i));
            if (j) dp[i][j] = max(dp[i][j], dp[i][j - 1] + A[p[i + j]] * abs(p[i + j] - (n - j + 1)));
            if (i + j == n) ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 26312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, a, b, max;
		
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.valueOf(string);
			max = 0;
			int Caliburne[] = new int[]{0, 1 << 29};
			int cost[][] = new int[10][10];
			for(int i = 0; i < 10; i++){ Arrays.fill(cost[i], 1 << 29); }
			for(int i = 0; i < n; i++){
				String str[] = reader.readLine().split(" ");
				a = Integer.valueOf(str[0]);
				b = Integer.valueOf(str[1]);
				max = Math.max(max, Math.max(a, b));
				cost[a][b] = cost[b][a] = Integer.valueOf(str[2]);
			}
			for(int k = 0; k < 10; k++){
				for(int i = 0; i < 10; i++){
					for(int j = 0; j < 10; j++){
						cost[i][j] = Math.min(cost[i][j], cost[i][k] + cost[k][j]);
					}
				}
			}
			for(int i = 0; i <= max; i++){ cost[i][i] = 0; }
			int res[] = new int[max + 1];
			for(int i = 0; i <= max; i++){
				for(int j = 0; j <= max; j++){
					res[i] += cost[i][j];
				}
				if(res[i] < Caliburne[1]){
					Caliburne[1] = res[i];
					Caliburne[0] = i;
				}
			}
			System.out.println(Caliburne[0] + " " + Caliburne[1]);
		}
		reader.close();
	}
}

Measured memory_bytes: 24284
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	scanf("%d", &n);

	ll a[10000];
	int max = 1e9;
	int cnt2 = 0;
	REP(i, n) {
		scanf("%lld", &a[i]);
		ll tmp = a[i];
		while (tmp % 2 == 0) {
			tmp /= 2;
			cnt2++;
		}
		/*
		int cnt = 0;
		while (tmp * 3 < 1e9) {
			tmp *= 3;
			cnt++;
		}
		max = Max(max, cnt);
		*/
	}
	PRINTD(Min(max, cnt2));
}

Measured memory_bytes: 256
W, H = map(int, input().split())
D = []
for i in range(W):
    D.append((int(input()), 0))

for i in range(H):
    D.append((int(input()), 1))

D = sorted(D)
A, B = H + 1, W + 1
ans = 0
for i, k in D:
    if k == 0:
        ans += i * A
        B -= 1
    else:
        ans += i * B
        A -= 1

print(ans)

Measured memory_bytes: 70744
"use strict";

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  var input0 = input[0].split(" ");
  var N = parseInt(input0[0]);
  var T = parseInt(input0[1]);
  var t = input[1].split(" ");
  for (var i=0; i<N; i++) {
    t[i] = parseInt(t[i]);
  }
  
  var count = 0;
  var t_i;
  for (var i=1; i<N; i++) {
    t_i = t[i]-t[i-1];
    if (t_i<T) {
      count += t_i;
    } else {
      count += T;
    }
  }
  
  console.log (count+T);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

#define INF 2<<29
#define F first
#define S second

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

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



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<bits/stdc++.h>
#define ll long long 
#define jaldi_chal  ios_base::sync_with_stdio(0); cin.tie(0);
#define tr(c,i) for(auto i=(c).begin(); i != (c).end(); i++)
#define REP(i,k) for( ll i=0;i<k;i++)
#define REW(i,a,b) for(ll i=a;i<=b;i++)
#define M 1000000007
#define F first
#define dbg(x)  cout<<#x<<" " <<x<<endl;
#define S second
#define inf 1e10
#define endl "\n"


int main() {
jaldi_chal
ll n;
cin>>n;
ll sum=0;
for(ll i=1;i<=n;i++)
{
	if(i%3==0||i%5==0) continue;
	sum+=i;
}
cout<<sum<<endl;


	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
// string S;
// bool dfs(string M){
//     if(M.size()>=S.size()){
//         if(M==S)return true;
//         else return false;
//     }
//     if(dfs(M+"dream")) return true;
//     if(dfs(M+"dreamer")) return true;
//     if(dfs(M+"erase")) return true;
//     if(dfs(M+"eraser")) return true;
//     return false;
// }
// int main(){
//     cin>>S;
//     cout<<(dfs("")?"YES":"NO")<<endl;
// }
int main(){
    string S;
    cin>>S;
    reverse(S.begin(),S.end());
    for(;;){
        if(S.size()>=5){
            if(S.substr(0,5)=="maerd"||S.substr(0,5)=="esare"){
                S.erase(0,5);
                continue;
            }
            if(S.size()>=6){
                if(S.substr(0,6)=="resare"){
                    S.erase(0,6);
                    continue;
                }
                if(S.size()>=7){
                    if(S.substr(0,7)=="remaerd"){
                        S.erase(0,7);
                        continue;
                    }   
                }
            }
        }
        if(S.size()==0)cout<<"YES"<<endl;   
        else cout<<"NO"<<endl;
        break;
    }
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int n = sc.nextInt();
		
		System.out.println((n == 100? 101 : n)*(int)Math.pow(100, d));
	}
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto A = RDR.ARR;
	long ans = long.max;
	foreach (i; 0..N)
	{
		auto x = A[i];
		long cnt;
		while (x % 2 == 0)
		{
			x /= 2;
			++cnt;
		}
		ans = min(ans, cnt);
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  rep(i, S.length()) {
    if (S[i]+N > 'Z') {
      S[i] = S[i] + N - 26;
    } else {
      S[i] = S[i] + N;
    }
  }
  
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	string s;
	cin >> s;
	cout << s[0] << s.length() - 2 << s[s.length() - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

int v[100001],rmq[100001][18],lg[100001];

int gcd(int a,int b)
{
    while(b)
    {
        int r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main()
{
    int n,i,j,maxgcd;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
        scanf("%d",&v[i]);
    for(i=2; i<=n; i++)
        lg[i]=lg[i/2]+1;
    for(i=1; i<=n; i++)
        rmq[i][0]=v[i];
    for(j=1; j<=lg[n]; j++)
        for(i=(1<<j); i<=n; i++)
            rmq[i][j]=gcd(rmq[i][j-1],rmq[i-(1<<(j-1))][j-1]);
    maxgcd=0;
    for(i=1; i<=n; i++)
    {
        if(i==1)
            maxgcd=max(maxgcd,gcd(rmq[n][lg[n-1]],rmq[1+(1<<lg[n-1])][lg[n-1]]));
        if(i==n)
            maxgcd=max(maxgcd,gcd(rmq[n-1][lg[n-1]],rmq[1<<lg[n-1]][lg[n-1]]));
        if(i>1 && i<n)
        {
            int G=gcd(gcd(rmq[n][lg[n-i]],rmq[i+(1<<lg[n-i])][lg[n-i]]),gcd(rmq[i-1][lg[i-1]],rmq[1<<lg[i-1]][lg[i-1]]));
            maxgcd=max(maxgcd,G);
        }
    }
    printf("%d",maxgcd);

    return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>
#define MAX 2000000
int n,d[MAX+1];
void change(int I,int L){
    int temp;
    temp=d[I];
    d[I]=d[L];
    d[L]=temp;
}
void maxHeapify(int j){
  int l,r,largest;
  l = 2 * j;
  r = 2 * j +1;
  largest = (l<=n && d[l] > d[j]) ? l: j;
  if(r<=n && d[r] > d[largest]) largest = r;
  if(largest != j){
    change(j,largest);
    maxHeapify(largest);
  }
}
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&d[i]);
  for(i=n/2;i>=1;i--) maxHeapify(i);
  for(i=1;i<=n;i++) printf(" %d",d[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3644
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] heights = new int[n];
    int[] dp = new int[n];
    for(int i = 0; i < n; i++){
      heights[i] = sc.nextInt();
      dp[i] = 2000000001;
    } 
    dp[0] = 0;

    for(int i = 0; i < n; i++){
      for(int j = 1; j <= k && i + j < n; j++){
        if(dp[i+j] > dp[i] + Math.abs(heights[i] - heights[i+j])){
          dp[i+j] = dp[i] + Math.abs(heights[i] - heights[i+j]);
        }
      }
    }

    System.out.println(dp[n-1]);
 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 22356
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int n,lc,d[31][31],c[501][501],cost[31][3];
  cin >> n >> lc;
  REP1(i,lc){
    REP1(j,lc){
      cin >> d[i][j];
    }
  }
  REP1(i,n){
    REP1(j,n){
      cin >> c[i][j];
    }
  }
  REP1(i,lc){
    REP(j,3){
      cost[i][j]=0;
    }
  }
  REP1(i,lc){
    REP1(j,n){
      REP1(k,n){
        cost[i][(k+j)%3]+=d[c[j][k]][i];
      }
    }
  }
  int r = INTMAX;
  REP1(i,lc){
    REP1(j,lc){
      if(i!=j){
        REP1(k,lc){
          if(i!=k&&j!=k){
            int nr = cost[i][0]+cost[j][1]+cost[k][2];
            if (nr<r) r = nr;
          }
        }
      }
    }
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int N=1234;
struct EdgeNode{
	int to,next;
}Edges[N];
int bj[N];
int head[N];
int ans;
int col;
void add(int u,int v){
	Edges[++col].to=v;
	Edges[col].next=head[u];
	head[u]=col;
}
void dfs(int k,int n,int c){
	if(c==n){
		ans++;
		return;
	}
	for(int i=head[k];i;i=Edges[i].next){
		if(!bj[Edges[i].to]){
			bj[Edges[i].to]=1;
			dfs(Edges[i].to,n,c+1);
			bj[Edges[i].to]=0;
		}
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int u,v;
	col=0;
	for(int i=0;i<m;i++){
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	memset(bj,0,sizeof(bj));
	ans=0;
	bj[1]=1;
	dfs(1,n,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
ways = [list(map(int, input().split())) for i in range(M)]
observatoryList = [1] * N
for i in range(M):
  if H[ways[i][0] - 1] <= H[ways[i][1] - 1]:
    observatoryList[ways[i][0] - 1] = 0
  if H[ways[i][0] - 1] >= H[ways[i][1] - 1]:
    observatoryList[ways[i][1] - 1] = 0
goodObservatoryCount = observatoryList.count(1)
print(goodObservatoryCount)

Measured memory_bytes: 32000
import sys
def input(): return sys.stdin.readline().rstrip()
H, W = map(int, input().split())
a = [list(input()) for i in range(H)]
dp = [[0]*(W+1) for i in range(H+1)]
dp[0][1] = 1
mod = 10**9 + 7
for i in range(1, H+1):
    for j in range(1, W+1):
        if a[i-1][j-1] == ".":
            dp[i][j] += dp[i-1][j] + dp[i][j-1]
            dp[i][j] %= mod
            
ans =dp[H][W]
print(ans)

Measured memory_bytes: 56292
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Char

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [d,g] <- getIntList
    pc <- fmap (zip [1..]) $ replicateM d $ do
        [p,c] <- getIntList
        return (p,c)
    let tfs = sequence $ replicate d [True,False]
    let solve tf = ans
            where solve' tf = foldl' (\(a,b) (a',b') -> (a+a',b+b')) (0,0) $ zipWith f pc tf
                      where f (i,(p,c)) True = (p, i*100*p + c)
                            f _ False = (0,0)
                  (probs,score) = solve' tf
                  m = g - score
                  ans | m <= 0 = (probs,score)
                      | otherwise = (probs+p',score+s')
                              where (i',(pi',_)) = fst . last . filter (not . snd) $ zip pc tf
                                    p' = min pi' $ (m - 1) `div` (i' * 100) + 1
                                    s' = i' * 100 * p'
    let anss = map solve tfs
    print . minimum . map fst $ filter ((g<=) . snd) anss

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

int main()
{
    int D;

    cin >> D;

    switch( D ){
        case 25:
            cout << "Christmas" << endl;
            break;
        case 24:
            cout << "Christmas Eve" << endl;
            break;
        case 23:
            cout << "Christmas Eve Eve" << endl;
            break;
        case 22:
            cout << "Christmas Eve Eve Eve" << endl;
            break;
    }
}


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

int main()
{
	int n;
	scanf("%d",&n);
	char str[102];
	scanf("%s",&str);
	int len=strlen(str);
	if(len>n)
	{
		str[n]='.';
		str[n+1]='.';
		str[n+2]='.';
		str[n+3]='\0';
	}
	printf("%s",str);
	return 0;
}

Measured memory_bytes: 1704
import sys
readline = sys.stdin.readline
N, K = map(int, readline().split())
a = [int(readline())-1 for _ in [0]*N]
result = a.count(-1)

nodes = set()
node_add = nodes.add
hoge = set()
hoge_add = hoge.add
for i in range(N):
    if a[i] in hoge:
        node_add(a[i])
    hoge_add(a[i])

visited = set()
add = visited.add
startnode = {v: K-1 for v in {i for i in range(N) if a[i] > -1} - set(a)}
while startnode:
    nextnode = dict()
    for v, l in startnode.items():
        #print("start:", v, "length:", l)
        result += (v not in visited)
        add(v)
        v = a[v]
        while a[v] > -1 and v not in nodes and l > 0:
            #print(v)
            if v not in visited:
                result += 1
                add(v)
            l -= 1
            v = a[v]
        if a[v] > -1 and v in nodes and l > 0:
            #print("->", v)
            nextnode[v] = max(nextnode.get(v, 0), l-1)
    startnode = nextnode

print(result)

Measured memory_bytes: 29612
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

struct TStorage {
  int numZeroes = 0;
  int numOnes = 0;
  ll value = 0;

  void Add(char c) {
    if (c != 'M' && c != 'C') return;
    if (c == 'M') {
      numZeroes++;
    } else {
      numOnes++;
      value += numZeroes;
    }
  }
  void Remove(char c) {
    if (c != 'M' && c != 'C') return;
    if (c == 'M') {
      numZeroes--;
      value -= numOnes;
    } else {
      numOnes--;
    }
  }

  ll GetValue() {
    return value;
  }
};

ll Solve(const string& s, int k) {
  ll result = 0;
  TStorage storage;
  for (int i = 0; i < k; ++i) storage.Add(s[i]);
  int l = 0;
  int r = k - 1;
  while (l < s.size()) {
    if (s[l] == 'D') {
      result += storage.GetValue();
    }

    storage.Remove(s[l]);
    l++;
    r++;
    if (r < s.size()) storage.Add(s[r]);
  }
  return result;
};

int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    cout << Solve(s, k) << endl;
  }
  return 0;
}


Measured memory_bytes: 1412
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int,greater<int>>大到小
#include <vector>// ::iterator it;
#include <stack>
#include <cmath> // auto &Name : STLname  Name.
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
#define mod9 998244353
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+8;
inline ll read(){ll s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
using namespace std;

int t,n,m,k,ans=0,cnt=0,sum=0;
char c;
int main(){
    scanf("%d %c %d",&t,&c,&n);
    if(c=='+') printf("%d\n",t+n);
    else printf("%d\n",t-n);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#define DEBUG
#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF (0x7fffffff)
#else
#define INF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}
 
struct UnionFind {
  vector<int> data;
  UnionFind(int sz)
  {
    data.resize(sz, -1);
  }
  int find(int x)
  {
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return -1;
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return -data[x];
  }
};
 
struct edge {
  int u, v, w;
  edge(){}
  edge(int u, int v, int w):u(u), v(v), w(w){}
  bool operator < (const edge& e) const {
    return w < e.w;
  }
};
 
vector<edge> es;
int N, M;
 
int kruskal(int idx)
{
  UnionFind uf(N);
  for(int i = idx; i < es.size(); i++) {
    edge& e = es[i];
    if(uf.unite(e.u, e.v) == N) {
      return e.w - es[idx].w;
    }
  }
  return INF;
}
 
int main()
{
  while(cin >> N >> M, N) {
    es.clear();
    for(int i = 0; i < M; i++) {
      int a, b, w;
      cin >> a >> b >> w; --a, --b;
      es.push_back(edge(a, b, w));
    }
    sort(es.begin(), es.end());
    int ans = INF;
    for(int i = 0; i <= M-N+1; i++) {
      ans = min(ans, kruskal(i));
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3256
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1, n-1):
    if h[i] <= h[i+1] + 1:
        if h[i-1] != h[i]:
            h[i] -= 1
    else:
        print('No')
        exit()
for i in range(n-1):
    if h[i] > h[i+1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 14224