akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    // vector<P> ab(m); for (auto &e: ab) cin >> e.first >> e.second;
    vector<vector<int>> graph(n);
    rep (i, m) {
        int a, b; cin >> a >> b; a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> dist(n, (int)1e8);
    priority_queue<P, vector<P>, greater<P>> pq;
    dist[0] = 0; pq.emplace(0, 0);
    vector<int> from(n);
    while (!pq.empty()) {
        P p = pq.top(); pq.pop();
        int v = p.second, d = p.first;
        if (dist[v] < d) continue;
        for (int i : graph[v]) {
            if (chmin(dist[i], d + 1)) {
                pq.emplace(d + 1, i);
                from[i] = v;
            }
        }
    }
    cout << "Yes\n";
    rep (i, 1, n) cout << from[i] + 1 << "\n";
    return 0;
}

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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INF 114514

int x[10000][10000];
int color[10000];
int MIN[10000];
int sum;
int sum_min = INF;

int main() {
	int n, a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			MIN[j] = INF;
			color[j] = WHITE;
		}
		b = INF;
		a = n;
		color[i] = GRAY;
		MIN[i] = 0;
		while (a != 0) {
			b = INF;
			for (int j = 0; j < n; j++) {
				if (color[j] == GRAY) {
					if (b > MIN[j]) {
						b = MIN[j];
						c = j;
					}
				}
			}
			color[c] = BLACK;
			a -= 1;
			for (int k = 0; k < n; k++) {
				if (color[k] != BLACK && x[c][k] != -1) {
					color[k] = GRAY;
					MIN[k] = min(x[c][k], MIN[k]);
				}
			}
		}
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += MIN[j];
		}
		sum_min = min(sum_min, sum);
	}
	cout << sum_min << endl;
	return 0;
}

Measured memory_bytes: 3508
//It doesn't matter as long as you rise to the top - Katsuki Bakugo
#include<bits/stdc++.h>
using namespace std;
     
     
#define Fast_as_duck ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back 
#define forn(i,st,n) for(int i = st; i < n ; i++)
#define rev(i,st,n) for(int i = st; i >= n ; i--)
#define ss second
#define ff first
#define ll long long 

typedef pair <int , int> pii;

const int N = 1e5 + 10 , mod =  1000000007;

void solve(){

    ll x , k  , d;
    cin >> x >> k >> d;

    if(x < 0)x = x * (-1);

    // if(x == 0)cout << "0\n";

    ll steps = x / d;

    if(steps == k){
        cout << x - (steps*d) << "\n";

    }else if(steps< k){
        x = x - steps*d;
        k = k - steps;

        if(k %2 == 0){
            cout << x << "\n";
        }
        else{
            cout << abs(x - d) << "\n";
        }
        // cout << min( (x - (steps*d)) , abs(x - ((steps +1)*d )) ) << "\n";

    }else{
        cout << x - k *d << "\n"; 
    }


    
    

    
    
        


}

int main(){
    Fast_as_duck;

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
*/
    int t = 1; 
    
    // cin >> t;
    

    while(t--){
        solve();
    }




    return 0;
}
      
       


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

int main(){

	int n;
	cin>>n;

	int a[n+5];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int sum=0;
	int j=1;
	int last_index=0;
	for(int i=0;i<n;i++){
		if(a[i]==j){

			j++;
			continue;
		}
		else{
			sum++;
		}
	}
	if(j<=1){
		cout<<"-1"<<endl;
	}
	else
	cout<<sum<<endl;
}

Measured memory_bytes: 1024
n, res = int(input()), 1
a = []
for i in range(n):
  a.append((int(input()), 1))
for i in range(n):
  a.append((int(input()), -1))
a.sort()
t = 0
for i in a:
  if abs(i[1] + t) != abs(i[1]) + abs(t):
    res = (res * abs(t)) % 1000000007
  t += i[1]
print(res)


Measured memory_bytes: 69848
#include<stdio.h>

int main(){
  int a = 0;
  int b = 0;
  int c = 0;
  int gcd = 0;
  int hogeA = 0;
  int hogeB = 0;
  int hogeC = 0;
  scanf("%d %d %d",&a,&b,&c);
  
  hogeA = a;
  hogeB = b;
  while(1){
    hogeC = hogeA % hogeB;
    if(hogeC == 0){
      gcd = hogeB;
      break;
    }else{
      hogeA = hogeB;
      hogeB = hogeC;
    }
  }
  if(c % gcd == 0){
    printf("YES");
  }else{
    printf("NO");
  }
  return 0;
}
    

Measured memory_bytes: 128
from sys import stdin, setrecursionlimit
#input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

#N = int(input())
S = input()
T = input()
#N, M = map(int, input().split())
#A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
#ABC = [list(map(int, input().split())) for _ in range(N)]

answer = 0
for i in range(len(S)):
    if S[i] != T[i]:
        answer += 1
        
print(answer)

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

int main() {
  string S;
  cin >> S;
  int count_zero = 0;
  int count_one = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '1') count_one++;
    else count_zero++;
  }
  cout << min(count_zero,count_one) * 2 << endl;
  
}


