akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;

int main(){
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll numlr = 0, numrl = 0;
    ll ans = 0;
    for(int i = 0; i < n - 1; ++i){
        if(s.at(i) == 'L' && s.at(i + 1) == 'R'){
            numlr++;
        }else if(s.at(i) == 'R' && s.at(i + 1) == 'L'){
            numrl++;
        }
        if(s.at(i) == s.at(i + 1)){
            ans++;
        }
    }
    ll op2 = min(k, min(numlr, numrl));
    ans += 2 * op2;
    k -= op2;
    numlr -= op2;
    numrl -= op2;
    if(k > 0 && numlr > 0 && s.back() == 'R'){
        k--;
        ans++;
        numlr--;
    }
    if(k > 0 && numlr > 0 && s.front() == 'R'){
        k--;
        ans++;
        numlr--;
    }
    if(k > 0 && numrl > 0 && s.back() == 'L'){
        k--;
        ans++;
        numrl--;
    }
    if(k > 0 && numrl > 0 && s.front() == 'L'){
        k--;
        ans++;
        numrl--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from decimal import * 
from math import ceil
N = int(input())
T,A = 1,1
for i in range(N):
    Ti,Ai = map(int,input().split())
    r = Decimal(max(ceil(T/Ti),ceil(A/Ai)))
    T,A = Ti*r,Ai*r
print(T+A)


Measured memory_bytes: 5332
const input = require("fs").readFileSync("/dev/stdin", "utf8")
const lines = input.split('\n')
const [A, B, H, M] = lines[0].split(' ').map(Number)

const radH = (H * 30 + M / 2) * ( Math.PI / 180 )
const radM = M * 6 * ( Math.PI / 180 )

const posHX = Math.cos(radH) * A
const posHY = Math.sin(radH) * A

const posMX = Math.cos(radM) * B
const posMY = Math.sin(radM) * B

const dist = Math.sqrt(Math.pow(posHX - posMX, 2) + Math.pow(posHY - posMY, 2))
console.log(dist)

Measured memory_bytes: 29728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

#define MAX_N 100000
struct UF{
    int par[MAX_N];
    int rank[MAX_N];
    int si[MAX_N];

    void init(int n){
        rep(i,n){
            par[i] = i;
            rank[i] = 0;
            si[i] = 1;
        }
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        
        if(rank[x] < rank[y]){
            par[x] = y;
            si[y] += si[x];
        } else{
            par[y] = x;
            if(rank[x] == rank[y]) rank[x]++;
            si[x] += si[y];
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
} uf;

int n;
int a[100000];

int main() {
    cin >> n;
    uf.init(n);
    rep(i,n) cin >> a[i];
    {
        bool zero = true;
        rep(i,n) if (a[i] != 0) zero = false;
        if (zero) {
            cout << "Yes" << endl;
            return 0;
        }
        if (n%3 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i,30) {
        int cnt = 0;
        int root = -1;
        rep(j,n) {
            if ((a[j]>>i) & 1) cnt++;
        }
        if (cnt != 0 && cnt != 2*(n/3)) {
            cout << "No" << endl;
            return 0;
        }
        if (cnt != 0) {
            rep(j,n) {
                if (!((a[j]>>i) & 1)) {
                    if (root == -1) root = j;
                    else uf.unite(root, j);
                }
            }
        }
    }
    rep(i,n) {
        if (i != uf.par[i]) continue;
        if (uf.si[i] > n/3) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  ll ans = 0;
  for (int l = 0, r = 0, v = a[0]; l < n; l++) {
    for (; r < n - 1 && (a[r + 1] & v) == 0;) v |= a[++r];
    ans += r - l + 1;
    v &= ~a[l];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		for (int k = 0; k < a.length; k++) {
			if (k == a.length - 1) {
				System.out.println(a[k]);
			} else {
				System.out.print(a[k] + " ");
			}
		}
		for (int i = 1; i < a.length; i++) {

			int v = a[i];
			int j = i - 1;
			while (j >= 0 && a[j] > v) {
				a[j + 1] = a[j];
				j--;
				a[j + 1] = v;

			}
			for (int k = 0; k < a.length; k++) {
				if (k == a.length - 1) {
					System.out.println(a[k]);
				} else {
					System.out.print(a[k] + " ");
				}
			}
		}
		


	}

}


Measured memory_bytes: 31208
using System;

class AGC019A
{
	static public void Main(string[] args)
	{
		int Q,H,S,D;
		int N;
		string[] vals = Console.ReadLine().Split(' ');
		Q = int.Parse(vals[0]);
		H = int.Parse(vals[1]);
		S = int.Parse(vals[2]);
		D = int.Parse(vals[3]);
		N = int.Parse(Console.ReadLine());
		
		long cost2l = long.MaxValue;;
		int q2l = Q * 8;
		int h2l = H * 4;
		int s2l = S * 2;
		int d2l = D;
		if(cost2l > q2l)
			cost2l = q2l;
		if(cost2l > h2l)
			cost2l = h2l;
		if(cost2l > s2l)
			cost2l = s2l;
		if(cost2l > d2l)
			cost2l = d2l;

		long cost1l = long.MaxValue;
		int q1l = Q * 4;
		int h1l = H * 2;
		int s1l = S;
		if(cost1l > q1l)
			cost1l = q1l;
		if(cost1l > h1l)
			cost1l = h1l;
		if(cost1l > s1l)
			cost1l = s1l;
		Console.WriteLine((N / 2) * cost2l + (N % 2) * cost1l);
	}

}


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

vector<int> anntena(5);
int k;

int main() {
  for (int i = 0; i < 5; i++) {
    cin >> anntena[i];
  }
  cin >> k;
  sort(anntena.begin(), anntena.end());
  string ans = (anntena[4] - anntena[0] > k) ? ":(" : "Yay!";
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = gets.chomp.split(' ').map(&:to_i)
shops = []
n.times { |i| shops << gets.chomp.split(' ').map(&:to_i) }
num = 0
money = 0

shops.sort_by { |s| s[0] }.each do |shop|
  shop[1].times do |i|
    money += shop[0]
    num += 1
    break if num == m
  end
  break if num == m
end

puts money

Measured memory_bytes: 12664
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>

using namespace std;

long long int conbi(long long int n) {
	return n * (n - 1) / 2;
}

int main() {
	int n;
	vector<int> a;
	map<int,int> v;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v[a[i]]++;
	}
	long long int allc = 0;
	for (auto x : v) {
		allc += conbi(x.second);
	}
	for (int i = 0; i < n; i++) {
		cout << allc - (v[a[i]] - 1) << endl;
	}
	

	return 0;
}


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

string color[8] = {
	"black","blue","lime","aqua","red","fuchsia","yellow","white"
};
int dr[8] = {0,0,0,0,255,255,255,255};
int dg[8] = {0,0,255,255,0,0,255,255};
int db[8] = {0,255,0,255,0,255,0,255};

int to_i(string s){
	int n=0;

	if( s[0] >= '0' && s[0] <= '9' ){
		n += (s[0]-'0')*16;
	}else{
		n += (s[0]-'a'+10)*16;
	}
	if( s[1] >= '0' && s[1] <= '9' ){
		n += s[1] - '0';
	}else{
		n += s[1] - 'a' + 10;
	}
	return n;
}

vector<int> to_RGB(string s){
	vector<int> c;
	c.push_back( to_i( s.substr(1,2) ) );
	c.push_back( to_i( s.substr(3,4) ) );
	c.push_back( to_i( s.substr(5,6) ) );
	return c;
}

int d(int r,int rk,int g,int gk,int b,int bk){
	return (r-rk)*(r-rk) + (g-gk)*(g-gk) + (b-bk)*(b-bk);
}

int main(){
	string s;
	while( cin >> s , s != "0" ){
		vector<int> c = to_RGB( s );
		int ans = 200000;

		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			ans = min( ans , dk );
		}
		for(int i=0 ; i < 8 ; i++ ){
			int dk = d( c[0] , dr[i] , c[1] , dg[i] , c[2] , db[i] );
			if( dk == ans ){
				cout << color[i] << endl;
				break;
			}
		}
	}
}

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

int main(){
    int N, K;
    cin >> N >> K;
    string S; cin >> S;
    if(S.at(K-1)=='A') S.at(K-1)='a';
    if(S.at(K-1)=='B') S.at(K-1)='b';
    if(S.at(K-1)=='C') S.at(K-1)='c';
    cout << S << endl;
}

Measured memory_bytes: 256
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <complex>
using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;

typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;

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

//repetition
//------------------------------------------
#define FOR(t,a,b) for(int t=(a);t<(b);++t)
#define REP(t,n)  FOR(t,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;



const LL mod = 1000000007;

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

#define Yes_ cout<<"Yes"<<endl; return 0;
#define No_ cout<<"No"<<endl; return 0;


#define YES_ cout<<"YES"<<endl; return 0;
#define NO_ cout<<"NO"<<endl; return 0;

#define POSSIBLE cout<<"POSSIBLE"<<endl; return 0;
#define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0;

int main() {

	int a, b, c;
	string s;
	cin >> a >> b;

	cout << ((b>=a)? a:a-1) << endl;


}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

for check in list(Counter(read().rstrip().decode()).values()):
    if check % 2 == 1:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 3316
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;

int main() {
	int N; cin >> N;
	cout << N * (N + 1) / 2 << endl;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll 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;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    int h, n;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        h -= a;
    }
    if(h <= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int K,S; cin >> K >> S;
    ll ans = 0;
    reps(i,0,K){
        reps(j,0,K){
            if(S - i - j >= 0 && S-i-j<=K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement, dropwhile
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

def base10to(n, b):  # b < 0 is OK!
    if n == 0:
        return "0"
    ret = []
    while n != 0:
        r = n % b
        if r < 0:
            r += abs(b)
        n = (n-r)//b
        ret.append(str(r))
    return "".join(reversed(ret))

n = I()
print(base10to(n, -2))


Measured memory_bytes: 63340
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main() {
	ll N, L;
	cin >> N >> L;
	ll ans = (N * (N + 1)) / 2 + N * (L - 1);
	if (L > 0) {
		cout << ans - L << endl;
	}
	else if (L + N - 1 < 0) {
		cout << ans - (L + N - 1) << endl;
	}
	else {
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
//Name: Mirror Cave
//Level: 3
//Category: シミュレーション,幅優先探索,BFS
//Note:

/*
 * [Lの位置][Rの位置]を状態にして幅優先探索する。
 */
#include <iostream>
#include <string>
#include <queue>
 
using namespace std;
 
const int dr[] = {0, -1, 0, 1};
const int dc[][4] = {
    {1, 0, -1, 0},
    {-1, 0, 1, 0}
};

inline bool in_range(int a, int x, int b) {
    return a <= x && x < b;
}

int hash(const pair<int,int> &p) {
    return p.first*50 + p.second;
}

pair<int,int> unhash(int n) {
    return make_pair(n/50, n%50);
}

struct Tag {
    pair<int,int> pos[2];

    Tag() {}
    Tag(pair<int,int> *pa) {
        pos[0] = pa[0];
        pos[1] = pa[1];
    }

    void get(pair<int,int> *pa) const {
        pa[0] = pos[0];
        pa[1] = pos[1];
    }
};

bool solve() {
    int W, H;
    cin >> W >> H;
    if(!W && !H) return false;

    vector<string> field[2];
    pair<int,int> starts[2];
    for(int r = 0; r < H; ++r) {
        string a, b;
        cin >> a >> b;
        field[0].push_back(a);
        field[1].push_back(b);
    }
    for(int i = 0; i < 2; ++i) {
        for(int r = 0; r < H; ++r) {
            for(int c = 0; c < W; ++c) {
                if(field[i][r][c] == "LR"[i]) {
                    starts[i] = make_pair(r, c);
                    field[i][r][c] = '.';
                }
            }
        }
    }

    queue<Tag> q;
    vector<vector<unsigned char> > memo(2500, vector<unsigned char>(2500, 0));
    memo[hash(starts[0])][hash(starts[1])] = 1;
    q.push(starts);
    bool ans = false;
    while(!q.empty()) {
        const Tag t = q.front();
        //cout << t.pos[0].first << ' ' << t.pos[0].second << ' ';
        //cout << t.pos[1].first << ' ' << t.pos[1].second << endl;
        q.pop();

        for(int dir = 0; dir < 4; ++dir) {
            pair<int,int> np[2];
            t.get(np);
            int goalcnt = 0;
            for(int i = 0; i < 2; ++i) {
                int nr = np[i].first + dr[dir];
                int nc = np[i].second + dc[i][dir];
                if(in_range(0, nr, H) && in_range(0, nc, W)) {
                    switch(field[i][nr][nc]) {
                        case '#':
                            nr = np[i].first;
                            nc = np[i].second;
                            break;
                        case '%':
                            goalcnt++;
                            break;
                    }
                } else {
                    nr = np[i].first;
                    nc = np[i].second;
                }
                np[i] = make_pair(nr, nc);
            }
            if(goalcnt == 2) {
                ans = true;
                goto end;
            } else if(goalcnt == 0) {
                const int h1 = hash(np[0]);
                const int h2 = hash(np[1]);
                if(!memo[h1][h2]) {
                    memo[h1][h2] = 1;
                    q.push(Tag(np));
                }
            }
        }
    }
end:
    cout << (ans ? "Yes" : "No") << endl;
    return true;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
     
    for(; solve(); ) ;
    return 0;
}

Measured memory_bytes: 8368
N, X, Y = map(int, input().split())
dist_dict = {k:0 for k in range(1, N)}

def calc_dist(i,j):
  if i <= X:
    if j <= X: return j - i
    if X < j <= Y: return min(j - i, X - i + 1 + Y - j)
    if Y < j: return min(j - i, X - i + 1 + j - Y)
  elif X < i <= Y:
    if j <= Y: return min(j - i, i - X + 1 + Y - j)
    if j > Y: return min(j - i, i - X + 1 + j - Y)
  else:
    return j - i


for i in range(1, N):
  for j in range(i+1, N+1):    
    dist = calc_dist(i,j)
    dist_dict[dist] += 1

for k in range(1, N):
  print(dist_dict[k])

Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
  static class Solver {
    // int INF = (1 << 30) - 1;
    // long L_INF = (1L << 62) - 1;
    // long MOD = (long) 1e9 + 7;

    int S, W;
    // int[] A;

    // write your code
    public void solve(InputReader in, PrintWriter out) {
      S = in.nextInt();
      W = in.nextInt();
      //   A = new int[N];
      //   for (int i = 0; i < N; i++) {
      //     A[i] = in.nextInt();
      //   }

      if (S <= W) {
        out.println("unsafe");
      } else {
        out.println("safe");
      }
    }

    void debug(Object... os) {
      System.err.println(Arrays.deepToString(os));
    }
  }

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    Solver solver = new Solver();
    solver.solve(in, out);
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
  }
}


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


#define ll long long int
#define ld long double
#define mod 998244353
#define big 1e18+10
#define small -big
#define pb push_back



template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}


vector<ll> A[200005];
bool visited[200005];
ll N, M;
ll ma = 0;
set<ll> g;

void dfs(ll v) {
        if(visited[v]) {
                return;
        }
        
        visited[v] = true;
        

        
      g.insert(v);
        
        for(auto it : A[v]) {
                if(!visited[it]) {
                            dfs(it);
                }
        }
}
void solve() {
            
            memset(visited, false, sizeof(visited));
            
            
            cin >> N >> M;
            
            for(ll i = 1; i <= M; i++) {
                    ll a, b;
                    cin >> a >> b;
                    A[a].pb(b);
                    A[b].pb(a);
            }
        
            
           for(ll i = 1; i <= N; i++) {
                if(!visited[i]) {
                        g.clear();
                        dfs(i);
                        ma = max(ma, ((ll) g.size()));
                }
           }
           
         
            cout << ma << endl;
       
        
           
       
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   

    int t=1;
    //cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 33464
import copy
def bubble(array):
    flag = set()
    for i in range(n):
        for j in range(1, n):
            if (array[j-1][1] > array[j][1]):
                tmp = array[j-1]
                array[j-1] = array[j]
                array[j] = tmp

    return array

def selection(array):
    flag = set()
    for i in range(0, n):
        minimum = i
        for j in range(i, n):
            if (array[j][1] < array[minimum][1]):
                minimum = j
        tmp = array[minimum]
        array[minimum] = array[i]
        array[i] = tmp

    return array

n = int(input())
array = input().split(" ")

for alg in [bubble, selection]:
    thirteen = [[] for _ in range(13)]
    for elmnt in array:
        thirteen[int(elmnt[1])-1].append(elmnt)
    sorted_ary = alg(copy.copy(array))

    sorted13 = [[] for _ in range(13)]
    for elmnt in sorted_ary:
        sorted13[int(elmnt[1])-1].append(elmnt)

    isStable = True
    print(" ".join(sorted_ary))
    for x, y in zip(thirteen, sorted13):
        if (x != y):
            isStable = False
    if isStable:
        print("Stable")
    else:
        print("Not stable")



Measured memory_bytes: 6348
#include<iostream>
#include<climits>
#include<cmath>
#define inf 1000000000
using namespace std;

void solve(int *a,int n)
{
	long long dp[n+1];
	dp[1]=0;
	for(int i=2;i<=n;i++)	
	{
		int op1=dp[i-1]+abs(a[i-1]-a[i]);
		int op2=(i==2)?inf:dp[i-2]+abs(a[i-2]-a[i]);
		dp[i]=min(op1,op2);
	}
	cout<<dp[n];
}
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	cin>>a[i];
	solve(a,n);
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int n,m; cin >> n >> m;
    int lmax=1, rmin=n, l, r;
    for(int i=0;i<m;++i) {
        cin >> l >> r;
        lmax = max(lmax, l);
        rmin = min(rmin, r);
    }
    cout << max(0, rmin-lmax+1) << endl;
    return 0;
}


Measured memory_bytes: 256
import Control.Applicative

type Sheet = [[Int]]

type Problem = (Int, Sheet)

type Result = Sheet

solve :: Problem -> Result

solve (cols, sheet)
    = nrows ++ [lower] where
        nrows = [row ++ [sum row] | row <- sheet]
        lower = [sum [row !! col | row <- nrows] | col <- [0..cols]]

output :: Result -> String

output sheet
    = init.concat $ [(init.concat $ [show x ++ " " | x <- row]) ++ "\n" | row <- sheet]
    
input :: IO Problem

input
    = do
        [rows, cols] <- map read.words <$> getLine
        sheet <- inputSheet rows []
        return (cols, sheet)
        
inputSheet :: Int -> Sheet -> IO Sheet

inputSheet 0 sheet
    = return sheet
    
inputSheet rows sheet
    = do
        row <- map read.words <$> getLine
        inputSheet (rows - 1) $ sheet ++ [row]
    
main :: IO ()

main
    = putStrLn.output =<< solve <$> input

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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}


int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    int a[n+1];
    rep(i,1,n+1) cin >> a[i];
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=1; i<=k; i++) sum+=a[i];
    cout << sum;
    return 0;
}


Measured memory_bytes: 3664
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var N int
	var A, B int

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &A)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &B)

	ps := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &ps[i])
	}

	fst := 0
	snd := 0
	thd := 0

	for _, p := range ps {
		if p <= A {
			fst++
		} else if A < p && p <= B {
			snd++
		} else {
			thd++
		}
	}

	fmt.Println(min(fst, snd, thd))
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
#include <iostream>
#include<string.h>
using namespace std;
int main(void){
    // Here your code !
    int n,p;
    cin>>n>>p;
    long long int a[n];
    long long int ans[n+1][2];
    
    memset(a,0,n*sizeof(int));
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    ans[0][0]=1;
    ans[0][1]=0;
    
     for(int i=0;i<n;i++){
        if(a[i]%2-1){
            ans[i+1][0]=ans[i][0]*2;
            ans[i+1][1]=ans[i][1]*2;
        }
        else{
            ans[i+1][0]=ans[i][0]+ans[i][1];
            ans[i+1][1]=ans[i][0]+ans[i][1];
        }
    }
    
    
    cout<<ans[n][p];
}


Measured memory_bytes: 256
#include<stdio.h>
 
 
int main(){
 
    int a[3][3], x , b[10], check[3][3];
 
    for(int i = 0 ; i < 3 ; i++ ) {
        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    }

    scanf("%d",&x);
    
    for(int j = 0 ; j < x ; j++ ){
        scanf("%d",&b[j]);
 
        for(int  l = 0 ; l < 3 ; l++ ) {
            for(int k = 0 ; k < 3 ; k++ ){
                if( b[j] == a[l][k] ) {
                    check[l][k] = 1;
                }
            }   
        }
    }   
    
    if( (check[1][1] == 1 && check[2][2] == 1 && check[0][0] == 1  )
    || (check[2][0] == 1 && check[1][1] == 1 && check[0][2] == 1  )
    || (check[0][0] == 1 && check[0][1] == 1 && check[0][2] == 1  )
    || (check[1][0] == 1 && check[1][1] == 1 && check[1][2] == 1  )
    || (check[2][0] == 1 && check[2][1] == 1 && check[2][2] == 1  )
    || (check[0][0] == 1 && check[1][0] == 1 && check[2][0] == 1  )
    || (check[0][1] == 1 && check[1][1] == 1 && check[2][1] == 1  )
    || (check[0][2] == 1 && check[1][2] == 1 && check[2][2] == 1  )
    ) {   
        printf("Yes\n");
    } else {
        printf("No\n");
    }

        return 0;
}

Measured memory_bytes: 1620
S=input()
s=''.join(list(reversed(S)))
a=S[:int((len(S)-1)/2)]
b=S[int((len(S)+3)/2)-1:]
c=''.join(list(reversed(a)))
d=''.join(list(reversed(b)))
if S==s and a==c and b==d:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include <cstdio>
using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	int sol = 0, streak = 0;
	for (int i = 1; i <= N; i++) {
		int x;
		scanf("%d", &x);
		if (x == i)
			streak++;
		else {
			sol += (streak + 1) / 2;
			streak = 0;
		}
	}
	sol += (streak + 1) / 2;

	printf("%d\n", sol);
		
	return 0;
}

