akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let (n,m,x) = {
        let xs = read_vec_i64();
        (xs[0] as usize, xs[1] as usize, xs[2])
    };
    let xs = read_vec_i64();
    let t = xs.iter().fold(0, |t, &y| if y < x { t + 1 } else { t });
    let res = min(t, m-t);
    println!("{}", res);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {

  string s, t;
  cin >> s >> t;

  const string hoge = "UNRESTORABLE";
  if (s.size() < t.size()) {
    cout << hoge << endl;
    return 0;
  }

  for (int i = 0; i + t.size() <= s.size(); i++) {
    bool ok = true;
    rep(j, t.size()) { ok &= s[i + j] == t[j]; }
    if (ok) {
      string u = "";
      rep(j, s.size()) {
        if (s[j] == '?')
          u += "a";
        else
          u += s[j];
      }
      cout << u << endl;
      return 0;
    }
  }

  vector<string> cand;
  for (int i = 0; i + t.size() <= s.size(); i++) {
    bool ok = true;
    rep(j, t.size()) {
      if (s[i + j] == '?')
        continue;
      ok &= s[i + j] == t[j];
    }
    if (ok) {
      string u = "";
      rep(j, i) {
        if (s[j] == '?')
          u += "a";
        else
          u += s[j];
      }
      u += t;
      for (int j = i + t.size(); j < s.size(); j++) {
        if (s[j] == '?')
          u += "a";
        else
          u += s[j];
      }
      cand.push_back(u);
    }
  }

  if (cand.size() > 0) {
    sort(cand.begin(), cand.end());
    cout << cand[0] << endl;
  } else {
    cout << hoge << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

b = [1] * N
b[0] = -1
for i in range(M):
    x, y = map(int, input().split())
    if b[x - 1] < 0:
        b[x - 1] += 1
        if b[y - 1] >= 0:
            b[y - 1] = -(b[y - 1] + 1)
        else:
            b[y - 1] -= 1
    else:
        b[x - 1] -= 1
        if b[y - 1] >= 0:
            b[y - 1] += 1
        else:
            b[y - 1] -= 1
print(len([x for x in b if x < 0]))


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

int main()
{
	long long k,pro=0;
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int l=1;l<=k;l++)
			{
				pro+=__gcd(i,__gcd(j,l));
			}
		}
	}
	cout<<pro;
}

Measured memory_bytes: 3636
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]
for i in range(N - M + 1):
    for j in range(N - M + 1):
        if all([A[i+x][j+y] == B[x][y] for x in range(M) for y in range(M)]):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
