akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
AB = list( list(map(int, input().split())) for _ in range(M) )

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

  
ans_lst = [0] * (M+1)
ans_lst[0] = N * (N - 1) // 2

uf = UnionFind(N)
cnt = 1
for a,b in AB[::-1]:
  if uf.same(a-1, b-1):
    ans_lst[cnt] = ans_lst[cnt-1]
    #print(uf.all_group_members())
  else:
    #print(uf.size(a-1), uf.size(b-1))
    ans_lst[cnt] = ans_lst[cnt-1] - uf.size(a-1) * uf.size(b-1)
    uf.union(a-1,b-1)
    #print(uf.all_group_members())
  cnt += 1

for m in range(1,M+1):
  print(ans_lst[M-m])

Measured memory_bytes: 34640
#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n;
  cin >> n;
  map<string, int> ma;

  rep(i, n) {
    string s;
    cin >> s;
    ma[s]++;
  }
  int mx = 0;
  for (auto it : ma) {
    mx = max(mx, it.second);
  }
  // map内部ではkeyが昇順になるようになっているのでソートはしない
  for (auto it : ma) {
    if (mx == it.second) cout << it.first << endl;
  }

  return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin>>n;
  if(n[0]==n[1]&&n[1]==n[2])cout<<"Yes"<<endl;
  else if(n[1]==n[2]&&n[2]==n[3])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int> x(n);
	rep(i, n) cin >> x[i];

	int ans = 0;

	rep(i, n) {
		ans += min(2*abs(x[i]), 2*abs(x[i] - k));
	}

	dunk(ans);

	return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  char b,ans;
  cin >> b;
  if(b=='A'){
    ans = 'T';
  }
  if(b=='T'){
    ans = 'A';
  }
  if(b=='C'){
    ans = 'G';
  }
  if(b=='G'){
    ans = 'C';
  }
  cout << ans<< endl;
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<LL> a(N);
    for(int i = 0;i < N;i++)    cin >> a[i];
    LL ans = 200*200*100+1;
    for(int i = -100;i <= 100;i++){
        LL count = 0;
        for(int j = 0;j < N;j++){
            count += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans, count);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

g = [[] for _ in range(N+1)]
ig = [[] for _ in range(N+1)]
for _ in range(M):
    x, y = map(int, input().split())
    g[x].append(y)
    ig[y].append(x)

dp1 = [0] * (N+1)
dp2 = [0] * (N+1)
dp3 = [0] * (N+1)
dp1[1] = 1

for i in range(1, N+1):
    for j in ig[i]:
        dp1[i] += dp1[j]/len(g[j])
df = 0
for i in range(N, 0, -1):
    for v in g[i]:
        dp2[i] += (dp2[v]+1)/len(g[i])
        if len(g[i]) != 1:
            dp3[i] += (dp2[v]+1)/(len(g[i])-1)
    for v in g[i]:
        if len(g[i]) != 1:
            pv = dp3[i] - (dp2[v]+1)/(len(g[i])-1)
            df = max(df, dp1[i]*(dp2[i]-pv))
print(dp2[1]-df)


Measured memory_bytes: 62300
#include <stdio.h>

int month[]={-99999,20,19,20,19,20,19,20,19,20,19};

int diff(int y,int m,int d){
	int sum=0,i;
	for(i=y+1;i<=999;i++){
		if(i%3==0){
			sum+=200;
		}else{
			sum+=195;
		}
	}
	for(i=m+1;i<=10;i++){
		if(y%3==0){
			sum+=20;
		}else{
			sum+=month[i];
		}
	}
	if(y%3==0)
		sum+=20-d+1;
	else
		sum+=month[m]-d+1;
	return sum;
}

int main(){
	int i,n,y,m,d;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d\n",&y,&m,&d);
		printf("%d\n",diff(y,m,d));
	}
	return 0;
}

Measured memory_bytes: 600
N, K = map(int, input().split(" "))
Values = list(map(int, input().split(" ")))
maxS = 0

