akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N, L;
	cin >> N >> L;
	vector<string>S(N);
	rep(i, N) {
		cin >> S[i];
	}
	sort(S);
	string ans = S[0];
	for (int i = 1; i < N; i++) {
		ans = ans + S[i];
	}
	cout << ans << endl;
}

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

int main() {
  int N, x;
  cin >> N;
  
  for (int i = 0;i < N;i++) {
    int l, r;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
typedef long long lint;

struct seg{
	pi tree[530000];
	int lim;
	void init(int n, int *a){
		for(lim = 1; lim <= n; lim <<= 1);
		for(int i=1; i<=n; i++){
			tree[i + lim] = pi(a[i], i);
		}
		for(int i=lim; i; i--){
			tree[i] = min(tree[2*i], tree[2*i+1]);
		}
	}
	pi query(int s, int e){
		s += lim;
		e += lim;
		pi ret(1e9, 1e9);
		while(s < e){
			if(s%2 == 1) ret = min(ret, tree[s++]);
			if(e%2 == 0) ret = min(ret, tree[e--]);
			s >>= 1;
			e >>= 1;
		}
		if(s == e) ret = min(ret, tree[s]);
		return ret;
	}
}seg;

int n, a[200005];

lint solve(int s, int e){
	if(s > e) return 0;
	pi v = seg.query(s, e);
	lint ret = solve(s, v.second - 1) + solve(v.second + 1, e);
	ret += 1ll * (v.second - s + 1) * (e - v.second + 1) * v.first;
	return ret;
}

int main(){
	cin >> n;
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
	}
	seg.init(n, a);
	cout << solve(1, n) << endl;
}


Measured memory_bytes: 17664
#include<iostream>
using namespace std;
int main(){
    char s[10010] = {0};
    while(cin >> s){
        int J = 0;
        int I = 0;
        int len = 0;
        while(1){
            if(s[len] == 0){
                break;
            }
            len++;
        }
        for(int i = 0;i < len-2;i++){
            if(s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I'){
                J++;
                i++;
            }
            else if(s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I'){
                I++;
                i++;
            }
        }
        cout << J << endl << I << endl;
        for(int i = 0;i < 10010;i++){
            s[i] = 0;
        }
    }
    return 0;
}

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

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

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

    vector<int> h(n);
    rep(i, n) cin >> h[i];

    sort(h.begin(), h.end(), greater<int>());

    ll res = 0;

    rep(i, n){
        if(i<k) continue;
        res += h[i];
    }

    cout << res << endl;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace id_0337cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var vs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(ToYear(vs[0], vs[1]));
        }
        static string ToYear(int e, int y)
        {
            var isAD = e == 0;
            var isMeiji = e == 1;
            var isTaisho = e == 2;
            var isShouwa = e == 3;
            if (isAD)
            {
                return ToAD(y);
            }
            if (isMeiji)
            {
                return (y + 1867).ToString();
            }
            if (isTaisho)
            {
                return (y + 1911).ToString();
            }
            if (isShouwa)
            {
                return (y + 1925).ToString();
            }
            return (y + 1988).ToString();
        }
        static string ToAD(int y)
        {
            if(1868<= y && y <= 1911) {
                return "M" + (y - 1867).ToString();
            }
            if (1912 <= y && y <= 1925)
            {
                return "T" + (y - 1911).ToString();
            }
            if (1926 <= y && y <= 1988)
            {
                return "S" + (y - 1925).ToString();
            }
            return "H" + (y - 1988).ToString();
        }
    }
}