struct way{
	int cost,time;
}a[1000];
bool cmp(way x,way y){
	/*if(x.cost<y.cost){
		return x.cost;
	}
	else{
		return y.cost;
	}*/
	return x.cost<=y.cost;
}
int main(){
	int n,t,ans=1010;
	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>a[i].cost>>a[i].time;
		if(a[i].time>t) a[i].cost=1010;
	}
	for(int i=0;i<n;i++){
		if(a[i].cost<ans) ans=a[i].cost;
	}
	if(ans==1010) cout<<"TLE";
	else{
		cout<<ans;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define se set<ll>
#define vec vector<ll>
#define inf 10000000000000000
bool mark[100005];
vec adj[100005];
ll counter;
vec cnt;
vector<string> forsubs;
ll b;
ll a;

void addedge(ll u, ll v)

	{
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

bool dfs(ll node)
	{
		cout<<node<<endl;
		mark[node]=1;
		

		for(auto i:adj[node])
		{	
			if(!mark[i])
				dfs(i);
		}			

			
	}

void substring(string s,int n)
	{
		for(auto i=0;i<n;i++)
			{
				for(auto len=1;len<=n-i;len++)
					forsubs.push_back(s.substr(i,len));
			}
	}	

int main()
{    
 

	#ifdef APNA_IO
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

ll n;
cin>>n;
ll sum=0;
int square_root = (int) sqrt(n)+1;

for(auto i=1;i<square_root;i++)
	{
		if(n%i==0)
		{
			ll m=n/i-1;
			if(m>i)
			sum+=m;

			ll j=i-1;
			if(j>i)
				sum+=j;

		}
	}
	
cout<<sum;

}		





Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <set>
#include <deque>
#include <map>
#include <iomanip>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
using namespace std;
int ky[8] = {-1,1,-2,2,-2,2,-1,1}; 
int kx[8] = {-2,-2,-1,-1,1,1,2,2};
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int ddy[8] = {-1,0,1,-1,1,-1,0,1};
int ddx[8] = {-1,-1,-1,0,0,1,1,1};
typedef long long ll;
#define pi pair
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define rep1(i,a,b) for(int i = a; i < b; i++)
#define rep2(i,a,b) for(int i = a; i <= b; i++) 
#define INF 999999999999
const double PI = acos(-1.0); 
ll n;
long double ans;
ll a[100000];
bool ok;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    ans = 1LL;
    rep1(i,0,n) cin >> a[i];
    sort(a,a+n);

    rep1(i,0,n){
        ans *= a[i];
        if(ans > (ll)1e18){
            ok = true;
            break;
        }
    }

    if(ok) cout << -1;
    else cout << (ll)ans;
	return 0;
}


Measured memory_bytes: 4396
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
      	int b = Integer.parseInt(sc.next());
      
      	int result = 1 <= a & a < 10 && 1 <= b && b < 10 ? a*b : -1;
      	System.out.println(result);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define iiMPQ priority_queue<ii,vector<ii>,greater<ii> >
#define MPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define iiUS unordered_set<ii>
#define ST stack<int>
#define MS multiset<int>
#define scan1(n) cin>>n
#define scan2(a,b) cin>>a>>b
#define scan3(a,b,c) cin>>a>>b>>c
#define print(n) cout<<n
#define println(n) cout<<n<<"\n"
#define vi vector<int>
#define vii vector<ii>
#define viii vector<iii>
#define fi first
#define se second
#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,s,e) for(int i=s;i<e;++i)
#define REPS(i,s,e,st) for(int i=s;i<e;i+=st)
#define rep(i,n) for(int i=n-1;i>=0;--i)
#define repr(i,s,e) for(int i=s;i>=e;--i)
#define reps(i,s,e,st) for(int i=s;i>=e;i-=st)
#define SET(arr,k) memset(arr,k,sizeof arr)
#define speed ios::sync_with_stdio(0); cin.tie(0);
#define mp make_pair
#define pb push_back
#define Qu queue
#define Vt vector
#define Dq deque
#define prints(n) cout << n << " ";

void m1(){
  int n; string s;
  cin >> n >> s;
  int red = 0, res = 1023456789;
  for(int i=0;i<n;++i){
    if(s[i] == 'R') ++red;
  }
  res = min(red, n-red);
  int white = 0;
  for(int i=0;i<red;++i){
    if(s[i] == 'W') ++white;
  }
  res = min(res, white);
  cout << res;
}
/* 
void m2(){
  int t; scan1(t);
  while(t--) m1();
}
*/
 
signed main(){
  speed;
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}


Measured memory_bytes: 3772
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n - 1):
  a, b = map(int, input().split())
  g[a - 1].append(b - 1)
  g[b - 1].append(a - 1)
li = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  li[p - 1] += x
s = [0]
done = [0] * n
done[0] = 1
while s:
  d = s.pop()
  for node in g[d]:
    if done[node] == 0:
      li[node] += li[d]
      s.append(node)
      done[node] = 1
print(' '.join(map(str, li)))


Measured memory_bytes: 66848
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N;
	string c;
	cin >> N >> c;
	int W = 0, R = 0;
	rep(i, N)if (c[i] == 'W')W++;
	R = N - W;
	int nw = 0;
	rep(i, R)if (c[i] == 'W')nw++;
	int nr = 0;
	rep(i, W) {
		int j = N - 1 - i;
		if (c[j] == 'R')nr++;
	}
	int ans = max(nw, nr);
	cout << ans;
}

Measured memory_bytes: 3728
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<int> a(n+10);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        if(a[i]%2 == 0 && a[i]%3 != 0 && a[i]%5 != 0){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;

 }

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

