akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    int num[3]={-1, -1, -1};
    
    for(int i=0; i<m; i++){
        int s, c;
        scanf("%d %d", &s, &c);
        if(num[s-1]==-1)num[s-1]=c;
        else if(num[s-1]!=c){
            printf("-1\n");
            return 0;
        }
    }
    
    if(n!=1 && num[0]==0){
        printf("-1\n");
        return 0;
    }
    
    if(n!=1 && num[0]==-1)num[0]=1;
    
    for(int i=0; i<n; i++){
        if(num[i]==-1)printf("0");
        else printf("%d", num[i]);
    }
    return 0;
}


Measured memory_bytes: 1708
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
const int N=200005,inf=0x3f3f3f3f;
int n,k;
int a[N],r[N],b[N];
int suma[N],sumb,sumr;
void init()
{
	read(n); read(k);
	for (int i=1;i<=n;++i)
	{
		read(a[i]);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for (int i=1;i<=k;++i)
	{
		read(r[i]);
	}
	sort(r+1,r+k+1);
	reverse(r+1,r+k+1);
	for (int i=1;i<=k;++i)
	{
		read(b[i]);
	}
	sort(b+1,b+k+1);
	reverse(b+1,b+k+1);
	for (int i=1;i<=n;++i)
	{
		suma[i]=suma[i-1]+a[i];
		sumb+=b[i];
		sumr+=r[i];
	}
}

int dp[62][62][3005];
void solve()
{
	int ans=inf;
	memset(dp,-1,sizeof dp);
	dp[0][0][0]=0;
	//outarr(a,1,n);
	for (int i=0;i<=k;++i)
	{
		for (int j=0;j<=k&&i+j<=n;++j)
		{
			for (int sum=0;sum<=suma[i+j];++sum)
			{
				if (dp[i][j][sum]==-1) continue;
				//out(i); out(j); out(sum); outln(dp[i][j][sum]);
				if (n==i+j)
				{
					if (sumr>=sum&&sumb>=suma[n]-sum)
					{
						//out(i); out(j); out(sum); outln(suma[n]-sum);
						checkmin(ans,suma[n]-dp[i][j][sum]);
					}
					continue;
				}
				if (i<k)
				{
					int new_sum=sum+a[i+j+1];
					checkmax(dp[i+1][j][new_sum],dp[i][j][sum]+_min(r[i+1],a[i+j+1]));
				}
				if (j<k)
				{
					int new_sum=sum;
					checkmax(dp[i][j+1][new_sum],dp[i][j][sum]+_min(b[j+1],a[i+j+1]));
				}
			}
		}
	}
	if (ans==inf) ans=-1;
	printf("%d\n",ans);
}

#undef int
int main()
{
	init();
	solve();
    return 0;
}


Measured memory_bytes: 48416
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,a=0;
	bool ans=true;
	cin>>n;
	string s;
	for(int i=0;i<n;i++){
		cin>>s;
		a--;
		if(s=="A")a+=2;
		if(a<0)ans=false;
	}
	if(a!=0)ans=false;
	if(ans)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 3156
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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

    d.sort();
    debug!(d);
    let mut cnt = 1;
    for i in 1..n {
        if d[i]>d[i-1] {
            cnt += 1;
        }
    }

    println!("{}", cnt);

}


Measured memory_bytes: 2188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;
const int maxN=202000;
const int maxM=maxN<<1;
const ll INF=1e18;

class Edge{
    public:
    int u,v;ll w;
};

int n,m,Q,ufs[maxN];
ll Val[maxN];
Edge E[maxM];

bool cmp(Edge A,Edge B);
int find(int x);
int main(){
    scanf("%d%d",&n,&Q);for (int i=1;i<=n;i++) Val[i]=INF;
    while (Q--){
        int a,b,c;scanf("%d%d%d",&a,&b,&c);++a;++b;
        E[++m]=((Edge){a,b,c});Val[a]=min(Val[a],(ll)c+1);Val[b]=min(Val[b],(ll)c+2);
    }
    Val[1]=min(Val[1],Val[n]+2);for (int i=2;i<=n;i++) Val[i]=min(Val[i-1]+2,Val[i]);
    Val[1]=min(Val[1],Val[n]+2);for (int i=2;i<=n;i++) Val[i]=min(Val[i-1]+2,Val[i]);
    E[++m]=((Edge){n,1,Val[n]});for (int i=1;i<n;i++) E[++m]=((Edge){i,i+1,Val[i]});
    sort(&E[1],&E[m+1],cmp);ll Ans=0;for (int i=1;i<=n;i++) ufs[i]=i;
    for (int i=1;i<=m;i++) if (find(E[i].u)!=find(E[i].v)) Ans+=E[i].w,ufs[find(E[i].u)]=find(E[i].v);
    printf("%lld\n",Ans);return 0;
}
bool cmp(Edge A,Edge B){
    return A.w<B.w;
}
int find(int x){
    if (ufs[x]!=x) ufs[x]=find(ufs[x]);
    return ufs[x];
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

vector<LL> fact;
vector<LL> inver(2000001);
 
LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}
 
 
LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}
 
void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=2000000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[2000000]=fpow(fact[2000000],mod-2);
    for(int i=1999999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}


