akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int[] v = Zalgo(T + S);
		int[] u = Zalgo(rev(T) + rev(S));
		int ans = 0;
		v = Arrays.copyOfRange(v, T.length(), T.length() + S.length());
		u = Arrays.copyOfRange(u, T.length(), T.length() + S.length());
		for (int i = 0; i < S.length(); ++i) {
			if (S.length() - 1 - i - (T.length() - 1) < u.length && S.length() - 1 - i - (T.length() - 1) >= 0)
				if (v[i] + u[S.length() - 1 - i - (T.length() - 1)] == T.length() - 1)
					++ans;
		}
		System.out.println(ans);

	}

	String rev(String S) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < S.length(); ++i) {
			sb.append(S.charAt(S.length() - 1 - i));
		}
		return sb.toString();
	}

	int[] Zalgo(String S) {
		char[] s = S.toCharArray();
		int n = s.length;
		int[] ret = new int[n];
		ret[0] = n;
		int i = 1, j = 0;
		while (i < n) {
			while (i + j < n && s[j] == s[i + j])
				++j;
			ret[i] = j;
			if (j == 0) {
				++i;
				continue;
			}
			int k = 1;
			while (i + k < n && k + ret[k] < j) {
				ret[i + k] = ret[k];
				++k;
			}
			i += k;
			j -= k;

		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 50800
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}

int main()
{
   ll K,n;
   cin>>K>>n;
   ll i,A[n];
   for(i=0;i<n;i++)
   {
       cin>>A[i];
   }
   vector<pair<ll,ll> > vec;
   vec.push_back({K-A[n-1]+A[0],A[1]-A[0]});
   for(i=1;i<n-1;i++)
   {
       vec.push_back(make_pair(A[i]-A[i-1],A[i+1]-A[i]));
   }
   vec.push_back({A[n-1]-A[n-2],K-A[n-1]+A[0]});
   ll ans=1e12;
   for(i=0;i<n;i++)
   {
       ans=min(ans,min(K-vec[i].first,K-vec[i].second));
   }
   cout<<ans;

}


Measured memory_bytes: 7920
#include<iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>

using namespace std;

void solve(long long N, std::vector<long long> a){
	map<int,int> mp;
	vector<int> v;
	for(int i = 0;i < N;i++)mp[a[i]]++, v.emplace_back(a[i]);
	sort(v.begin(), v.end());
	int ans = 0;
	for(auto &&it:mp){
		if(it.first <= it.second){
			ans += it.second - it.first;
		}else{
			ans += it.second;
		}
	}
	cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    std::cin >> N;
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> a[i];
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 5880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    float d,t,s;
    cin>>d>>t>>s;
    if((d/s)<=t)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;

}

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

main(){
  int a[4];
  for (int i = 0; i < 4; ++i) std::cin >> a[i];
  std::sort(a, a + 4);
  std::cout << (a[0] == a[1] && a[2] == a[3] ? "yes" : "no") << std::endl;
}

Measured memory_bytes: 3116
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
//#define int long long 
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int N;
int a[MAXN], sum = 0;
int check(int val) {
	int ret = 0;
	for(int i = 1; i <= N; i++)
		ret += val % a[i];
	return ret;
}
main() {
	N = read();
	for(int i = 1; i <= N; i++) 
		a[i] = read(), sum += a[i] - 1;
	printf("%d", sum); 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, K);
    CINS(int, h, N);

    sort(h.begin(),h.end());

    int ans = 1e9;
    for (int i = 0; i < N-K+1; i++) {
        ans = min( ans, h[i+K-1]-h[i] );
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int h, w;
	int i, j;

	while(1){
		scanf("%d %d ", &h, &w);
		if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

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

int main(){
    int n;
    string s[100005];
    map<string, int> mp;
    cin >> n;
    rep(i,n){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s+n);

 
    rep(i,n-1){
        if(s[i] == s[i+1]) mp[s[i]]++;
    }

    ll ans = 0;
    for(auto m : mp){
        ll v = m.second + 1;
        ans += (v * (v - 1) / 2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8192
def resolve():
    n, m = map(int, input().split())
    troubles = []
    for _ in range(m):
        a, b = map(int, input().split())
        troubles.append((a, b))

    ans = 0
    saw = 0

    key_func = lambda x: x[1]
    troubles.sort(key=key_func)

    for a, b in troubles:
        if saw <= a:
            saw = b
            ans += 1

    print(ans)
    
resolve()

Measured memory_bytes: 18220
import itertools


result = 0
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
time = 0

# item
for i in itertools.permutations([a,b,c,d,e], r=5):
    result = 0
    result = result  +  i[0]
    if result %10 != 0:
        result = result + (10-i[0]%10)
    result = result  +  i[1]
    if result %10 != 0:
        result = result + (10-i[1]%10)
    result = result  +  i[2]
    if result %10 != 0:
        result = result + (10-i[2]%10)
    result = result  +  i[3]
    if result %10 != 0:
        result = result + (10-i[3]%10)
    result = result  +  i[4] 
# order
    if time == 0:
        time = result
    elif time > result:
        time= result

# result
print(time)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll sq(ll x) {return (x * x) % MOD;}
ll modP(ll a, ll b) {return (!b ? 1 : (sq(modP(a, b / 2)) * (b % 2 ? a : 1)) % MOD);}

int ps[maxN];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	ps[0] = 0;
	for (int i = 0; i < n; i++){
		ps[i + 1] = ps[i] + (s[i] == 'C' && s[i - 1] == 'A');
	}
	while (q--){
		int l, r;
		cin >> l >> r;
		cout << ps[r] - ps[l] << endl;
	}
	return 0;
}



Measured memory_bytes: 1488
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
void solve(int x,string y){
	int n=y.size();
	bool same=false;
	int mx=-1;
	vector<int> mvc;
	rep(i,1<<(n-1)){
		int a[7]={};
		rep(j,n-1) a[j]=(i>>j)&1;
		int sum=0,now=y[0]-'0';
		vector<int> vc;
		rep(j,n-1){
			if(a[j]==0){
				now*=10;
				now+=y[j+1]-'0';
			}else{
				sum+=now;
				vc.pb(now);
				now=y[j+1]-'0';
			}
		}
		sum+=now;
		vc.pb(now);
		if(x<sum||sum<mx) continue;
		if(sum==mx){
			same=true;
			continue;
		}
		mx=sum;
		same=false;
		mvc=vc;
	}
	if(same){
		puts("rejected");
		return;
	}
	if(mx==-1){
		puts("error");
		return;
	}
	cout<<mx;
	for(int a:mvc) cout<<" "<<a;
	puts("");
}
int main(){
	while(true){
		int x;
		string y;
		cin>>x>>y;
		if(x==0) break;
		solve(x,y);
	}
}

Measured memory_bytes: 1224
n = int(input())
a_inputs = [int(input()) for i in range(n)]

max_a = max(a_inputs)
max_index = a_inputs.index(max(a_inputs))
next_max = sorted(a_inputs)[-2]

for i in range(n):
    if i==max_index:
        print(next_max)
    else:
        print(max_a)


Measured memory_bytes: 13380
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		int t = sc.nextInt(); sc.nextLine();
		while (t-->0) {
			String line = sc.nextLine();
			System.out.println(line.replaceAll("Hoshino", "Hoshina"));
		}
	}
}

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

def factorization(n):#次数だけ
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append(cnt)

    if temp!=1:
        arr.append(1)

    if arr==[]:
        arr.append(0)

    return arr
     
p=factorization(M)#素因数分解して次数を調べる

    
def cmb(n, r, mod):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r])%mod

mod=10**9 + 7
fact=[1,1]
factinv=[1,1]
inv=[0,1]
 
N2=N+max(p)    

for i in range(2, N2 + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)
    

        
ans=1
for i in range(len(p)):
    ans*=cmb(p[i]+N-1,p[i],mod)
    ans%=mod

print(ans)




Measured memory_bytes: 57968
#include<bits/stdc++.h>
using namespace std;
//max=({});

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size();
	bool flag = false;
	for (int i = 0;i < n;++i) {
		if (s == t) {
			flag = true;
		}
		s = s.back() + s.substr(0, s.size() - 1);
	}
	if (flag)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        System.out.println(lcm(a,b));
        sc.close();

    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static long gcd(long a, long b) {
        if (a < b)
            return gcd(b, a);
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

}


Measured memory_bytes: 21844
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut h: isize = iterator.next().unwrap().parse().unwrap();

    let mut a_max: isize = 0;
    let mut b: Vec<isize> = Vec::new();
    for _ in 0..n {
        let ai: isize = iterator.next().unwrap().parse().unwrap();
        let bi: isize = iterator.next().unwrap().parse().unwrap();
        a_max = max(a_max, ai);
        b.push(bi);
    }
    b.sort();
    b.reverse();

    let mut count: usize = 0;
    for bi in b {
        if h <= 0 {
            break;
        }
        if bi < a_max {
            break;
        }
        h -= bi;
        count += 1;
    }

    if h <= 0 {
        return count.to_string();
    }

    if h % a_max == 0 {
        count += (h / a_max) as usize;
    } else {
        count += (h / a_max) as usize + 1;
    }

    return count.to_string();
}