Measured memory_bytes: 9608
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=100005;
int neg[nmax],poz[nmax];
int n,k,i,x,nr1,nr2,ans;
int main()
{
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x<0) neg[++nr1]=-x;
        else poz[++nr2]=x;
    }
    reverse(neg+1,neg+nr1+1);
    ans=(1<<30);
    for(i=0;i<=min(k,nr1);i++)
        if(k-i<=nr2)
    {
        ans=min(ans,neg[i]+poz[k-i]+min(neg[i],poz[k-i]));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{char a[51],b[51],c[101];
int i,w;
while(cin>>a>>b)
{  w=0;



    for(i=0;i<= 100;i++)
    {
    if(i%2!=0)
       { c[i]=b[w];w++;}
     else
        {
            c[i]=a[w];
        }
    }cout<<c<<endl;
}

return 0;}


Measured memory_bytes: 256
N = int(input())
dp = [1] * (N+1)
for i in range(2, N+1):
    k = 1
    while i * k <= N:
        dp[i*k] += 1
        k += 1
ans = 0
for i in range(1, N+1):
    ans += i * dp[i]
print(ans)


Measured memory_bytes: 145704
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,M; cin >> N >> M;
    int a,b;
    vector<pair<long,int>> p(N);
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        p[i] = make_pair(a,b);
    }

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

    long sum = 0;
    for(int i = 0; i < N && M > 0; i++){
        if(p[i].second - M <= 0){
            M = M - p[i].second;
            sum += p[i].first * p[i].second;
        }else{
            sum += p[i].first * M;
            M = 0;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 1792
n = gets.to_i
a = gets.split.map &:to_i
b = gets.split.map &:to_i
c = gets.split.map &:to_i

result = 0

a.each_cons(2){ |x| result += c[x[0] - 1] if x[0]+1 == x[1] }

result += b.inject(:+)

puts result

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;


int main(int argc, char* argv[]){

long long A, B, V, W, T;
scanf("%lld %lld %lld %lld %lld", &A, &V, &B, &W, &T);

//printf("%lld %lld %lld %lld %lld", A, V, B, W, T);
if((V-W)*T>=abs(A-B)){
	printf("YES\n");
}else{
	printf("NO\n");
}
	return 0;
}






Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a; i<b; ++i)
#define rFOR(i, a, b) for(int i=a-1; i>=b; --i)
#define REP(i, n) for(int i=0; i<n; ++i)
#define rREP(i, n) for(int i=n-1; i>=0; --i)
#define all(a)  a.begin(), a.end()
using namespace std;



int main(){
  int n;  cin >> n;
  int x[200000], b[200000];
  REP(i, n){
    cin>>x[i];
    b[i]=x[i];
  }
  sort(x, x+n);
  REP(i, n){
    if(b[i]<x[n/2]) cout << x[n/2] << endl;
    else  cout << x[n/2-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
N,*A=list(map(int, open(0).read().split()))

m1 = 0
m1i = 0
m2 = 0
for i,a in enumerate(A):
    if a > m2:
        m2 = a
    if a > m1:
        m2 = m1
        m1 = a
        m1i = i

for n in range(N):
    if n == m1i:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 25036
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    long long N,K;
    long long answer=0;
    cin>>N>>K;
    if(K==0){
        cout<<N*N<<endl;
    }else{
        for(int b=K+1;b<=N;b++){
            int sequence=(1+N)/b;
            answer+=sequence*(b-K);
            int remain=1+N-sequence*b-K;
            if(remain>=1){
                answer+=remain;
            }
        }
        cout<<answer<<endl;
    }
    
    

	
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b){
    int c;
    while(b!=0){
        c = a%b;
        a = b;
        b = c; 
    }
    return a;
    
}


int main(void){
    int n, max=0;
    cin>>n;
    int a[n],l[n],r[n],m[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    
    l[0] = a[0];
    r[n-1] = a[n-1];
    for(int i=1; i<n; i++)
        l[i] = gcd(l[i-1],a[i]);
        
    for(int i=n-2; i>=0; i--){
        r[i] = gcd(r[i+1], a[i]);
    }
    
    m[0] = r[1];
    m[n-1] = l[n-2];
    
    for(int i=0; i<n; i++){
        if(i!=0 && i!=n-1)
            m[i] = gcd(l[i-1], r[i+1]);
        if (m[i] > max)
            max = m[i];
    }
    
    cout<<max<<endl;
}


Measured memory_bytes: 1792
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	s = int(rl())

	def binom_tables(n, q):
		fact = [1 for _ in range(n + 1)]
		inv = [1 for _ in range(n + 1)]
		for i in range(1, n+1):
			fact[i] = (fact[i-1] * i) % q
			inv[i] = pow(fact[i], q-2, q)
		return fact, inv

	F, I = binom_tables(s + s//3 + 10, MOD)

	def binom(n, k, q):
		return (F[n]*((I[k]*I[n-k])%q))%q

	ans = 0
	for r in range(1, 700):
		objects = s - 3*r
		if objects + r - 1 < objects or objects < 0: 
			break
		x = binom(objects + r - 1, objects, MOD)
		ans += x
		ans %= MOD 

	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 70288
moji = input().rstrip()
mojilist = list(moji)
evenset = set()
oddset = set()

for i in range(len(mojilist)):
  if i % 2 == 0:
    oddset.add(mojilist[i])
  else:
    evenset.add(mojilist[i])

if ((oddset <= {"R","U","D"}) and (evenset <= {"L","U","D"})):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3060
from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]

ans = []
for k, v in sorted(Counter(A).items(), reverse=True):
    if v >= 4:
        ans.append(k)
        ans.append(k)
    elif v >= 2:
        ans.append(k)
    if len(ans) >= 2:
        break
if len(ans) >= 2:
    print(ans[0] * ans[1])
else:
    print(0)


Measured memory_bytes: 21412
#include <cstdio>
#include <cstring>
const int maxn = 55;
int node[maxn];
int main()
{
	int n, m;
	while(~scanf("%d%d", &n, &m)) {
		memset(node, 0, sizeof(int) * maxn);
		while(m-- > 0) {
			int a, b;
			scanf("%d%d", &a, &b);
			node[a]++;
			node[b]++;
		}
		for (int i = 1; i <= n; ++i) {
			printf("%d\n", node[i]);
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    int month;
    int day;
    cin>>month>>day;
    int takashis = 0;
    if(month==1) {
        cout<<1;
        return 0;
    } else {
        takashis = month - 1;
    }
    if(day>=month) {
        takashis++;
    }
    cout<<takashis;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <memory.h>
int main(void){
    int n,m,line[10000][2],line1[501],line2[501],sum;
    for(;sum=0,memset(line1,0,sizeof(line1)),memset(line2,0,sizeof(line2)),scanf("%d\n%d",&n,&m),n+m;){
        for(int i=0;i<m;i++){
            scanf("%d %d",&line[i][0],&line[i][1]);
            if(line[i][0] == 1){
                line1[line[i][1]]=line2[line[i][1]]=1;
                sum++;
            }
        }
        for(int i=0;i<m;i++){
            if(line[i][0] != 1 && line1[line[i][0]]==1 && line2[line[i][1]]==0){
                sum++;
                line2[line[i][1]]=1;
            }
            else if(line[i][0]!=1&&line1[line[i][1]]==1 && line2[line[i][0]]==0){
                sum++;
                line2[line[i][0]]=1;
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

  

Measured memory_bytes: 2656
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define int long long
#define sz(v) ((ll)v.size())
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define F first
#define S second
#define pii pair<int,int> 
#define MAXN 2000004
#define trace1(x)                cerr << #x << ": " << x << "\n";
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << "\n";
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << "\n";
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << "\n";
#define N 62
#define LOGN 18
#define mod   1000000007ll
#define pi 3.14159265359
#define base 302393ll
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
const double EPS = 1e-9;
const int INF = 2; // it doesn't actually have to be infinity or a big number
int a[200002];
int b[1000002];
int freq[1000002];
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(b[a[i]]==0 and freq[a[i]]==0){
            for(int j=2*a[i];j<1000002;j+=a[i])
                b[j]=1;
        }
        freq[a[i]]++;
    }
    int ans=0;
    for(int i=0;i<n;i++) if(b[a[i]]==0 and freq[a[i]]==1) ans++;
    cout<<ans;
}

Measured memory_bytes: 20816
def a():return input()#s
def ai():return int(input())#a,n or k
def ma():return map(int, input().split())#a,b,c,d or n,k
def ms():return map(str, input().split())#,a,b,c,d
def lma():return list(map(int, input().split()))#x or y
def lms():return list(map(str, input().split()))#x or y
a,k = ma()
x = lma()
dp =[0]+[float("INF")]*(a-1)
for i in range(1,a):
    for j in range(1,k+1):
        if i-j>=0 : dp[i] = min(dp[i],dp[i-j]+abs(x[i]-x[i-j]))
print(dp[a-1])

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

int main() {
	int i,j,k,l;
	int n, y_count = 0;
	while (cin >> n) {
		for (i = 0; i < 10; i++) {
			for (j = 0; j < 10; j++) {
				for (k = 0; k < 10; k++) {
					for (l = 0; l < 10; l++) {
						if (i+j+k+l == n) y_count++;
					}
				}
			}
		}
		cout << y_count << endl;
		y_count = 0;
	}
	return 0;
}

Measured memory_bytes: 3092
// g++ -std=gnu++1y -O2 xxx.cpp

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    int N; cin>>N;
    vector<int> Pn(N);
    vector<int> Qn(N);
    int P=0,Q=0;

    for (int i=0;i<N;i++) {
        cin >> Pn[i];
        P = P * 10 + Pn[i];
    }

    for (int i=0;i<N;i++) {
        cin >> Qn[i];
        Q = Q * 10 + Qn[i];
    }

    int cnt=0;
    if (P < Q) {
        do {
            if (Pn == Qn) {
                break;
            }
            cnt++;
        } while (next_permutation(Pn.begin(),Pn.end()));

    } else if (P > Q) {
        do {
            if (Pn == Qn) {
                break;
            }
            cnt++;
        } while (next_permutation(Qn.begin(),Qn.end()));

    } else {
        cnt = 0;
    }

    cout << cnt << endl;

    return 0;
}

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

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll; 
typedef long double ld; 
typedef pair<int,int> p32;   
typedef pair<ll,ll> p64;  
typedef pair<double,double> pd; 
typedef pair<ld,ld> pld; 
typedef vector<int> v32;  
typedef vector<ll> v64;  
typedef vector<pd> vpd;   
typedef vector<p32> vp32;  
typedef vector<p64> vp64;  
typedef vector<v32> vv32;  
typedef vector<v64> vv64;  

#define pb push_back
#define mp make_pair
#define prarr(a,n) cerr<<#a<<" : ";for(ll i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define prmat(mat,row,col) cerr<<#mat<<" :\n";for(ll i=0;i<row;i++) {for(ll j=0;j<col;j++) cerr<<mat[i][j]<<"\t";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
#define all(a) a.begin(),a.end()
#define sz(x) ((int)x.size())
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(NULL); cin.tie(NULL)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {ll idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
template <class T> void prall(T a) { prc(all(a)); }

#include <bits/extc++.h> /** keep-include */
using namespace __gnu_pbds;
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const int inf=1000*1000*1000+9; 
const ll infl=1ll*inf*inf; 
int mod=1000*1000*1000+7;  
// ----------------------------------------------------------------------------	-------------- 

void pre(){
}
void solve(){
  int n,k,s; cin>>n>>k>>s; 
  for(int i=0;i<k;i++) cout<<s<<" " ; 
    for(int i=k;i<n;i++){
      if(s==mod-7){
        cout<<s-1<<" " ; 
      }
      else {
        cout<<mod-7<<" " ; 
      }
    }
    cout<<endl; 
}



int main(){
	// clock_t beg=clock(); 
  fast_io; 
  int testcases=1; 
  pre(); 
  // cin>>testcases; 
  cout << fixed << setprecision(13); 
  while(testcases--){
    solve(); 	
  }
	// clock_t end=clock(); 
	// fprintf(stderr, "%lf\n", (double)(end-beg)/(CLOCKS_PER_SEC));
}


Measured memory_bytes: 1280
using System;

namespace ABC159
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var p = new ProblemB();
            Console.WriteLine(p.GetAnswer(s));
        }
    }

    public class ProblemB
    {
        public string GetAnswer(string s)
        {
            var isKaibun = IsKaibun(s)
                && IsKaibun(s.Substring(0, (s.Length - 1) / 2))
                && IsKaibun(s.Substring((s.Length + 2) / 2));
            return isKaibun ? "Yes" : "No";
        }

        private static bool IsKaibun(string s)
        {
            for (int i = 0; i < s.Length / 2; i++)
            {
                if (s[i] != s[s.Length - i - 1]) { return false; }
            }
            return true;
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,K;
  cin >> N >> K;

  long long ans = 1;
  long long a = N / K;
  for(int i = 0;i < 3;i++) {
      ans *= a;
  }
  
  if(K % 2 == 0) {
    long long num = 0;
    for(int i = 0;i <= N;i++) {
      if(i % K == K / 2) num++;
    }
    long long b = 1;
    for(int i = 0;i < 3;i++) {
      b *= num;
    }
    ans += b;
  }

  cout << ans << endl;

}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b-1);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>x(n);
  ll sxx=0,sx=0;
  rep(i,n)cin>>x[i];
  rep(i,n){
    sxx+=x[i]*x[i];
    sx+=x[i];
  }
  ll res=1e18;
  rep(i,100){
    chmin(res,sxx+i*i*n-2*i*sx);
  }
  cout<<res<<endl;


  return 0;

}


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

int main() {
  int N,M;
  cin>>N>>M;
  set<int> a;
  rep(i,M) {
    int x;
    cin>>x;
    a.insert(x);
  }
  uint64_t y = pow(10,9)+7;
  vector<uint64_t> dp(N+1);//i段目にいくまでに何通り移動法があるか。ans=dp[N]
  dp[0]=1;
  if(!(a.count(1))) dp[1]=1;
  for(int i=2;i<=N;i++){
    if(!(a.count(i))){
      if(a.count(i-1)&&a.count(i-2)){//答えは0で確定
        cout<<0<<endl;
        return 0;
      }
      else if(a.count(i-1)){//i-2からくるしかない
        dp[i]=dp[i-2];
      }
      else if(a.count(i-2)){//i-1からくるしかない
        dp[i]=dp[i-1];
      }
      else{
        dp[i]=dp[i-1]+dp[i-2];
        dp[i] %= y;//最終的な数がuint64_tでも間に合わなくなる可能性があるので適宜減らす
      }
    }
  }
  cout<<dp[N]<<endl;  
  return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);
ll dp[105][2]; 
// dp[a][b]:= 左から a bitまで見て 
// K以下が b=0:確定していない b=1確定している
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    rep(i,105)dp[i][0] = dp[i][1] = -1;
    dp[50][0] = 0;
    for(int bit=49;bit>=0;bit--){ // bit bit 目を考える
        ll mask = (1LL<<bit);
        ll num = 0; // bit bit 目が立っている A[i] の個数
        rep(i,N)if(A[i]&mask)num++; // もしもbitが立っていたらnumを加算

        if(dp[bit+1][1]>=0)chmax(dp[bit][1],dp[bit+1][1] + mask*max(num,N-num));
        //if(dp[bit+1][0]>=0){
            if(K&mask){
                // もしも K の bit bit 目が 1 だったならば
                // 1を選んだ場合
                dp[bit][0] = dp[bit+1][0] + mask*(N-num);
                // 0を選んだ場合
                chmax(dp[bit][1],dp[bit+1][0] + mask*num);
            }else{
                dp[bit][0] = dp[bit+1][0] + mask*num; 
            }
        //}
    }
    cout << max(dp[0][0],dp[0][1]) << endl;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        double r = in.nd();
        out.println(2*Math.PI*r);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 33348
<?php

fscanf(STDIN, "%s", $s);

function isMM($str) {
    switch ($str) {
        case '01':
        case '02':
        case '03':
        case '04':
        case '05':
        case '06':
        case '07':
        case '08':
        case '09':
        case '10':
        case '11':
        case '12':
            return true;
        default:
            return false;
    }
}

$first = substr($s, 0, 2);
$last = substr($s, 2);

$is_yymm = isMM($last);
$is_mmyy = isMM($first);

if ($is_yymm && $is_mmyy) {
    echo 'AMBIGUOUS';
} else if ($is_yymm) {
    echo 'YYMM';
} else if ($is_mmyy) {
    echo 'MMYY';
} else {
    echo 'NA';
}


Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const ll INF = 9223372036854775807;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    int ret1 = vec.at(N - 1);
    auto itr = lower_bound(vec.begin(),vec.end(),(ret1 + 1) / 2);
    int A = itr - vec.begin();
    int ret2;
    if(abs(vec.at(A) - (ret1 + 1) / 2) >= abs(vec.at(A - 1) - (ret1 + 1) / 2)) {
        ret2 = vec.at(A - 1);
    }
    else {
        ret2 = vec.at(A);
    }
    cout << ret1 << " " << ret2 << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = 2 * (a + b);
        System.out.println(area + " " + length);
        sc.close();
    }
}


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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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(void){
  ios::sync_with_stdio(false);

  int N;
  vector<vector<int>> A(3, vector<int>(3));

  REP(i, 3){
    REP(j, 3){
      cin >> A[i][j];
    }
  }

  cin >> N;
  vector<int> b(N);
  REP(i, N){cin >> b[i];}

  vector<vector<int>> flag(3, vector<int>(3));
  REP(i, 3){
    REP(j, 3){
      flag[i][j] = 0;
    }
  }
  REP(i, N){
    REP(j, 3){
      REP(k, 3){
        int val = b[i];
        int conf = A[j][k];
        if (val == conf){flag[j][k] = 1;}
      }
    }
  }
  int x[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  int y[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  bool res = false;
  int tmp_val = 0;
  REP(i, 3){
    REP(j, 3){
      int tmp;
      REP(k, 8){
        tmp = 0;
        int nx = i;
        int ny = j;
        int x_dx = i + x[k];
        int y_dy = j + y[k];
        if (flag[nx][ny] == 1){
        while (x_dx >= 0 and x_dx < 3 and y_dy >= 0 and y_dy < 3 and flag[x_dx][y_dy] == 1)
        {tmp++;
        nx = x_dx;
        ny = y_dy;
        x_dx += x[k];
        y_dy += y[k];}}
        tmp_val = max(tmp_val, tmp);
      }
    }
  }
  if (tmp_val == 2){res = true;}
  if (res) cout << "Yes" << endl;
 else cout << "No" << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll rec(ll n, ll x){
    if(n == 0) return 1;
    ll len = (1ll<<(n+1)) - 3;
    ll num = (1ll<<(n)) - 1;
    if(x == 1) return 0;
    else if(x <= len + 1) return rec(n-1,x-1);
    else if(x == len + 2) return num + 1;
    else if(x < (len + 1) * 2) return num + 1 + rec(n-1, x - len -2);
    else return num * 2 + 1;
}
int main(){
    cout << fixed << setprecision(10);
    ll k;
    ll x;
    cin >> k >> x;
    cout << rec(k,x) << endl;
    return 0;
}

Measured memory_bytes: 3560
S = input()
S = S[::-1]
check = ['maerd', 'remaerd', 'esare', 'resare']
T = []
now = 0

while now < len(S):
    if S[now:now+5] == 'maerd':
        now += 5
        T.append('maerd')
    elif S[now:now+5] == 'esare':
        now += 5
        T.append('esare')
    elif S[now:now+7] == 'remaerd':
        now += 7
        T.append('remaerd')
    elif S[now:now+6] == 'resare':
        now += 6
        T.append('resare')
    else:
        print('NO')
        break
if ''.join(T) == S:
    print('YES')

Measured memory_bytes: 3316
while(n=gets.to_i)!=0
  puts n.times.map{gets.split.map(&:to_i)}.sort_by{|a,b|b}.reduce([[0,0]]){|a,b|a<<[a[-1][0]+b[0],b[1]]}.any?{|a|a[0]>a[1]}?"No":"Yes"
end

Measured memory_bytes: 8768
n,*a=map(int,open(0).read().split());x=abs
c=[0]+a+[0];y=sum(x(c[t]-c[t+1])for t in range(n+1))
for i in range(n):s,t,r=c[i:i+3];print(y+x(r-s)-x(t-s)-x(t-r))

Measured memory_bytes: 13932
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

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

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


int main() {

	string s;

	cin >> s;

	int sum = 0;

	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			sum++;
		}
		else {
			sum--;
		}

		
	}
	cout << sum << endl;

	return 0;
}

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

int main()
{


        long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX;
        long long x=0,y=0,cnt=0,res=0,ttl=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1;
        vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst;
        set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr;

        scanf("%lld %lld",&m,&n);

        for(i=1;i<=n;i++)
        {
            scanf("%lld",&a);  mp[a]=1;
        }


        for(i=0;i<=200;i++)
        {
            if(mp[i]==0)
            {
                if(abs(m-i)<mn){mn=abs(m-i);  fr=i;}

            }


        }

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














    return 0;
}





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

void Main()
{
  ll x; cin >> x;
  if (x <= 6) {cout << 1 << endl;}
  else if (x <= 11) {cout << 2 << endl;}
  else {
    ll q = x / 11;
    ll res = x % 11;
    if (res == 0) {cout << 2*q << endl;}
    else if (res <= 6) {cout << 2*q + 1 << endl;}
    else {cout << 2*q + 2 << endl;}
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
s = input()
out_s='1'*(m)
if out_s in s:
    print(-1)
    exit()
s = s[::-1]
if s[0] == "1":
    print(-1)
    exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
    now = stack.pop()
    if now == n:
        break
    for i in range(1, m + 1):
        tsugi = now + i
        if tsugi > n:
            continue
        if s[tsugi] == "1":
            continue
        pre[tsugi] = now
        stack.append(tsugi)
else:
    print(-1)
    exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
    ans.append(ato - mae)
    ato = mae
    mae = pre[ato]
print(*ans, sep=" ")


Measured memory_bytes: 10264
import itertools
def rec (nums,st,step,cot,hugo):
    if step==4:
        if cot == 7:
            print(st+"=7")
            exit()
    else:

        if hugo > 0:
            temp = "+" + str(nums[step])
            cot += nums[step]
        else:
            temp = "-" + str(nums[step])
            cot -= nums[step]
        rec(nums,st+temp,step+1,cot,1)
        rec(nums, st+temp, step + 1, cot, -1)


def do():
    nums = list(map(int,list(input())))
    rec(nums,str(nums[0]),1,nums[0],1)
    rec(nums,str(nums[0]),1,nums[0],-1)


if __name__ == "__main__":
    do()

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    if(0<=x-r && w>=x+r && 0<=y-r && h>=y+r){
        cout << "Yes" <<endl;
    }
    else{
        cout <<"No" <<endl;

    }
}


Measured memory_bytes: 3120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();

		boolean result = true;
		if (s.equals("AAA") || s.equals("BBB")) {
			result = false;
		}
		printBool(result);
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

}


Measured memory_bytes: 22996
using System;
using System.Linq;
using System.Collections.Generic;

namespace d
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var n = int.Parse(_[0]);
            var k = int.Parse(_[1]);

            var __ = Console.ReadLine().Split();
            var r = int.Parse(__[0]);
            var s = int.Parse(__[1]);
            var p = int.Parse(__[2]);

            var t = Console.ReadLine().ToCharArray();
            var h = new char[n];

            var point = 0;
            for(var i = 0; i < n; i++){
                var idx = i - k;
                if(t[i] == 'r'){
                    if(idx >= 0 && h[idx] == 'p'){
                        h[i] = 'x';
                        point += 0;
                    }else{
                        h[i] = 'p';
                        point += p;
                    }
                }else if(t[i] == 's'){
                    if(idx >= 0 && h[idx] == 'r'){
                        h[i] = 'x';
                        point += 0;
                    }else{
                        h[i] = 'r';
                        point += r;
                    }
                }else if(t[i] == 'p'){
                    if(idx >= 0 && h[idx] == 's'){
                        h[i] = 'x';
                        point += 0;
                    }else{
                        h[i] = 's';
                        point += s;
                    }
                }
            }

            Console.WriteLine(point);
        }
    }
}


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

namespace ABC112 {
	class ABC112_A {
		static void Main(string[] args) {
			int N = int.Parse(Console.ReadLine());
			if (N == 1) Console.WriteLine("Hello World");
			if (N == 2) Console.WriteLine("{0}", int.Parse(Console.ReadLine()) + int.Parse(Console.ReadLine()));
		}
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int r;
  cin >> r;
  cout << r*r << endl;
         
         
  
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    cout << std::min(B / A, C) << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
if N == 0:
    print(0)
else:
    ans = ""
    while N != 1:
        if N % -2:
            ans += str(N % 2)
            N = N // -2 + 1
        else:
            ans += "0"
            N //= -2
    ans += "1"
    print("".join(reversed(ans)))

Measured memory_bytes: 2940
import java.util.Scanner;

   class Main{
      public static void main(String args[]){
       Scanner scan = new Scanner(System.in);

       while(true){

       int n = scan.nextInt();

       if(n==0){

          break;

       }

       int s[] = new int[n];
       double m = 0;
       double sum = 0;

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

          s[i]=scan.nextInt();
          m+=s[i];

       }

       m/=n;

       for(int j =0;j<n;j++){

          sum+=Math.pow(s[j]-m,2);

       }

       sum/=n;

       System.out.println(Math.sqrt(sum));

       }
       }
   }


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

#define int long long
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

const unsigned int M = 1e9 + 7;

int32_t main() {
	fastio;

	int a;
	cin >> a;
	cout << a + (a * a) + (a * a * a);

	return 0;
}


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

using namespace std;
int N,C;
typedef long long ll;
const ll mod = 1e9 + 7;

ll memo[401][401];
ll dp[401][401];
int A[401],B[401];

int main() {
  cin >> N >> C;
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++) cin >> B[i];
  
  for(int i = 0; i < N; i++) {
    for(int j = A[i]; j <= B[i]; j++) {
      ll p = 1;
      for(int k = 0; k <= C; k++) {
	memo[i][k] += p;
	p *= j;
	p %= mod;
	memo[i][k] %= mod;
      }
    }
  }

  dp[0][0] = 1;

  for(int i = 1; i <= N; i++) {
    for(int j = 0; j <= C; j++) {
      for(int k = 0; k <= j; k++) {
	dp[i][j] += dp[i-1][k] * memo[i-1][j-k];
	dp[i][j] %= mod;
      }
    }
  }
  cout << dp[N][C] <<endl;
}
  
      
      
  


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define cd complex<long double>
#define MOD 1000000007
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
const double PI = acos(-1);
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}
ll isPrime[1000010]={0};
vector<ll> Prime;

void sieve(){
	ll i,j;
	isPrime[0] = isPrime[1] = 1;
	for( i=2; i<1000010; i++)if(isPrime[i]==0)for(j=2*i; j<1000010; j+=i)isPrime[j]=1;
	for( i=1; i<1000010; i++)if(isPrime[i]==0)Prime.push_back(i);
}

ll modMul(ll a,ll b,ll mod){
	ll res=0;
	while(b){
		if(b&1)res = (res+a)%mod;
		a = (2*a)%mod;
		b = b/2;
	}
	return res;
}

ll modPow(ll x,ll n,ll mod){
	ll r = 1;
	while(n){
		if(n&1)r = modMul(r,x,mod);
		x = modMul(x,x,mod);
		n = (n>>1);
	}
	return r;
}

ll bitR(ll x,ll len){
ll r=0;
while(len--){r = (r<<1) + (x%2);x = (x>>1);}
return r;
}

void fft(vector<cd> &V,bool invert){
ll n=1,i,j,len,Blen=0;
n=V.size();
j=n-1;
while(j){Blen++;j=(j>>1);}

for(i=0;i<n;++i)if(i<bitR(i,Blen))swap(V[i],V[bitR(i,Blen)]);

for(len=2;len<=n;len=(len<<1)){
    long double ang = 2*PI/len * (invert ? -1 : 1);
    cd wlen(cos(ang),sin(ang));
    for(i=0;i<n;i+=len){
        cd w(1);
        for(j=0;j<len/2;j++){
            cd u = V[i+j],v = V[i+j+len/2]*w;
            V[i+j] = u+v;
            V[i+j+len/2] = u - v;
            w *= wlen;
        }
    }
}
if(invert)for (cd & x: V)x /= n;

}



int main()
{
	ll t,i,j,k,l,n,m,r,a,b,c;
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	cin>>n;
	ll A[n];
	for(i=0;i<n;++i){
        cin>>A[i];
	}
	map<ll,ll> M1,M2;
	set<ll> S1,S2;
	for(i=0;i<n;++i){
        if(i%2==0){
            S1.insert(A[i]);
            M1[A[i]]++;
        }else{
            S2.insert(A[i]);
            M2[A[i]]++;
        }
	}
	vector<pair<ll,ll> > V;
	for(auto it:S2){V.push_back({M2[it],it});}
	sort(V.begin(),V.end());
	ll ans=1e9;
	for(auto it:S1){
        m = n/2 - M1[it];
        for(i=V.size()-1;i>=0;--i){
            if(V[i].second!=it){
                ans = min(ans,m+n/2-V[i].first);
                break;
            }else{
                ans = min(ans,m+n/2);
            }
        }
	}
	cout<<ans;

	return 0;
}


Measured memory_bytes: 13176
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int n, dim;
  cin >> n >> dim;
  vector<vector<int>> x(n, vector<int>(dim));
  rep(i, n) rep(d, dim) cin >> x[i][d];

  int ans = 0;
  rep(i, n) rep(j, n) {
    if(i >= j) continue;
    int sqd = 0;
    rep(d, dim) {
      int dx = x[i][d] - x[j][d];
      sqd += dx * dx;
    }
    int dist = sqrt(sqd);
    if(dist * dist == sqd) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)



int main(){
	ll n, count=0, sub_max=0, max=0;
	vector<pair<ll, ll>> pairs(50);
	vector<pair<ll, ll>> vec(2500);
	pair<ll, ll> maxv;
	cin >> n;
	rep(i, n) cin >> pairs[i].first >> pairs[i].second;

	pairs.resize(n);
	vec.resize(n * n);

	rep(i, n){
		rep(k, n){
			vec[count] = make_pair(pairs[i].first - pairs[k].first, pairs[i].second - pairs[k].second);
			count++;
		}
	}



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

	rep(i, n * n){
		// cout << "debug i:" << i <<" " << vec[i].first << " " << vec[i].second << endl;
		if (vec[i].first == vec[i + 1].first && vec[i].second == vec[i + 1].second)
		{
			if (!(vec[i].first == 0 && vec[i].second == 0)){
				sub_max++;
			}
		}else{
			sub_max =1;
		}
		if(sub_max > max){
			max = sub_max;
			maxv = make_pair(vec[i].first, vec[i].second);
		}
	}

	// cout << "debug " <<maxv.first << " "<<maxv.second << endl;
	// cout << "debug n:" << n << " max:" << max << endl;
	cout << n - max;

	return 0;
}

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

int main(void){
    int n;
    int odd,even2,even4;
    int b[100000];
    int a[100000];
    int c=1;
    
     

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

odd=0, even2=0,even4=0;

for(int i=0;i<n;i++){
   
     if(a[i]%4==0){
         even4+=1;
        
    }
    else if(a[i]%2==0){
       even2+=1;
       
    }
     if(a[i]%2!=0){
        odd+=1;
    }
    
    
}



if(even4<odd){
    c=0;
}
if(even4==0&&odd==0&&even2<=1){
    c=0;
}
if(odd-even4==1&&even2==0){
    c=1;
}


if(c==1){
    cout<<"Yes"<<endl;
}
if(c==0){
    cout<<"No"<<endl;
}
}

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

using namespace std;
typedef long long ll;

int c[100001];

int main(void) {
    int n, m;
    cin >> n >> m;
    for(int i=0; i<m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        c[a-1]++; c[b-1]++;
    }
    for(int i=0; i<n; i++) {
        if(c[i] % 2 == 1) return !printf("NO\n");
    }

    return !printf("YES\n");
}

Measured memory_bytes: 640