Measured memory_bytes: 512
def isPrime(n):
    n = abs(n)
    if n == 2:
        return True
    if n < 2 or n & 1 == 0:
        return False
    return pow(2, n - 1, n) == 1

def gcd(n, m):
    while m:
        n, m = m, n % m
    return n

def lcm(n, m):
    return n * m // gcd(n, m)

def main():
    a, b, c = list(map(lambda x: int(x), input().split()))
    ans = 0
    for i in range(1000000 + 1):
        login_coin = i * a
        bonus_coin = i // 7 * b
        total = login_coin + bonus_coin
        if total >= c:
            ans = i
            break

    print(ans)

if __name__ == '__main__':
    main()



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
  gearup;
  ll a,b,c,k; cin >> a >> b >> c >> k;
  ll res = 0;
  if(a<=k){
    res+=a;
    k-=a;
  }
  else{
    res+=k;
    out(res);
    return 0;
  }
  if(k > 0){
    k-=b;
  }
  if(k>0){
    res-=k;
  }
  out(res);
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	while (true) {
		c -= b;
		if (c <= 0) {
			cout << "Yes" << "\n";
			return 0;
		}
		a -= d;
		if (a <= 0) {
			cout << "No" << "\n";
			return 0;
		}

	} 

}

Measured memory_bytes: 3576
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, s, word string
	fmt.Scan(&n)
	fmt.Scan(&s)

	isRepeat := false
	for _, v := range strings.Split(s, "") {
		word = word + fmt.Sprintf("%s", v)
		if s == word+word {
			isRepeat = true
			break
		}
	}

	ans := "No"
	if isRepeat {
		ans = "Yes"
	}
	fmt.Print(ans)
}


Measured memory_bytes: 640
// Template by [thunder_blade]
// IIIT ALLAHABAD
// includes :)

#include <bits/stdc++.h>
using namespace std;
#define TEST  ll test_case; cin>>test_case; while(test_case--)
#define all(v) (v).begin(),(v).end()
#define fi  first
#define se  second
#define pb push_back
#define mp make_pair
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);  cin.tie(0);  cout.tie(0);
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define pf(x) printf("%f\n",x)
#define ps(x) printf("%s\n",x)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sf(x) scanf("%f",&x)
#define ss(x) scanf("%s",x)
#define pis(x) printf("%d ",x)
#define pls(x) printf("%lld ",x)
#define pfs(x) printf("%f ",x)
#define pss(x) printf("%s ",x)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define mod 1000000007
#define pii pair<int,int>
#define tr(container, it)  for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
ll power(ll a, ll n) {
	ll p = 1;
	while (n > 0) {
		if(n&1) {
			p = ((p%mod) * (a%mod))%mod; 
		} 
		n >>= 1; 
		a = ((a%mod)*(a%mod))%mod;
	} 
	return p%mod;
}
ll inf  = 1000;
const long long B = 100000007; 
const long long C = 10010107; 
const int N = 5000005;
const int LN = 25;

int a[N], dp[N];

int main()
{
	string s;
	cin>>s;
	int ma[26] = {0};
	for(int i=0;i<s.length();i++){
		ma[s[i]-'a']++;
		if(ma[i] > 1){
			cout<<"-1"<<endl;
			return 0;
		}
	}
	for(int i=0;i<26;i++){
		if(ma[i] == 0){
			int ch = 'a' + i;
			s.pb(ch);
			cout<<s<<endl;
			return 0;
		}
	}
	while(s.length()>0){
		int i = (int)s.length()-1;
		int x = s[i]-'a';
		ma[x]--;
		s.pop_back();
		for(int j = x+1;j<26;j++){
			if(ma[j] == 0){
				int ch = j + 'a';
				s.pb(ch);
				cout<<s<<endl;
				return 0;
			}
		}
	}
	pi(-1);
}

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

using namespace std;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif
typedef long long int LL;
typedef unsigned int uint;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<LL> VLL;

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

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

#define MP make_pair
#define PB push_back
#define F first
#define S second
#define SZ(x)           x.size()
#define MAX(a, b)      ((a)>(b)?(a):(b))
#define MIN(a, b)      ((a)<(b)?(a):(b))
#define ALL(a)         std::begin(a), std::end(a)
#define Fill(n, x)      memset(n,x,sizeof n);
#define IN_REP         int _t; cin >> _t ; while(_t--)
#define IOS            ios::sync_with_stdio(false);cin.tie(NULL)
#define Cin(a)         cin>>a;
#define Cin2(a, b)      cin>>a>>b;
#define Cin3(a, b, c)    cin>>a>>b>>c;
#define Cin4(a, b, c, d)  cin>>a>>b>>c>>d;
#define Cout(n)           cout<<n<<endl;
#define REP(i, n)       for(int i=0;i<(n);i++)
#define FOR(i, a, b)     for(int i=(a);i<(b);i++)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS 1e-9

template<typename T>
inline T GCD(T a, T b) {
    LL t;
    while (a) {
        t = a;
        a = b % a;
        b = t;
    }
    return b;
}