for garbage in range((K+1)//2):
    for i in range(K-garbage+1):
        catch = []
        if K-garbage >= N:
            catch = Values
        else:
            catch = Values[0:K-garbage-i] + Values[N-i:N]
        S = sum(catch)
        catch = sorted(catch)
        tmp = garbage
        for c in catch:
            if tmp == 0 or c >= 0:
                break
            S -= c
            tmp -= 1
        maxS = max(S, maxS)
print(maxS)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;

int n,m,c,a,b[20],sum=0,ans=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n>>m>>c;
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		sum=0;
		for(int j=0;j<m;j++){
			cin>>a;
			sum+=(a*b[j]);
		}
		sum+=c;
		if(sum>0)
			ans++;
	}
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 256
# 値の入力
C=str(input())

result=""

Alfa=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

# 処理
result=Alfa[Alfa.index(C)+1]

print(result) 

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int C = ni();
        int[] s = new int[N];
        int[] t = new int[N];
        int[] c = new int[N];
        int[] tt = new int[(int)200002];
        int[] sm = new int[(int)200002];
        for (int i = 0; i < N; i++) {
            s[i] = ni();
            t[i] = ni();
            c[i] = ni()-1;
        }
        for (int i = 0; i < C; i++) {
            for (int j = 0; j < tt.length; j++) {
                tt[j] = 0;
            }
            for (int j = 0; j < N; j++) {
                if(c[j] == i){
                    tt[s[j]*2-1]++;
                    tt[t[j]*2]--;
                }
            }
            for (int j = 1; j < tt.length; j++) {
                tt[j] += tt[j-1];
            }
            for (int j = 0; j < tt.length; j++) {
                if(tt[j]>0) sm[j]++;
            }
            // for (int j = 0; j < 40; j++) {
            //     System.out.print(tt[j]);
            // }
            // System.out.println();
        }
        int ans = 0;
        for (int i = 0; i < sm.length; i++) {
            ans = Math.max(ans, sm[i]);
        }
        out.println(ans);
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 58068
#include<iostream>
using namespace std;
int main() {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if (
    x - r >= 0 &&
    x + r <= w &&
    y - r >= 0 &&
    y + r <= h
  ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main() {
    int N, count, a, b, f, i;

    scanf("%d", & N);

    count = 0;
    for (a = 1; a <= N; a++) {
        f = 0;
        for (b = 1; b <= N; b++) {
            i = a * b;
            if (i >= N) {
                break;
            }
            count++;
            f = 1;
        }
        if (!f) {
            break;
        }
    }

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

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = 0;
    REP(i, N-1){
    	res += A[i]/2;
    	A[i] = A[i]%2;
    	if(A[i] == 1 && A[i+1] > 0){
    		res++;
    		A[i]--;
    		A[i+1]--;
    	}
    }
    res += A[N-1]/2;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

#define yes printf("Yes\n")
#define Yes printf("YES\n")
#define no printf("No\n")
#define No printf("NO\n")

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = max(a, b);
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = min(a, b);
		return true;
	}
	return false;
}

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

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

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

/*map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}*/

int n, ans;
int a, b, c, d, e;
map<int, int>mp;
vector<int>v;
void factring(int n) {
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++mp[i];
		}
	}
	if (n != 1) ++mp[n];
	return;
}
signed main() {
	cin >> n;
	rep(i, n) {
		factring(i + 1);
	}
	for (P p : mp) {
		int m = p.second + 1;
		if (75 <= m) a++;
		if (25 <= m) b++;
		if (15 <= m) c++;
		if (5 <= m) d++;
		if (3 <= m) e++;
	}
	cout << a + b * (e - 1) + c * (d - 1) + d * (d - 1) * (e - 2) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Integer n = sc.nextInt();
		Integer x = sc.nextInt();
		Integer[] a = new Integer[n + 1];
		Integer[][] b = new Integer[n + 1][n];
		Long result = Long.MAX_VALUE;
		for (int i = 1; i <= n; i++) {
			a[i] = sc.nextInt();
		}
		for (int k = 0; k < n; k++) {
			Long cost = (long) k * x;
			for (int i = 1; i <= n; i++) {
				if (k == 0) {
					b[i][k] = a[i];
				} else {
					if (i > k) {
						b[i][k] = Math.min(b[i][k - 1], a[i - k]);
					} else {
						b[i][k] = Math.min(b[i][k - 1], a[i - k + n]);
					}
				}
				cost += b[i][k];
			}
			if (cost < result) {
				result = cost;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 111340
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr 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;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<int>h(N);
	rep(i, N)cin >> h[i];
	vector<int>dp(N, INF);
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	REP(i, 2, N) {
		int a = dp[i - 1] + abs(h[i - 1] - h[i]);
		int b = dp[i - 2] + abs(h[i - 2] - h[i]);
		dp[i] = min(a, b);
	}
	cout << dp[N - 1] << "\n";

	return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S =="Sunny")
    cout << "Cloudy" <<endl;
  else if(S == "Cloudy")
    cout << "Rainy" << endl;
  else if (S == "Rainy")
    cout << "Sunny" << endl;
}


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

vi dx = {0, 0, -1, 1};
vi dy = {-1, 1, 0, 0};

int op(int a, int b) {
    return max(a, b);
}

int e() {
    return -1;
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &(a[i]));
    }

    int m = 300005;
    segtree<int, op, e> seg(m);


    int res = 0;
    rep(i, n) {
        int t = seg.prod(max(0, a[i]-k), min(m, a[i]+k+1));
        int s = seg.get(a[i]);

        if (s < t+1) {
            seg.set(a[i], t+1);
            res = max(res, t+1);
        }
    }

    cout << res+1 << endl;
    


    return 0;
}