Measured memory_bytes: 128
#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() {
    string s, t, ss;
    cin >> s >> t;
    ss = s + s;
    bool ok = false;
    rep(i,ss.size()) {
        if (ss.substr(i,s.size()) == t) ok = true;
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}



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

using namespace std;

const long long r = 1e9 + 7;

long long fac[200001];

long long f(long long a, long long p) {
	if (p == 1)
		return a;

	long long ret = f(a, p / 2);
	ret = ret * ret % r;
	if (p % 2 == 1)
		ret = ret * a % r;

	return ret;
}

long long c(int n, int m) {
	return fac[n] * f(fac[m] * fac[n - m] % r, r - 2) % r;
}

int main() {
	fac[0] = 1;
	for (int i = 1; i <= 200000; ++i)
		fac[i] = fac[i - 1] * i % r;

	int n, m, a, b;
	scanf("%d %d %d %d", &n, &m, &a, &b);
	a = n - a;

	long long ans = 0;
	for (int i = 1; i <= a; ++i) 
		ans = (ans + c(b + i - 2, b - 1) * c(m - b + n - i - 1, n - i) % r) % r;

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	int p, d1, d2, mah, mad;
	while(cin >> n && n)
	{
		mad = -1;

		rep(i, n)
		{
			cin >> p >> d1 >> d2;

			if(mad < d1 + d2)
			{
				mad = d1 + d2;
				mah = p;
			}
		}
		
		cout << mah << " " << mad << endl;
	}
}

