akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9;
const LL LINF = INF * INF;

const int MAX = 1 << 18;
int n;
int a[MAX];
map<int, int> mp;
vector<int> g[MAX];
int ans = 0;
char U[MAX];

void dfs(int v, int p = -1)
{
	U[v] = 1;
	for(auto i: g[v])
		dfs(i, v);
	
	if (p == -1)
	{
		if (__builtin_popcount(a[v]) == 1)
			ans += mp[a[v]] / 2;
		return;
	}
	
	int tut = mp[a[v]];
	int tam = mp[a[p]];
	
	if (tut <= tam)
	{
		ans += tut;
		mp[a[p]] -= tut;
		return;
	}
	
	if (__builtin_popcount(a[v]) > 1)
	{
		ans += tam;
		mp[a[p]] = 0;
		return;
	}
	
	if (tam == 0)
	{
		ans += tut / 2;
		return;
	}
	
	int she = tut - tam;
	if (she % 2 == 0)
	{
		ans += (tut + tam) / 2;
		mp[a[p]] = 0;
		return;
	}
	
	ans += tam / 2;
	mp[a[p]] = 1;
	
	tut -= tam - 1;
	ans += tut / 2;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	//freopen("Out.txt", "w", stdout);
	
	cin >> n;
	FOR(i, 0, n)
	{
		cin >> a[i];
		mp[a[i]]++;
	}
	
	sort(a, a + n);	
	FOR(i, 0, n)
	{
		if (i && a[i] == a[i - 1])
			continue;
		
		FOR(j, 2, 31)
		{
			if (a[i] >= (1 << (j - 1)))
				continue;
			
			auto it = lower_bound(a, a + n, (1 << j) - a[i]) - a;
			if (a[it] + a[i] != (1 << j))
				continue;
			
			g[i].PB(it);
		}
	}
	
	FOR(i, 0, n)
	{
		if (i && a[i] == a[i - 1])
			continue;
		if (U[i])
			continue;
		dfs(i);
	}	

	cout << ans << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 19456
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <string>
#include <map>
#include <list>
using namespace std;

int main() {
  int n,x;
  cin >> n >> x;
  int min=1001;
  int res=0;
  for(int i = 0; i < n; ++i){
    int m[n];
    cin >> m[i];
    if(min > m[i]){
      min = m[i];
    }
    x -= m[i];
    res++;
  }

  res += x / min;
  
  cout << res << endl;
}



Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

typedef complex<double> base;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main() 
{
    IOS
    int x;
    cin>>x;
    if(x>=30)
        print("Yes");
    else
        print("No");
}   


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

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

    bool choice_1 = true;
    bool choice_2 = true;
    bool choice_3 = true;

    if (a == 1 || b == 1)
    {
        choice_1 = false;
    }

    if (a == 2 || b == 2)
    {
        choice_2 = false;
    }

    if (a == 3 || b == 3)
    {
        choice_3 = false;
    }

    if (choice_1 == true)
    {
        cout << 1 << endl;
    }
    else if (choice_2 == true)
    {
        cout << 2 << endl;
    }
    else if (choice_3 == true)
    {
        cout << 3 << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        N = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
    	int answer = 0;
        int count = 0;
        
        for (int i=1; i<=N; i+=2) {
        	count = divisorCount(i);
        	if (count == 8) {
        		answer++;
        	}
        }
        
        return answer;
    }
    
    //約数の個数を返すメソッド
    private int divisorCount(int num) {
    	int count = 0;
    	
    	for (int i=1; i<=num; i++) {
    		if (num % i == 0) {
    			count++;
    		}
    	}
    	
    	return count;
    	
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35728
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

typedef long long ll ; 
typedef long double ld ; 
typedef pair<int,int> pii ; 
typedef pair<ll,ll> pll ;

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============
const int N=8 ; 
vt<int> p(N) ; 
vt<int> q(N) ; 
int n ;
int cnt = 0 ; 


int main() 
{ 
	int n ;
	cin >> n ; 
	int a[n] ; 
    rep(i,0,n) cin >> p[i] ; 
    rep(i,0,n) cin >> q[i] ;
    vt<int> s(n) ; 
    rep(i,0,n) s[i]  = i +1 ; 
    cnt = 1 ; 
    int pos1 = 0 , pos2 = 0 ; 
    while(next_permutation(all(s))) {
        bool ok = 1 ; 
        rep(i,0,n) {
            if(p[i] != s[i]) {
                ok = 0 ; 
                break ; 
            }
        }
        if(ok ) {
            pos1 = cnt ; 
        } 
        bool ok2 = 1 ; 
        rep(i,0,n) {
            if(q[i] != s[i]) {
                ok2 = 0 ; 
                break ; 
            }
        }
        if(ok2) {
            pos2 = cnt ; 
        } 
        cnt++;
    }
    cout << abs(pos2-pos1) ; 
    return 0; 
} 

Measured memory_bytes: 3572
import sys
 
sys.setrecursionlimit(10 ** 6)

N,X = map(int,input().split())

a,p = [1],[1]

for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N,X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1] + 1 + f(N-1,X-2-a[N-1])

print(f(N,X))

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

typedef long long ll;
const int maxn = 1e5 + 7;
int n, m;
struct job {
    int a, b;
    bool operator<(const job& t) const {
        return t.a > a;
    }
} jo[maxn];
int main() {
    //freopen("test.in", "r", stdin);
    //freopen("test.out", "w", stdout);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> jo[i].a >> jo[i].b;
    sort(jo + 1, jo + 1 + n);
    multiset<int> s;
    int cnt = 1, k = 1, ans = 0;
    while (cnt <= m) {
        while (k <= n && cnt >= jo[k].a) {
            s.insert(jo[k].b);
            k++;
        }
        if (s.size()) {
            multiset<int>::iterator pos = --s.end();
            ans += *pos;
            s.erase(pos);
        }
        cnt++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include <stdio.h>
int main(void)
{
    int N, M, C;
    int b[20], a[20][20];
    int i, j, cnt = 0, sum;
    scanf("%d%d%d", &N, &M, &C);
    for (i = 0; i < M; i++)
    {
        scanf("%d", &b[i]);
    }
    for (i = 0; i < N; i++)
    {
        for (j = 0; j < M; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (i = 0; i < N; i++)
    {
        sum = C;
        for (j = 0; j < M; j++)
        {
            sum += a[i][j] * b[j];
        }
        if (sum > 0)
        {
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll h, w;
	cin >> h >> w;
	bitset<80*160*2> dp[h][w];
	ll st = 80*160;

	ll a[h][w], b[h][w];
	rep(i, h){
		rep(j, w) cin >> a[i][j];
	}
	rep(i, h){
		rep(j, w) cin >> b[i][j];
	}

	dp[0][0][st+abs(a[0][0]-b[0][0])] = 1;
	dp[0][0][st-abs(a[0][0]-b[0][0])] = 1;
	rep(i, h){
		rep(j, w){
			if(i){
				dp[i][j] |= dp[i-1][j] >> abs(a[i][j]-b[i][j]);
				dp[i][j] |= dp[i-1][j] << abs(a[i][j]-b[i][j]);
			}
			if(j){
				dp[i][j] |= dp[i][j-1] >> abs(a[i][j]-b[i][j]);
				dp[i][j] |= dp[i][j-1] << abs(a[i][j]-b[i][j]);
			}
		}
	}

	ll ans = LINF;
	rep(i, 80*160*2){
		if(dp[h-1][w-1][i] == 1){
			chmin(ans, abs(i-st));
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 20352
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		List<String> result = new ArrayList<>();
		while (true) {
			int m = stdin.nextInt();
			int f = stdin.nextInt();
			int r = stdin.nextInt();
			if (m == -1 && f == -1 && r == -1) {
				break;
			}
			int grade = m+f;
			if ( grade < 30 || m == -1 || f == -1 ) {
				result.add("F");
			} else {

				if (grade >= 80) {
					result.add("A");
				} else if (grade >= 65 && grade < 80) {
					result.add("B");
				} else if (grade >= 50 && grade < 65) {
					result.add("C");
				} else if (grade >= 30 && grade < 50) {
					if( r >= 50 ) {
						result.add("C");
					}else {
						result.add("D");
					}				
				}
			}
		}
		for (int i = 0; i < result.size(); i++) {
			System.out.println(result.get(i));
		}

	}
}

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

int main(){
    int n,l;
    cin >> n >> l;

    int aps = 0;
    int min_ap = abs(l);
    rep(i,n){
        int taste = l+i;
        aps += taste;
        if(abs(min_ap) > abs(taste)) min_ap = taste;
    }
    cout << aps - min_ap << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    import math
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # map(int, input().split())

    s = input()[:-1]
    sakai = s.replace('RL', 'R,L').split(',')
    kodomo = [0] * (len(s)+1)
    pos = [0] * (len(sakai)+1)
    for i in range(len(sakai)):
        seq = sakai[i]
        pos[i + 1] = len(seq)+pos[i]
    for i in range(len(sakai)):
        seq = sakai[i]
        kodomo[pos[i + 1]-1] += (seq.count('R')+1) // 2  # 相手の左端にいる
        kodomo[pos[i + 1]] += seq.count('R') // 2  # 自分の右端にいる
        kodomo[pos[i]] += (seq.count('L')+1) // 2
        kodomo[pos[i] - 1] += seq.count('L') // 2
        # print(kodomo)
    # print(sakai)
    # print(pos)
    print(*kodomo[:-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 11448
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 A, B, C;
  std::cin >> A >> B >> C;
  std::cout << (std::unordered_set<i64>({A, B, C}).size() == 2 ? "Yes" : "No") << std::endl;
  return 0;
}

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

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> dice(n+1);
  for (int i = 1; i <= n; ++i) {
    int d = i;
    int c = 0;
    while (d < k) {
      d *= 2;
      ++c;
    }
    dice[i] = c;
  }

  double ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += pow(0.5, dice[i]);
  }
  ans /= n;
  printf("%.10f\n", ans);
  return 0;
}

Measured memory_bytes: 4156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  int  a,b,c;
  cin >>a>>b>>c;
  
  cout << a+b+c-max(max(a,b),c) << endl;
  
  
}



Measured memory_bytes: 256
# Your code here!
n,m=gets.split
n=n.to_i
m=m.to_i

array4=[]
m.times{
    
    array4<<gets.split.map(&:to_i)}
answer=0
jj=0
m.times{
array=array4-[array4[jj]]

array2=Array.new(n,0)
array3=Array.new(n,1)
m.times{
i=0
(m-1).times{
    
    if i==0
    array2[array[i][0]-1]=1
     array2[array[i][1]-1]=1
     
 elsif   array2[array[i][0]-1]==0 && array2[array[i][1]-1]==0
        array2[array[i][0]-1]=2
        array2[array[i][1]-1]=2
   elsif    array2[array[i][0]-1]==1 || array2[array[i][1]-1]==1
       array2[array[i][0]-1]=1
        array2[array[i][1]-1]=1
        
    else array2[array[i][0]-1]=2
        array2[array[i][1]-1]=2
 end
 i+=1
    
 
}

if  array2==array3
    break
end

}
if array2!=array3
    answer+=1
end
jj+=1

}

puts answer

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    int k;
    cin >> k;
    ll ans =0;
    queue<ll>que;
    for(int i=0;i<9;i++){
        que.push(i+1);
    }
    for(int i=0;i<k;i++){
        ll che = que.front();
        ans = que.front();
        que.pop();
        int keta = che%10;
        ll next = che*10;
        if(keta==0){
            que.push(next+keta);
            que.push(next+keta+1);
        }
        else if(keta==9){
             que.push(next+keta-1);
            que.push(next+keta);
        }
        else {
            que.push(next+keta-1);
            que.push(next+keta);
            que.push(next+keta+1);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
import math


result = []
n = int(input())

while n != 0:
    d = list(map(int, input().split()))
    mean = sum(d) / n
    var = [(i - mean) ** 2 for i in d]
    var = math.sqrt(sum(var) / n)
    result.append(var)
    
    n = int(input())

for i in result:
    print(i)


Measured memory_bytes: 5708
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 V, int NV> struct LazySegTree { // [L,R)
    vector<V> dat, lazy; LazySegTree() { dat.resize(NV * 2, def); lazy.resize(NV * 2, ldef); }
    void update(int a, int b, V v, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return;
        if (a <= l && r <= b) { setLazy(k, v); push(k, l, r); } else {
        update(a, b, v, k * 2 + 1, l, (l + r) / 2); update(a, b, v, k * 2 + 2, (l + r) / 2, r);
        dat[k] = comp(dat[k * 2 + 1], dat[k * 2 + 2]);}}
    V get(int a, int b, int k, int l, int r) { push(k, l, r); if (r <= a || b <= l) return def;
        if (a <= l && r <= b) return dat[k]; auto x = get(a, b, k * 2 + 1, l, (l + r) / 2);
        auto y = get(a, b, k * 2 + 2, (l + r) / 2, r); return comp(x, y);}
    void update(int a, int b, V v) { update(a, b, v, 0, 0, NV); }
    V get(int a, int b) { return get(a, b, 0, 0, NV); }
    // ---- Template ---------------------------------------------------------------------------------
    
    // 区間add, 区間max
    const V def = 0, ldef = 0;
    V comp(V l, V r) { return max(l, r); }
    void setLazy(int i, V v) { lazy[i] += v; }
    void push(int k, int l, int r) {
        dat[k] += lazy[k];
        if (r - l > 1) { setLazy(k * 2 + 1, lazy[k]); setLazy(k * 2 + 2, lazy[k]); }
        lazy[k] = ldef;
    }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N, M;
LazySegTree<ll, 1 << 18> dp;
vector<pair<int, int>> R[201010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;
    rep(i, 0, M) {
        int l, r, a; cin >> l >> r >> a;
        l--; r--;
        R[r].push_back({ l,a });
    }

    rep(r, 0, N) {
        ll opt = dp.get(0, r);
        dp.update(r, r + 1, opt);
        fore(p, R[r]) {
            int l, a; tie(l, a) = p;
            dp.update(l, r + 1, a);
        }
    }

    ll ans = dp.get(0, N);
    cout << ans << endl;
}


Measured memory_bytes: 19456
def calc(n, w):
    min_sub = 100000
    N = n
    num = w
    for i in range(1,N):
        S1 = num[:i]
        S2 = num[i:]
        sub = abs(sum(S1)-sum(S2))
        if min_sub > sub:
            min_sub = sub
    print(min_sub)
        
N = int(input())
W = [int(i) for i in input().split()]
calc(N, W)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REP2(i, a, b) for (int i = (a); i < (int)(b); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef long long ll;
#define ALL(V) V.begin(), V.end()


int Main(string S, string T)
{
    int ans = 0;
    REP(i, 3) if(S[i] == T[i]) ans++;
    return ans;
}

int main(void){
    string S, T;
    cin >> S >> T;
    cout << Main(S, T) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, k, h, diff int
	var dp []int
	var hList []int
	fmt.Scan(&n, &k)
	fmt.Scan(&h)
	hList = append(hList, h)
	dp = append(dp, 0)
	for i := 1; i < n; i++ {
		fmt.Scan(&h)
		hList = append(hList, h)
		dp = append(dp, -1)
		for j := 1; j <= i && j <= k; j++ {
			if hList[i] > hList[i-j] {
				diff = hList[i] - hList[i-j]
			} else {
				diff = hList[i-j] - hList[i]
			}
			if dp[i] == -1 || dp[i] > dp[i-j]+diff {
				dp[i] = diff + dp[i-j]
			}
		}
	}
	fmt.Println(dp[n-1])
}


Measured memory_bytes: 6528
s=input()
A=int((list(s))[0])
B=int((list(s))[1])
C=int((list(s))[2])
D=int((list(s))[3])

for i in range(2**3):
    a=[]
    b=A
    for k in range(3):
        if (i>>k)&1==1:
            a.append("+")
            b+=int(list(s)[k+1])
        else:
            a.append("-")
            b-=int(list(s)[k+1])
    if b==7:
        print(A,a[0],B,a[1],C,a[2],D,"=7",sep="")
        break

Measured memory_bytes: 38384
#include<stdio.h>
int main(){
  int box[100];
  int tmp,i,p,q;
  int hill[3];
  for(i=0;i<10;i++){
    scanf("%d",&box[i]);
  }
  for(p=0;p<10-1;p++){
    for(q=p+1;q<10;q++){
      if(box[p]<box[q]){
	tmp=box[p];
	box[p]=box[q];
	box[q]=tmp;
      }
    }
  }
  for(i=0;i<3;i++){
    hill[i]=box[i];
  }
  for(i=0;i<3;i++){
    printf("%d\n",hill[i]);
  }
  return(0);
}

Measured memory_bytes: 600
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数

const ll MOD=1e+9+7; //10^9+7
const int SIZE=2e+5+1;
//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>=(ll)(b);i--)

//グローバル変数


//ライブラリ挿入
vector<long long> fact, fact_inv, inv;
 
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
 
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}


int main(){
    ll N,k;
    cin >> N >> k;
    ll ans=0;
    init_nCk(SIZE);
    REP(i,min(N,k+1)){
        ans+=((nCk(N,i)*nCk(N-1,i))%MOD);
        ans%=MOD;
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n;
double x[100], y[100];

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 4) cin >> x[j] >> y[j];
		if (fabs((x[1] - x[0])*(y[3] - y[2]) 
			- (x[3] - x[2])*(y[1] - y[0]))<1e-10){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
const ll INF = 1e18;

int n;
ll R[105], C[105];
ll dp[105][105];

ll dfs(int l, int r){
    if(l == r) return 0;
    if(dp[l][r] != INF) return dp[l][r];
    ll cost = R[l]*C[r];
    ll res = INF;
    for(int k = l; k < r; k++){
        chmin(res, dfs(l,k) + dfs(k+1,r) + cost*C[k]);
    }
    return dp[l][r] = res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n) cin >> R[i] >> C[i];
    rep(i,n)rep(j,n){
        if(i == j) dp[i][j] = 0;
        else dp[i][j] = INF;
    }
    ll ans = dfs(0, n-1);
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

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

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

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

//----------------------------------------------------------------

int main()
{
    ll n;
    cin >> n;
    ll h;
    ll pre = 0;
    ll cnt = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h;
        cnt += seinomi(h - pre);
        pre = h;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main () {
    int A, B, X;
    scanf("%d %d %d", &A, &B, &X);

    if (A > X) {
        printf("NO");
    } else if (A == X) {
        printf("YES");
    } else if (A + B >= X) {
        printf("YES");
    } else {
        printf("NO");
    }

    return 0;
}


Measured memory_bytes: 128
N, M, C = map(int, input().split())
vecB = list(map(int, input().split()))
matA = [list(map(int, input().split())) for i in range(N)]
ans = 0
for i in range(N):
    value = 0
    for j in range(M):
        value += matA[i][j] * vecB[j]
    value += C
    if value > 0:
       	ans += 1
print(ans)

Measured memory_bytes: 62172
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define MOD 1000000007ULL;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
	ll x;
  	cin>>x;
  
  	ll ans=(2199-x)/200;
  	
  
  	cout<<ans<<endl;
}

Measured memory_bytes: 3632
N=int(input())
act=[list(map(int,input().split())) for _  in range(N)]

dp=[[0,0,0] for _ in range(N)]

dp[0][0]=act[0][0]
dp[0][1]=act[0][1]
dp[0][2]=act[0][2]

for i in range(N-1):
    dp[i+1][0]=act[i+1][0]+max(dp[i][1],dp[i][2])
    dp[i+1][1]=act[i+1][1]+max(dp[i][0],dp[i][2])
    dp[i+1][2]=act[i+1][2]+max(dp[i][0],dp[i][1])

print(max(dp[N-1]))

Measured memory_bytes: 47388
N,M,K=map(int,input().split())
cond=False
for i in range(N+1):
  for j in range(M+1):
    b=i*(M-j)+j*(N-i)
    if b==K:
      cond=True
      break
  if cond:
    break
print("Yes" if cond else "No")


Measured memory_bytes: 9116
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  string s;cin>>s;
  string a[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
  for(int i=0;i<7;i++){
  	if( s!="SUN" && a[i]==s){
  		cout<<(6-i);
  	}
  	else if(s=="SUN"){
  		cout<<7;
  		break;
  }
}
  return 0;
}
  

Measured memory_bytes: 3620
//変換は表を作成
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s, t;
    cin >> s >> t;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);
    repi(i, s.size(), 0)
    {
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if (start[a] != -1 || goal[b] != -1)
        {
            if (start[a] != b || goal[b] != a)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        else
        {
            start[a] = b;
            goal[b] = a;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define mod 1000000000+7
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int r;
  cin>>r;
  cout<<r*r;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <random>

using namespace std;

void pass(){
	return;
}

#define x first
#define y second
#define prev _prev
#define rand() rand()<<15+rand()
typedef long long ll;
typedef unsigned long long ull;

#define int long long
mt19937 rnd(rand());
const int MOD = 1e9 + 7;
const ll BIG_MOD = 1e18 + 7;
const int MAXN = 1e5 + 7;

signed main(){
	cout.tie(NULL);
	cout.precision(20);
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(false);
	int a, b, c, d, n;
	cin >> a >> b >> c >> d >> n;
	
	c = min(4 * a, min(2 * b, c));

	cout << min(c * n, (n / 2) * d + (n % 2) * c);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a) (a).begin(),(a).end()

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

  ll n,m;
  cin >> n >> m;

  // if(n/2 > m) {
  //   cout << n/2 << endl;
  //   return 0;
  // }

  // n=6 m=1
  if(m < n*2) {
    cout << m/2 << endl;
    return 0;
  }

  // n=1 m=6
  if(m > n*2) {
    ll mod = m - (n*2);
    cout << n + (mod/4) << endl;
    return 0;
  }
}


Measured memory_bytes: 256
def main():
    x = int(input())
    list1 = list(map(int, input().split(" ")))
    result = 1

    if 0 in list1:
        print(0)
        return

    for i in list1:
        result *= i
        if result > 1000000000000000000:
            print("-1")
            exit()
    print(result)

main()

Measured memory_bytes: 21608
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define dump(x) cerr << #x << " = " << (x) << endl;
#define dumpi(i, x) cerr << string((i), ' ') << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
using pii = pair<int, int>;
constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr double EPS = 1e-10;

int N, T;
int A[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> T;
  int mn = INF;
  vector<int> v;
  rep(i, 0, N) {
    cin >> A[i];
    mn = min(mn, A[i]);
    v.EB(A[i]-mn);
  }
  sort(all(v));
  reverse(all(v));
  int ans = 0;
  rep(i, 0, sz(v)) {
    if (v[i] == v[0]) ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1912
function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  var B = A.slice(A.length-1);
  var ans  = "";
  switch(B){
    case "0": ans="pon";break;
    case "1": ans="pon";break;
    case "2": ans="hon";break;
    case "3": ans="bon";break;
    case "4": ans="hon";break;
    case "5": ans="hon";break;
    case "6": ans="pon";break;
    case "7": ans="hon";break;
    case "8": ans="pon";break;
    case "9": ans="hon";break;
  }
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29632
N,M = map(int,input().split())
wa_list= [0]*(N+2)
ac_list=[-1]*(N+2)
for i in range(M):
  p,a = map(str,input().split())
  p = int(p)
  if a =='WA':
    wa_list[p]+=1
  if a =='AC' and ac_list[p] == -1:
    ac_list[p]+=(wa_list[p]+1)
count = 0;count2 = 0
for i in ac_list:
  if i>=0:
    count+=1
    count2+=i
print(count,count2)
    

Measured memory_bytes: 10380
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST(), reverse=True)

ans = 0
for i in range(1,n):
    if i == 1:
        ans += a[0]
    else:
        ans += a[i//2]

print(ans)

Measured memory_bytes: 33072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,m;
	cin>>n>>m;
	int out=0;
	rep(i,n){
		int a;
		cin>>a;
		out+=2*min(a,m-a);
	}
	cout<<out<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

struct Card{
  char s;
  int v;
};

struct Card L[MAX], R[MAX];

void merge(struct Card [], int, int, int, int);

void m_sort(struct Card [], int , int, int);

int partition(struct Card [], int , int , int );

void quickSort(struct Card [], int  ,int , int );


int main(){
  int i, n, v;
  //クイックソートとマージソートを比べるために二つ配列を用意する
  struct Card M[MAX], Q[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);
  for( i = 0 ; i < n ; i++){
    scanf("%s %d", S, &v);
    M[i].s = Q[i].s = S[0];
    M[i].v = Q[i].v = v;
  }
  //マージソート
  m_sort(M, n, 0, n);
  //クイックソート
  quickSort(Q, n, 0, n-1);

  for( i = 0 ; i < n ; i++){
    //クイックソートとマージソートを比べる
    if( Q[i].s != M[i].s ) stable = 0;
  }

  if( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for(i = 0 ; i < n ; i++){
    printf("%c %d\n", Q[i].s, Q[i].v);
  }
  return 0;
}

void merge(struct Card M[], int n, int left, int mid, int right){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  //左部分のマージ
  for( i = 0 ; i < n1 ; i++ ){
    L[i] = M[left + i];
  }
  // 右部分のマージ
  for( i = 0 ; i < n2 ; i++ ){
    R[i] = M[mid + i];
  }
  L[n1].v = R[n2].v = 2000000000;
  i = j = 0;
  for( k = left ; k < right ; k++){
    //　L側とR側に振り分け
    if( L[i].v <= R[j].v ){
      M[k] = L[i++];
    }
    else{
      M[k] = R[j++];
    }
  }
}

void m_sort(struct Card A[], int n, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    m_sort(A, n, left, mid);
    m_sort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

// 要素を分割し、要素の標準（ピボット）となる要素の番号を返す。
int partition(struct Card A[], int n, int p, int r){
  int i, j;
  struct Card t, x;
  // t 一時避難用、x元カード保持
  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++ ){
    if( A[j].v <= x.v ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}

void quickSort(struct Card Q[], int n ,int p, int r){
  int q;
  if( p < r ){
    // 要素の分割化
    q = partition(Q, n, p, r);
    // 分割した左部分
    quickSort(Q, n, p, q-1);
    // 分割した右部分
    quickSort(Q, n, q+1, r);
  }
}



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

int main(){
    int n;
    cin >> n;
    double ans;
    if (n%2 == 0){
        int x = n/2;
        ans = double(x)/double(n);
    }else{
        int x = (n+1)/2;
        ans = double(x)/double(n);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

bool u[30];

char s[30];

int n;

void solve() {                   
	scanf("%s", s);

    for (n = 0; s[n]; ++n);

    for (int i = 0; i < n; ++i) {
    	u[s[i] - 'a'] = 1;
    }

    if (n == 26) {     
		for (int i = n - 1; i >= 0; --i) {
			int p = -1;

			for (int j = s[i] - 'a' + 1; j < 26; ++j) {
				if (!u[j]) {
					p = j;
					break;
				}
			}

			if (p != -1) {
				for (int j = 0; j < i; ++j) {
					printf("%c", s[j]);
				}

				printf("%c", p + 'a');                
				return;
			}

			u[s[i] - 'a'] = 0;
		}

    	printf("-1\n");
    	return;
    }

    printf("%s", s);

    for (int i = 0; i < 26; ++i) {
    	if (!u[i]) {
    		printf("%c", i + 'a');
    		break;
    	}
    } 
}

int main() {    
    int tt = 1;

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

    return 0;
}


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

using namespace std;

int n;
bool arr[23][23] = {};
int M = 1000000007;
int memo[(1 << 21) + 1] = {};

int dp(int man, int rem_wmn)
{
    if (!rem_wmn)
        return 1;
    if (memo[rem_wmn])
        return memo[rem_wmn] - 1;
    int num = 0;
    for (int i = 0; i < n; i++)
    {
        if (!arr[man][n - 1 - i] || !(rem_wmn & (1 << i)))
            continue;
        num += dp(man + 1, rem_wmn ^ (1 << i));
        if (num >= M)
            num -= M;
    }
    memo[rem_wmn] = num + 1;
    return num;    
}

int main(void)
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            cin >> arr[i][j];
        }
        
    }
    int res;
    res = dp(0, (1 << n) - 1);
    printf("%d\n", res);
}

Measured memory_bytes: 12016
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int secTime = sc.nextInt();
        if (secTime == 0) {
            System.out.println("0:0:0");
            return;
        }
        int ansSec = secTime % 60;
        int min = secTime / 60;
        if (min == 0) {
            System.out.println("0:0:" + ansSec);
            return;
        }
        int ansMin = min % 60;
        int ansHour = secTime / (60 * 60);
        System.out.println(ansHour + ":" + ansMin + ":" + ansSec);
    }
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

const int MAX = 1000000;
const int MOD = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<int>a(n+5);
    rep(i, 0, n)cin >> a[i];
    map<int, int>mp;
    rep(i, 0, n){
        mp[a[i]]=i;
    }
    int length = 0;
    int cnt = 1;
    rep(i, 1, n){
        if(mp[i] < mp[i+1]){
            cnt++;
        }else{
            length = max(length,cnt);
            cnt = 1;
        }
    }
    length = max(length,cnt);
    cout << n-length << endl;
}

Measured memory_bytes: 13536
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <map>
#include <cmath>
#include <cstdlib>

//using ll = long long;
using namespace std;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  char c=s[0];
  for(int i=1;i<s.size();++i){
    if(c=='x' && s[i]=='x'){
      cout<<i<<endl;
      return 0;
    }
    c=s[i];
  }
  cout<<n<<endl;
  return 0;
}



Measured memory_bytes: 3304
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

s=input()
s=s[::-1]
n=len(s)
i=0
while i<n:
    if s[i:i+5]=="esare":i+=5
    elif s[i:i+6]=="resare":i+=6
    elif s[i:i+5]=="maerd":i+=5
    elif s[i:i+7]=="remaerd":i+=7
    else:
        print("NO")
        exit()
else:
    print("YES")


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main () {
    int n;
    string s;
    cin >> n >> s;

    ll cnt = 0;
    ll rcnt = 0;
    ll gcnt = 0;
    ll bcnt = 0;
    REP(i, n) {
        char c = s[i];
        if(c == 'R') {
            rcnt++;
        } else if(c == 'G') {
            gcnt++;
        } else {
            bcnt++;
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            char ci = s[i];
            char cj = s[j];
            int k = (2*j)-i;
            char ck = s[k];
            

            if(k < n && ci != cj && ci != ck && cj != ck) {
                cnt++;
            }
        }
    }

    cout << (rcnt*gcnt*bcnt) - cnt;

}

 


Measured memory_bytes: 3608
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  long n;
  cin>>n;
  long long arr[n];
  long long k=0;
  for (long i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  long long r;
  for (long j=0;j<(n-1);j++)
  {
    r=arr[j+1]-arr[j];
    if (r<0)
    {
      k=k-r;
      arr[j+1]=arr[j+1]-r;
    }
  }
  cout<<k<<endl;
  return 0;
}

Measured memory_bytes: 5148
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
local str2tbl = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
--
local N = read.nl()
local R = {}
for i=1,N do
    local s, p = read.l():split()
    table.insert(R, string.format("%s %03d %d", s, 100-tonumber(p), i))
end
table.sort(R)
for _,v in ipairs(R) do
    local c,pp,i = v:split()
    print(i)
end


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define int long long
using namespace std;
//Position this line where user code will be pasted.

int M = 1e9 + 7;

int nCr[2001][2001];

int32_t main() {
    
	int n, k;

    cin>>n>>k;

    for(int i=0;i<2001;i++){
        for(int j=0;j<2001;j++){
            if(i == j) nCr[i][j] = 1;
            else if(i == 0) nCr[i][j] = 0;
            else if(j == 0) nCr[i][j] = 1;
            else nCr[i][j] = (nCr[i-1][j-1] + nCr[i-1][j])%M;
        }
    }

    for(int i=1;i<=k;i++){
        int ans = 0;
        ans = (nCr[n-k+1][i]*nCr[k-1][i-1])%M;
        cout<<ans<<endl;
    }

    


}

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

using namespace std;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, t = 1;
    long long k;
    cin >> n >> k;
    vector<int> tv, vtv(n + 1, false);
    int tt[n + 1];
    for (int i = 1; i <= n; ++i) cin >> tt[i];

    while (--k && !vtv[t]) {
        vtv[t] = true;
        tv.push_back(t);
        t = tt[t];
    }

    if (!k) {
        cout << tt[t];
        return 0;
    }

    int dist = distance(tv.begin(), find(tv.begin(), tv.end(), t));
    k %= tv.size() - dist;

    cout << tt[*(tv.begin() + dist + k)];

    return 0;
}


Measured memory_bytes: 5476
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
using namespace std;


int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 1; i < N - 1; i++) {
	  bool fa[26] = { };
	  bool fb[26] = { };
	  for (int j = 0; j < i; j++) {
		  fa[S[j] - 'a'] = true;
		}
	  for (int j = i; j < N; j++) {
		  fb[S[j] - 'a'] = true;
		}
	  int c = 0;
	  for (int j = 0; j < 26; j++) {
		  if (fa[j] && fb[j]) {
			  c++;
			}
		}
	  ans = max(ans, c);
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N = int(input())
    ans = [0,0,0,0]
    for _ in range(N):
        s = input()
        if s == 'AC':
            ans[0] += 1
        elif s == 'WA':
            ans [1] += 1
        elif s == 'TLE':
            ans[2] += 1
        else:
            ans[3] += 1
    print('AC x '+str(ans[0]))
    print('WA x '+str(ans[1]))
    print('TLE x '+str(ans[2]))
    print('RE x '+str(ans[3]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9472