akhauriyash/Code-Regression huggingface dataset:
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include<boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<=n;i++)
#define fr(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
#define F first
#define S second
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
 
 
void solve()
{
  int n,k;
  cin >> k >> n;
  int a[n];
  f(i,n)
  {
      cin >> a[i];
  }
  int ans=a[n-1]-a[0];
  fp(i,1,n-1)
  {
      ans=min(k-a[i]+a[i-1],ans);
  }
  cout << ans << '\n';
  return ;
}

signed main()
{
   FAST;
	int T=1;
	// cin >> T;
	while(T--)
	{
		solve();
	}
    return 0;
}

Measured memory_bytes: 1792
def addbit(i):
    i += 1
    while i <= N:
        BIT[i] += 1
        i += i & (-i)
def getsum(i):
    ret = 0
    i += 1
    while i != 0:
        ret += BIT[i]
        i -= i&(-i)
    return ret
def bit(L):
    global BIT
    BIT=[0] * (N+1)
    re = 0
    for l in L:
        re += getsum(l)
        addbit(l)
    return N*(N-1)//2 - re
def get_rank(L):
    D = {x:i for i,x in enumerate(sorted(L))}
    return [D[x] for x in L]
def calc(Z):
    Z.sort()
    l, r, lc, rc = -1<<28, 1<<28, N*(N-1)//4+1, N*(N-1)//4+1
    while (r - l) / max(abs(l), 1) > 0.000000001:
        m = (l * rc + r * lc) / (lc + rc)
        A = get_rank([s*m+t for s, t in Z])
        c = bit(A)
        if c > N*(N-1)//4:
            l = m
            lc = ((c - N*(N-1)//4) * 2) ** 0.5
        else:
            r = m
            rc = ((N*(N-1)//4 - c) * 2 + 1) ** 0.5
    return l

N = int(input())
X, Y = [], []
for _ in range(N):
    a, b, c = map(int, input().split())
    X.append((-a/b, c/b))
    Y.append((-b/a, c/a))
print(calc(X), calc(Y))

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//____________________

const int N=1e5+5;
int par[N],sz[N],A[N],B[N],cur,ans[N],n;

void init()
{
  for(int i=1;i<=n;i++)
  {
    par[i]=i;
    sz[i]=1;
  }
}

int get(int v)
{
  if(v==par[v])
    return v;
  return par[v]=get(par[v]);
}

void unite(int a,int b)
{
  int pa=get(a);
  int pb=get(b);
  if(pa==pb)
    return;
  cur-=(sz[pa]*sz[pb]);
  if(sz[pa]>sz[pb])
  {
     par[pb]=pa;
     sz[pa]+=sz[pb];
     sz[pb]=0;
  }
  else//sz[b]>sz[a]
  {
     par[pa]=pb;
     sz[pb]+=sz[pa];
     sz[pa]=0;
  }
}

int32_t main()
{ 
  io;
 
  
  int m;
  cin>>n>>m;

  init();
  
  for(int i=1;i<=m;i++)
    cin>>A[i]>>B[i];

  cur=n*(n-1)/2;

  for(int i=m;i>=1;i--)
  {
      ans[i]=cur;
      unite(A[i],B[i]);
  }

  for(int i=1;i<=m;i++)
    cout<<ans[i]<<endl;

 return 0;
}

Measured memory_bytes: 5248
#include <stdio.h>

int main(void)
{
int S;
int h,m,s;
scanf("%d" , &S);
h = S / 3600;
m = (S-h*3600)/60;
s = S-h*3600-m*60;
printf("%d:%d:%d\n",h,m,s);
return 0;

}

Measured memory_bytes: 592
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <stack>
#include <string>
#define LINF 1000000000000000005LL
#define SIZE 1005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int T[SIZE],A[SIZE];
int n;

bool solve(ll x)
{
	ll L=x*(ll) T[n-1],R=x*(ll) A[n-1];
	for(int i=n-2;i>=0;i--)
	{
		ll m=min(L/(ll) T[i],R/(ll) A[i]);
		if(m==0) return false;
		L=m*(ll) T[i],R=m*(ll) A[i];
	}
	return true;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d %d",&T[i],&A[i]);
	ll L=0,R=LINF/(ll) (T[n-1]+A[n-1])+5;
	while(R-L>1)
	{
		ll m=(L+R)/2;
		if(solve(m)) R=m;
		else L=m;
	}
	printf("%lld\n",R*(ll) (T[n-1]+A[n-1]));
	return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    auto upd = [](pii &a, int x) {
        if (x > a.second) {
            a.second = x;
            if (a.first < a.second)swap(a.first, a.second);
        }
    };

    int N;
    cin >> N;
    int M = 1 << N;
    vi A(M);
    rep(i, M) cin >> A[i];
    int re = 0;
    FOR(S, 1, M) {
        pii ma(0, 0);
        int T = S;
        do {
            upd(ma, A[T]);
            T = (T - 1)&S;
        } while (S != T);
        smax(re, ma.first + ma.second);
        cout << re << endl;
    }
}

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

int main() {

  int N, X, Y;
  cin >> N >> X >> Y;

  vector<int> Kyori(N);
  int count = 0;

  for(int i = 1; i < N; i++){
    for(int j = i + 1; j <= N; j++){
      if(j - i <= (abs(j - Y) + abs(X - i) + 1)){
        Kyori[j - i]++;
      }else{
        Kyori[abs(j - Y) + abs(X - i) + 1]++;
      }
    }
  }
  for(int i = 1; i < N; i++){
    cout << Kyori[i] << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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 main(){
    int x, n;
    cin >> x >> n;
    if(n == 0) {
        cout << x << endl;
        return 0;
    }
    vi p(n);
    vector<bool> f(2*n, false);
    rep(i, n) {
        cin >> p[i];
        f[p[i]] = true;
    }
    int ans = -1;
    int min_ = 200;
    rep(i, 103) {
        if(min_ > abs(x-i) && !f[i]) {
            ans = i;
            min_ = abs(x-i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n, m;
	int i,j;
	cin>>n>>m;
	vector<vector<int> > 	A;
	A.resize(n);
	for(i=0;i<n;i++){
		A[i].resize(m);
	}
	vector<int> 		b(m), c(n);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>A[i][j];
		}
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			c[i] += A[i][j] * b[j];
		}
	}
	for(i=0;i<n;i++){
		cout << c[i] <<endl;
	}
	return 0;
}

Measured memory_bytes: 1244
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		if (isAbc(s)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	public static boolean isAbc(String s) {
		if (s.equals("abc")) {
			return true;
		} else if (s.equals("acb")) {
			return true;
		} else if (s.equals("bac")) {
			return true;
		} else if (s.equals("bca")) {
			return true;
		} else if (s.equals("cab")) {
			return true;
		} else if (s.equals("cba")) {
			return true;
		}

		return false;

	}

}


Measured memory_bytes: 23124
import Control.Monad
  ( replicateM )
import Data.List
  ( sort )

main :: IO ()
main = do
  [n,_] <- map read . words <$> getLine
  ss    <- replicateM n getLine
  putStrLn $ minimumCombination ss

minimumCombination
  :: [String] -> String
minimumCombination = concat . sort


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  long long int ans=(long long int)a*c;
	if(ans<(long long int)a*d)
    	ans=(long long int)a*d;
  	if(ans<(long long int)b*c)
      	ans=(long long int)b*c;
  	if(ans<(long long int)b*d)
  		ans=(long long int)b*d;
  cout<<ans<<'\n';

 	return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <string> 
using namespace std;

int main(void) {
    int A,B;
    cin >> A >> B;
    if (A == B) {
        cout << "Draw" << endl;
    }
    else if (A == 1) cout << "Alice";
    else if (B == 1) cout << "Bob";
    else if (A > B) cout << "Alice";
    else cout << "Bob";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n' 
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int


int main()
{
	fast;
	int x;cin>>x;
	if(x>=30)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3576
v, e = gets.split.map(&:to_i)
vst = [false]*v
g = v.times.map{[]}
rg = v.times.map{[]}
e.times do
  s,t = gets.split.map(&:to_i)
  g[s] << t
  rg[t] << s
end
cnt = 0
while vst.any?{ |e| !e }
  (0...v).each do |i|
    if rg[i].empty? && !vst[i]
      vst[i] = cnt
      g[i].each{|t| rg[t].delete(i)}
      break
    end
  end
  cnt += 1
end
vst.map.with_index{|e, i| [e, i]}.sort.each{|a| p a[1]}

Measured memory_bytes: 12716
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast()    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod   1000000007
int main()
{
	fast()
	int a[5];
    for(int i=0;i<5;i++)
    {
        cin>>a[i];
        if(a[i]==0)
        {cout<<i+1;
            break;}
    }
}

Measured memory_bytes: 3588
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    N = II()

    cnt = {}
    for x in range(1, 100):
        for y in range(1, 100):
            for z in range(1, 100):
                a = x ** 2 + y ** 2 + z ** 2 + x*y + y*z + z*x
                cnt[a] = cnt.get(a, 0) + 1
    # print(cnt)
    # print(cnt.get(6))

    for i in range(1, N+1):
        print(cnt.get(i, 0))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 11504
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  n <- (read::String -> Int) <$> getLine
  arr <- map (read::String -> Int) . words <$> getLine
  print . minimum $ map countPower arr

countPower::Int -> Int
countPower x = if x `mod` 2 == 0 then 1 + countPower (x `div` 2) else 0


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

typedef long long ll;

string s1;
string s2;
ll n1;
ll n2;
ll memo[3001][3001];
char mm[3001][3001];
int mm1[3001][3001];

ll func(ll i,ll j)
{
	if(i == n1-1 || j==n2-1)
	{
		if(s1[i] == s2[j])
			{
				mm[i][j]=s1[i];
				mm1[i][j]=0;
				return 1;
			}
		else if(i == n1-1 && j == n2-1)
			return 0;
		else if(i == n1-1)
		{
			mm1[i][j]=2;
			return func(i,j+1);
		}
		else
		{
			mm1[i][j]=1;
			return func(i+1,j);
		}
	}

	if(memo[i][j]!=-1)
		return memo[i][j];
	
	if(s1[i] == s2[j])
	{
		memo[i][j]=1+func(i+1,j+1);
		mm[i][j]=s1[i];
		mm1[i][j]=0;
		return memo[i][j];
	}
	else
	{
		ll tt=func(i+1,j);
		ll t1=func(i,j+1);
		memo[i][j]=max(tt,t1);
		if(tt>t1)
			mm1[i][j]=1;
		else
			mm1[i][j]=2;
		return memo[i][j];
	}
 }


int main() 
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
     		//freopen("input.txt", "rt", stdin);
 	#endif
	cin >> s1;
	cin >> s2;
	n1=s1.length();
	n2=s2.length();

	for(int i=0;i<3001;i++)
	{
		for(int j=0;j<3001;j++)
		{
			memo[i][j]=-1;
			mm[i][j]='1';
			mm1[i][j]=-1;
		}
	}
	
	ll vv = func(0,0);
	int i=0;
	int j=0;
	int count=0;
	while(mm1[i][j]!=-1)
	{
		if(mm1[i][j]==0)
		cout<<mm[i][j];
		if(mm1[i][j]==0)
		{
			i++;
			j++;
		}
		else if(mm1[i][j]==1)
		{
			i++;
		}
		else
		{
			j++;
		}
	}
	cout<<"\n";
 	return 0;	
}


Measured memory_bytes: 114816
#include <iostream>
#include <string>
#include <algorithm>
#include<math.h>
#include<set>
using namespace std;

int main() {
	string S;
	cin >> S;
	bool b[26] = { 0 };
	for (int i = 0; i < S.size(); i++) b[S[i]-'a']=1;
	for (int c = 0; c < 26; c++) {
		if (b[c] == 0) {
			cout << (char)(c + 'a') << endl;
			break;
		}
		if(c==25) cout << "None" << endl;
	}
}


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

int main(){
   long int H,count,ans;
   cin>>H;
   
   while(H>0){
      H/=2;
      count++;
   }
   ans=1;
   for(int i=0;i<count;i++){
   ans*=2;
   }
   cout<<ans-1<<endl;
}

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

using namespace std;

const int N=100000;
int n,v[N+5],cost=0;

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    cost+=abs(v[1]);
    for(int i=2;i<=n;i++)
        cost+=abs(v[i]-v[i-1]);
    cost+=abs(v[n]);
    cout<<cost-abs(v[1])-abs(v[2]-v[1])+abs(v[2])<<"\n";
    for(int i=2;i<n;i++)
    {
        cout<<cost-abs(v[i]-v[i-1])-abs(v[i+1]-v[i])+abs(v[i+1]-v[i-1])<<"\n";
    }
    cout<<cost-abs(v[n])-abs(v[n]-v[n-1])+abs(v[n-1])<<"\n";
    cout<<"\n";
    return 0;
}
/**

**/


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

int main(){
  int n; cin >>n;
  int num[100005] = {0};
  rep(i,n){
    int a; cin >>a;
    num[a]++; num[a+1]++;
    num[a-1]++;
  }
  int ans = 0;
  rep(i,100005){
    ans = max(num[i], ans);
  }
  cout << ans << endl;
  return 0; 
}

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

int main(){
    int i, n, x;
    bool check;
    cin >> n;
    for(i = 1; i <= n; i++){
        check = false;
        if(i % 3 == 0){ check = true; }
        else{
            x = i;
            while(x){
                if(x % 10 == 3) check = true;
                x = x / 10;
            };
        }
        if(check) cout << " " << i;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
using namespace std;

double dp[2][65];
double ans[100001];

int main(){
	int n;
	double cnt = 0;
	dp[0][0] = 1.0;
	
	int f = 0;
	for(int i=0;i<=100000;i++){
		
		fill(dp[f^1],dp[f^1] + 65,0);
		for(int j=0;j<=min(j,64);j++){
			double r = 1.0 / pow(2.0,j);
			dp[f^1][min(j+1,64)] += dp[f][min(j,64)] * r;	
			cnt += dp[f][min(j,64)] * r;
			dp[f^1][0] += dp[f][min(j,64)] * (1-r);
		}
		
		f ^= 1;
		ans[i+1] = cnt;
	}
	while(cin >> n , n){
		printf("%.4f\n",ans[n]);
	}
}

Measured memory_bytes: 1500
#include <cstdio>

int main() {
	int N;
	scanf("%d", &N);
	if (!(N & (N - 1)))
		return puts("No"), 0;
	puts("Yes");
	printf("%d %d\n", N + 1, 3);
	for (int i = 2; i < N; i += 2)
		printf("%d %d\n%d %d\n%d %d\n%d %d\n", i + 1, i, i, 1, 1, N + i + 1, N + i + 1, N + i);
	if (N % 2 == 0)
		for (int i = 2; i < N; ++i)
			if ((i ^ N ^ 1) >= 2 && (i ^ N ^ 1) < N) {
				printf("%d %d\n%d %d\n", i % 2 == 0 ? i : N + i, N, (i ^ N ^ 1) % 2 == 0 ? i ^ N ^ 1 : N + (i ^ N ^ 1), 2 * N);
				break;
			}
	return 0;
}


Measured memory_bytes: 2304
//Author:Nirmit Shah
//201701044
//Daiict,Gandhinagar
 
#include<bits/stdc++.h>
using namespace std;
 
//Macros
#define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define ll long long
#define error std::cerr
#define INF LONG_LONG_MAX
//#define MINF=LONG_LONG_MIN
#define MOD 1000000007
#define pii pair<int,int>
#define forn(i,j,n) for(ll i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define ull unsigned long long
 
//Debugging
#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
 
#define all(c) c.begin(),c.end()
 
ll min(ll x,ll y)
{
    if(x>y)
        return y;
    return x;
}
 
ll max(ll x,ll y)
{
    if(x>y)
        return x;
    return y;
}
 
ll gcd(ll x,ll y)
{
    if(!x)
        return y;
    return gcd(y%x,x);
}
 
ll calcpower(ll x, ll y)
{
    ll ans = 1;
    x = x % MOD;
    while (y > 0)
    {
        if (y & 1)
            ans = (ans*x) % MOD;
 
            y = y>>1;
            x = (x*x) % MOD;
    }
    return ans;
}
 
/*bool prime[1000005];
void Sieve(ll n)
{
    for(int i=0; i<1000005; i++)
        prime[i] = true;
    prime[1] = false;
    prime[0] = false;
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p])
        {
            for (ll i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
}*/
 
int main()
{
    Fast;
int a,b,c;
cin>>a>>b>>c;
int maxi=max(max(a,b),c);
if(maxi==a)
a=-1;
else if(maxi==b)
b=-1;
else 
c=-1;
int max2=max(max(a,b),c);
int res=maxi*10+max2;
if(max2==a)
a=-1;
else if(max2==b)
b=-1;
else
c=-1;
if(a!=-1)
res=res+a;
else if(b!=-1)
res=res+b;
else
res=res+c;
cout<<res<<endl;
return 0;
}

Measured memory_bytes: 256
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<int> C;
#define X real()
#define Y imag()
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima INT_MAX
#define imi INT_MIN
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
int n,w;
cin>>n>>w;
int we[n];
ll val[n];
for(int i=0;i<n;i++)
{
	cin>>we[i];
	cin>>val[i];
}
ll dp[n+1][w+1];
for(int i=0;i<n+1;i++)
{
	for(int j=0;j<=w;j++)
	{
		if(i==0||j==0)
		dp[i][j]=0;
		else
		{dp[i][j]=dp[i-1][j];
		if(j>=we[i-1])
			dp[i][j]=max(dp[i][j],val[i-1]+dp[i-1][j-we[i-1]]);
		}
	}
}

cout<<dp[n][w];
}return 0;}







Measured memory_bytes: 79232
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
//const int maxn = 100 + 10;
//int h[maxn];

int main(){
    string a, b;
    cin >> a;
    int len = a.length(), ans = 100000 + 10;
    for(int i = 0; i < len; i++){
        a[i] = a[i] - '0';
    }
    b = a;
    //int len = a.length(), ans = 100000 + 10;
    for(int i = 0; i < 2; i++){
        int j = 0, anw = 0;
        if(i == 0){
            j = 1;
        }
        else{
            a[0] = (a[0] + 1) % 2;
            anw = 1;
        }
        for(; j < len; j++){
            if(j != 0 && a[j] == a[j - 1]){
                a[j] = (a[j] + 1) % 2;
                anw++;
            }
        }
        a = b;
        ans = min(ans, anw);
    }
    cout << ans << endl;
    return 0;
}


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

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

  vector< vector<double> > dp(N + 1, vector<double>(N, -1e20));
  dp[0][0] = 0;
  REP(i, 0, N) REP(j, 0, i + 1) {
    ll sum = 0;
    REP(k, 0, N) if(i - k >= 0 && j - k >= 0) {
      sum += A[i - k];
      dp[i + 1][j] = max(dp[i + 1][j], dp[i - k][j - k] + (double) sum / (k + 1));
    }
  }

  double ans = 0;
  REP(i, N - M, N) ans = max(ans, dp[N][i]);
  printf("%.15lf\n", ans);
}



Measured memory_bytes: 5028
#include <iostream>
#include <list>
#include <algorithm>
#include <vector>
#include <memory>
#include <vector>

int main()
{
    size_t n, m;
    std::vector<size_t> xs;
    std::vector<std::pair<size_t, size_t>> rewrites;
    std::cin >> n >> m;
    xs.reserve(n);
    rewrites.reserve(m);
    for (size_t i = 0; i < n; i++) {
        size_t x;
        std::cin >> x;
        xs.push_back(x);
    }
    for (size_t i = 0; i < m; i++) {
        std::pair<size_t, size_t> p;
        std::cin >> p.first >> p.second;
        rewrites.push_back(p);
    }

    std::sort(xs.begin(), xs.end());
    std::sort(rewrites.begin(), rewrites.end(), [](auto x, auto y) { return x.second > y.second; } );


    size_t index = 0;
    for (auto p : rewrites) {
        size_t count = p.first;
        size_t value = p.second;
        for (size_t i = 0; i < count; i++) {
            if (index >= xs.size()) {
                goto end;
            }
            if (value < xs[index]) {
                goto end;
            }
            xs[index++] = value;
        }
    }
end:

    size_t sum = 0;
    for (auto x : xs) {
        sum += x;
    }
    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);
static const int mod = 1e9+7;
ll cnt[1005];

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

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }

  for (int i = 2; i <= N; i++) {
    int x = i;
    int div = 2;

    while (x > 1) {
      if (x % div == 0) {
        cnt[div]++;
        x /= div;
      } else {
        div++;
      }
    }

  }


  ll ans = 1LL;
  for (int i = 1; i <= N; i++) {
    if (cnt[i] == 0LL) continue;

    ans *= cnt[i] + 1LL;
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}

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


int main()
{
	int n, i, j;
	char egara[4] = {'S', 'H', 'C', 'D'};
	int num[4][13] = { 0 };
	char a[100] = { 0 };
	int b[100] = { 0 };

	cin >> n;

	for (i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}

	for (i = 0; i < n; i++)
	{
		switch (a[i])
		{
			case 'S':
				for (j = 0; j < 13; j++)
				{
					if (b[i] == j+1)
					{
						num[0][j] = b[i];
					}
				}
				break;
			case 'H' :
				for (j = 0; j < 13; j++)
				{
					if (b[i] == j + 1)
					{
						num[1][j] = b[i];
					}
				}
				break;
			case 'C':
				for (j = 0; j < 13; j++)
				{
					if (b[i] == j + 1)
					{
						num[2][j] = b[i];
					}
				}
				break;
			case 'D':
				for (j = 0; j < 13; j++)
				{
					if (b[i] == j + 1)
					{
						num[3][j] = b[i];
					}
				}
				break;
			default:
				break;
		}
	}

	for (i = 0; i < 4; i++)
	{
		for (j = 0; j < 13; j++)
		{
			if (num[i][j] == 0)
			{
				cout << egara[i] << " " << j+1;
				cout << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    if(s.size()%2) {
        cout << "No"; return 0;
    }else {
        for(int i = 0; i < s.size(); i+=2) {
            if(!(s[i] == 'h' && s[i + 1] == 'i')) {
                cout << "No"; return 0;
            }
        }
    } cout << "Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
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 main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    dsu uf(n);
    rep(i,q){
        int t,u,v;
        cin >> t >> u >> v;
        if(t==0){
            uf.merge(u,v);
        }else{
            cout << uf.same(u,v) << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
    // 整数の入力
    int N;
    unsigned long long int result = 1;
    cin >> N;

    for (int i = 1; i <= N; i++) {
        result = i * result % (int)(pow(10, 9) + 7);
    }

  	cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	string s, wall = "";
	vector<string> mp;
	int h, w;
	cin >> h >> w;
	REP(i, w+2) wall += ".";
	mp.push_back(wall);
	REP(i, h){
		cin >> s;
		mp.push_back("." + s + ".");
	}
	mp.push_back(wall);
	REP1(i, h){
		REP1(j, w){
			if(mp[i][j] == '.') mp[i][j] = '0';
			else continue;
			if(mp[i-1][j-1] == '#') mp[i][j]++;
			if(mp[i-1][j+0] == '#') mp[i][j]++;
			if(mp[i-1][j+1] == '#') mp[i][j]++;
			if(mp[i+0][j-1] == '#') mp[i][j]++;
			if(mp[i+0][j+1] == '#') mp[i][j]++;
			if(mp[i+1][j-1] == '#') mp[i][j]++;
			if(mp[i+1][j+0] == '#') mp[i][j]++;
			if(mp[i+1][j+1] == '#') mp[i][j]++;
		}
	}
	REP1(i,h) cout << mp[i].substr(1,w) << endl;
}

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

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

int main(){
    string N;
    cin >> N;
    int sum = 0;
    rep(i, N.length()){
        sum += N.at(i) - '0';
        sum %= 9;
    }
    if(sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3716
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=60;
const double eps=1e-10;
LL a[MAXN];

int main()
{
    LL n;
    while(scanf("%lld",&n)!=EOF)
    {
        for(int i=1;i<=n;++i)
            scanf("%lld",&a[i]);
        bool flag=true;
        LL ans=0,div=0;
        int p=0;
        while(flag)
        {
            p=1;
            if(a[p]<n) flag=false;
            for(int i=1;i<=n;i++)
            {
                if(a[i]>a[p]&&a[i]>=n)
                {
                    flag=true;
                    p=i;
                }
            }
            if(flag)
            {
                div=a[p]/n;
                ans+=div;
                a[p]%=n;
                for(int i=1;i<=n;i++)
                    if(i!=p) a[i]+=div;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

int main() {
    ll d; cin >> n >> d;
    ll dd = d*d;
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        ll x, y; cin >> x >> y;
        ll dis = x*x + y*y;
        if(dd >= dis) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std ;
long long n;
long long s;
//int ans;
long long KT(long long x,long long y)
{
	if(x<y)
	return x;
	else
	return KT(x/y,y)+x%y;
}
int main()
{
//	freopen("string.in","r",stdin);
//	freopen("string.out","w",stdout);
    cin>>n>>s;
    if(s>n)
    {
    	cout<<-1;
    	return 0;
    }
    if(s==n)
    {
    	cout<<1+n;
    	return 0;
    }
    long long sum=sqrt(1e11)+1;
//    if(n<sum)
//    {
    	for(long long i=2;i<=sum;i++)
    	{
    		if(KT(n,i)==s)
    		{
    			cout<<i;
				return 0;	
    		}
//    		else
//    		{
//    			cout<<-1;
//    			return 0;
//    		}
    	}
//    }
    long long ans=1e11; 
	n-=s;
    for(long long i=1;i*i<=n;i++) 
	{
        if(n%i==0) 
		{
            long long b=n/i+1;
            if(KT(n+s,b)==s) 
			ans=min(ans,b);
        }
    }
    if(ans!=1e11)
    cout<<ans;
    else 
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		double r = sc.nextDouble();
		
		System.out.printf("%.8f %.8f\n", r * r * Math.PI, 2 * r * Math.PI);
		
		sc.close();
	}

}



Measured memory_bytes: 28168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    string s = "";
    while(n) {
        ll rem = n % 26;
        n /= 26;
        if(!rem) {s += 'z'; n--;}
        else s += (char)((ll)'a' + rem - 1);
    }
    reverse(s.begin(), s.end());
    cout << s;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3628
def solve():
    h, w = map(int, input().split())
    grid = list(input() for _ in range(h))
    new_grid = []
    white_columns = set([i for i in range(w)])
    for line in grid:
        if line != "." * w:
            new_grid.append(line)
            white_columns &= set([i for i, c in enumerate(line) if c == "."])
    if white_columns:
        for line in new_grid:
            new_line = "".join([c for i, c in enumerate(line) if i not in white_columns])
            print(new_line)
    else:
        print("\n".join(new_grid))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 39024
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  double sum = 0;
  for(int i=0; i<n; i++) {
  	double l;
  	cin >> l;
  	sum += 1/l;
  }
  cout << 1/sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,w,i,l,m,r;
  cin>>n;
  vector<int> s(n+1);
  for(i=1;i<=n;i++){
    cin>>w;
    s.at(i)=s.at(i-1)+w;
  }
  l=0;
  r=n;
  while(r-l>1){
    m=(l+r)/2;
    if(2*s.at(m)<s.at(n)) l=m;
    else r=m;
  }
  cout<<min(s.at(n)-2*s.at(l),2*s.at(r)-s.at(n))<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
int c[10001]={};
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        c[a]++;
    }
    for(int i=0;i<10000;i++){
        for(int j=0;j<c[i];j++){
            printf("%d%c",i,(n==1)?'\n':' ');
            n--;
        }
    }
    return 0;
}


Measured memory_bytes: 2752
def Q3(x):
    N = x[0][0]
    lst = x[1][:]
    s = lst[0]
    allsum = sum(lst)
    minimum = abs(allsum - s * 2)
    
    for k in range(1, N - 1):
        s += lst[k]
        a = abs(allsum - s * 2)
        minimum = min(minimum, a)
    return minimum

l = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
n = [l,m]
print(Q3(n))

Measured memory_bytes: 23800
s=input()
t=input()

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        if len(t)==1:
            li.append(s[:i-len(t)+1]+t+s[i+1:])
        else:

            while True:
                if s[i+1] ==t[tid] or s[i+1]=='?':

                    check+=1
                    i+=1
                    tid+=1

                    if check==len(t):
                        li.append(s[:i-len(t)+1]+t+s[i+1:])
                        break
                else:
                    break

li2=[]      

for i in li:

    li2.append(i.replace('?','a'))
    

li2.sort()


print(li2[0] if li2 else 'UNRESTORABLE')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        //System.out.println("n:" + n);

        int before = 0;
        int longest = 0;
        int longestIndex = 0;

        int[] a = new int[n];
        for(int i=0; i<n;i++){
            a[i] = sc.nextInt();

            int length = a[i] - before;

            if (length > longest){
                longest = length;
                longestIndex = i;
            }
            before= a[i];
        }

        int first = a[0] + (k-a[n-1]);
        if(first > longest){
            longest = first;
        }
        System.out.println(k-longest);




        //System.out.println("k:" +k + " n:" + n + " a[0]:" + a[0] + " a[n]" + a[n-1]);
    }

}

Measured memory_bytes: 66216
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n,greater<int>());
  ll ans=0;
  for(int i=0;i<n;i++){
    if(i==0){
      continue;
    }
    ans+=a[i/2];
  }
  cout<<ans<<endl;
  return 0;
}


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

const int mxN=400;
int n, a[mxN];
long long ps[mxN+1], dp[mxN+1][mxN+1];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];
	for(int i=0; i<n; ++i)
		ps[i+1]=ps[i]+a[i];
	for(int i=n-1; i>=0; --i) {
		for(int j=i+2; j<=n; ++j) {
			dp[i][j]=LLONG_MAX;
			for(int k=i+1; k<j; ++k)
				dp[i][j]=min(dp[i][k]+dp[k][j]+ps[j]-ps[i], dp[i][j]);
		}
	}
	cout << dp[0][n];
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int a[2000], b[2000];
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];
    int mx = *max_element(a, a + n);
    int my = *min_element(b, b + m);
    for (int i = x + 1; i <= y; ++i)
    if (mx < i && i <= my) {
        cout << "No War\n";
        return 0;
    }
    cout << "War\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ls(x) (x)<<1
#define rs(x) (x)<<1|1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define ll rt<<1
#define rr rt<<1|1
#define PI acos(-1)
#define MM int m=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl '\n'
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) (x)&(-x)
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (x)%mo_num
#define vc vector
#define vct vector<int>
#define fa(i,V) for(auto i:V)
#define out(i) cout<<(i)<<endl;
#define fi first
#define sc second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
//#define P pair<int,int>
using namespace std;
const int INF=LLONG_MAX;
const int maxn=1e5+5;
const int mo_num=1e9+7;
int n,m,a[maxn],b[maxn],ans;
struct node{
    int to,next;
}e[maxn<<2];
int vis[maxn<<2],head[maxn<<2],yy[maxn],f[maxn],cnt;
void get_m(int x)
{
    if(x>maxn-5)m++;
    vis[x]=1;
    for(int i=head[x];~i;i=e[i].next)
    {
        int v=e[i].to;
        if(!vis[v])get_m(v);
    }
}
void did(int x)
{
    if(x<=maxn-5) {
        ans += m;
        for (int i = head[x]; ~i; i = e[i].next) {
            ans--;
        }
    }
        f[x]=1;
    for(int i=head[x];~i;i=e[i].next)
    {
        int v=e[i].to;
        if(!f[v])did(v);
    }
}
void add(int x,int y){
    e[cnt]={y,head[x]};//这一行实现了简洁！
    head[x]=cnt++;
}

int32_t main()
{
    IOS
    cin>>n;
    memset(head ,-1,sizeof head);
    fun(i)
    {
        int u,v;
        cin>>u>>v;
        add(u,v+maxn-5),add(v+maxn-5,u);
    }
    fu(i,1,maxn-5)
    {
        if(head[i]==-1 or f[i])continue;
        m=0;
        get_m(i);
        did(i);
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 15616
N, M = map(int, input().split()) # 横に2個
X = list(map(int, input().split()))

if N >= M:
    ans = 0
else:
    X = sorted(X)
    dif = []
    for i in range(M-1):
        dif.append(X[i+1] - X[i])
    dif.sort(reverse=True)
    ans = X[M-1] - X[0] - sum(dif[:N-1])

print(ans)

Measured memory_bytes: 13964
n = int(input())
s = input()

lst = []
for i in range(1,n-1):
    left = s[:i]
    right = s[i:]

    cnt = 0
    for j in set(left):
        if j in set(right):
            cnt += 1
    lst.append(cnt)

if not lst:
    print(0)
else:
    print(max(lst))

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

typedef pair <int, int> ii;

const int Maxn = 105;

int n;
bool ign[Maxn][Maxn];
vector <ii> res;

int main()
{
    scanf("%d", &n);
    int m = n / 2 * 2;
    int l = 1, r = m;
    while (l < r) {
        ign[l][r] = true;
        l++; r--;
    }
    for (int i = 1; i <= n; i++)
        for (int j = i + 1; j <= n; j++) if (!ign[i][j])
            res.push_back(ii(i, j));
    printf("%d\n", int(res.size()));
    for (int i = 0; i < res.size(); i++)
        printf("%d %d\n", res[i].first, res[i].second);
    return 0;
}


Measured memory_bytes: 384
//FIRST THINK THEN CODE.

  #include <bits/stdc++.h>


  using namespace std;

  typedef long long ll;

  #define rep(i,a,b) for(ll i=a;i<b;++i)
  #define rrep(i,a,b) for(ll i=a;i>b;--i)
  #define FOR(i,n)  for(ll i=0;i<n;i++)
  #define vi vector<int>
  #define vl vector<ll>
  #define ld long double
  #define vld vector<ld>
  #define vvi vector<vector<int>>
  #define vvl vector<vector<long long>>
  #define vvld vector<vector<ld>>
  #define pii pair<int,int>
  #define pll pair<long,long>
  #define vpii vector<pii>
  #define vpll vector<pll>
  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define d1(x) cout<<(x)<<endl
  #define d2(x,y) cout<<(x)<<" "<<(y)<<endl
  #define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  #define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
  #define PI 3.1415926535897932384626433832795
  #define fix(f,n) fixed<<setprecision(n)<<f
  #define all(x) x.begin(),x.end()
  #define rev(p) reverse(p.begin(),p.end());
  #define endl "\n"
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define popcount(x) __builtin_popcountll(x)
  #define sz(x) ((ll)x.size())
  const ll M=1000000007;
  const ll MM=998244353;
  ll begtime = clock();
  #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
  //#define _Find_next 
  //#define _Find_first 



  ll newmod(ll a,ll b)
  {
  return ((a%b)+b)%b;
  }


  ll powM(ll a,ll b,ll m )
  { 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
  if(b&1)ans=ans*a%m;
  a=a*a%m;
  b>>=1;
  }

  return ans;
  }



  ll poww(ll a,ll b)
  { 

  ll ans=1;
  while(b)
  {
  if(b&1)ans=ans*a;
  a=a*a;
  b>>=1;
  }

  return ans;

  }

  template<typename T,typename F>
  void chmax( T &a,F b){
  if(b>a)a=b;
  }

  template<typename T,typename F>
  void chmin( T &a,F b){
  if(b<a)a=b;
  }

string tostring(ll x){
  stringstream sss;
  sss<<x;
  string ans=sss.str();
  return ans;
}


  const ll N=1e6+5;


  int main()
  { 

    IOS;

ll a ,b,c;
cin>>a>>b>>c;

ll y=b*c;

if(y>=a)cout<<"Yes";
else cout<<"No";

//end_routine();

  return 0;

  }

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
	cin.tie(0);
	int n;
	cin >> n;
	int num, k;
	vector<vector<int>> c(10, vector<int>(10));
	for(int i=1; i<=n; i++){
		int r = i%10;
		int l;
		num = i;
		while(num!=0){
			k = num%10;
			num = num/10;
		}
		l = k;
		c[l][r]++;
	}
	long long int total = 0;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			total += c[i][j]*c[j][i];
		}
	}
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 3640
W = []
K = []
for i in range(1,21):
    a= int(input())
    if i<11:
        W.append(a)
    else:
        K.append(a)
    i += 1
w = sorted(W, reverse=True)
k = sorted(K, reverse=True)
b = [w[0],w[1],w[2]]
c = [k[0],k[1],k[2]]
print(sum(b),sum(c))


Measured memory_bytes: 5600
from sys import stdin


def validate_num(num, n, sc):
    num = str(num)
    if not len(num) == n:
        return False

    for s, c in sc:
        if not num[s-1] == str(c):
            return False

    return True


def get_result(data):
    N, M = data[0]
    sc = data[1:]
    # 全探索する
    for i in range(1000):
        if validate_num(i, N, sc):
            return i

    return '-1'



if __name__ == '__main__':
    raw_data = [val.rstrip('\n') for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int a,b;

int main(){
    cin>>a>>b;
    if(a+b==3){
        cout<<3;
    }
    else if(a+b==4){
        cout<<2;
    }
    else{
        cout<<1;
    }
}


Measured memory_bytes: 3596
N = input()
N = int(N)
if not(1 <= N and N <= 10**9):
    exit()
ans = 0

if N % 2 == 0:
    i = int(N/2)
    ans = (N+1) * i
    ans -= N
else:
    i = int(N/2)
    ans = N * i

    
print(ans)

Measured memory_bytes: 3060
def main():
    H, W, K = map(int, input().split())
    dp = [[0] * W for _ in range(H + 5)]
    dp[0][0] = 1
    MOD = 10 ** 9 + 7
    for h in range(H):
        for i in range(1 << W-1):
            a = str(bin(i))[2:].zfill(W-1)
            if a.count('11') >= 1:
                continue
            for w in range(W):
                if w == 0:
                    if a[w] == '1':
                        dp[h+1][w+1] += dp[h][w]
                        dp[h+1][w+1] %= MOD
                    elif a[w] == '0':
                        dp[h+1][w] += dp[h][w]
                        dp[h+1][w] %= MOD
                elif w == W - 1:
                    if a[w-1] == '1':
                        dp[h+1][w-1] += dp[h][w]
                        dp[h+1][w-1] %= MOD
                    elif a[w-1] == '0':
                        dp[h+1][w] += dp[h][w]
                        dp[h+1][w] %= MOD
                else:
                    if a[w-1] == '1':
                        dp[h+1][w-1] += dp[h][w]
                        dp[h+1][w-1] %= MOD
                    elif a[w] == '1':
                        dp[h+1][w+1] += dp[h][w]
                        dp[h+1][w+1] %= MOD
                    else:
                        dp[h+1][w] += dp[h][w]
                        dp[h+1][w] %= MOD

    print(dp[H][K-1])







if __name__ == "__main__":
    main()

Measured memory_bytes: 42352
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
#include<set>
#define itn int
#define retrun return
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
//ここまで共通
int N, ans = 0;
vector<int> L;
int BS(int m, int M, int l) {
  	if(l >= L[m]){
      	return m - 1;
    }
	else if (L[m] > l && l >= L[m + 1]) {
		return m;
	}
	else if (L[M] > l) {
		return M;
	}
	else if(M - m <= 4){
		int mid = (m + M) / 2;
		if (L[mid] > l && l >= L[mid + 1]) {
			return mid;
		}
		else if (L[mid] < l) {
			return BS(m, mid, l);
		}
		else {
			return BS(mid, M, l);
		}
	}
  	else{
      	for(int i = m; i <= M; i++){
          	if(L[i] > l && l >= L[i + 1]){
              	return i;
            }
        }
    }
}
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
	}
	sort(L.begin(), L.end(), greater<int>());
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			int k = BS(j + 1, N - 1, L[i] - L[j]);
			ans += k - j;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
L = [["A", 1, 399],
	["B", 400, 799],
	["C", 800, 1199],
	["D", 1200, 1599],
	["E", 1600, 1999],
	["F", 2000, 2399],
	["G", 2400, 2799],
	["H", 2800, 3199],
    ["I", 3200, 4800]]

N = int(input())
P = [int(i) for i in input().split()]
C = []

cnt_I = 0
for i in P:
  if i >= 3200:
    cnt_I += 1
  for c, m, x in L:
      if m <= i and i <= x:
        C.append(c)
        break
        
if "I" in C:
  mx = len(set(C)) - 1 + cnt_I
  mn = len(set(C)) - 1
  if mn == 0:
    mn = 1
else:
  mx = len(set(C))
  mn = len(set(C))

print(mn, mx)

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

int main() {
    int N,r=0;
    string S;
    cin >> N >> S;
    map<char,int> l;
    set<char> f;

    rep(i,N) {
        if(!l.count(S.at(i)))
            l[S.at(i)] = 1;
        else
            l.at(S.at(i))++;
    }

    rep(i,N) {
        int c=0;
        l.at(S.at(i))--;
        if(l.at(S.at(i)) == 0)
            l.erase(S.at(i));

        f.insert(S.at(i));
        for(char t : f)
            if(l.count(t))
                c++;
        r = max(r,c);
    }

    cout << r << endl;
}

Measured memory_bytes: 256