Measured memory_bytes: 9620
num = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(num):
    cmd = input()
    if cmd == "AC":
        ac += 1
    elif cmd == "WA":
        wa += 1
    elif cmd == "TLE":
        tle+= 1
    elif cmd == "RE":
        re += 1

print("AC x "+ str(ac))
print("WA x "+ str(wa))
print("TLE x "+ str(tle))
print("RE x "+ str(re))


Measured memory_bytes: 9168
N,M = map(int,input().split())
N_ = []
M_ = []
for i in range(N):
  N_.append(list(input()))
  
for i in range(M):
  M_.append(list(input()))

for i in range(N-M+1):
  for j in range(N-M+1):
    count = 0
    for p in range(M):
        for q in range(M):
          if N_[i+q][j+p] == M_[p][q]:
            count = count + 1
    if count == M*M:
      break
  else:
      continue
  break
if count == M*M:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, x, ans = 0;
	cin >> N >> x;
	vector <int> a(N);
	rep(i, N)
		cin >> a[i];
	sort(ALL(a));
	rep(i, N-1) {
		x -= a[i];
		if (x >= 0)
			ans++;
	}
	if (x == a[N - 1])
		ans++;
	cout << ans;
}

Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
restaurants = defaultdict(list)
for i in range(n):
    s, p = input().split()
    p = int(p)
    restaurants[s].append([p, i])

cnt = 0
for k, v in sorted(restaurants.items(), key=lambda x: x[0]):
    for p, i in sorted(v, key=lambda x: -x[0]):
        print(i + 1)


Measured memory_bytes: 3316
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] input = Console.ReadLine().Split(' ');
            int r = int.Parse(input[0]);

            int m = 3 * (r * r );

            Console.WriteLine(m.ToString());
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
ll sa(ll a, ll b) {
	if (a < b)
		swap(a, b);
	ll r = a % b;
	ll x = a * b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return x / b;
}
 
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = 0;
	ans += b / c - (a - 1) / c;
	ans += b / d - (a - 1) / d;
	ans -= b / sa(c, d) - (a - 1) / sa(c, d);
	cout << b - a - ans + 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a1(n);
    vector<int> a2(n);
    for(int i=0; i<n; i++){
        cin >> a1[i];
    }
    for(int i=0; i<n; i++){
        cin >> a2[i];
    }
    int tmp=0;
    int mx=0;
    for(int i=0; i<n; i++){
        tmp = 0;
        for(int j=0; j<n; j++){
            if(j>i){
                tmp += a2[j];
            }else if(j==i){
                tmp += a1[j];
                tmp += a2[j];
            }else{
                tmp += a1[j];
            }
            //cout << tmp << " ";
        }
        mx = max(mx,tmp);
       //cout << tmp << endl;
    }
    cout << mx << endl;
}




Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

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

    int H[N];
    for (int i=0; i<N; ++i) cin >> H[i];

    sort(H, H+N);

    int min = INT_MAX;
    for (int i=0; (i+K-1)<N; ++i)
    {
        int val = H[i+K-1]- H[i];
        if (val < min) min = val;
    }

    cout << min << endl;

    return 0;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	map<int,int>mp;
    map<int,int>::iterator it;


	f(i,0,n-1)
	{
	    cin>>k;

	    if(mp[k]==0){
            mp[k]=1;
	    }
	    else if(mp[k]==1){
            mp[k]=0;
	    }
	}

    for(it=mp.bb;it!=mp.ee;it++){
        if(it->se==1) count++;
    }
    cout<<count<<endl;

}


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