int main()
{
    long long int N,k;
    while(cin>>N>>k){
    long long int x,d;
    if(N%k==0){
        x=0;
        goto en;
    }
    if(N<k){
        d=k-N;
        if(d>N){
            x=N;
        }
        if(d<=N){
            x=d;
        }
        goto en;
    }
    if(N>k){
        d=N/k;
        long long int n=d*k;
        N=N-n;
        while(N>=0){
            N=N-k;
        }
        x=-N;
        goto en;
    }
    en :
    cout<<x<<endl;
    }
}

Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    *A, = map(int, input().split())

    A.sort()

    print(sum(A[:K]))


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9232
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    string s;cin>>s;
    int n=s.length();
    V<int>ans(n);
    for(ll i=0;i<n;i++)ans[i]=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='R'){
            if(s[i+1]=='L'){
                ans[i]+=1;
                ans[i+1]+=1;
            }
        }
    }
    int cnt=0;
    for(ll i=0;i<n;i++){
        if(s[i]=='R'&&s[i+1]!='L'){
            cnt++;
        }
        else if(s[i]=='R'&&s[i+1]=='L'){
            ans[i]+=cnt/2;
            ans[i+1]+=cnt/2;if(cnt%2!=0)ans[i+1]++;
            cnt=0;
        }
    }
    cnt=0;
    for(ll i=n-1;i>=0;i--){
        if(s[i]=='L'&&s[i-1]!='R'){
            cnt++;
        }
        else if(s[i]=='L'&&s[i-1]=='R'){
            ans[i]+=cnt/2;
            ans[i-1]+=cnt/2;if(cnt%2!=0)ans[i-1]++;
            cnt=0;
        }
    }
    for(int i=0;i<n;i++)cout<<ans[i]<<" ";
        cout<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------








































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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);

	string A, B, C;
	cin >> A >> B >> C;
	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include <iomanip>
using namespace std;
int main(){
    int N, M;
    int a[200000];
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        cin >> a[i];
    }
    long long count[200000];
    int inc = 0;

    count[0] = 1;
    if(a[inc] == 1){
        count[1] = 0;
        inc++;
    }
    else{
        count[1] = 1;
    }


    for (int i = 2; i <= N; i++){
        if(i == a[inc]){
            count[i] = 0;
            inc++;
        }
        else{
            count[i] = count[i - 1] + count[i - 2];
            count[i] = count[i] % 1000000007;
        }
    }
    cout << count[N]  << endl;
    return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll r;
	cin>>r;
	ll ir=0;
	if(n>=10)
	{
		ir=r;
	}
	else
	{
		ir=r+(100*(10-n));
	}
	cout<<ir<<"\n";
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<int>v(N); for(auto& e :v) cin >> e;
  int mini = (1 << 30);

  for(int i = 1; i < N; ++i)
    mini = min(mini, abs(
      accumulate(v.begin(),v.begin() + i,0) - accumulate(v.begin() + i,v.end(),0)));
  cout << mini << endl;
}



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

int main(){ 
	int a,b;
	cin>>a>>b;
	int A[]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	if(A[a]==A[b]){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, dp[1001][1001], pref[mxn], a[mxn], sum = 0;

int main(){
    cin >> n;
    for (int i = 1; i <= 3 * n; i ++){
        cin >> a[i];
    }llong k = 3 * n;
    sort(1 + a, 1 + a + k);
    for (int i = n + 1; i <= 3 * n; i += 2){
        sum += a[i];
    }cout << sum;
    return 0;
}


Measured memory_bytes: 4352
s = input()
t = input()
flag = False
for i in range(len(s) - len(t) + 1):
    part = s[len(s) - len(t) - i: len(s) - i]
    flag2 = True
    for j in range(len(t)):
        if part[j] == t[j] or part[j] == "?":
            pass
        else:
            flag2 = False
            break
    if flag2 == True:
        flag = True
        ans = s[:len(s) - len(t) - i] + t + s[len(s) - i:]
        break
if flag == False:
    print("UNRESTORABLE")
else:
    print(ans.replace("?", "a"))

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


int main(){
	
	long long h;
	cin>>h;
	
	long long j=0;
	long long ans=0;
	while(h){
		h /=2;
		ans += pow(2,j);	
		j++;
		
		
	}
	cout<<ans;
	return 0;
}

//4 - 2 2 - 1 1 2 - 1 1 1 1 - 

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

int main(){
  int n; cin >> n;
  vector<int> a(n+2, 0);
  long long sum = 0;
  
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    sum += abs(a[i] - a[i-1]);
  }
  sum += abs(a[n] - a[n+1]);
  
  for(int i = 1; i <= n; i++){
    cout << sum - abs(a[i] - a[i-1])
      - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]) << endl;
  }
  
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(105), VMAX(1e5 + 5), mod(1e9 + 7);
int dp[N][VMAX], sp[VMAX], v[N], n, k;
int main() {
    DAU
    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
        cin >> v[i];
    dp[0][0] = 1;
    /// sp[x] - sum(dp[i][j]) j < x
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= k; ++j)
            sp[j + 1] = (sp[j] + dp[i-1][j]) % mod;
        for (int j = 0; j <= k; ++j)
            dp[i][j] = (sp[j + 1] - sp[max(0, j - v[i])] + mod) % mod;
    }
    cout << dp[n][k];
    PLEC
}