int main(){
    set_combi();
    LL x,y;cin >> x >> y;
    if(2*x-y<0||2*y-x<0||(2*x-y)%3||(2*y-x)%3){
        cout << 0 << endl;
        return 0;
    }
    LL a = (2 * x - y) / 3;
    LL b = (2 * y - x) / 3;
    cout << combi(a+b,a) << endl;
    return 0;
}




Measured memory_bytes: 34408
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

#define C(I) cout<<(I)<<endl

string s;
int a,m;

vector<int> to2(int target,int digit){
    vector<int> tovec;
    for(int i=0;i<digit;i++){
        tovec.push_back(target%2);
        target=target>>1;
    }
    return tovec;
}


int main(){
    cin>>s;
    vector<int> q;
    int as[]={int(s[0])-int('0'),int(s[1])-int('0'),int(s[2])-int('0'),int(s[3])-int('0')};
    for(int i=0;i<7;i++){
        a=as[0];
        q=to2(i,3);
        for(int i=1;i<4;i++){
            if(q[i-1]==0)a+=as[i];
            else a-=as[i];
        }
        if(a==7){
            m=i;
            break;
        }
    }
    for(int i=0;i<3;i++){
        q=to2(m,3);
        cout<<as[i];
        cout<<(q[i] ? "-":"+");
    }
    cout<<as[3]<<"=7";
    cout<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n, a, b;
    scanf("%d", &n);
    if(n == 1)
    {
        printf("Hello World\n");
    }
    else if(n == 2)
    {
        scanf("%d%d", &a, &b);
        printf("%d\n", a + b);
    }
    return 0;
}

Measured memory_bytes: 128
while 1:
    try:
        C1, C2, C3 = map(int, input().split())
    except:
        break

    card = list(range(1, 11))

    card.remove(C1)
    card.remove(C2)
    card.remove(C3)

    cnt = 0
    for c in card:
        sum = C1 + C2 + c
        if sum <= 20:
            cnt += 1

    if cnt > 3:
        print("YES")
    else:
        print("NO")



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

int main(){
  int N, Wnum, Enum, WEnum, minnum;
  char S[300001];
  int Wsum[300001];
  
  cin >> N;
  for(int i=1; i<N+1; ++i) cin >> S[i];
  
  Wsum[0] = 0;
  for(int i=0; i<N; ++i)
    Wsum[i+1] = Wsum[i] + ((S[i+1]=='W')?1:0);
  minnum = N;
  for(int i=1; i<N+1; ++i) {
    Wnum = Wsum[i-1];
    Enum = (N-i)-(Wsum[N]-Wsum[i]);
    WEnum = Wnum + Enum;
    if(minnum > WEnum) minnum = WEnum;
  }
  
  cout << minnum << endl;
  return 0;
  
}

Measured memory_bytes: 1664
import sys
n = int(input())
ls = []
_sum = 0
_min = None
for i in range(n):
    s = int(sys.stdin.readline())
    _sum += s
    if s % 10 != 0:
        _min = s if _min is None else min(_min, s)
if _min is None:
    print(0)
else:
    if _sum % 10 == 0:
        print(_sum - _min)
    else:
        print(_sum)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int c = b - a;
		int b_ = 0;
		for (int i = 1; i <= c; i++) {
			b_ += i;
		}
		System.out.println(b_ -b);

	}

}