int main(){
 ll n;
 cin>>n;
 ll ans = 0;
 for(ll i=2;i*i<=n;i++){
  ll cnt = 0;
  while( n%i == 0 ){
   n/=i;
   cnt++;
  }
 // cout<<i<<' '<<cnt<<endl;
  for(ll j=1;j<=cnt;j++){
   if( cnt-j >= 0 ){
    cnt-=j;
    ans++;
   }
  }

 }
 if( n != 1 ) ans++;
 cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
S = readline().decode().rstrip()
ans = ''
A = ord('A')
for i in range(len(S)):
    char = chr(A + (ord(S[i])+N-A)%26)
    ans += char
print(ans)

Measured memory_bytes: 9092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			StringTokenizer st=new StringTokenizer(br.readLine());
			int n=Integer.parseInt(st.nextToken());
			int x=Integer.parseInt(st.nextToken());

			if(n==0 && x==0) {
				break;
			}

			int count=0;
			for(int a=1;a<=n;a++){
				for(int b=1;b<=n;b++) {
					for(int c=0;c<=n;c++) {
						if(a+b+c==x && a<b && b<c) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}



Measured memory_bytes: 25680
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int n;
    cin >> n;
    vll a(n);
    forn(i, n) cin >> a[i];
    ll ans = a[0] / 2;
    a[0] %= 2;
    forn1(i, n){
        if (a[i - 1] >= 1 && a[i] >= 1){
            a[i - 1]--, a[i]--, ans++;
        }
        ans += a[i] / 2;
        a[i] %= 2;
    }
    cout << ans << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s) {
	return '"' + s + '"';
}
string debug_string(bool b) {
	return (b ? "true" : "false");
}
string debug_string(const char* s) {
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string {
	template<typename...>
	static int f(...) {
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a) {
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p) {
	string s = "(";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += ")";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0;i < n;++i) {
		cin >> a[i].first;
		a[i].second = i + 1;
	}
	sort(a.begin(), a.end());
	for (auto x : a) {
		cout << x.second << ' ';
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const int INF = 1001001001;

int main(){
    int d;
    cin>>d;
    int c[26];
    for(int i=0;i<26;i++)cin>>c[i];
    int s[d][26];
    for(int i=0;i<d;i++)for(int j=0;j<26;j++){
        cin>>s[i][j];
    }
    int t[d];
    int score=0;
    int last[26]={};
    for(int i=1;i<=d;i++){
        int con=-1,maxs=-INF;
        for(int j=0;j<26;j++){
            int tmp=0;
            tmp+=(i-last[j])*c[j];
            tmp+=s[i-1][j];
            if(tmp>maxs){
                maxs=tmp;
                con=j;
            }
        }
        t[i-1]=con+1;
        score+=s[i-1][con];
        last[con]=i;
        for(int j=0;j<26;j++){
            score-=(i-last[j])*c[j];
        }
        cout<<t[i-1]<<endl;
    }
}

Measured memory_bytes: 3688
N, P = map(int, input().split())

def factorize(n):
    from collections import defaultdict
    d = defaultdict(int)
    for i in range(2, int(n**0.5)+1):
        while n%i==0:
            d[i] += 1
            n //= i
        if not n:
            break
    if n>1:
        d[n] += 1
    return d

d = factorize(P)
ans = 1
for i, j in d.items():
    ans *= (i ** (j//N))
print(ans)

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

typedef struct edge { int u, v, w;} E;
typedef struct graph {
  E e[200008];
  int vcnt, ecnt;
  int id[100004];
} G;

int esort(const void *a, const void *b){
  E *x, *y;
  x = (E *)a; y = (E *)b;
  if(x->u < y->u) return -1;
  if(x->u > y->u) return  1;
  if(x->v < y->v) return -1;
  return 1;
}

void MakeGraph(G *g, int n, int m){
  g->vcnt = n; g->ecnt = 2 * m;
  int p, q, d;
  for(int i = 0; i < m; i++){
    scanf("%d %d %d", &p, &q, &d);
    p--; q--;
    g->e[2 * i].u = p;
    g->e[2 * i].v = q;
    g->e[2 * i].w = d;
    g->e[2 * i + 1].u = q;
    g->e[2 * i + 1].v = p;
    g->e[2 * i + 1].w = d;
  }

  qsort(g->e, g->ecnt, sizeof(E), esort);

  p = 0;
  for(int i = 0; i < g->vcnt; i++){
    while(p < g->ecnt && g->e[p].u < i) p++;
    g->id[i] = p;
  }
  g->id[g->vcnt] = g->ecnt;
}

//dfs
void coloring(int k, int c, G *g, long long *d, int *s){
  s[k] = c;
  for(int i = g->id[k]; i < g->id[k + 1]; i++){
    if(s[(g->e[i]).v] == 0){
      d[g->e[i].v] = d[k] + (long long)g->e[i].w;
      if((d[g->e[i].v] & 1) == 0){
	coloring(g->e[i].v, 1, g, d, s);
      }else{
	coloring(g->e[i].v, -1, g, d, s);
      }
    }
  }
  return;
}

int
main(int argc, char *argv[])
{
  int n; G g;
  scanf("%d", &n);
  MakeGraph(&g, n, n - 1);


  
  int s[100001] = {}; long long d[100001] = {};
  coloring(0, 1, &g, d, s);
  

  for(int i = 0; i < n; i++) printf("%d\n", (s[i] + 1) / 2);

  return 0;
}


Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int x;cin>>x;
    int y=1;
    while(true){
        if(360*y%x==0){
            cout<<360*y/x<<endl;
            return 0;
        }
        y++;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long  long 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;


  
int main()
{
	#ifndef ONLINE_JUDGE


		 freopen("input.txt","r",stdin);
		 freopen("output.txt","w",stdout); 

	#endif

    ll k;
    cin>>k;
   
    ll sum=0;
  for (int i = 0; i <1000000; ++i)
  {

    sum=sum*10+7;
    sum=sum%k;
    if(sum==0)
     {
      cout<<i+1;
      return 0;
    }
  }
  cout<<-1;
      
return 0;
}




Measured memory_bytes: 3588
/**
*    created: 05.05.2020 05:25:15
**/

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

int main() {
    int n=0;
    //n(a-1)+1>=ba
    int a,b;
    cin >> a>>b;
    while(n*(a-1)+1<b){
        n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mk make_pair
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
string s[500];
int h,w,sum=0;
vector<int>x,y;
void del(int t1,int t2){
  vector<pair<char,pair<int,int> > >p;
  for(int i=t1;i<h;i++)if(s[i][t2]!='.'){
    p.push_back(mk(s[i][t2],mk(i,t2)));
    break;
  }
  for(int i=t1;i>=0;i--)if(s[i][t2]!='.'){
    p.push_back(mk(s[i][t2],mk(i,t2)));
    break;
  }
  for(int i=t2;i<w;i++)if(s[t1][i]!='.'){
    p.push_back(mk(s[t1][i],mk(t1,i)));
    break;
  }
  for(int i=t2;i>=0;i--)if(s[t1][i]!='.'){
    p.push_back(mk(s[t1][i],mk(t1,i)));
    break;
  }
  sort(p.begin(),p.end());
  if(p.size()>=2){
    r(i,p.size()-1){
      if(p[i].first==p[i+1].first){
        sum++;
        s[p[i].second.first][p[i].second.second]='.';
        s[p[i+1].second.first][p[i+1].second.second]='.';
      }
    }
  }
}
int main(){
  cin>>h>>w;
  r(i,h)cin>>s[i];
  r(i,h)r(j,w)if(s[i][j]!='.'){
      y.push_back(i),x.push_back(j);
      if(i+1<h)y.push_back(i+1);
      if(j+1<w)x.push_back(j+1);
    }
  r(k,10)r(i,y.size())r(j,x.size())
    if(s[y[i]][x[j]]=='.')del(y[i],x[j]);
  cout<<sum*2<<endl;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int maxsize = 2010;

class Combination {
   public:
    Combination(int n) {
        fac = new ll[n];
        inv = new ll[n];
        finv = new ll[n];
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        REP(i, 2, n) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    ll cnr(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

   private:
    ll *fac, *inv, *finv;
};

ll power(ll n, ll p, ll mod) {
    ll ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ans;
}

ll modinv(ll n, ll mod) {
    return power(n, mod - 2, mod);
}

Combination comb(4 * maxsize);

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N);
    REP(i, 0, N) cin >> A[i] >> B[i];

    vector<vector<int>> dp(2 * maxsize, vector<int>(2 * maxsize, 0));
    REP(i, 0, N) dp[maxsize - A[i]][maxsize - B[i]]++;
    REP(i, 0, 2 * maxsize - 1) {
        REP(j, 0, 2 * maxsize - 1) {
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j] + dp[i][j + 1]) % MOD;
        }
    }
    
    ll ans = 0;
    REP(i, 0, N) ans = (ans + dp[maxsize + A[i]][maxsize + B[i]]) % MOD;
    REP(i, 0, N) ans = (MOD + ans - comb.cnr(2 * A[i] + 2 * B[i], 2 * A[i])) % MOD;
    cout << (ans * modinv(2, MOD)) % MOD << endl;
    return 0;
}

Measured memory_bytes: 65280
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n = I()
B = LI()

A = [0] * n

for i in range(1, n-1):
    A[i] = min(B[i-1], B[i])

A[0] = B[0]
A[n-1] = B[n-2]
print(sum(A))

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

char s[5001], t[6], c[5];
int k, n, l[6], i, j, iM;
int main() {
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  for (c[0] = 'a'; c[0] <= 'z'; ++c[0]) {
    t[0] = c[0];
    l[1 + 0] = -1;
    for (i = l[0], iM = n - 0; i < iM; ++i) {
      if (s[i + 0] != t[0]) continue;
      l[1 + 0] = i;
      break;
    }
    if (l[1] < 0) continue;
    if (k == 1) {
      printf("%s\n", t);
      return 0;
    }
    --k;
    for (c[1] = 'a'; c[1] <= 'z'; ++c[1]) {
      t[1] = c[1];
      l[1 + 1] = -1;
      for (i = l[1], iM = n - 1; i < iM; ++i) {
        if (s[i + 0] != t[0] || s[i + 1] != t[1]) continue;
        l[1 + 1] = i;
        break;
      }
      if (l[2] < 0) continue;
      if (k == 1) {
        printf("%s\n", t);
        return 0;
      }
      --k;
      for (c[2] = 'a'; c[2] <= 'z'; ++c[2]) {
        t[2] = c[2];
        l[1 + 2] = -1;
        for (i = l[2], iM = n - 2; i < iM; ++i) {
          if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2]) continue;
          l[1 + 2] = i;
          break;
        }
        if (l[3] < 0) continue;
        if (k == 1) {
          printf("%s\n", t);
          return 0;
        }
        --k;
        for (c[3] = 'a'; c[3] <= 'z'; ++c[3]) {
          t[3] = c[3];
          l[1 + 3] = -1;
          for (i = l[3], iM = n - 3; i < iM; ++i) {
            if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2] || s[i + 3] != t[3]) continue;
            l[1 + 3] = i;
            break;
          }
          if (l[4] < 0) continue;
          if (k == 1) {
            printf("%s\n", t);
            return 0;
          }
          --k;
          for (c[4] = 'a'; c[4] <= 'z'; ++c[4]) {
            t[4] = c[4];
            l[1 + 4] = -1;
            for (i = l[4], iM = n - 4; i < iM; ++i) {
              if (s[i + 0] != t[0] || s[i + 1] != t[1] || s[i + 2] != t[2] || s[i + 3] != t[3] || s[i + 4] != t[4]) continue;
              l[1 + 4] = i;
              break;
            }
            if (l[5] < 0) continue;
            if (k == 1) {
              printf("%s\n", t);
              return 0;
            }
            --k;
          }
          t[4] = 0;
        }
        t[3] = 0;
      }
      t[2] = 0;
    }
    t[1] = 0;
  }
}


Measured memory_bytes: 1668
from bisect import bisect_left
s=input()
t=input()
al=[[] for i in range(26)]
for i in range(len(s)):
    al[ord(s[i])-97].append(i)
ans=0
now=-1
ok=True
for i in range(len(t)):
    c=t[i]
    o=ord(c)-97
    b=bisect_left(al[o],now+1)
    if(b==len(al[o])):
        ans+=len(s)-now-1
        now=-1
        b=bisect_left(al[o],now)
        if(b==len(al[o])):
            ok=False
    if ok:
        ans+=al[o][b]-now
        now=al[o][b]
    else:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 45680
#include<bits/stdc++.h>
using namespace std;
#define  pb  push_back
queue<int>q;
int main()
{
    int i,j,n,m,x,y,f,mx=0;
    cin>>n>>m;
    int ind[n+2],dp[n+2];
    vector<int>v[n+2];
    memset(ind,0,sizeof(ind));
    memset(dp,0,sizeof(dp));
    for(i=0;i<m;i++)
    {
        cin>>x>>y;
        v[x].pb(y);
        ind[y]++;
    }
    for(i=1;i<=n;i++)
    {
        if(ind[i]==0)
        {
            q.push(i);
        }
    }
    while(!q.empty())
    {
        f=q.front();
        q.pop();
        for(auto y: v[f])
        {
            dp[y]=max(dp[y],1+dp[f]);
            mx=max(mx,dp[y]);
            ind[y]--;
            if(ind[y]==0)
            {
                q.push(y);
            }
        }
    }
    cout<<mx<<"\n";
    return 0;
}

Measured memory_bytes: 6528
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math


#N = int(input())
#A,B= map(int,input().split())
#P = list(map(int,input().split()))
S = str(input())
T = str(input())
c=0
for i in range(len(S)):
    if S[i]!=T[i]:
        c+=1
print(c)


Measured memory_bytes: 9348
def main():
    n = input()

    flag = True
    s, e = 0, len(n)
    while (s < e//2):
        if n[s] != n[e-s-1]:
            flag=False
            break
        s += 1
    if flag:
        print("Yes")
    else:
        print("No")
        

if __name__ == "__main__":
    main()

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

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

int main() {
    int n;
    cin >> n;
    if(n<1200){
        cout << "ABC" << endl;
    }else if(n<2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC"<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
nums=list(map(int,input().split()))
count=0
def merge(nums,left,mid,right):
    global count
    inf=10**9
    L=nums[left:mid]+[inf]
    R=nums[mid:right]+[inf]
    i=0
    j=0
    for k in range(left,right):
        count+=1
        if R[j]>=L[i]:
            nums[k]=L[i]
            i+=1

        else:
            nums[k]=R[j]
            j+=1

def merge_sort(nums,left,right):
    if left+1<right:
        mid=(right+left)//2
        merge_sort(nums,left,mid)
        merge_sort(nums,mid,right)
        merge(nums,left,mid,right)

merge_sort(nums,0,n)

def show(nums):
    l=len(nums)
    for i in range(l):
        if i!=l-1:
            print(nums[i],end=" ")
            
        else:
            print(nums[i])
            
show(nums)
print(count)


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

int main(){
  ll n;
  cin >> n;
  vl dp(100007, 0);
  for (ll i = 1; i * i * 6 <= n;i++){
    dp[6 * i * i]++;
  }
  for (ll i = 1; 3*i*i <= n;i++){
    for (ll j = i + 1; 3*i * i + j * j <= n;j++){
      dp[3 * i * i + j * j + 2 * i * j] += 3;
    }
  }
  for (ll i = 1; 6 * i * i <= n; i++){
    for (ll j = i + 1; i * i + 3 * j * j <= n;j++){
      dp[3 * j * j + i * i + 2 * i * j] += 3;
    }
  }
  for (ll i = 1; 6 * i * i <= n;i++){
    for (ll j = i + 1; i * i + j * j + i * j <= n;j++){
      for (ll k = j + 1; i * i + j * j + k * k <= n;k++){
        dp[i * i + j * j + k * k + i * j + j * k + k * i] += 6;
      }
    }
  }
  for (ll i = 1; i <= n;i++){
    print(dp[i]);
  }
}


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

using namespace std;
typedef long long ll;

int main()
{
    string s,t;
    cin >> s >> t;
    int x=0;
    for(int i = 0 ; i <s.size() ; i++)
    {
        if(s[i]!=t[i])
            x++;
    }
    cout << x;
    return 0;
}


Measured memory_bytes: 3900