Measured memory_bytes: 864
// catch me if you can :)
#include <bits/stdc++.h>
#define int long long
#define hash hashhash
#define X first
#define Y second
#define endl "\n"
#define Mp make_pair
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
inline int in(){int32_t x ; scanf("%d",&x) ; return x ; }
inline long long lin(){long long x ; scanf("%lld",&x) ; return x ;}
char ch[4000010];
inline string get(){ scanf("%s",ch) ; return string(ch) ; }
inline void read(int *a , int n ) { for (int i = 0 ; i < n ; i ++) a[i] = in() ; }
template <class blank> inline void out(blank x) {cout << x << endl ; exit(0) ;}
template <class blank , class blank2> inline void smin(blank &a , blank2 b) {a = a <= b ? a : b ;}
template <class blank , class blank2> inline void smax(blank &a , blank2 b) {a = a >= b ? a : b ;}
typedef pair<int , int > pii;
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vii;
const int maxn  = 1e5 + 10;
const int maxm = 4e6 + 10;
const int maxlg = 20;
const int base = 29;
const int mod = 1e9 + 7;
const int inf = 2e18 + 10;
const double eps = 1e-9;
int32_t main()
{
    int n = in();
    string s , t;
    cin >> s >> t;
    for (int esht = n ; esht >= 0 ; esht --)
    {
        bool fl = true;
        for (int j = n - esht ; j < n ; j ++)
            fl &= s[j] == t[j - (n - esht)];
        if (fl)
            out( 2 * n - esht);
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int x = sc.nextInt();
        int a = 0;
        int b = 1;				
        for(int i=0;i<n;i++){a+=sc.nextInt();
                             if(a<=x){b++;
                                     }
                            }        
		System.out.println(b);
	}
}


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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