Measured memory_bytes: 40832
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		START:
		while(true){
			String in = sc.next();
			
			if("#".equals(in)){
				break;
			}
			
			String[] clauses = in.split("\\|");
			LOOP:
			for(String clause : clauses){
				clause = clause.substring(1, clause.length() - 1);
				String[] literals = clause.split("\\&");
				
				String[] vals = new String[literals.length];
				for(int i = 0; i < literals.length; i++){
					vals[i] = literals[i].length() == 1 ? literals[i] : literals[i].substring(1);
				}
				
				//System.out.println(Arrays.toString(vals));
				
				for(int i = 0; i < literals.length; i++){
					for(int j = i + 1; j < literals.length; j++){
						if(vals[i].equals(vals[j]) && !literals[i].equals(literals[j])){
							continue LOOP;
						}
					}
				}
				
				System.out.println("yes");
				continue START;
			}
			
			System.out.println("no");
		}
	}

}

Measured memory_bytes: 51756
import collections

def primes(x):
    res = []
    a = 2
    while x >= a*a:
        while x % a == 0:
            x //= a
            res.append(a)
        a += 1
    if x != 1:
        res.append(x)
    return res

x = int(input())
if x < 4:
    print(1)
else:
    for i in reversed(range(2,x+1)):
        p = primes(i)
        ctr = collections.Counter(p)
        cnt = ctr[p[0]]
        if cnt >= 2 and all([cnt == v for v in ctr.values()]):
            print(i)
            break


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

int main()
{
	int a, b, d,r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = (double)a /(double)b;
	cout << d << " " << r << " " <<fixed<<setprecision(5) << f << endl;
	return 0;
}