template<typename T>
inline T Pow(T base, T exp) {
    LL result = 1;
    while (exp) {
        if (exp & 1)result *= base;
        exp >>= 1;
        base *= base;
    }
    return result;
}

template<typename T>
inline T Mulmod(T a, T b, T c) {
    LL x = 0, y = a % c;
    while (b > 0) {
        if (b & 1) x = (x + y) % c;
        y = (y << 1) % c;
        b >>= 1;
    }
    return x;
}

template<typename T>
inline T Pow(T base, T exp, T mod) {
    LL x = 1, y = base;
    while (exp > 0) {
        if (exp & 1) x = Mulmod(x, y, mod);
        y = Mulmod(y, y, mod);
        exp >>= 1;
    }
    return x;
}

template<typename T>
inline T Cube(T a) { return a * a * a; }

#define INF 1000000000000000
#define MAXN 5000005
const int MOD = (int) 1e9 + 7;

int main() {
    IOS;
#ifdef RDS
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("log.txt", "w", stderr);
#endif
    LL n, k;
    cin >> n >> k;
    VLL x(n);
    REP(i, n) cin >> x[i];
    LL ans = INF;
    REP(i, n - k + 1){
		ans = MIN(ans, abs(x[i] - x[i + k - 1]) + abs(x[i]));
    	ans = MIN(ans, abs(x[i] - x[i + k - 1]) + abs(x[i + k - 1]));
	}
    cout << ans << endl;
#ifdef RDS
    fprintf(stdout,"\nTIME: %.3lf sec\n", (double)clock()/(CLOCKS_PER_SEC));
#endif
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
int N,i=0,p=0,q=0;string S;cin>>N>>S;
for(;i<N;i++)if(S[i]==')'){if(p){p--;}else{q++;}}else{p++;};
cout<<string(q,'(')+S+string(p,')')<<"\n";
}

Measured memory_bytes: 256
'use strict'

function main(s) {

  s = s.split('\n');
  const H = Number(s[0].split(' ')[0]);
  const W = Number(s[0].split(' ')[1]);
  const table = s.slice(1, -1).map(line => line.split(''));

  const dh = [-1, 0, 1, 0];
  const dw = [0, 1, 0, -1];

  let answer = 'Yes';

  for (let h = 0; h < H; h++) {
    for (let w = 0; w < W; w++) {
      if (table[h][w] === '.') continue;

      let count = 0;

      for (let d = 0; d < 4; d++) {
        const nh = h + dh[d];
        const nw = w + dw[d];

        if (nh < 0 || H <= nh) continue;
        if (nw < 0 || W <= nw) continue;

        if (table[nh][nw] === '#') count += 1;
      }

      if (count === 0) answer = 'No'
    }
  }

  console.log(answer);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.nio.file.Files;
import java.nio.charset.StandardCharsets;
//给出两个数a,b 求出[a,b]中各位数字之和能整除原数的数的个数。
public class Main {

    int mod ;
    void solve(int v, int[] arr) {
        Set<Integer> set = new HashSet<>();
        int n = arr.length;
        for(int i=0;i<n;i++){
            set.add(arr[i]);
        }
        int add = 0;
        while(true){
            if(!set.contains(v-add)){
                System.out.println((v-add));
                return;
            }else if(!set.contains(v+add)){
                System.out.println((v+add));
                return;
            }
            add++;
        }

    }


    public static void main(String[] args)  throws IOException {
        // Use the Scanner class

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[]  s = br.readLine().split(" ");
        Main test = new Main();

        int n = Integer.parseInt(s[0]);
        int len = Integer.parseInt(s[1]);
        int[] arr = new int[len];
        s = br.readLine().split(" ");
        for(int i=0;i<len;i++) {
           arr[i] = Integer.parseInt(s[i]);

        }

        test.solve(n, arr);
        //int tot = Integer.parseInt(br.readLine());


//        int i =1;
//        System.out.println();
//        while(tot>0){
//
//            String s = br.readLine();
//            String[] sr = s.split(" ");
//            List<Long> ls = new ArrayList<>();
//            for(String ss:sr){
//                ls.add(Long.parseLong(ss));
//            }
//            Main tt = new Main();
//            tt.sol(ls);
//            // String Buffer to store answer
//            StringBuffer sb = new StringBuffer();
////            Solution obj = new Solution();
////
////            System.out.println("Case #"+i+": "+obj.sol());
//            tot--;
//            i++;
//        }
    }

}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
string S[222];

int dp[2][1<<16];

signed main(){
    cin>>H>>W;
    S[0]="";
    rep(i,H)cin>>S[i+1];

    fill_n(*dp,2*(1<<16),INT_MIN);
    dp[0][0]=0;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<(1<<W);k++){
                if(dp[(i*W+j)&1][k]==INT_MIN)continue;
                chmax(dp[(i*W+j+1)&1][(k<<1)&((1<<W)-1)],dp[(i*W+j)&1][k]);

                int l=__builtin_popcount(k&((1<<j)-1));
                if(l<S[i+1].size()){
                    int po=0;
                    if(j&&(k&1)&&S[i+1][l]==S[i+1][l-1])po++;
                    if(k>>(W-1)&1){
                        int m=__builtin_popcount(k)-l;
                        m=S[i].size()-m;
                        if(S[i][m]==S[i+1][l])po++;
                    }
                    chmax(dp[(i*W+j+1)&1][((k<<1)&((1<<W)-1))+1],dp[(i*W+j)&1][k]+po*2);
                }

                dp[(i*W+j)&1][k]=INT_MIN;
            }
        }
        for(int j=0;j<1<<W;j++)if(__builtin_popcount(j)!=S[i+1].size())dp[(i*W+W)&1][j]=INT_MIN;
    }

    int ans=INT_MIN;
    rep(i,1<<W)chmax(ans,dp[(H*W)&1][i]);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