//================================================
bool func(vector<LD>x, vector<LD>y) {
	if ((y[1] - y[0]) * (x[3] - x[2]) == (y[3] - y[2]) * (x[1] - x[0])) return true;
	else return false;	
}


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

	int num;
	cin >> num;

	vector<LD>x(4); vector<LD>y(4);
	while(num--) {
		REP(i, 4) cin >> x[i] >> y[i];
		cout << (func(x, y) ? "YES" : "NO") << "\n";
	}
	return 0;
}

Measured memory_bytes: 3256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int m = 1e9+7;
ll dp[45][1<<20];
int main() {
    int n,x,y,z,l,mask,fbd;
    scanf("%d%d%d%d", &n, &x, &y, &z);
    l = x+y+z-1;
    mask = (1<<l)-1;
    fbd = (1 << (x+y+z-1)) | (1 << (y+z-1)) | (1 << (z-1));
    dp[0][0] = 1;
    for(int i=0;i<n;i++){
        for(int a=1;a<=10;a++){
            for(int s=0;s< 1<<l;s++){
                int t = (s << a) | (1 << (a-1));
                if ((fbd & t) == fbd)continue;
                dp[i+1][t & mask] += dp[i][s];
                dp[i+1][t & mask] %= m;
            }
        }
    }
    ll ans = 1;
    for(int i=0;i<n;i++)ans = ans*10%m;
    for(int s=0;s<l<<l;s++)ans = (ans-dp[n][s]+m)%m;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 82176
/*Bismillahir Rahmanir Rahim
->>Code by Ashraful Islam Paran
->>CUET,CSE
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define f(a,b,x) for(int a=b;a<x;a++)
#define pb push_back
#define endl "\n"
#define MX 200000
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define vi vector<int>

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int x,n,p[101],a=0,ans=0,b=0,ans2=0,y;
    cin>>x>>n;
    y=x;
    f(i,0,n)
    {
        cin>>p[i];
        if(p[i]==x)
        {
            a=1;
        }
    }
    if(!a)
    {
        cout<<x<<endl;
    }
    else
    {
        while(1)
        {
            b=0;
            x--;
            f(i,0,n)
            {
                if(p[i]!=x)
                {
                    b++;
                }
            }
            if(b==n)
            {
                ans=x;
                break;
            }
        }
        while(1)
        {
            b=0;
            x++;
            f(i,0,n)
            {
                if(p[i]!=x)
                {
                    b++;
                }
            }
            if(b==n)
            {
                ans2=x;
                break;
            }
        }
        if((y-ans)==(ans2-y))
        {
            cout<<min(ans,ans2)<<endl;;
        }
        else if(y-ans<ans2-y)
        {
            cout<<ans<<endl;
        }
        else
        {
            cout<<ans2<<endl;
        }

    }
    //cout<<ans<<" "<<ans2<<endl;
    //if(x-ans)
    return 0;
}


Measured memory_bytes: 3644
// inputに入力データ全体が入る
function Main(input) { 	
  	var args = input.split("\n");  	
  	var num = parseInt(args[0], 10); // 移動回数
  	var plan = []; // 移動計画
  	var position = [0, 0] // 自己位置
  	var judge = "";
  	
  	for(var i=1; i<args.length; i++){
      plan.push(args[i].split(" ").map(n => parseInt(n,10)))
    }
  
  	for(var i=0; i<num; i++){
      	if(i!=0){
          	// 前回の時間を引いた数が今回の時間
			var t = plan[i][0] - plan[i-1][0];
        }else{
        	var t = plan[i][0]; 
        }
      	var x = plan[i][1];
      	var y = plan[i][2];
      
      	// 移動し時間を進める
   		if(i!=0){   
        	x_move = x-plan[i-1][1];
      		y_move = y-plan[i-1][2];
        }else{
        	x_move = x;
      		y_move = y;
        }
      /*
      console.log("x: "+x);
      console.log("y: "+y);
      console.log("t: "+t);
      console.log("x_move: "+x_move);
      console.log("y_move: "+y_move);
      */
      	
      	// 移動量と時間の偶奇が一致したら可能
      	if( (x_move+y_move)<=t && (Math.abs(x_move)+Math.abs(y_move))%2 === t%2 ){
			judge = "Yes";         	 
        }else{
         	judge = "No" 
          	break;
        }
    }
  
  	console.log(judge);
}

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