Measured memory_bytes: 10232
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<functional>
#include<cmath>
#include<algorithm>
#define INF 999999999
typedef  long long ll;
 
int main() {
	ll a[100] = {},n = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	std::sort(a, a + n);
	std::cout << std::abs(a[n-1] - a[0]) << std::endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    ll a, b, c, d; cin >> a >> b >> c >> d;

    cout << max({a*c, a*d, b*c, b*d}) << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>

using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
//SOLVE


void solve(void)
{
  string str;cin>>str;
  
  reverse(ALL(str));
  str.push_back('0');
  int ANS = 0;
  for (int i = 0; i < str.size(); i++)
  {
    int X = str[i] - '0';
    if(X >= 10)
    {
      X  -=10;
      str[i] ='0' + X;
      str[i+1]++;
    }
    int next = str[i+1] - '0';
    if(X<5 || (X == 5 && next <=4))
    {
      ANS += X;
    }
    else
    {
      ANS += 10 -X;
      str[i+1]++;
      str[i] ='0';
    }
    // DEBUG(X);
  }
  //  DEBUG(str);

  cout<<ANS<<endl;
  

  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 1948
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

int ans[4][4];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin>>n;
    cout<<n/2 + (n%2)<<endl;

}

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

int main()
{
  string s,t ;
  cin>>s>>t ;
  sort(s.begin(),s.end()) ;
  sort(t.begin(),t.end()) ;
  reverse(t.begin(),t.end()) ;
  if(s<t) cout<<"Yes"<<endl ;
  else cout<<"No"<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int n, a, i;
	while (cin >> n && n)
	{
		int r[7] = {0};
		for (i = 0; i < n; i++)
		{
			cin >> a;
			if (a < 10)		r[0]++;
			else if (a < 20)r[1]++;
			else if (a < 30)r[2]++;
			else if (a < 40)r[3]++;
			else if (a < 50)r[4]++;
			else if (a < 60)r[5]++;
			else			r[6]++;
		}
		for (i = 0; i < 7; i++)
			cout << r[i] << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

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

int N;
ll W; 
ll w[110];
ll v[110];
ll dp[110][100010] = {0};

int main(){
    cin >> N >> W;
    REP(i,N) cin >> w[i] >> v[i];
    
    REP(i,N){
        REP(j,W+1){
            if(j-w[i]>=0) chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,A,B;
	scan(N>>A>>B);
	prin(min({N*A,B}));
	return 0;
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

struct UnionFind{
	vector<int> parent;
	vector<int> rank;
	UnionFind(int n)
		:parent(n + 1),rank(n + 1,1){
			for(int i = 1;i <= n;i++) parent [i] = i;
	}
	int find(int x){
		if(parent [x] == x) return x;
		return parent [x] = find(parent [x]);
	}
	bool connect(int x,int y){
		x = find(x),y = find(y);
		if(x == y) return false;
		if(rank [x] < rank [y]) swap(x,y);
		if(rank [x] == rank [y]) rank [x]++;
		parent [y] = x;
		return true;
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
};

int N,K,L;

int main()
{
	scanf("%d%d%d",&N,&K,&L);
	UnionFind x(N),y(N);
	FOR(i,0,K){
		int p,q;
		scanf("%d%d",&p,&q);
		x.connect(p,q);
	}
	FOR(i,0,L){
		int r,s;
		scanf("%d%d",&r,&s);
		y.connect(r,s);
	}
	map< pair<int,int>,vector<int> > mp;
	for(int i = 1;i <= N;i++){
		mp [make_pair(x.find(i),y.find(i))].push_back(i);
	}

	vector<int> ans(N + 1);
	for(auto it : mp){
		FOR(i,0,it.second.size()){
			ans [it.second [i]] = it.second.size();
		}
	}

	for(int i = 1;i <= N;i++){
		printf("%d%s",ans [i],i == N ? "\n" : " ");
	}

	return 0;
}


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

int main() {
    int p, q, r;
    cin >> p >> q >> r;

    int ans = 0;
    if (p >= q && p >= r)
        ans += q + r;
    else if (q >= p && q >= r)
        ans += p + r;
    else
        ans += p + q;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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; }

int main(){
    int A,B,C; cin >> A >> B >> C;
    if (A<=C && C<=B) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n, r, t, base;
		
		n = scan.nextInt();
		
		for(int i = 0; i < n; i++) {
			r = scan.nextInt();
			t = scan.nextInt();
			
			base = t / 30 * 5  + r / 100;
			
			if(r % 100 == 0) {
				if(t % 30 == 0) {
					System.out.println(base);
					
				} else {
					System.out.println(base + " " + (base + 5));
					
				}
			} else {
				if(t % 30 == 0) {
					System.out.println(base + " " + (base + 1));
					
				} else {
					System.out.println(base + " " + (base + 1) + " " + (base + 5) + " " + (base + 6));
				}
			}
			
		}
		
		scan.close();
	}
}

Measured memory_bytes: 26352
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
struct robo{
    ll l,r;
};
bool comp(struct robo a,struct robo b){
    if(b.l>a.r)
    return b.l>a.r;
    else
    return a.r<b.r;
}

int main() {
    ll n;
    cin>>n;
    vector<struct robo> cov;
    for(ll i=0;i<n;i++){
        ll x,range;
        cin>>x>>range;
        cov.pb({x-range,x+range});
    }
    sort(cov.begin(),cov.end(),comp);
    ll ci=0,ans=1;
    for(ll i=1;i<n;i++){
        if(cov[i].l>=cov[ci].r){
            ans++;
            ci=i;
        }
        //cout<<cov[i].l<<" "<<cov[i].r<<" \n";
    }
    cout<<ans;
}

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

int selectionSort(int A[], int N){
    int sw = 0, minj;
    for(int i = 0; i < N-1; i++){
        minj = i;
        //
        for(int j = i; j < N; j++){
            if(A[j] < A[minj]){
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if(i != minj) sw++;
    }
    return sw;
}

int main(){
    int n, A[100], ans;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    ans = selectionSort(A,n);
    //結果の出力
    rep(i,n){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3120
import java.io.*;
import java.util.*;

class RC {
	int r;
	int c;
	
	RC() {}
	
	RC(int r, int c) {
		this.r = r;
		this.c = c;
	}
}

class Solution {
	final int SIZE = 1000;
	int[] dr = { 0, 1, 0, -1 };
	int[] dc = { 1, 0, -1, 0 };
	int h, w, n;
	char[][] graph = new char[SIZE][];
	int[][] distance = new int[SIZE][SIZE];
	boolean[][] visit = new boolean[SIZE][SIZE];
	RC s = new RC();
	Queue<RC> que = new LinkedList<RC>();
	int chikara;
	int ans;

	void compute() {
		Scanner scanner = new Scanner(System.in);
		h = scanner.nextInt();
		w = scanner.nextInt();
		n = scanner.nextInt();
		scanner.nextLine();
		for (int i = 0; i < h; i++) {
			graph[i] = scanner.nextLine().toCharArray();
			Arrays.fill(visit[i], false);
			for (int j = 0; j < w; j++) {
				if (graph[i][j] == 'S') {
					s.r = i;
					s.c = j;
				}
			}
		}
		chikara = 1;
		ans = 0;
		for (int i = 0; i < n; i++) {
			bfs();
			ans += distance[s.r][s.c];
			chikara++;
		}
		System.out.println(ans);
		scanner.close();
	}

	void bfs() {
		for (int i = 0; i < h; i++) {
			Arrays.fill(distance[i], -1);
		}
		que.clear();
		distance[s.r][s.c] = 0;
		que.add(s);
		while (!que.isEmpty()) {
			RC rc = que.poll();
			for (int i = 0; i < 4; i++) {
				RC nrc = new RC(rc.r + dr[i], rc.c + dc[i]);
				if (nrc.r >= 0 && nrc.r < h && nrc.c >= 0 && nrc.c < w && graph[nrc.r][nrc.c] != 'X' && distance[nrc.r][nrc.c] == -1) {
					distance[nrc.r][nrc.c] = distance[rc.r][rc.c] + 1;
					if (Character.isDigit(graph[nrc.r][nrc.c]) && graph[nrc.r][nrc.c] - '0' <= chikara && !visit[nrc.r][nrc.c]) {
						visit[nrc.r][nrc.c] = true;
						s = nrc;
						return;
					} else {
						que.add(nrc);
					}
				}
			}
		}
	}
	
	void debug() {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				System.out.print(distance[i][j] + " ");
			}
			System.out.println();
		}
		System.out.println();
	}
}

public class Main {
	public static void main(String args[]) {
		Solution solution = new Solution();
		solution.compute();
	}
}


Measured memory_bytes: 156188
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll n,k;
char matrix[2000][2000];

string func(ll i,ll j)
{
	string ans;
	ll x=i,y=j;
	while(x<n || y<n)
	{
		    	if(x==n-1)
    			{
    				ans.pb(matrix[x][y+1]);
    				y++;
    				continue;
    			}
    			if(y==n-1)
    			{
    				ans.pb(matrix[x+1][y]);
    				x++;
    				continue;
    			}
    	if(matrix[x+1][y]<matrix[x][y+1])
    	{
    		ans.pb(matrix[x+1][y]);
    		x++;
    	}
    	else if(matrix[x+1][y]>matrix[x][y+1])
    	{
    		ans.pb(matrix[x][y+1]);
    		y++;
    	}
    	else
    	{
    		ans.pb(matrix[x+1][y]);
    		string t=min(func(x+1,y),func(x,y+1));
    		ans+=t;
    		return ans;
    	}
	}
	return ans;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
    // freopen("alchemy_input.txt", "r", stdin);
 //    // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	ll i,j,n;
    	cin>>n;
    	vector<ll>h(n);
    	rep(i,0,n-1) cin>>h[i];
    	ll dp[n];
    	dp[0]=0;
    	dp[1]=abs(h[1]-h[0]);
    	for(i=2;i<n;i++)
    	{
    		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    	}
    	cout<<dp[n-1];
    }

	return 0;
}

Measured memory_bytes: 5044
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <math.h>
using namespace std;
int main(){

	int A,B,C;
	cin >> A >> B >> C;
	if(A > C && C > B){
		cout << "Yes" << endl;
	}
	if(A < C && C < B){
		cout << "Yes" << endl;
	}
	if(A > C && B > C){
		cout << "No" << endl;
	}
	if(A < C && C > B){
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    
    int L[2*N];
    
    for(int i=0; i<2*N; i++){
        cin >> L[i];
    }
    
    sort(L,L+2*N);
    
    int ans=0;
    for(int i=0; i<2*N; i+=2){
        ans+=L[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    static int[] x,y,h;
    static int n;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = new int[n];y = new int[n];h = new int[n];
        for(int i=0;i<n;i++){
            x[i]=sc.nextInt();
            y[i]=sc.nextInt();
            h[i]=sc.nextInt();
        }
        for(int i=0;i<=100;i++){
            for(int j=0;j<=100;j++){
                int res = check(i,j);
                if(res>0){
                    System.out.println(Integer.toString(i)+" "+Integer.toString(j)+" "+Integer.toString(res));
                    return;
                }
            }
        }
    }
    static int check(int cx, int cy){
        int hmax = Integer.MAX_VALUE;
        HashSet<Integer> rec = new HashSet<>();
        for(int i=0;i<n;i++){
            if(h[i]==0) hmax=Math.min(hmax,Math.abs(cx-x[i])+Math.abs(cy-y[i]));
            else rec.add(Math.abs(cx-x[i])+Math.abs(cy-y[i])+h[i]);
        }
        if(rec.size()!=1) return -1;
        for(int w:rec){
            return w<=hmax?w:-1;
        }
        return -1;
    }
}


Measured memory_bytes: 42656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    ll a, b; cin >> a >> b; b++;
    int po = floor(log2(b))+1;
    debug(po);
    vector<pair<ll, ll>> bits(po+1, {0, 0});
    rep(i, po+1) {
        ll m = pow(2, i);
        ll base = 0, add = 0;
        base = a / m;
        if (base%2!=0) {
            add = a % m;
        }
        base /= 2;
        bits[i].fi = base*m+add;
        base = 0, add = 0;
        base = b / m;
        if (base%2!=0) {
            add = b % m;
        }
        base /= 2;
        bits[i].se = base*m+add;
    }
    ll ans = 0;
    rep(i, po+1) {
        debug(pow(2,i), bits[i].fi, bits[i].se, bits[i].se-bits[i].fi);
        if ((bits[i].se-bits[i].fi)%2) ans += 1ll << i;
    }
    cout << ans << endl;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	string a, b, c;
	cin >> a >> b >> c;
	int ca, cb, cc;
	ca = cb = cc = 0;
	char x = a[0];
	while (1) {
		if (x == 'a')x = a[ca++];
		else if (x == 'b')x = b[cb++];
		else if (x == 'c')x = c[cc++];

		if (ca == a.size()+1 || cb == b.size()+1 || cc == c.size()+1) {
			if (ca == a.size()+1)cout << 'A' << endl;
			else if (cb == b.size()+1)cout << 'B' << endl;
			else if (cc == c.size()+1)cout << 'C' << endl;
			break;
		}
		dump(x);
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s1, s2, sub;
  cin >> s1 >> s2;
  sub = s2.substr(0,s1.size());
  if(sub == s1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3600
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
// #define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

vector<int> get_positions(const string &t, int s) {
    vector<int> ans;
    for (int i = 0; i < len(t); ++i) {
        if (t[i] == 'x') continue;
        ans.pb(i);
        i += s;
    }
    return ans;
}

void run() {
    int n, k, s;
    string t;
    cin >> n >> k >> s >> t;
    vector<int> pos1 = get_positions(t, s);
    if (len(pos1) > k) {
        return;
    }
    reverse(all(t));
    vector<int> pos2 = get_positions(t, s);
    for (auto &x : pos2) {
        x = n - x - 1;
    }
    reverse(all(pos2));
    for (int i = 0; i < len(pos1); ++i) {
        if (pos1[i] == pos2[i]) {
            cout << pos1[i] + 1 << endl;
        }
    }
}

Measured memory_bytes: 3468
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#include<numeric>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

    int n,t;
    cin>>n>>t;
    vvi in(n,vi(2));
    rep(i,n)rep(j,2)cin>>in[i][j];
    sort(all(in));
    vvi dp(n,vi(t));
    rep(i,n-1){
        dp[i+1]=dp[i];
        for(int j=t-1;j>=0;j--)
            if(j+in[i][0]<t)cmax(dp[i+1][j+in[i][0]],dp[i][j]+in[i][1]);
    }
    int out=0,ma=0;
    rep(i,n-1){
        cmax(ma,in[n-1-i][1]);
        cmax(out,dp[n-1-i][t-1]+ma);
    }
    cout<<out<<endl;
}


Measured memory_bytes: 70912
#include <cstdio>
#include <cstring>
int n,k,dp[2001][2001],fac[4000001],ifac[4000001];const int p=1e9+7;
inline int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;bs=1ll*bs*bs%p;ex>>=1;}return ans;}
inline int binom(int n,int m){return 1ll*fac[n]*ifac[m]%p*ifac[n-m]%p;}
int main()
{
	scanf("%d%d",&n,&k);if(k==1){putchar(49);putchar(10);return 0;}
	fac[0]=1;for(int i=1;i<=n*k;++i)fac[i]=1ll*fac[i-1]*i%p;ifac[n*k]=qpow(fac[n*k],p-2);for(int i=n*k-1;~i;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%p;
	for(int i=0;i<=n;++i)dp[i][0]=1;
	for(int i=1;i<=n;++i)
	{
		for(int j=1;j<=i;++j)
		{
			(dp[i][j]+=dp[i-1][j])%=p;
			(dp[i][j]+=1ll*dp[i][j-1]*(n-j+1)%p*binom(n*k-i-1-(j-1)*(k-1),k-2)%p)%=p;
		}
	}
	printf("%d\n",dp[n][n]);return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long n;
    cin >> n;
    vector <long long> qw (10000);
    for (long long i=1; i*i<=n; ++i)
        for (long long ii=1; ii*ii<=n; ++ii)
            for (long long iii=1; iii*iii<=n; ++iii)
                if (10000>=i*i+ii*ii+iii*iii+i*ii+i*iii+ii*iii)
                    qw[i*i+ii*ii+iii*iii+i*ii+i*iii+ii*iii-1]+=1;
    for (int i=0; i<n; ++i)
        cout << qw[i] << endl;
}


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

using namespace std;

int main()
{
 int N;
 int m;
 vector<int>v;
 cin >> N;
 for(int i = 0;i < N;i++)
 {
   cin >> m;
   v.push_back(m);
   if(v[i] % 2 != 0)
   {
     cout << 0 << endl;
     return 0;
   }
 }
 int result = 0;
 int val = 1;
 while(1)
 {
   result++;
   for(int i = 0; i<N;i++)
   {
     v[i] = v[i] / 2;
     if(v[i] % 2 != 0)
     {
       val = 0;
       break;
     }
   }
   if(val==0)
   {
     break;
   }
 }
  cout << result << endl;
  return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int N_MAX = 2010;
ll arr[N_MAX][N_MAX];

int main() {
	int n;
	ll x;
	scanf("%d%lld", &n, &x);
	for(int i = 0; i < n; i++) {
		scanf("%lld", arr[0]+i);
		for(int j = 1; j < n; j++)
			arr[j][(i-j+n)%n] = arr[0][i];
		arr[i][n] = arr[0][i];
	}
	for(int i = 0; i < n; i++)
		for(int j = n-1; j >= 0; j--)
			arr[i][j] = min(arr[i][j], arr[i][j+1]);
	ll ans = 1e18;
	for(int i = 0; i < n; i++) {
		ll tmp = x*i;
		for(int j = 0; j < n; j++)
			tmp += arr[j][n-i];
		ans = min(ans, tmp);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 31616
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 10**6

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x - 1] + b[y - 1] - c)

ans = min(ans, min(a) + min(b))

print(ans)

Measured memory_bytes: 65084
n,m=gets.split.map(&:to_i)
lines=readlines.map{|line|line.split.map(&:to_i)}
stu=lines[0..n-1]
poi=lines[n..-1]
poi_len=poi.length
stu.each do |n| 
sum=[]
n.each_cons(2) do |x,y| 
     for i in 0..poi_len-1
            x_result=(x-poi[i][0]).abs
           y_result=(y-poi[i][1]).abs
           sum<< x_result+ y_result
     end
end
min=sum.min
puts sum.index(min)+1
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
  int n , m , c ;
  cin >> n >> m >> c ;
  vector < int > b(m) ;
  for( int i = 0 ; i < m; i++)  cin >> b[i];
  vector < vector < int > > a(n,vector < int > (m));
  for( int i = 0 ; i < n ; i++){
    for( int j = 0 ;j  < m ; j++){
        cin >> a[i][j];
    }
  }
    int ans = 0 ;
    for( int i = 0 ; i< n ;i++){
        int k = 0 ;
        for( int j = 0 ; j < m ; j++){
            k+=a[i][j]*b[j];
        }
        k+=c;
        if(k>0)
            ans++;
    }
    cout << ans ;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    X--; Y--;

    vector<int> ans(N);
    rep(i, N - 1) rep(j, i + 1, N) {
        if (i <= X) {
            if (j <= X) ans[j - i]++;
            else if (j <= Y) ans[X - i + min(j - X, Y - j + 1)]++;
            else ans[X - i + j - Y + 1]++;
        }
        else if (i <= Y) {
            if (j <= Y) ans[min(j - i, i - X + Y - j + 1)]++;
            else ans[min(j - i, i - X + j - Y + 1)]++;
        }
        else ans[j - i]++;
    }

    rep(i, 1, N) write(ans[i]);
}

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

int main(){
    int N,L;
    cin >> N >> L;
    string S[110];
    for (int i = 0; i < N; ++i) cin >> S[i];

    sort(S, S + N);

    string s;
    for (int i = 0; i < N; ++i) {
        s += S[i];
    }
    cout << s << endl;
    
}

Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in ('0 ' + input() + ' 0').split()]
ans = 0

for i in range(n+1):
    ans += abs(A[i+1] - A[i])
    
for i in range(1, n+1):
    print(ans + abs(A[i+1] - A[i-1]) - (abs(A[i+1] - A[i]) + abs(A[i] - A[i-1])))

Measured memory_bytes: 14176
#include <stdio.h>

int main(){
    int x, y;
    
    while(1){
        scanf("%d %d",&x,&y);
        if((x+y)==0) break;
        if(x<=y){
            printf("%d %d\n",x,y);
        }else{
            printf("%d %d\n",y,x);
        }
    }
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int64_t> Lucas(N + 1);
  for (int i = 0; i < N + 1; i++) {
    Lucas.at(0) = 2;
    Lucas.at(1) = 1;
    if (i > 1) {
      Lucas.at(i) = Lucas.at(i - 1) + Lucas.at(i - 2);
    }
  }
  cout << Lucas.at(N) << endl;
}

Measured memory_bytes: 256
# coding:utf-8
inp = input()
N = int(inp)

eigyo = []

b = []
Ci = []
for i in range(N):
    N_ = list(map(int, input().split()))
    eigyo.append(N_)
    Ci.append(sum(N_))

P = []
for i in range(N):
    P.append(list(map(int, input().split())))


ans = -(1<<30)
a = list(map(lambda x: x*0, list(range(10))))
count = 0

def func():
    #score = 0
    global count
    count += 1
    #print(count, a)
    cc = 0
    if count!=1:
        for i in range(N):
            count_c = 0
            for j,element in enumerate(eigyo[i]):
                if element==a[j] and a[j]==1:
                    count_c += 1
            cc += P[i][count_c]
        global ans
        ans = max(ans, cc)
            
    #ans = max(ans, score)

def dfs(pos):
    if pos==10:
        func()
        return
    a[pos] = 0
    dfs(pos+1)
    a[pos] = 1
    dfs(pos+1)


dfs(0)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main() {
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b)*h / 2 << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool isInclude3(int n) {
    bool ret = false;

    for (int i = n; i > 0; i /= 10) {
        if (i % 10 == 3) {
            ret = true;
        }
    }

    return ret;
}

bool isDivide3(int n) {
    bool ret = (n % 3 == 0) ? true : false;

    return ret;
}

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

    for (int i = 1; i <= n; ++i) {
        if (isDivide3(i) || isInclude3(i)) {
            cout << " " << i;
        }
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int h,w;
	cin>>h>>w;
	vector <string> en(h);
	int me[h][w];
	for(int i=0;i<h;i++){
		cin>>en[i];
		me[i][0] = 0;
		if(i){
			me[i][0] = me[i-1][0];
			if(en[i][0]=='#'&&en[i-1][0]=='.')me[i][0]++;
		}
		else if(en[i][0]=='#')me[i][0] = 1;
		for(int j =1;j<w;j++){
			me[i][j] = me[i][j-1];
			if(en[i][j]=='#'&&en[i][j-1]=='.')me[i][j]++;
			if(i){
				int can = me[i-1][j];
				if(en[i][j]=='#'&&en[i-1][j]=='.')can++;
				me[i][j] = min(me[i][j],can);
			}
		}
	}
	cout<<me[h-1][w-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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; }

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

    int n = s.size();
    rep(i, n) rep(j, n) {
        if (i > j) continue;
        string t = s;
        t.erase(i, j-i);
        if (t == "keyence") {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}


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

int main(void) 
{
    int x,y,z;
    cin >> x >> y >> z;
    cout << z  << ' '<< x << ' ' << y << endl;

}

Measured memory_bytes: 256