Measured memory_bytes: 22100
#include <iostream>
using namespace std;
int dp[110][19];//[??\][????????\????????????????????????????\????????????]
int pst[110];
int main(){
	int N,K,tmp,sum;
	cin>>N>>K;
	for(int i=0;i<=N;i++){
		for(int j=0;j<9;j++){
			dp[i][j]=0;
		}
		pst[i]=0;
	}
	for(int i=0;i<K;i++){
		cin>>tmp;
		cin>>pst[tmp];
	}
	switch(pst[1]){
	case 0:
		dp[1][1]=1;
		dp[1][2]=1;
		dp[1][3]=1;
		break;
	case 1:
		dp[1][3]=1;
		break;
	case 2:
		dp[1][1]=1;
		break;
	case 3:
		dp[1][2]=1;
		break;
	}
	
	//dp [i][j]???????????\??????????????¢??¬%10000
	for(int i=1;i<N;i++){
		switch(pst[i+1]){
		case 0:
			dp[i+1][0]=(dp[i][3]+dp[i][6])%10000;
			dp[i+1][1]=(dp[i][0]+dp[i][3]+dp[i][6])%10000;
			dp[i+1][2]=(dp[i][0]+dp[i][3]+dp[i][6])%10000;
			dp[i+1][3]=(dp[i][1]+dp[i][4]+dp[i][7])%10000;
			dp[i+1][4]=(dp[i][1]+dp[i][7])%10000;
			dp[i+1][5]=(dp[i][1]+dp[i][4]+dp[i][7])%10000;
			dp[i+1][6]=(dp[i][2]+dp[i][5]+dp[i][8])%10000;
			dp[i+1][7]=(dp[i][2]+dp[i][5]+dp[i][8])%10000;
			dp[i+1][8]=(dp[i][2]+dp[i][5])%10000;
			break;
		case 1:
			dp[i+1][0]=(dp[i][3]+dp[i][6])%10000;
			dp[i+1][3]=(dp[i][1]+dp[i][4]+dp[i][7])%10000;
			dp[i+1][6]=(dp[i][2]+dp[i][5]+dp[i][8])%10000;
			break;
		case 2:
			dp[i+1][1]=(dp[i][0]+dp[i][3]+dp[i][6])%10000;
			dp[i+1][4]=(dp[i][1]+dp[i][7])%10000;
			dp[i+1][7]=(dp[i][2]+dp[i][5]+dp[i][8])%10000;
			break;
		case 3:
			dp[i+1][2]=(dp[i][0]+dp[i][3]+dp[i][6])%10000;
			dp[i+1][5]=(dp[i][1]+dp[i][4]+dp[i][7])%10000;
			dp[i+1][8]=(dp[i][2]+dp[i][5])%10000;
			break;
		}
	}
	sum=0;
	for(int i=0;i<9;i++){
		sum+=dp[N][i];
	}
	sum%=10000;
	cout<<sum<<endl;

	/*
	for(int i=0;i<=N;i++){
		for(int j=0;j<9;j++){
			cout<<"dp["<<i<<"]["<<j<<"]="<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/

	return 0;
}

Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {
  static int counter;
  public static void main(String[] args) {
    Scanner scanInt = new Scanner(System.in);
    int N = scanInt.nextInt();
    int[] nums = new int[N];
    for(int i = 0; i < N; i++){
      nums[i] = scanInt.nextInt();
    }
    for(int i = 0; i < N; i++){
      for(int j = nums.length - 1; j > i; j--){
        if(nums[j] < nums[j-1]){
          int dum = nums[j];
          nums[j] = nums[j-1];
          nums[j-1] = dum;
          counter ++;
        }
      }
    }

    for(int i = 0; i < N-1; i++){
      System.out.print(nums[i] + " ");
    }
    System.out.println(nums[N-1]);
    System.out.println(counter);
  }

}



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

//143_C

int N;

int main(){
    cin>>N;
    char s[N],c;
    int ans=1;
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    c=s[0];
    for(int i=1;i<N;i++){
        if(c!=s[i]){
            ans++;
            c=s[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
*T[99]={"OUT OF MAIN PANEL"},X[99],Y[99],V[99],W[99],c[99],w;P(p){for(c[p]=0;scanf("%a[^/>]>%d,%d,%d,%d<",T+w,X+w,Y+w,V+w,W+w)&&scanf("%*[^>]>%[<]",X,c[p]++,P(w++)););}main(n,x,y,i){for(;scanf("%d\n<",&n)*n;)for(w=1,P(0);n--;printf("%s %d\n",T[i],c[i]))for(scanf("%d%d",&x,&y),i=w;--i&&x<X[i]|y<Y[i]|x>V[i]|y>W[i];);}

Measured memory_bytes: 0
//  cd Desktop/Prog_Contest
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define rep(i,n) for(i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

int main(){
    int i,n,a[100002]={},ans[100002]={},tmp=0;
    scanf("%d",&n);
    rep(i,n){
        scanf("%d",&a[i]);
        ans[a[i]-1]=i;
    }
    rep(i,n){
        tmp=ans[i];
        printf("%d ",tmp+1);
    }
    return 0;
}

Measured memory_bytes: 2456
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();
    if(t*s>=d){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 35856
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long *)a>*(long long*)b)return 1;
    return -1;
}
long long Max(long long a,long long  b){
    if(a>b )return a;
    return b;
}
long long Min(long long  a,long long  b){
    if(a<b )return a;
    return b;
}
int main()
{   int a,b,c,n,k,i,m=0,x[100]={0},y;
    scanf("%d%d%d",&a,&b,&k);
    for(i=1;i<=Min(a,b);i++){
        if(a%i==0&&b%i==0){
            x[m]=i;
            m++;
        }
    
    }
    for(i=m;i>=0;i--){
        if(m-i==k){
            printf("%d",x[i]);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <optional>
#include <queue>
#include <set>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

int64_t read_int() {
    int64_t ret = 0, sgn = 1;
    int ch = getchar_unlocked();
    while (isspace(ch)) { ch = getchar_unlocked(); }
    if (ch == '-') { sgn = -1; ch = getchar_unlocked(); }
    for (; isdigit(ch); ch = getchar_unlocked())
        ret = (ret * 10) + (ch - '0');
    ungetc(ch, stdin);
    return sgn * ret;
}

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

template <typename T> inline void assign_min(T& x, const T& value) noexcept { x = min(x, value); }
template <typename T> inline void assign_max(T& x, const T& value) noexcept { x = max(x, value); }

constexpr char LF = '\n';

//-------------------------------------------------------------------------------------------------

int64_t median(vector<int64_t>& X) {
    sort(ALL(X));
    int n = X.size();
    if (n % 2 == 0) {
        return X[n/2-1] + X[n/2];
    } else {
        return X[n/2];
    }
}

int main() {
    int N = read_int();
    vector<int64_t> A(N), B(N);
    REP(i, N) {
        A[i] = read_int();
        B[i] = read_int();
    }
    auto a = median(A);
    auto b = median(B);
    cout << (b - a + 1) << LF;
}


Measured memory_bytes: 5992
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(x) x.begin(),x.end()

int main(){
    int n;
    while(cin>>n){
        if(n==0)break;
        string data[10001];
        string ans[10001]={};
        rep(i,n) cin>>data[i];
        
        bool tate[10001]={false};
        for(int i=n-1;i>=0;i--){
            rep(j,data[i].size()){
                if(data[i][j]=='.'){
                    if(tate[j]==true){
                        if(0<i && data[i-1][j]=='.' && data[i][j+1]=='.')ans[i]+='|';
                        else{
                            ans[i]+='+';
                            tate[j]=true;
                            for(int k=j+1;k<data[i].size();k++) tate[k]=false;
                        }
                    }
                    else if(j<data[i].size()-1 && data[i][j+1]!='.'){
                        tate[j]=true;
                        for(int k=j+1;k<data[i].size();k++) tate[k]=false;
                        ans[i]+='+';
                    }
                    else ans[i]+=' ';
                }
                else ans[i]+=data[i][j];
            }
        }
        for(int i=0;i<n;i++)cout<<ans[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 2852
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())




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

	long long n, m;
	cin >> n >> m;

	if (n == 1 && m == 1) {
		cout << 1 << endl;
	}
	else if (n == 1) {
		cout << m - 2 << endl;
	}
	else if (m == 1) {
		cout << n - 2 << endl;
	}
	else {
		cout << (n - 2)*(m - 2) << endl;
	}


	return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
string S,T;

signed main(){
    cin>>N>>S>>T;

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

    vint A,B;
    rep(i,N-1){
        if(S[i+1]==S[i])A.pb(i);
        if(T[i+1]==T[i])B.pb(i);
    }


    int ans=LLONG_MAX;

    rep(uku,2){
        for(int d=0;d<=N;d++){
            if((S[0]-'0'+d)%2!=(T[0]-'0'))continue;
            int cost=0;
            rep(i,d){
                if(i<B.size())cost+=B[i]+1;
                else cost+=N-2+1+1;
            }
            rep(i,A.size()){
                if(i+d<B.size())cost+=abs(A[i]-B[i+d]);
                else cost+=N-2-A[i]+1;
            }
            for(int i=d+A.size();i<B.size();i++)cost+=N-2-B[i]+1;
            chmin(ans,cost);
        }
        swap(A,B);
    }




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


Measured memory_bytes: 384
n=int(input())
a=[None]*n
max = 0
max_i = 0
for i in range(n):
  a[i] = int(input())
  if a[i] > max:
    max = a[i]
    max_i = i

max_2 = 0
for i in range(n):
  if i == max_i:
    continue
  elif a[i] > max_2:
    max_2 = a[i]

for i in range(n):
  if i != max_i:
    print(max)
  else:
    print(max_2)
    




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

long long spf[1000009],ara[1000009],mod=1000000007;
map<long long,long long>mp;

long long bigmod(long long n,long long p)
{
     if(p==0)return 1;
     if(p%2==0)
     {
         long long ret=bigmod(n,p/2);
         return ((ret%mod)*(ret%mod))%mod;
     }
     else
        return ((n%mod)*(bigmod(n,p-1)%mod))%mod;
}


long long getfactor(long long num,long long lcm)
{
    while(num!=1)
    {
        long long x=spf[num];  mp[x]++;
        if(mp[x]>ara[x])
        {
            lcm=(lcm*x)%mod;  ara[x]=mp[x];
        }

        num=num/x;


    }

    return lcm;


}


int main()
{


    long long n,m,i,j,k,a,b,c,d,e,ans=0,lcm=1;  vector<long long>v;

    spf[1]=1;

    for(i=2;i<=1000006;i+=2)spf[i]=2;

    for(i=3;i<=1000006;i+=2)
    {
        if(spf[i]==0)
        {

            spf[i]=i;

            for(j=3*i;j<=1000006;j+=(2*i))
            {
                spf[j]=i;
            }

        }


    }

    scanf("%lld",&n);

    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a);  v.push_back(a);

        mp.clear();  e=getfactor(a,lcm);  lcm=e;


    }


    for(i=0;i<n;i++)
    {

        b=v[i];  c=bigmod(b,mod-2);  d=(c*lcm)%mod;  ans=(ans+d)%mod;


    }


    printf("%lld\n",ans);


    return 0;
}


Measured memory_bytes: 15428
from collections import Counter
N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

d=Counter(D)
for i in range(M):
    if T[i] not in d or d[T[i]]==0:
        print('NO')
        exit()
    d[T[i]]-=1
print('YES')

Measured memory_bytes: 41700
a,b=map(int,input().split())
s = input()
sa = [s[i] for i in range(a)]
sb = [s[j] for j in range(a+1,a+b+1)]
if '-' not in sa and '-' not in sb and s[a] == '-':
        print('Yes')
else:
        print('No') 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y); // merge technique
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) {
    return -par[root(x)];
  }
};

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

  ll n,m,k;
  cin>>n>>m>>k;

  UnionFind uf(n);

  vll A[n],B[n];
  REP(i,m){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    A[a].push_back(b);
    A[b].push_back(a);
    uf.merge(a,b);
  }

  REP(i,k){
    ll c,d;
    cin>>c>>d;
    d--;
    c--;
    B[d].push_back(c);
    B[c].push_back(d);
  }

  vll t(n,0);

  map<ll,ll> p;
  REP(i,n){
    ll x = uf.root(i);
    p[x] += 1;
  }

  REP(i,n){
    ll x = uf.root(i);
    t[i] = p[x]-1;
    REP(j,A[i].size()){
      ll y = A[i][j];
      if(x==uf.root(y))
        t[i]--;
    }
    REP(j,B[i].size()){
      ll y = B[i][j];
      if(x==uf.root(y))
        t[i]--;
    }
  }


  cout<<t[0];
  REP1(i,n)cout<<" "<<t[i];
  cout<<endl;
}


Measured memory_bytes: 17792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n, k, ll;
    vector<int> l;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> ll;
        l.push_back(ll);
    }
    sort(l.begin(), l.end());
    int ans = 0;
    for(int i = n-1; i >= n-k; i--){
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R(i,n) for(int i=0;i<n;i++)
using namespace std;main(){int N,M,i,j;cin>>N>>M;vector<int>D(N);vector<int>C(M);R(i,N){cin>>D[i];}R(i,M){cin>>C[i];}vector<vector<int> >dp(M+1,vector<int>(N+1,1<<30));dp[0][0]=0;R(i,M){R(j,N+1){if(j==0){dp[i+1][j]=dp[i][j];}else{dp[i+1][j]=min(dp[i][j],dp[i][j-1]+C[i]*D[j-1]);}}}printf("%d\n",dp[M][N]);}

Measured memory_bytes: 5868
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

import numpy as np

N = int(inp())
A = np.array(inp().split(), dtype=np.int64)
MOD = 10**9+7

ans = 0
for k in range(60):
  x0 = 0 # k桁目のbitが0になる総数
  x1 = 0 # k桁目のbitが1になる総数
  B = (A>>k) & 1 # k桁目が1になる要素
  
  # k桁目が 0, 1 のどちらかを数えておく
  x1 = np.count_nonzero(B)
  x0 = N - x1
  # x0 * x1 が 0, 1 の組み合わせ数
  cmb = x0 * x1  
  ans += (cmb * 2**k) % MOD # 10進数に変換
print(ans%MOD)  
  

Measured memory_bytes: 36988
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll mod = 1e9 + 7;

int main() {
    ll N, M;
    cin >> N >> M;
    V<ll> S(N), T(M);
    for(ll &e : S) cin >> e;
    for(ll &e : T) cin >> e;
    
    auto dp = make_v<ll>(-1, N + 2, M + 2);
    for(ll i = 0; i <= N; i++) dp[i][0] = 1;
    for(ll i = 0; i <= M; i++) dp[0][i] = 1;

    function<ll(ll, ll)> calc = [&](ll si, ll ti) {
        DEBUG(PLL(si, ti));
        if(dp[si][ti] != -1) return dp[si][ti];
        ll ret = 0;
        if(S[si - 1] == T[ti - 1]) {
            ret = calc(si - 1, ti -1);
            DEBUG(make_tuple(si, ti, ret));
        }
        (ret += calc(si - 1, ti) + calc(si, ti - 1)) %= mod;
        (ret += mod - calc(si - 1, ti - 1)) %= mod;
        return dp[si][ti] = ret;
    };


    ll ans = calc(N, M);
    DEBUG(dp);
    // for(ll i = 0; i <= N; i++) for(ll j = 0; j <= M; j++) chmax(ans, dp[i][j]);

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


Measured memory_bytes: 32256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
class UnionFind{
public:
  //親の番号を格納する変数。数値がマイナスの場合は親であり、その絶対値のサイズのグループを持っている
  vector<int> Parent;
  
  //コンストラクタ。-1で初期化する。
  UnionFind(int N){
    Parent = vector<int>(N,-1);
  }
  
  //Aが何処のグループに属しているか返す
  int root(int A){
    if(Parent[A] < 0) return A; //0以下の時は自分が親。自分のグループなので自分を返す
    return Parent[A] = root(Parent[A]); //根でなかった場合は再帰的に関数を呼ぶ。ついでにParent[A]を更新して次の時高速化する。
  }
  
  //自分の親の頂点数を返す。マイナスでグループのサイズを持っているので反転して返す。
  int size(int A){
    return -Parent[root(A)];
  }
  
  //AとBを連結する関数
  bool connect(int A, int B){
    A = root(A); //Aの親を持ってくる
    B = root(B); //Bの親を持ってくる
    if (A==B){ //親が同じだったらくっつけない
      return false;
    }
    
    //Aが必ず大きい数にする
    if (size(A) < size(B)) swap(A,B);
    
    //AにBのグループをくっつける。
    Parent[A] += Parent[B];
    //Bの親をAにする。
    Parent[B] = A;
    
    return true;
  }
};

int main(){
  int N,M; cin >> N >> M;
  vector<int> P(N);
  rep(i,N) cin >> P[i];
  
  UnionFind Uni(N);
  
  rep(i,M){
    int x,y;
    cin >> x >> y; x--; y--;
    Uni.connect(x,y);
  }
  
  int cnt = 0;
  rep(i,N){
    if(Uni.root(i) == Uni.root(P[i]-1)) cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

long long n,a,m,k,q,b,c=1;
string ss,s1,s2;
int main(){
    cin>>s1>>s2;
    for (int i=0; i<3; i++){
        if (s1[i]==s2[i]){
            a++;
        }
    }
    cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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 h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];

  auto check = [&](int y, int x) {
    bool ok = false;
    rep(i,4) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (!(0 <= ny && ny <= h-1 && 0 <= nx && nx <= w-1)) continue;
      if (s[ny][nx] == '#') ok = true;
    }
    return ok;
  };

  rep(y,h) {
    rep(x,w) {
      if (s[y][x] == '.') continue;
      if (!check(y,x)) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
/*
[abc123] D - Cake 123
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_X = 1000;
const ll MAX_A = 1e10;

int X[3], K;
ll A[3][MAX_X];

bool can(ll t) {
    int cnt = 0;
    for (int i = 0; i < X[0]; i++) {
        for (int j = 0; j < X[1]; j++) {
            for (int k = 0; k < X[2]; k++) {
                ll s = A[0][i] + A[1][j] + A[2][k];
                if (s < t) {
                    break;
                }
                cnt++;
                if (cnt >= K) {
                    return true;
                }
            }
        }
    }

    return false;
}

vector<ll> solve() {
    for (int i = 0; i < 3; i++) {
        sort(A[i], A[i] + X[i], greater<ll>());
    }

    ll ok = 0, ng = MAX_A * 3;
    while (ng - ok > 1) {
        ll m = (ng + ok) / 2;
        if (can(m)) {
            ok = m;
        } else {
            ng = m;
        }
    }

    ll t = ok;
    vector<ll> ans;
    for (int i = 0; i < X[0]; i++) {
        for (int j = 0; j < X[1]; j++) {
            for (int k = 0; k < X[2]; k++) {
                ll s = A[0][i] + A[1][j] + A[2][k];
                if (s < t) {
                    break;
                }
                ans.push_back(s);
            }
        }
    }
    sort(ans.begin(), ans.end(), greater<ll>());
    ans.resize(K);

    return ans;
}

int main() {
    cin >> X[0] >> X[1] >> X[2] >> K;
    for (int j = 0; j < 3; j++) {
        for (int i = 0; i < X[j]; i++) {
            cin >> A[j][i];
        }
    }

    auto ans = solve();
    for (ll v : ans) {
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 133468
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

	vector<int> f(m);
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			a--;
			f[a]++;
		}
	}

	int cnt = 0;
	for (int i = 0; i < m; i++) {
		if (f[i] == n) {
			cnt++;
		}
	}

	cout << cnt << endl;
}


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

long long int gcd(long long int m,long long int n ){
  if(0 == n) return m;
  return gcd(n,m%n);
}

long long int lcm(long long int m,long long int n){
  long long int g=gcd(m,n);
  return m/g*n;
}

int main(){
  int N;
  cin >>N;
  long long int T;
  long long int ans=1;
  for(int i=0;i<N;i++){
    cin >>T;
    ans = lcm(ans,T);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    cout << 111 * ceil(N / 111.0) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>


typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

template<typename T>
T fastPow(T a, T b, T mod = 0) {
	if (a == 0 and b == 0) {
		return -1;
	}
	if (a == 0) {
		return 0;
	}
	if (b == 0) {
		return 1;
	}
	long long tmp = fastPow(a, b / 2, mod);
	if (mod != 0) {
		if (b % 2 == 0) {
			return (tmp * tmp) % mod;
		}
		else {
			return ((tmp*tmp) % mod * (a % mod)) % mod;
		}
	}
	else {
		if (b % 2 == 0) {
			return (tmp*tmp);
		}
		else {
			return tmp * tmp * a;
		}
	}
}
int main() {
	ll m, n;
	cin >> m >> n;
	cout << fastPow(m, n, mop) << endl;
}



Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

struct col{
	double L;
	double a;
	double b;
};

double dist( col c1, col c2 ) {
	double d =
		( c1.L - c2.L ) * ( c1.L - c2.L )
		+ ( c1.a - c2.a ) * ( c1.a - c2.a ) 
		+ ( c1.b - c2.b ) * ( c1.b - c2.b );
	return d;
}

int main(void){
	vector< unsigned int > bits;
	vector< col > cols;
	vector< double > ds;

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i++ ) {
		col c;
		cin >> c.L >> c.a >> c.b;
		cols.push_back( c );
	}
	
	if( M == 0 ) {
		printf("%lf\n" , 0.0);
		return 0;
	}

	//ビットテーブル作成
	unsigned long long  S = ( 1ULL << M ) - 1ULL;
	unsigned long long  E = ~(( 1ULL << N ) - 1ULL );
	while( !( S & E ) ) {
		bits.push_back(S);
		unsigned long long smallest  = S & -S;
		unsigned long long ripple = S + smallest;
		unsigned long long nsmallest = ripple & -ripple;
		S = ripple | (( ( nsmallest / smallest ) >> 1 ) - 1);
	}

	for(int i = 0; i < bits.size(); i++) {
		double d = 0.0;
		for(int j = 0; j < N; j++) {
			if( !( bits[i] & (1 << j) ) ) continue;
			for(int k = j + 1; k < N; k++) {
				if( !( bits[i] & ( 1 << k ) ) ) continue;
				d += dist( cols[j], cols[k] );
			}
		}
		ds.push_back( d );
	}

	double max = 0.0;
	for(int i = 0; i < ds.size(); i++)
		if( max < ds[i] ) max = ds[i];

	printf("%.8lf\n", max);

    return 0;
}

Measured memory_bytes: 3884
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ford(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

void solve()
{
    int n;
    cin>>n;

    vector<int> a(n);
    int sum = 0;
    rep(i,0,a.size())
    {
        cin>>a[i];
        sum += a[i];
    }
    int sum1 = sum;
    sum = ceil(sum/(float)n);
    sum1 = floor(sum1/(float)n);
    // out1(sum1);
    int ans1 = 0,ans2 = 0;

    rep(i,0,a.size())
    {
        ans1 += (sum-a[i])*(sum-a[i]);
        ans2 += (sum1-a[i])*(sum1-a[i]);
    }

    cout<<min(ans1,ans2)<<endl;

}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<int> v(5);
  for(int i = 0; i< 5; i++)
  {
    cin>> v[i];
  }
  int flag = 0;
  int k;
  cin>>k;
  int dist = 0;
  for(int i = 0; i < 5; i++)
  {
    for(int j = 0; j < 5; j++)
    {
      dist = abs(v[i]-v[j]);
      if(dist>k)
      {
        flag = 1;
      }
    }
  }
  if(flag == 0)
  {
    cout<<"Yay!";
  }
  else
  {
    cout<<":(";
  }
  return 0;
}



Measured memory_bytes: 256
from fractions import gcd

MOD = 1000000007
N = int(input())
A = list(map(int, input().split()))
lcm = 1
for c in A:
    g = gcd(lcm, c)
    lcm *= c // g
ans = 0
for c in A:
    ans += lcm // c
print(ans % MOD)

Measured memory_bytes: 6112
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
int k,n;
char num[15];
bool chack(char a[])
{
	int flag1 = 0, flag2 = 0, flag3 = 0;
	for (int i = 1;i <= k;i++)
	{
		if (a[i] == '3') flag1 = 1;
		if (a[i] == '5') flag2 = 1;
		if (a[i] == '7') flag3 = 1;
	}
	if (flag1 && flag2 && flag3) return true;
	else return false;
}
ll qpow(int x, int y)
{
	ll res = 1;
	for (int i = 0;i < y;i++)
	{
		res *= 1ll * x;
	}
	return res;
}
ll st[1000010],s;
char b[4] = { '\0','3','5','7' };
void dfs(int t)
{
	if (t > k)
	{
		if (chack(num))
		{
			s++;
			for (int i = 1,j=k-1;i <= k;i++,j--)
			{
				st[s] += (1ll*num[i] - '0') * qpow(10, j);
			}	
		}
		return;
	}
	for (int i = 1;i <= 3;i++)
	{
		num[t] = b[i];
		dfs(t + 1);
		num[t] = '\0';
	}
}
int main()
{
	int digt= 0;
	cin >> n;
	int tmp = n;
	while (tmp)
	{
		digt++;
		tmp /= 10;
	}
	for (k = 3;k <= digt+1;k++)
	{
		dfs(1);
	}
	sort(st + 1, st + s + 1);
	int ans = 0;
	for (int i = 1;i <= s;i++)
	{
		if (st[i] > n)
		{
			ans = i - 1;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
  cin>>n;
  int ar[n+1]={0};
  for(int i=1;i<n;i++)
  {
    int x;
    cin>>x;
    ar[x]++;}
  for(int i=1;i<=n;i++)
    cout<<ar[i]<<endl;
  return 0;
}


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

int balls_cnt(int x, string S, int y, string T, string U){
    if(S == U){
        return 0;
    }else{
        return 1;
    }
}

int main(){
    string S,T; cin >> S >> T;
    int A, B; cin >> A >> B;
    string U; cin >> U;

    if(balls_cnt(A,S,B,T,U)==0){
        cout << A-1 << " " << B << endl;
    }
    else{
        cout << A << " " << B-1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		String S = sc.nextLine();
        String T = sc.nextLine();
      int ans=0;
      for(int i=0;i<S.length();i++){
        char s=S.charAt(i);
        char t=T.charAt(i);
        if(s!=t){
          ans++;
        }
      }
      System.out.println(ans);
}
}

Measured memory_bytes: 42632
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):
    f = False
    n = len(S)
    for i in range(n):
        if S[n-i:]+S[:n-i] == T:
            f = True

    if f:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;


signed main()
{
    // int x = 5;
    // cout << x++;
    // cout << x;
    // return 0;
    int n;
    cin >> n;
    vector<vector<int>> adj; // Outside main
    adj.resize(n); // Inside main
    vector<pair<int, int>> vp(n-1);
    rep(i, 0, n-1)
    {
        int a, b;
        cin >> a >> b;
        a--; b--; // To have graph indexed from 0
        adj[a].push_back(b);
        adj[b].push_back(a);
        vp[i] = {a, b};
    }
    // vector<vector<int>> adj;  // adjacency list representation
    // int n; // number of nodes
    int s = 0; // source vertex
    int mx = 0;
    map<pair<int, int>, int> mp;
    queue<int> q;
    vector<bool> used(n);
    // vector<int> d(n), p(n);
    vector<int> cs(n, 0);
    q.push(s);
    used[s] = true;
    // p[s] = -1;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        mx = max(mx, (int)adj[v].size());
        int curr = 1;
        for (int u : adj[v]) {
            if (!used[u]) {
                if (cs[v] == curr)
                    curr++;
                cs[u] = curr;
                // mp[{u,v}] = curr;
                mp[{v,u}] = curr;
                curr++;
                used[u] = true;
                q.push(u);
            }
        }
    }
    cout << mx << endl;
    for (auto x:vp)
        cout << mp[x] << endl;    
    return 0;
}

Measured memory_bytes: 17968
def bit_make(n,m):
    s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)]
    s2 = []
    for i in range(2**n):
        if sum(s[i])==m:
            s2.append(s[i])
    return s2

n = int(input())
march = [0]*5
c = [0]*5
ans = 0
for i in range(n):
    s = input()
    if s[0] == 'M':
        march[0]+=1
        c[0]=1
    if s[0] == 'A':
        march[1]+=1
        c[1]=1
    if s[0] == 'R':
        march[2]+=1
        c[2]=1
    if s[0] == 'C':
        march[3]+=1
        c[3]=1
    if s[0] == 'H':
        march[4]+=1
        c[4]=1
m = sum(c)
march.sort(reverse = True)
x = bit_make(m,3)
ans1 = 1
for i in range(len(x)):
    for j in range(m):
        if x[i][j]==1:
            ans1*=march[j]*x[i][j]
    ans+=ans1
    ans1=1

print(ans)


Measured memory_bytes: 3064
using System;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var A = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var ans = int.MaxValue;

        for (var i = 0; i < N; i++)
        {
            var cnt = 0;
            while (A[i] % 2 == 0)
            {
                cnt++;
                A[i] /= 2;
            }
            ans = Math.Min(ans, cnt);
        }
        WriteLine(ans);
    }
}


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

int main()
{
	int N,M;cin >> N >>M;
	int ans=0;
	vector<vector<int>> lamp (M,vector<int>(N,0));
	int k,s;
	for (int i=0;i<M;i++)
	{
		cin >>k;
		for (int j=0;j<k;j++)
		{
			cin >> s;
			s--;
			lamp[i][s]=1;
		}
	}
	vector<int> p(M);
	for (int i=0;i<M;i++) cin >>p[i];
	for (int i=0;i<1<<N;i++)
	{
		bool can=true;
		vector<int> on;
		for (int r=0;i>>r>0;r++)
		{
			if ((i>>r)&1) on.push_back(r);
		}
		for (int j=0;j<M;j++)
		{
			int cnt=0;
			for (int k:on)
			{
				if (lamp[j][k]) cnt++;
			}
			if (cnt%2!=p[j]) can=false;
		}
		if (can) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String t = sc.next();
		
		char[] cs = s.toCharArray();
		char[] ct = t.toCharArray();
		
		Arrays.sort(cs);
		Arrays.sort(ct);
		
		s = new String(cs);
		t = new String(ct);
		t = new StringBuilder(t).reverse().toString();
		
		System.out.println(s.compareTo(t) < 0 ? "Yes" : "No");
		
		sc.close();
	}
}

Measured memory_bytes: 23764
#include <stdio.h>

int main(int argc, char *argv[]){
     int dice[6]={1,2,3,4,5,6}, t[6], n, sum, i;
     char buf[6];
     
     while(scanf("%d",&n), n!=0){
	  sum=1, dice[0]=1, dice[1]=2,
	       dice[2]=3, dice[3]=4, dice[4]=5, dice[5]=6;
	  
	  while(n--){
	       scanf("%s",buf);

	       /* tempツづ可コツピツー */
	       for(i=0; i<6; i++) t[i]=dice[i];
	  
	       switch(buf[0]){
	       case 'N':
		    dice[0]=t[1], dice[1]=t[5], dice[2]=t[2],
			 dice[3]=t[3], dice[4]=t[0], dice[5]=t[4];
		    break;
	       case 'E':
		    dice[0]=t[3], dice[1]=t[1], dice[2]=t[0],
			 dice[3]=t[5], dice[4]=t[4], dice[5]=t[2];
		    break;
	       case 'W':
		    dice[0]=t[2], dice[1]=t[1], dice[2]=t[5],
			 dice[3]=t[0], dice[4]=t[4], dice[5]=t[3];
		    break;
	       case 'S':
		    dice[0]=t[4], dice[1]=t[0], dice[2]=t[2],
			 dice[3]=t[3], dice[4]=t[5], dice[5]=t[1];
		    break;
	       case 'R':
		    dice[0]=t[0], dice[1]=t[2], dice[2]=t[4],
			 dice[3]=t[1], dice[4]=t[3], dice[5]=t[5];
		    break;
	       case 'L':
		    dice[0]=t[0], dice[1]=t[3], dice[2]=t[1],
			 dice[3]=t[4], dice[4]=t[2], dice[5]=t[5];
		    break;
	       }
	       
	       sum+=dice[0];
	  }
	  
	  printf("%d\n",sum);
     }
     
     return 0;
}

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

using namespace std;

const int maxn = 20;
const int INF = 1e9 + 100;


int main() {
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, m, k;
    cin >> n >> m >> k;

    for (int a = 0; a <= n; ++a) {
        int b = n - a;
        for (int c = 0; c <= m; ++c) {
            int d = m - c;
            if (a * c + b * d == k) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256