Measured memory_bytes: 50624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<vector>
#define ll long long
using namespace std;

const ll mod = 998244353;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

void exgcd(ll &x,ll &y,ll a,ll b)
{
	if (b==0)
	{
		x=1;y=0;
		return;
	}
	exgcd(x,y,b,a%b);
	ll tmp = x;
	x=y;
	y=tmp-a/b*y;
}

ll x,y;
ll gc;
ll inv[1000010];
ll ans;
ll n,a,b,k;

ll qsm(ll i,ll j)
{
	ll ans=1;
	i%=mod;
	while (j)
	{
		if (j&1) ans=ans*i%mod;
		i=i*i%mod;
		j>>=1;
	}
	return ans;
}

int main()
{
  cin>>n>>a>>b>>k;
  inv[0]=1;
  if ((a+b)*n<k) 
  {
  	cout<<0;
  	return 0;
  }
  for (int i=1;i<=n;i++) inv[i]=inv[i-1]*i%mod;
  for (int i=0;i<=n;i++)
  {
  	ll tmp = k-a*i;
  	if (tmp%b==0)
  	{
  		ll y = tmp/b;
  		if (y>n || y<0) continue;
  		if (i>n) continue;
  		ans=ans+inv[n]*qsm(inv[i],mod-2)%mod*qsm(inv[n-i],mod-2)%mod*inv[n]%mod*qsm(inv[y],mod-2)%mod*qsm(inv[n-y],mod-2)%mod;
  		ans%=mod;
	}
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 4352
#include <stdio.h>
int a[105];
int t, sum;
int main(void)
{
	int n;
	scanf("%d", &n);
	scanf("%d", &t);
	a[0] = a[1] = t;
	for(int i = 1; i < n - 1; i++)
	{
	 	scanf("%d", &t);
		if(a[i] > t)
			a[i] = t;
		a[i + 1] = t;
	}
	for(int i = 0; i < n; i++)
	{
		sum += a[i];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
(n,_),*s=[[*map(int,t.split())]for t in open(0)]
d=[1,-1]+[c:=0]*2*n
for i in range(n):
 c=(c+d[i])%998244353
 for l,r in s:d[i+l]+=c;d[i-~r]-=c
print(c)

Measured memory_bytes: 24740
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}
var mod = 998244353;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  invs.length=n+1,invs[0]=invs[1]=1;
  for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  //pow2.length=n+1,pow2[0]=1;
  //for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],inv(fac[r]),inv(fac[n-r]));}
function npr(n,r){return mul(fac[n],finv[r]);}
function mput(n){return (n%mod+mod)%mod;}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var [n,m,k] = nexts(3);
  var ans = 0;
  fset(Math.max(n,m));
  for(var i = 0; i <= k; i++){
    var t = ncr(n-1,i);
    t = mul(m,t);
    t = mul(t,pow(m-1,n-1-i));
    ans += t;
  }
  return ans % mod;
}

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

int main() {
    int n;
    string s;

    cin >> n >> s;

    int c = 0;
    int size = s.size();
    string a = "ABC";
    for (int i = 0; i < size - 2; ++i) {
        string temp = "";
        temp += s[i];
        temp += s[i+1];
        temp += s[i+2];
        if (temp == a) {
            c++;
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<string.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int x;
    set<int>st;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        st.insert(x);
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys

(x, n) = map(int, sys.stdin.readline().strip().split())
list_input = list(map(int, input().split()))

if x not in list_input:
    print(x)
    exit()

for i in range(1, n+1):
    if x - i not in list_input:
        print(x-i)
        exit()
    elif x + i not in list_input:
        print(x+i)
        exit()


Measured memory_bytes: 61808
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#include<deque>
#define rep(i,rept)	for(int i = 0; i<(ll)rept;++i)
typedef long long ll;
using namespace std;

//25日目

int n = 0, m = 0, ans = 0;
int a[50] = {}, b[50] = {};
bool graph[50][50] = {};//つながっているかを保存する
bool visited[50] = {};//頂点について、探索済みかどうか保存する
bool bridge = false;//橋があったかどうか確認する


void dfs(int x) {
	if (visited[x] == true) {
		return;
	}
	visited[x] = true;
	rep(i, n) {
		if (graph[x][i] == true) {
			dfs(i);
		}
	}
}



int main() {

	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}

	rep(i, m) {

		//辺を一つずつ取り除いていく
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

		rep(j, n) {
			visited[j] = false;
		}

		dfs(0);

		bridge = false;
		rep(k, n) {
			if (visited[k] == false) {
				bridge = true;
			}
		}
		if (bridge == true) {
			ans++;
		}


		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;

	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
using namespace std;
const int N=1e5+5;
int n,m; ll len,x,y,w; char s[N],t[N];
int main(){
	scanf("%d%d%s%s",&n,&m,s+1,t+1); len=(ll)n/__gcd(n,m)*m;
	x=len/n,y=len/m; w=__gcd(x,y);
	for (ll i=1,j=1;i<=n&&j<=m;i+=y/w,j+=x/w)
		if (s[i]!=t[j]) return puts("-1"),0;
	printf("%lld\n",len);
	return 0;
}

Measured memory_bytes: 384
mod = 10**9+7

def prepare(n, mod):
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%mod
    invs = [1]*(n+1)
    invs[n] = pow(facts[n], mod-2, mod)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % mod
    return facts, invs

def make_combi(facts,invs,n,r,mod):
    return facts[n]*invs[r]*invs[n-r]%mod

n,k = map(int,input().split())
a = list(map(int,input().split()))
facts, invs = prepare(n,mod)
a.sort()

mi_sum = 0
ma_sum = 0

for i,j in enumerate(a):
    if i+1 >= k:
        ma_sum += j*make_combi(facts,invs,i,k-1,mod)
        ma_sum %= mod
    if n-i >= k:
        mi_sum += j*make_combi(facts,invs,n-i-1,k-1,mod)
        mi_sum %= mod

print((ma_sum-mi_sum)%mod)

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

int main(){
    using namespace std;

    long N, x;
    cin >> N >> x;

    vector<long> a(N);
    for(auto& i : a)cin >> i;

    sort(a.begin(), a.end());
    partial_sum(a.begin(), a.end(), a.begin());

    if(x > a[N - 1])cout << N - 1 << endl;
    else cout << upper_bound(a.begin(), a.end(), x) - a.begin() << endl;
}

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

int f(const void *a,const void *b){
  return *(double*)b-*(double*)a;
}

int main(){
  int N;
  double v[55];
  double S=0.0,P=2.0;
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%lf",v+i);
  qsort(v,N,sizeof(double),f);
  for(int i=0;i<N;i++){
    S+=v[i]/P;
    if(i<N-2) P*=2.0;
  }
  printf("%lf\n",S);
  return 0;
}

Measured memory_bytes: 1732
/*
  ------------------------- Hachiikung ---------------------------------
  ---------------------- Worrachate Bosri ------------------------------
  ------ Faculty of Computer Engineering Chulalongkorn University ------
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i,FN) for(int i=0;i<FN;i++)
#define FOR(i,ST,FN) for(int i=ST;i<=FN;i++)
#define FORD(i,FN,ST) for(int i=FN;i>=ST;i--)
#define FORX(i,c) for(typeof(c.begin())i=c.begin();i!=c.end();i++)
#define pause system("pause")
#define S scanf
#define P printf
#define X first
#define Y second
#define pb push_back
#define PII pair<int,int>
#define mp make_pair
#define sz size()
#define eps 1e-8

const int MOD(1000000007);
const int INF((1<<30)-1);
const int MAXN(100005);

long long x[MAXN], y[MAXN];

int main(){

    int n,m;
    S("%d%d",&n,&m);
    REP(i,n)
        S("%lld",&x[i]);
    REP(i,m)
        S("%lld",&y[i]);

    sort(x,x+n);
    sort(y,y+m);

    long long sumx, sumy = 0, ans = 0;

    REP(i,m-1)
    {
        sumy += (y[i+1]-y[i])*(i+1)%MOD*(m-i-1)%MOD;
        sumy %= MOD;
    }

    REP(i,n-1)
    {
        sumx = (x[i+1]-x[i])*(i+1)%MOD*(n-i-1)%MOD;
        ans += sumx*sumy%MOD;
        ans %= MOD;
    }

    cout << ans << endl;

}


Measured memory_bytes: 1792