string s;
bool even(string s){
	if(s.substr(0,s.size()/2)==s.substr(s.size()/2))return true;return false;
}
int main(){
	cin>>s;
	while(1){
		if(s.size()%2)
			s=s.substr(0,s.size()-1);
		else{
			s=s.substr(0,s.size()-2);
		}
		if(even(s)){
			cout<<s.size();
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int dp[100005];
int cost(int a[],int p)
{
    
    if(dp[p]!=-1)
    return dp[p];

    if(p>=n-1)
    return 0;

    if(p<n-2)
    return dp[p]=min(abs(a[p+1]-a[p])+cost(a,p+1) , (abs(a[p+2]-a[p])+cost(a,p+2) ));
    else
    return min(abs(a[p+2]-a[p]),abs(a[p+1]-a[p]));
    /*if(p==n-3)
    return abs(a[p+1]-a[p]);/*/
    
}

int main()
{
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i)
    cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<cost(a,0)<<endl;
}

Measured memory_bytes: 4992
from sys import stdin, setrecursionlimit
from collections import defaultdict


def main():
    input = stdin.readline
    n = int(input())
    dic = defaultdict(list)
    for i in range(1, n + 1):
        s, p = map(str, input().split())
        dic[s].append([int(p), i])
        dic[s].sort(reverse=True)
    s_dic = sorted(dic.items(), key=lambda x: x[0])

    for k, arr in s_dic:
        for ai in arr:
            print(ai[1])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	string a[n];
	zep(i, 0, n){
		cin >> a[i];
	}
	
	ll cnti[n], cntj[n];
	memset(cnti, 0, sizeof(cnti));
	memset(cntj, 0, sizeof(cntj));
	
	ll z = 0;
	zep(i, 0, n){
		zep(j, 0, n){
			if(a[i][j] == '#'){
				cnti[i]++;
				cntj[j]++;
			}
			else{
				z++;
			}
		}
	}
	if(z == n*n){
		print(-1)
		return 0;
	}
	
	ll cost = n;
	zep(i, 0, n){
		if(cntj[i] > 0){
			cost = min(n-cnti[i], cost);
		}
		else{
			cost = min(n-cnti[i]+1, cost);
		}
	}
	
	ll cnt = 0;
	zep(j, 0, n){
		if(cntj[j] == n){
			cnt++;
		}
	}
	print(n-cnt+cost)
	return 0;
}

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

#include <iostream>
#include <fstream>

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

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

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

using namespace std;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e:t) fill_v(e, v);
}

typedef pair<int, int> P;
int fac[200005], rev[200005];
int mod = 1e9 + 7;

int binpow(int x, int p) {
    if (p == 0) return 1;

    if (p % 2 == 0)
        return binpow((x * x) % mod, p / 2);
    else
        return (x * binpow(x, p - 1)) % mod;
}

int nCr(int n, int r) {
    if (r > n) return 0;
    if (r == 0) return 1;
    return ((fac[n] * rev[r]) % mod * rev[n - r]) % mod;
}

void precalc(int n) {
    fac[0] = fac[1] = 1;
    FOR(i, 2, n + 2)fac[i] = (fac[i - 1] * i) % mod;

    rev[n + 1] = binpow(fac[n + 1], mod - 2) % mod;
    REV(i, n, 0) { rev[i] = (rev[i + 1] * (i + 1)) % mod; }
}

class ECellDistance {
public:

    int sub(int N, int M, int K) {
        int res = 0;
        FOR(k, 1, N - 1) {
            int mm = (M * M) % mod;
            int t = ((N - k) * mm) % mod;
            int n = nCr(N * M - 2, K - 2) % mod;
            res += (((t * n) % mod) * k) % mod;
            res %= mod;
        }
        return res;
    }

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

        precalc(200005);

        int res = 0;
        res += sub(N, M, K);
        res %= mod;
        res += sub(M, N, K);
        res %= mod;
        cout << res << endl;
    }
};


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

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