Measured memory_bytes: 3260
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void) {
	string s;
	cin >> s;
	int n = s.size();
	bool ok = true;
	string t = s;
	reverse(t.begin(), t.end());
	if (s != t) ok = false;

	string
		s1 = s.substr(0, (n - 1) / 2),
		t1 = s1,
		s2 = s.substr((n + 3) / 2 - 1),
		t2 = s2;
	reverse(t1.begin(), t1.end());
	reverse(t2.begin(), t2.end());
	if (s1 != t1) ok = false;
	if (s2 != t2) ok = false;
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=1e5+5;
const int mod=1e9+7;

int n,k,dp[N],a[105];
bool rec(int x){
    if(x<0) return 1;
    int &cache=dp[x];
    if(cache!=-1) return cache;
    cache=0;
    rep(i,1,n) cache|=(rec(x-a[i])==0);
    return cache;
}
signed main(){
    FastIO;
    cin>>n>>k;
    rep(i,1,n) cin>>a[i];
    memset(dp,-1,sizeof dp);
    cout<<(rec(k)?"First":"Second");
    return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int N;
  cin >> N;
  int a[N];
  ll ans=0;
  rep(i,N){
    cin >> a[i];
  }
  sort(a,a+N);
  int t=1;
  rep1(i,N-1){
    if(a[i]==a[i-1]){
      t++;
       if(i==N-1){
	 if(t>a[i]){
	   ans += t-a[i];
	 }
	 else if(t<a[i]){
	   ans += t;
	 }
       }
    }
    else{
      if(t>a[i-1]){
	ans += t-a[i-1];
      }
      else if(t<a[i-1]){
	ans += t;
      }
      if(i==N-1){
	if(a[i]==1){}
	else ans++;
      }
      t=1;
    }
  }
  if(N==1){
    if(a[0]==1) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
  }
  
  cout << ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 640
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

A, B, K = map(int, input().split(" "))

a_divisor = divisor(A)
b_divisor = divisor(B)

print(sorted(list(set(a_divisor) & set(b_divisor)), reverse=True)[K-1])

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;

ll power(ll x,ll y) 
{   
    x%=mod;
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
}

int main()
{
    IOS

  ll n,m;
  cin>>n>>m;
  pll a[m];
  for(ll i=0;i<m;i++)
  {
    cin>>a[i].ff>>a[i].ss;

  }
  sort(a,a+m,[](pll x,pll y){return x.ss<y.ss;});
  ll last=a[0].ss-1;
  ll ans=1;
  for(ll i=1;i<m;i++)
  {
    if(a[i].ff>last)
    {
      ans++;
      last=a[i].ss-1;
    }
  }

  cout<<ans<<endl;
    

}




    

    
 
    
    


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;
int main() {
    int N;
    int a[100];
    cin >> N;
    for (int i=0; i<N; i++) cin >> a[i];

    int sum = 0;
    for (int i=0; i<N; i++) sum += a[i];

    int min_diff = 100;
    int min_index = -1;

    for (int i=0; i<N; i++) {
        int diff = (a[i] * N - sum);
        if (diff < 0) diff *= -1;
        if (min_diff > diff) {
            min_diff = diff;
            min_index = i;
        }
    }

    cout << min_index << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%lld",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9
// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int a[505][505];

int main() {
    int h, w, cnt = 0;
    vi ans;
    cin>>h>>w;
    forall(i,0,h){
        forall(j,0,w){
            cin>>a[i][j];
        }
    }
    forall(i,0,h){
        forall(j,0,w){
            if (i == h - 1 && j == w - 1){
                continue;
            } else if (a[i][j] & 1){
                if (j != w - 1){
                    a[i][j]--;
                    a[i][j + 1]++;
                    ans.pb(i);
                    ans.pb(j);
                    ans.pb(i);
                    ans.pb(j + 1);
                    cnt++;
                } else {
                    a[i][j]--;
                    a[i + 1][j]++;
                    ans.pb(i);
                    ans.pb(j);
                    ans.pb(i + 1);
                    ans.pb(j);
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
    for(int i = 0; i + 4 <= ans.size(); i += 4){
        cout<<ans[i] + 1<<" "<<ans[i + 1] + 1<<" "<<ans[i + 2] + 1<<" "<<ans[i + 3] + 1<<endl;
    }
  return 0;
}


Measured memory_bytes: 5232
#include<iostream>
#include<cstdio>
#include<cstdlib>
#define N 2010
#define ll long long
using namespace std;
int nxt[N<<1],to[N<<1],head[N],cnt;
void add(int u,int v)
{
	nxt[++cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
bool choose[N];
ll f[N];
int siz[N];
void dfs(int u,int pre)
{
	siz[u]=choose[u];
	f[u]=0;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v==pre) continue;
		dfs(v,u);
		siz[u]+=siz[v];
		f[u]+=f[v]+siz[v];
	}
}
int work(int u,int pre)
{
	int p=0;
	for(int i=head[u];i;i=nxt[i])
	{
		int v=to[i];
		if(v==pre) continue;
		if(!p || f[v]>f[p]) p=v;
	}
	if(!p) return 0;
	ll res=work(p,u)+siz[p],ans=f[u]-f[p]-siz[p];
	
	if(ans>=res) return f[u]&1;
	else return res-ans;
}
char str[N];
int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s",str+1);
	for(int i=1;i<=n;i++) choose[i]=str[i]=='1';
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	ll ans=10000000000;
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(!work(i,0))
		ans=min(ans,f[i]);
	}
	printf("%lld\n",ans>=10000000000?-1:ans/2);
	return 0;
}


Measured memory_bytes: 384
/*                                                                                 
	Author :- Gaurang_Kothiya
	
	Quote :- " Practice makes a man perfect. "		
*/  
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

#define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ld long double
#define f(i,x,n) for(auto i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(auto i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define ook(num) order_of_key(num)
#define fbo(num) find_by_order(num)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
const ll inf= 1e9;
const ll inf64= 1e18;
const ll MOD= 1e9 +7;



void Solve()
{
	string s,t;
	cin>>s>>t;
	int ans=0;
	f(i,0,s.length()-1)
	{
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans;
}
 
signed main() 
{
	speed		
	
	int q=1;
	//	cin>>q;
	
	while(q--)
	Solve();
		
	return 0;
} 

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


int main() {
  
  int N;
  cin >> N;
  
  int a,b,c,d;
  a=N/1000;
  b=(N-1000*a)/100;
  c=(N-1000*a-100*b)/10;
  d=N-1000*a-100*b-10*c;
  
  if(a==b && b==c){
    cout << "Yes" << endl;
  }
  else if (b==c && c==d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1L<<61);

int main() {
  int n; cin >> n;
  vl a(n); ina(a,n);

  ll ans = 1;
  vl rgb(3,-1);
  rep(i,n) {
    int cnt = 0, x = -1;
    rep(j,3) {
      if (a[i] == rgb[j]+1) {
        x = j;
        cnt++;
      }
    }
    if (x != -1) {
      rgb[x]++;
    }
    ans *= cnt;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

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

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

signed main(void) {
	int n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	int xsize = lcm(n, m);
	int a = xsize / n;
	int b = xsize / m;
	for (int i = 0; i*a < xsize; i++) {
		if (i*a%b == 0) {
			if (s[i] != t[i*a / b]) {
				print("-1");
				return 0;
			}
		}
	}
	print(xsize);
}

Measured memory_bytes: 3716
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  int N; cin >> N;
  int x[N], y[N]; rep(i,N) cin >> x[i] >> y[i];

  int result = N;
  rep(i, N) for(int j=i+1; j<=N; j++) {
    int p = x[i]-x[j], q = y[i]-y[j];
    int tmp = N;
    rep(k, N) rep(l, N) {
      if (x[k]-x[l]==p && y[k]-y[l]==q) tmp--;
    }
    result = min(result, tmp);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e15;
ll MOD = 1e9 + 7;
ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    return gcd(b, a%b);
}
ll mod_pow(ll x, ll y)
{
    ll res = 1;
    while(y > 0)
    {
        if(y & 1)
        {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        y >>= 1;
    }
    return res;
}
ll add(ll &a, ll b)
{
    a = (a+b)%MOD;
}
int main()
{
    ll h, w, t;
    cin >> h >> w >> t;
    ll gh = gcd(h, t);
    ll gw = gcd(w, t);
    ll uh = h / gh;
    ll uw = w / gw;
    ll g1 = gcd(uh, uw);
    ll ans = 0;
    add(ans, mod_pow(2, g1));
    add(ans, mod_pow(2, uh));
    add(ans, mod_pow(2, uw) - 3);
    ll tans = mod_pow(ans, gh * gw);
    cout << tans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50010;
struct node
{
	int u,v,w;
	bool mark,del,use;
	node(int x = 0,int y = 0,int z = 0)
	{
		u = x;
		v = y;
		w = z;
		mark = del = use = false;
	}
	friend bool operator < (const node &a,const node &b)
	{
		return a.w < b.w;
	}
}e[maxn];

int uf[510],n,m,cnt;
bool flag[maxn];

int find(int x)
{
	return uf[x] = uf[x] == x?uf[x]:find(uf[x]);
}
void init()
{
	for(int i = 0;i <= n;i++) uf[i] = i;
}

int kruscal(bool &Unique,bool first)
{
	init();
	int ans,x,y;
	ans = 0;
	cnt = 0;
	for(int i = 0;i < m;i++)
	{
		if(!first && e[i].del) continue;
		x = find(e[i].u);
		y = find(e[i].v);
		if(x != y)
		{
			uf[x] = y;
			ans += e[i].w;
			if(first) 
		    {
			e[i].use = 1;
			if(e[i].mark) Unique = 0;
		    }
		    if(++cnt == n-1) return ans;
		}
		
		
	}
	return ans;
}


int main()
{
	//freopen("data.in","r",stdin);
	while(~scanf("%d %d",&n,&m))
	{
	int u,v,w,res1,res2;
	bool Unique = 1;
	memset(flag,0,sizeof(flag));
	for(int i = 0;i < m;i++)
	{
		scanf("%d %d %d",&u,&v,&w);
		e[i] = node(u,v,w);
	}
	sort(e,e+m);
	for(int i = 1;i < m;i++)
	{
		if(e[i].w == e[i-1].w) e[i].mark = e[i-1].mark = 1;
	}
	int MST = kruscal(Unique,true);
	if(Unique) printf("%d %d\n",cnt,MST);
	else
	{
	res1 = 0,res2 = 0;
	for(int i = 0;i < m;i++)
	{
		if(e[i].mark && e[i].use)
		{
			e[i].del = 1;
	    	int mst = kruscal(Unique,false);
	    	if(mst == MST && cnt == n-1)
			flag[i] = 1;
	    	e[i].del = 0;
		}
	
		if(!flag[i] && e[i].use)
		{
			res1 ++;
			res2 += e[i].w;
		}
   } 
	printf("%d %d\n",res1,res2);	
}
}
}

Measured memory_bytes: 2016
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        int h = scan.nextInt();
        int H = scan.nextInt();
        int k = scan.nextInt();
        int K = scan.nextInt();
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();

        if (a * h + b * H + (h / 10) * c + (H / 20) * d > a * k + b * K + (k / 10) * c + (K / 20) * d) {
            System.out.println("hiroshi");

        } else if (a * h + b * H + (h / 10) * c + (H / 20) * d < a * k + b * K + (k / 10) * c + (K / 20) * d) {
            System.out.println("kenjiro");

        } else {
            System.out.println("even");
        }

    }
}



Measured memory_bytes: 26208
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto s = sread();
    long n = s.length;
    long max_x = long.min;
    long min_x = long.max;
    foreach (i; 0 .. n)
    {
        if (s[i] == 'A')
        {
            // writeln(i);
            min_x = min(min_x, i);

        }
    }
    foreach (i; 0 .. n)
    {
        if (s[i] == 'Z')
        {
            // writeln(i);
            max_x = max(max_x, i);
        }
    }
    // writeln(min_x);
    // writeln(max_x);
    writeln(max_x - min_x + 1);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, m;
    cin >> n >> m;
    VL a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    VP ope(m);
    rep(i,m){
        cin >> ope[i].second >> ope[i].first;
    }
    sort(rall(ope));
    int left = 0, i = 0;
    while(left < n){
        if (ope[i].first < a[left]) {
            left++;
            continue;
        }
        while(ope[i].second){
            a[left] = ope[i].first;
            left++;
            ope[i].second--;
            if (left >= n || a[left] > ope[i].first) break;
        }
        i++;
    }
    ll ans = 0;
    rep(i,n) ans += a[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4852
use itertools::Itertools;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        xyz: [(usize, usize, usize); m],
    }

    let mut uf = UnionFind::new(n);

    for (x, y, _) in xyz {
        uf.unite(x - 1, y - 1);
    }

    let ans = (0..n).map(|x| uf.find(x)).unique().count();

    println!("{}", ans);
}

#[derive(Debug)]
struct UnionFind {
    parent: Vec<usize>,
    sizes: Vec<usize>,
}

#[allow(dead_code)]
impl UnionFind {
    fn new(n: usize) -> UnionFind {
        UnionFind {
            parent: (0..n).collect(),
            sizes: vec![1; n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.parent[x] {
            x
        } else {
            let x = self.parent[x];
            self.parent[x] = self.find(x);
            self.parent[x]
        }
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x != y {
            if self.sizes[x] < self.sizes[y] {
                std::mem::swap(&mut x, &mut y);
            }
            self.parent[y] = x;
            self.sizes[x] += self.sizes[y];
            true
        } else {
            false
        }
    }

    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn size(&mut self, x: usize) -> usize {
        let root = self.find(x);
        self.sizes[root]
    }
}


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

using namespace std;

int main(void)
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		int c = s[i]-65;
		c += n;
		if (c >= 26)
			c -= 26;
		printf("%c", 65+c);
	}
	cout << endl;
	return 0;
}

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

vector<int> idx(string str) {
    vector<int> res;
    for (int i = 0; i < str.size() - 2; i++) {
        if (str[i] == 'A' && str[i+1] == 'B' && str[i+2] == 'C')
            res.push_back(i);
    }

    return res;
}

bool dfs(string str) {
    if (str == "ABC") return true;
    if (str.size() < 3) return false;

    string next;
    int n = str.size();
    int flag = 0;
    auto d = idx(str);

    if (d.size() == 0) return false;
    d.push_back(n);

    for (int i = 0, x = 0; i < n; i++) {
        if (d[x] + 2 < i) x++;
        if (i < d[x]) {
            if (str[i] == 'A') flag |= 1;
            else if (str[i] == 'B') flag |= (1<<1);
            else flag |= (1<<2);
        }
    }

    char x;
    if (flag == 3) x = 'C';
    else if (flag == 6) x = 'A';
    else if (flag == 5) x = 'B';
    else return false;

    for (int i = 0, c = 0; i <= n; i++) {
        if (d[c] + 2 < i) c++, next += x;
        if (i == n) break;
        if (i < d[c]) next += str[i];
    }

    return dfs(next);
}

int main() {
    string str;
    cin >> str;

    cout << (dfs(str) ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 21864
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2] && s[0] == s[2]){
        cout << "No";
    }else{
        cout << "Yes";
    }
    return 0;
}


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

int main() {
    int n, time, c, t, ans = INT_MAX;
    cin >> n >> time;
    rep(i, n) {
        cin >> c >> t;
        if(time >= t) ans = min(ans, c);
    }
    if(ans != INT_MAX) cout << ans << endl;
    else cout << "TLE" << endl;
}

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

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int N = 100;
constexpr int INF = 1 << 30;

void solve() {
    int a, b;
    std::cin >> a >> b;

    auto ds = vec(a + 1, vec(b + 1, 0));
    for (int x = 1; x <= a; ++x) {
        for (int y = 1; y <= b; ++y) {
            std::cin >> ds[x][y];
        }
    }

    auto graph = vec(N + 1, vec(N + 1, 0));
    for (int x = 1; x <= a; ++x) {
        for (int y = 1; y <= b; ++y) {
            auto d = ds[x][y];

            for (int i = 0; i <= N; ++i) {
                for (int j = 0; j <= N; ++j) {
                    graph[i][j] = std::max(graph[i][j], d - x * i - y * j);
                }
            }
        }
    }

    for (int x = 1; x <= a; ++x) {
        for (int y = 1; y <= b; ++y) {
            int dmin = INF;
            for (int i = 0; i <= N; ++i) {
                for (int j = 0; j <= N; ++j) {
                    dmin = std::min(dmin, graph[i][j] + x * i + y * j);
                }
            }

            if (dmin != ds[x][y]) {
                std::cout << "Impossible" << std::endl;
                return;
            }
        }
    }

    std::cout << "Possible" << std::endl;

    std::cout << (N + 1) * 2 << " " << N * 2 + (N + 1) * (N + 1) << std::endl;
    for (int v = 1; v <= N; ++v) {
        std::cout << v << " " << v + 1 << " X" << std::endl;
    }
    for (int v = 1; v <= N; ++v) {
        std::cout << N + 1 + v + 1 << " " << N + 1 + v << " Y" << std::endl;
    }

    for (int u = 0; u <= N; ++u) {
        for (int v = 0; v <= N; ++v) {
            std::cout << u + 1 << " " << N + 1 + v + 1 << " "
                      << graph[u][v] << std::endl;
        }
    }

    std::cout << 1 << " " << N + 2 << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;

  cin >>A>> B>>C>> D;
A+=B;
  C+=D;
  if(A==C  ){
 cout <<"Balanced" <<endl;
  }
  else if(A>C)
  {
   cout <<"Left" <<endl;
}else    cout <<"Right" <<endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<long long> vll;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

void solve(long long a, long long b) {
  string str = to_s(a) + to_s(b);
  ll n = to_T<ll>(str);

  REP(i, n / 2) {
    if (i * i == n) {
      cout << "Yes" << endl;
      return;
    } else if (i * i > n) {
      break;
    }
  }

  cout << "No" << endl;
}

int main() {
  ios::sync_with_stdio(false);
  long long b;
  long long a;
  cin >> a;
  cin >> b;
  solve(a, b);
  return 0;
}


Measured memory_bytes: 764