Measured memory_bytes: 3328
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { N: number, H: number[] } => {
  const N = +lines[0]
  const H = lines[1].split(' ').map(line => +line)
  const obj = { N, H }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { N, H } = parseLines(lines)
  let current = H[0]
  let maxMoveCount = 0
  let moveCount = 0
  for (let i = 1; i < N; i++) {
    if (current >= H[i])  {
      current = H[i]
      moveCount++
    } else {
      current = H[i]
      moveCount = 0
    }
    if (maxMoveCount < moveCount) {
      maxMoveCount = moveCount
    }
  }
  return `${maxMoveCount}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 27596
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()

const int inf = 1 << 28;

struct Edge{
    int to, cost, weight;
    Edge(){}
    Edge(int to_, int cost_, int weight_):to(to_), cost(cost_), weight(weight_){}
};

int N, M, L;
vector<vector<Edge> > G;
vector<vector<int> > w;

int solve(int s){
    w.assign(N+1, vector<int>(L+1, inf));
    w[s][L] = 0;
    priority_queue<pair<int, int> > q;
    for(q.emplace(L, s); !q.empty();){
        int c = q.top().first, v = q.top().second; q.pop();
        if(v == N)continue;
        for(auto e: G[v]){
            if(e.cost <= c && w[v][c] < w[e.to][c-e.cost]){
                w[e.to][c-e.cost] = w[v][c];
                q.emplace(c - e.cost, e.to);
            }
            if(e.weight + w[v][c] < w[e.to][c]){
                w[e.to][c] = e.weight + w[v][c];
                q.emplace(c, e.to);
            }
        }
    }
    return *min_element(all(w[N]));
}

int main(){
    while(cin >> N >> M >> L, N|M|L){
        G.assign(N+1, vector<Edge>(0));
        rep(i, M){
            int A, B, D, E;
            cin >> A >> B >> D >> E;
            G[A].emplace_back(B, D, E);
            G[B].emplace_back(A, D, E);
        }
        cout << solve(1) << '\n';
    }
    return 0;
}

Measured memory_bytes: 1652
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>//pair
#include<cmath>//abs,sqrt
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int INF=1e+9;
const ll INFLL=1e+17;
int main(){
  int r,g,b;
  cin>>r>>g>>b;
  int num=100*r+10*g+b;
  if(num%4==0) prin("YES");
  else prin("NO");

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     int X,A;
     cin >> X >> A;
     if(X < A){
          cout << 0 << endl;
     }else{
          cout << 10 << endl;
     }
     return 0;
}

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

int sl;
char s[105];
bool c = false,f = false;
int main(){
	scanf("%s",s);
	sl = strlen(s);
	for(int i=0;i<sl;i++){
		if(s[i] == 'C'){
			c = true;
		}
		if(c && s[i] == 'F'){
			f = true;
			break;
		}
	}
	if(c && f){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	while (n--){
		int x;cin>>x;
		if (x%2==0 && x%3!=0 && x%5!=0){
			puts("DENIED");return 0;
		}
	}
	puts("APPROVED");
	return 0;
} 

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())

if a%d==0:
    last_ao=0
else:
    last_ao=1
    
if c%b==0:
    last_taka=0
else:
    last_taka=1
    
if (a//d +last_ao) >= (c//b + last_taka):
    print("Yes")
else:
    print("No")

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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

bool isedge[55][55];
bool isbridge[55][55];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	vii graph(n,vector<int>());
	vector<pair<int,int>> edges (m);
	for(int i = 0; i < m; i++) {
		int u,v;
		cin >> u >> v;
		u--;
		v--;
		isedge[u][v] = isedge[v][u] = isbridge[u][v] = isbridge[v][u] = true;
		edges[i] = make_pair(u,v);
	}
	int cnt = 0;
	for(int i = 0; i < m; i++) {
		isedge[edges[i].first][edges[i].second] = isedge[edges[i].second][edges[i].first] = false;
		stack<int> st;
		vector<bool> was (n,false);
		was[0] = true;
		st.push(0);
		int wascnt = 1;
		while(!st.empty()) {
			int v = st.top();
			st.pop();
			for(int u = 0; u < n; u++) {
				if(isedge[u][v]) {
					if(!was[u]) {
						wascnt++;
						was[u] = true;
						st.push(u);
					}
				}
			}
		}
		if(wascnt < n) {
			cnt++;
		}
		isedge[edges[i].first][edges[i].second] = isedge[edges[i].second][edges[i].first] = true;
	}
	cout << cnt;
	return 0;
}



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

int main()
{
    int count = 0;
    int happy = 0;
    int N, K;
    string S;
    
    cin >> N;
    cin >> K;
    cin >> S;
    
    for(int i=1; i<N-1; i++){
        if(S[i] == 'R' && S[i+1] == 'R'){
            happy++;
        }
        if(S[i] == 'L' && S[i-1] == 'L'){
            happy++;
        }
    }
    if(S[0] == 'R' && S[1] == 'R') happy++;
    if(S[N-1] == 'L' && S[N-2] == 'L') happy++;
    
//    for (int i=1; i<N-1; i++){
//        if (S[i] == 'R' && S[i+1] == 'L'){
//            count++;
//        }
//
//    }
//    if(S[0] == 'R' && S[1] == 'L') count++;
//    if(S[N-1] == 'L' && S[N-2] == 'R') count++;
    
    cout << min((happy+2*K),N-1) << endl;
    
    return 0;
}


Measured memory_bytes: 512
sx,sy,tx,ty=map(int,input().split())
tempx=tx-sx
tempy=ty-sy
ans=["R"]*tempx+["U"]*tempy+["L"]*tempx+["D"]*tempy+["D"]+["R"]*(tempx+1)+["U"]*(tempy+1)+["L"]+["U"]+["L"]*(tempx+1)+["D"]*(tempy+1)+["R"]
print("".join(ans))

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
double  inf = 1e9;
typedef pair<double,mp> mmp;

int main(){
    while(1){
	ll n,m,p,a,b;
	cin>>n>>m>>p>>a>>b;
	if(n==0)break;
	a--,b--;
	vector<vector<mp> > g(m);
	vector<ll> t(n);
	for(int i=0;i<n;i++)cin>>t[i];
	for(int i=0;i<p;i++){
		ll x,y,z;
		cin>>x>>y>>z;
		x--,y--;
		g[x].push_back(mp(z,y) );
		g[y].push_back(mp(z,x) );
	}
	//vector<vector<double> > dp( m,vector<double>( 1<<n , inf) );
	vector<vector<bool> > used( m,vector<bool>( 1<<n , false ) );
	priority_queue< mmp,vector<mmp> ,greater<mmp> > q;
	q.push( mmp(0.0, mp(0,a) ) );
	bool f = true;
	while(!q.empty() ){
		mmp now = q.top();
		q.pop();
		ll nn = now.second.second;
		ll tt = now.second.first;
		double time = now.first;
		if( nn == b){
			printf("%0.10lf\n",time);
			f = false;
			break;
		}
		if( used[nn][tt] ) continue;
		used[nn][tt] = true;
		//if( dp[nn][tt] <= time ) continue;
		//dp[nn][tt] = time;
		for(int i=0;i<g[nn].size();i++){
		    ll next = g[nn][i].second;
		    double dis = g[nn][i].first;
		    for(int j=0;j<n;j++){
			if( (tt>>j) & 1 ) continue;
			if( used[next][ tt | (1<<j) ] ) continue;
			q.push( mmp( time + dis/t[j] , mp( (tt|(1<<j) ) , next  ) )  );

		    }
		}
	}
	if(f){
		cout<<"Impossible"<<endl;
	}

    }
	return 0;
}



Measured memory_bytes: 21396
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
const int maxx  = 3*1e5 , limit = 9*1e18 , MOD=998244353;
#define boost  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n';
int32_t main(){
    boost;
    int n,k;
    cin>>n>>k;
    map<int,int>mark;
    for(int i = 0 ;i < k ; i++ ){
        int a,b;
        cin>>a>>b;
        for(int i=a ;i<=b; i++ ){
            mark[i]=1;
        }
    }
    int l,r;
    bool flag=false;
    vector< pair< int,int> > range;
    for(int i =1; i <= 1e6 ; i++ ){
        
        if(mark[i] == 1){
             if(!flag){
                 l=i;
                 flag=true;
             }  
        }else{
            if(flag){
                r=i-1;
                flag=false;
                range.pb(mp(l,r));
            }
            
        }
        
    }
    
    // for(int i=0 ; i< range.size() ; i++ ){
    //     cout<<range[i].fi<<" "<<range[i].se<<endl;
    // }
    
    
    int dp[n+2];
    zeros(dp);
    dp[1]=1;
    dp[0]=0;
    int pre[n+2];
    zeros(pre);
        
    pre[0]=0;
    pre[1]=1;
    
    for(int i =2 ; i<= n ; i++ ){
        
        for(int j = 0 ; j< range.size() ; j++ ){
            
            int l=range[j].fi;
            int r=range[j].se;
            // cout<<l<<
            
            if(l >= i)continue;
            
            l = i-l;
            r = i-r;
            
            
            if(r < 1) r=1;
           
            // cout<<l<<" "<<r<<endl;
            int minl = min(l,r);
            int maxr = max(l,r);
            
            dp[i] = (dp[i] + (pre[maxr]-pre[minl-1]+2*MOD)%MOD)%MOD;
            
        }
        
        pre[i] = (pre[i-1]+dp[i])%MOD;

    }    
        
        
    
    
    cout<<dp[n]<<endl;
    
}

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

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> P(N);
    for (int i = 0; i < N; i++) {
        std::cin >> P[i];
    }
    
    int res = 0;
    constexpr int MAX = 100;
    
    for (int i = 1; i <= MAX; i++) {
        int count = 0;
        for (int p : P) {
            if (p >= i) {
                count++;
            }
        }

        if (count >= i) {
            res = i;
        }
    }
    
    std::cout << res << std::endl;
    
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector <long> a(n), b(n), c(n);
    rep(i,n) cin >> a[i] >> b[i];

    rep(i,n) c[i] = a[i]%b[i];

    long count=0;

    for(int i=n-1; i>=0; i--){
        if((count+c[i])%b[i] != 0){
            count += b[i] - (count+c[i])%b[i];
        }
    }

    cout << count << endl;
}   


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int cmp(const void *a, const void *b)
{
    return strcmp(a,b);
}
int main(void)
{
    int n,l;
    char s[110][110];
    scanf("%d%d", &n, &l);
    for(int i=0;i<n;i++) scanf("%s", s[i]);
    qsort(s,n,sizeof(s[0]),cmp);
    for(int i=0;i<n;i++) printf("%s",s[i]);
    printf("\n");
    return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	string s;
	cin >> s;
	rep(i,3){
		if(s[i] == s[i+1])
		{

			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS)
class Point{
public:
  double x,y;
  Point(double x = 0, double y = 0):x(x), y(y) {}
  Point operator + (Point p){
    return Point(x+p.x,y+p.y);
  }
  Point operator - (Point p){
    return Point(x-p.x,y-p.y);
  }
  Point operator * (double k){
    return Point(x*k,y*k);
  }
  Point operator / (double k){
    return Point(x/k,y/k);
  }
  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;
typedef vector<Point> Polygon;
double dot(Vector a,Vector b){
  return a.x * b.x + a.y * b.y;
}
double cross(Vector a,Vector b){
  return a.x * b.y - a.y * b.x;
}
// IN 2 ON 1 OUT 0
int contains(Polygon g,Point p){
  int n=g.size();
  bool x = false;
  for(int i=0;i<n;i++){
    Point a = g[i] - p, b = g[(i+1)%n] - p;
    if(fabs(cross(a,b))<EPS && dot(a,b) < EPS ) return 1;
    if(a.y > b.y ) swap(a,b);
    if(a.y<EPS && EPS < b.y && cross(a,b) > EPS) x = !x;
  }
  return ( x ? 2:0);
}
int main(){
  Point a,b,c,d;
  while(cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> d.x >> d.y){
    Polygon g;
    g.push_back(a);g.push_back(b);g.push_back(c);
    if(contains(g,d)==2) cout << "YES" <<endl;
    else cout << "NO" <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n,a[N],nxt[N],suf[N];
char s[N];
ll ans;

int main(){
	scanf("%s",s+1),n=strlen(s+1);
	int cnt=0;
	For(i,1,n) if (s[i]=='1') ++cnt,ans+=(cnt+1)/2;
	int now=cnt+1;
	Dow(i,n,1) 
		if (s[i]=='0') a[now]++;
			else --now;
	Dow(i,cnt,1){
		suf[i]=suf[i+1]+(i&1);
		if (a[i+1]||i==cnt) nxt[i]=i+1;
			else nxt[i]=nxt[i+1];
	}
	int pre=0;
	For(i,1,cnt) if (a[i]||i==1){
		pre+=a[i],ans+=1ll*(nxt[i]-i)*(pre/2);
		if (pre&1) ans+=(nxt[i]-i)-(suf[i]-suf[nxt[i]]);
		if (a[i]) ans+=1ll*(n-cnt-pre)*max(suf[i]-suf[nxt[i]],(nxt[i]-i)-(suf[i]-suf[nxt[i]]));
			else ans+=1ll*(n-cnt)*(suf[i]-suf[nxt[i]]);
	}
	printf("%lld\n",ans);
}
/*
010101
*/

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

int main(){
    string s, t;
    cin >> s >> t;

    bool can = false;
    int index = 0;
    rep(i,(int)s.size()-(int)t.size()+1){
        bool flag = true;
        rep(j,(int)t.size()){
            if (s[i+j] != t[j] && s[i+j] != '?'){
                flag = false;
                break;
            }
        }
        // cout << flag << endl;
        if (flag){
            can = true;
            index = max(index, i);
        }
    }

    rep(i,(int)t.size()) s[i+index] = t[i];

    rep(i,(int)s.size()){
        if (s[i] == '?') s[i] = 'a';
    }

    cout << (can? s : "UNRESTORABLE") << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ull n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0;
    return 0;
  }
  if (n > k) {
    cout << k - (n % k);
  } else if (n == k) {
    cout << 0;
  } else {
    if (n * 2 > k) {
      cout << k - (n % k);
    } else {
      cout << n;
    }
  }
}


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

int main()
{
	int X,mx=1;
	cin >> X;
	for (int b = 2; b <= X; b++)
	{
		for(int m = b * b;m <= X;m*=b)
		{
			if (m <= X)
				mx = max(m, mx);
			else
				break;
		}
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
X = int(input())
# その時の数字と、3,5,7が今までに含まれていたか
q = deque([""])
q_is3 = deque([0])
q_is5 = deque([0])
q_is7 = deque([0])
N = "357"
ans = 0
while q:
    num = q.popleft()
    is3 = q_is3.popleft()
    is5 = q_is5.popleft()
    is7 = q_is7.popleft()
    for n in N:
        next_v = num + n
        if int(next_v) > X: continue
        else:
            next_is3 = is3 or n == "3"
            next_is5 = is5 or n == "5"
            next_is7 = is7 or n == "7"
            q.append(next_v)
            q_is3.append(next_is3)
            q_is5.append(next_is5)
            q_is7.append(next_is7)
            if next_is3 and next_is5 and next_is7:
                ans += 1
print(ans)


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

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

    int x,y; cin >> x >> y;
    for(int i = 0; i <= x; ++i){
        if(2*i + 4*(x-i) == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3592
n = int(input())
sp = {}
for i in range(n):
    s,p = input().split()
    p = int(p)
    if s not in sp:
        sp[s] = []
    sp[s].append((p,i+1))

keys = list(sp.keys())
keys.sort()

for k in keys:
    sp[k].sort(reverse=True)
    for p,i in sp[k]:
        print(i)

Measured memory_bytes: 3316
#include <stdio.h>

int main(){
	int n,j,tmp, i=0;
	int set1[12000] = { 0};
	int set2[12000] = { 0 };
	while (1){
		scanf("%d%d", &set1[i],&set2[i]);
		if (set1[i] > set2[i]){
			tmp = set1[i];
			set1[i] = set2[i];
			set2[i] = tmp;
		}
		if (set1[i] == 0&&set2[i]==0){
			break;
		}
		i++;
	}
	for (j = 0; j < i; j++){
		printf("%d %d\n", set1[j], set2[j]);

	}
	return 0;
}

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

int main()
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    int idx = 0;
    int left = 0;
    for (int i = 0; i < N; i++, idx++)
    {
        if (S[idx] == '(')
        {
            left++;
        }
        else
        {
            left--;
        }

        if (left < 0)
        {
            S.insert(0, "(");
            idx++;
            left++;
        }
    }

    while (left > 0)
    {
        S.insert(S.size(), ")");
        left--;
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int i,j,n,m,dp[3003][3003];
  string s,t,str;
  cin>>s;
  cin>>t;
  n=s.size();
  m=t.size();
  for(i=0;i<=n;i++)
  {
    for(j=0;j<=m;j++)
    {
      if(i==0 || j==0)
        dp[i][j]=0;
    }
  }
  for(i=1;i<=n;i++)
  {
    for(j=1;j<=m;j++)
    {
      if(s[i-1]==t[j-1])
        dp[i][j]=dp[i-1][j-1]+1;
      else 
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
  i=s.size();
  j=t.size();
  while(i>0 && j>0)
  {
    if(s[i-1]==t[j-1])
    {
    	 str.push_back(s[i-1]);
      i--;
      j--;
     
    }
    else 
    {
      if(dp[i][j-1]>dp[i-1][j])
        j--;
      else 
        i--;
    }
  }
  n=str.size();
  for(i=n-1;i>=0;i--)
    cout<<str[i];
  return 0;
}
      
        
      
        


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

int main() {
    char c1, c2, c3, c4, c5, c6;
    cin >> c1 >> c2 >> c3 >> c4 >> c5 >> c6;

    if (c1 == c6 and c2 == c5 and c3 == c4) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) ((x+mo_num)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define P pair<int,int>
#define SET set<int>
#define mp map<int,int>
#define mk make_tuple
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define got(container,num) get<num-1>(container)
using namespace std;
const int INF=LLONG_MAX/2;
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//up down left right
const int maxn=1e6+1e5;
const int mo_num=1e9+7;
int n,m,t,a[maxn],b[maxn],ans;

main()
{
    IOS
    fu(i,1,5)
    {
        int x;
        cin>>x;
        if(!x)a[i]=1;
    }
    fu(i,1,5)if(a[i])out(i);
    return 0;
}

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

using namespace std;

int main(){
	int n , m; 
	cin >> n >> m;
	if(abs(n) > abs(m)){
		if (n > 0 && m > 0){ 
		    cout << abs(n) - abs(m) + 2 << endl; 
		}
		if(n > 0 && m == 0){ 
		    cout << abs(n) + 1 << endl; 
		}
		if(n < 0 && m == 0){ 
		    cout << abs(n) << endl; 
		}
		if(n < 0 && m > 0){ 
		    cout << abs(n) - abs(m) + 1 << endl; 
		}
		if(n > 0 && m < 0){ 
		    cout << abs(n) - abs(m) + 1 << endl; 
		}
		if(n < 0 && m < 0){ 
		    cout << abs(n) - abs(m) << endl; 
		}
	}
	else if(abs(n) == abs(m)){
		cout << 1 << endl;
	}
	else {
		if(n > 0 && m > 0){ 
		    cout << m - n << endl; 
		}
		if(n == 0 && m > 0){ 
		    cout << m - n << endl; 
		}
		if(n == 0 && m < 0){ 
		    cout << n - m + 1 << endl; 
		}
		if(n < 0 && m < 0){ 
		    cout << abs(m) - abs(n) + 2 << endl; 
		}
		if(n > 0 && m < 0){ 
		    cout << abs(m) - n + 1 << endl; 
		}
		if(n < 0 && m > 0){ 
		    cout << m - abs(n) + 1 << endl; 
		}
	}
	cin >> n;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A,B;
  scanf("%d %d",&A,&B);
  
  if(A >= 6 && A<= 12)
    B /= 2;
  else if(A<6)
    B=0;
  
  printf("%d\n",B);
  return 0;
}

Measured memory_bytes: 128
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
s = input().strip()
acc = 0
prev = '#'
for i in range(n):
  if s[i] != prev:
    acc += 1
  prev = s[i]
print(acc)


Measured memory_bytes: 3316