akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const lli MOD=1e9+7;

int main(){
	lli N;
	cin>>N;
	lli ans=1;
	rep1(i,N){
		ans=(ans*i)%MOD;
	}
	cout<<ans;
}

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

template<typename T1, typename T2> void cmax(T1 &a, T2 b) { if (a < b) a = b; }
template<typename T1, typename T2> void cmin(T1 &a, T2 b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  long ans = 0;
  int mx = INT_MIN;
  for (auto a : A) {
    if (a < mx) ans += mx - a;
    cmax(mx, a);
  }
  cout << ans << "\n";
}

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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int ll;
const int maxn = 3010;
ll cost[maxn][maxn];
int n, m;
ll dp[maxn][maxn][4];
ll gao(int i, int j, int inrow) {
  if (i == n) return 0;
  if (j == m) return 0;
  if (dp[i][j][inrow] != -1LL) return dp[i][j][inrow];
  ll ans = 0;
  ans = max(ans, gao(i + 1, j, 3));
  ans = max(ans, gao(i, j + 1, inrow));
  if (inrow > 0) {
    ans = max(ans, cost[i][j] + gao(i + 1, j, 3));
    ans = max(ans, cost[i][j] + gao(i, j + 1, inrow - 1));
  }
  return (dp[i][j][inrow] = ans);
  //return ans;
}
int main() {
  int k;
  scanf("%d %d %d", &n, &m, &k);
  while (k--) {
    int i, j;
    ll val;
    scanf("%d %d %lld", &i, &j, &val);
    cost[i - 1][j - 1] = val;
  }
  memset(dp, -1, sizeof(dp));
  printf("%lld\n", gao(0, 0, 3));
  return 0;
}

Measured memory_bytes: 357896
#include <iostream>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main()
{
  cin >> N >> W;
  for (int i = 0; i < N; ++i)
    cin >> weight[i] >> value[i];

  // DPループ
  for (int i = 0; i < N; ++i)
  {
    for (int sum_w = 0; sum_w <= W; ++sum_w)
    {
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
      // i 番目の品物を選ぶ場合
      if (sum_w - weight[i] >= 0)
      {
        chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }

      // i 番目の品物を選ばない場合
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
    }
  }

  // 最適値の出力
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
from sys import stdin

N = int(stdin.readline().rstrip())
A = [int(s) for s in stdin.readline().rstrip().split()]
ans = 0

for i in range(len(A)):
    if i == 0:
        continue

    if A[i-1] > A[i]:
        tmp = A[i-1]-A[i]
        ans = ans + tmp
        A[i] = A[i] + tmp

print(ans)


Measured memory_bytes: 32020
int main(void){
	int a,b,i,m;
	char op;
	for(i=1;i<=20000;i++){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?')
		 break;
		if(op=='+'){
			m=a+b;
		}
		if(op=='-'){
			m=a-b;
		}
		if(op=='*'){
			m=a*b;
		}
		if(op=='/'){
			m=a/b;
		}
		printf("%d\n",m);
	}
return 0;
}


Measured memory_bytes: 2148
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    int SIZE = 5 * 100_000;
    long MOD = 1_000_000_007;
    long inv[] = new long[5 * 100_000 + 1];
    long fac[] = new long[5 * 100_000 + 1];
    long fac2[] = new long[5 * 100_000 + 1];

    void solve(Scanner sc, PrintWriter pw) {
        inv[0] = 1;
        inv[1] = 1;
        for (int i = 2; i <= SIZE; i++) {
            inv[i] = (MOD - (MOD / i) * inv[(int) (MOD % i)] % MOD) % MOD;
        }
        fac[0] = 1;
        fac2[0] = 1;
        for (int i = 1; i <= SIZE; i++) {
            fac2[i] = (fac2[i - 1] * inv[i]) % MOD;
            fac[i] = (fac[i - 1] * i) % MOD;
        }
        int N = sc.nextInt();
        int M = sc.nextInt();
        long result = 0;
        for (int common = 0; common <= N; common++) {
            long positive = (common % 2) == 0 ? 1L : -1L;
            long abineFirst = abine(M, common);
            long abineSecond = abine(M - common, N - common);
            long secondPart = (abineFirst * ((abineSecond * abineSecond) % MOD)) % MOD;
            long combine = combine(N, common);
            long part = (positive * ((combine * secondPart) % MOD)) % MOD;
            result = (((result + part) % MOD) + MOD) % MOD;
            //System.out.println(String.format("a(m, i) %d, a(m- i, n - i) %d, combine %d, part %d, result %d", abineFirst, abineSecond, combine, part, result));
        }
        pw.println(result);
    }

    private long power(long l, long k) {
        if (k == 0) {
            return 1;
        }
        long half = power(l, k / 2);
        long part = (half * half) % MOD;
        if ((k % 2) == 1) {
            return (part * l) % MOD;
        } else {
            return part;
        }
    }

    long combine(int n, int k) {
        return (fac[n] * ((fac2[k] * fac2[n - k]) % MOD)) % MOD;
    }

    long abine(int n, int k) {
        return (fac[n] * ((fac2[n - k]))) % MOD;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        new Main().solve(sc, pw);
        pw.flush();
        pw.close();
        sc.close();
    }
}


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

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

	vector<long long int> a;
	long long int sum = 0;

	long long int t;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		a.push_back(t);
		sum += t;
	}


	long long int smin;
	long long int p, q;
	p = a[0];
	q = sum - p;
	smin = abs(p - q);

	long long int temp;

	if (n > 2)
	{
		for (int i = 1; i < n - 1; i++)
		{
			p += a[i];
			q = sum - p;
			temp = abs(p-q);

			if (smin > temp)
			{
				smin = temp;
			}
		}
	}

	cout << smin << endl;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
    KAKA
    ll n;
    cin>>n;
    ll digit = n % 10;
    if((digit == 2) or (digit == 4) or (digit == 5) or (digit == 7) or (digit == 9))
    cout<<"hon"<<"\n";
    else if((digit == 0) or (digit == 1) or (digit == 6) or (digit == 8))
    cout<<"pon"<<"\n";
    else cout<<"bon"<<"\n";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#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=998244353;
const LL LINF=1LL<<62;


int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << c-(d-b) << " " << d+(c-a) << " " << a-(d-b) << " " << b+(c-a) << endl;  
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define sf scanf
#define pf printf
#define REP(i,n) for (int (i) = 0;(i) < (n);++(i))
#define FORN(i,a,b) for (int i = (a);i <=(b); ++i)
#define FORD(i,a,b) for (int i = (a); i >= (b); --i)
#define SORT(list) sort(ALL((list)));
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SIZE(x) ((int)(x).size())
#define IOS  cin.tie(0),cout.tie(0); ios::sync_with_stdio(false);
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef double db;
 
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int main() {
    IOS
    int n;
    scanf("%d",&n);
    printf("%d\n",(int)ceil(n / 2.0));
    return 0;
}

Measured memory_bytes: 256
n,a=int(input()),list(map(int,input().split()))
dp=[[a[0],-float('inf')]]
for i in range(1,n):
	dp.append([max(dp[i-1][0]+a[i],dp[i-1][1]+a[i]),max(dp[i-1][0]-2*a[i-1]-a[i],dp[i-1][1]+2*a[i-1]-a[i])])
print(max(dp[n-1]))

Measured memory_bytes: 24808
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b = LI()
    if a*b % 2 == 0:
        return 'No'

    return 'Yes'


print(main())


Measured memory_bytes: 7492
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;

	// Left
	if(x - r < 0){
		cout << "No" << endl;
	}
	// Right
	else if(x + r > W){
		cout << "No" << endl;
	}
	// Down
	else if(y - r < 0){
		cout << "No" << endl;
	}
	// Up
	else if(y + r > H){
		cout << "No" << endl;
	}
	// Other
	else{
		cout << "Yes" << endl;
	}

	return 0;
}




Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int MOD  = 1e9 + 7;
int N;

int mazak(){
	int ans = 0;
	int mul = 1;
	int arr[N];
	for(int i=0;i<N;++i)
		cin>>arr[i];

	for(int k=0;k<60;++k){
		int ones = 0;
		for(int i=0;i<N;++i){
			if((arr[i])&(1ll << k))
				++ones;
		}
		ans += ((ones*(N-ones))%MOD)*mul;
		ans %= MOD;
		mul *= 2;
		mul %=MOD;
	}
	return ans;
}

signed main(){

	cin>>N;
	cout<<mazak();

}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    map<int,int> m;
    rep(i,n){
        int x;
        cin >> x;
        m[x]++;
    }
    int q;
    cin >> q;
    int ans = 0;
    rep(i,q){
        int x;
        cin >> x;
        ans += m[x]>0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10112
#include<stdio.h>
#include<stdlib.h>
int main(void) {
	int h, w;
	scanf("%d %d", &h, &w);
	int i, j;
	char** a = malloc(sizeof(char*) * h);
	for (i = 0; i < h; i++) {
		a[i] = malloc(sizeof(char) * w);
	}
	for (i = 0; i < h; i++)
		scanf("%s", a[i]);
	int k, count = 0;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (a[i][j] == '.') {
				count = 0;
				if (j != 0) {
					if (a[i][j - 1] == '#')
						count++;
				}
				if (j != w - 1) {
					if (a[i][j + 1] == '#')
						count++;
				}
				if (i != 0) {
					if (a[i - 1][j] == '#')
						count++;
					if (j != 0) {
						if (a[i - 1][j - 1] == '#')
							count++;
					}
					if (j != w-1) {
						if (a[i - 1][j + 1] == '#')
							count++;
					}
				}
				if (i != h-1) {
					if (a[i + 1][j] == '#')
						count++;
					if (j != 0) {
						if (a[i + 1][j - 1] == '#')
							count++;
					}
					if (j != w - 1) {
						if (a[i + 1][j + 1] == '#')
							count++;
					}
				}
					
				a[i][j] = '0' + count;
			}
		}
	}
	for (i = 0; i < h; i++) {
		printf("%s\n", a[i]);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())

A = []

for i in range(N):

    a = list(map(int,input().split()))

    A.append(a)

Q = []
for i in range(N):

    if A[ A[i][0]-1 ][0] == i + 1 and A[i][0]-1 > i:
        Q.append([min(A[i][0]-1,i),max(A[i][0]-1,i),1])

day = 0

while len(Q) > 0:

    q = Q.pop(0)

    del A[q[0]][0]
    del A[q[1]][0]




    if len(A[q[0]]) > 0 and A[ A[q[0]][0] - 1 ][0] == q[0] + 1:
        Q.append([min(A[q[0]][0] - 1,q[0]),max(A[q[0]][0] - 1,q[0]),q[2]+1])

    if len(A[q[1]]) > 0 and A[ A[q[1]][0] - 1 ][0] == q[1] + 1:
        Q.append([min(A[q[1]][0] - 1,q[1]),max(A[q[1]][0] - 1,q[1]),q[2]+1])

    day = max(day,q[2])

flag = True

for a in A:
    if len(a) > 0:
        flag = False
        
if flag:
    print (day)
else:
    print (-1)


Measured memory_bytes: 35056
MOD = 10**9 + 7
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, mod):
    g, x, y = xgcd(a, mod)
    assert g == 1, 'modular inverse does not exist'
    return x % mod

factorials = [1]
def factorial(n, mod):
    # n! % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    if len(factorials) < n+1:
        for i in range(len(factorials), n+1):
            factorials.append(factorials[-1]*i % mod)
    return factorials[n]

def comb(n, r, mod):
    # nCr % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
    
    return perm(n, r, mod) * modinv(factorial(r, mod), mod) % mod

def perm(n, r, mod):
    # nPr % mod
    assert n >= 0, 'Argument Error! n is "0 <= n".'
    assert n >= r >= 0, 'Argument Error! r is "0 <= r <= n".'
    return factorial(n, mod) * modinv(factorial(n-r, mod), mod) % mod

x, y = sorted(map(int, input().split()))
MOD = 10 ** 9 + 7
q, r = divmod(x+y, 3)
 
if r != 0:
    print(0)
else:
    try:
        print(comb(q, y - q, MOD))
    except AssertionError:
        print(0)

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

int main()
{
    string s;
    cin>>s;
    int l = s.length();
    bool flage = true;
    for(int i = 0 ;i<l && flage==true;i++) 
    {
        if(i%2==0 && s[i]=='L')
            flage=false;
        else if(i%2==1 && s[i]=='R')
            flage=false;
    }
    if(flage)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
	n, m = map(int,raw_input().split(" "))
	if n == m == 0:
		break
	fert = [map(float,raw_input().split(" ")) for i in range(n)]
	dp = [[0. for i in range(n)] for i in range(m)]
	dp[0] = [1. for i in range(n)]
	for i in range(m-1):
		for j in range(n):
			for k in range(n):
				tmp = dp[i][j] * fert[j][k]
				if tmp > dp[i+1][k]:
					dp[i+1][k] = tmp
	print "{0:.2f}".format(round(max(dp[m-1]), 2))

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;
typedef tree<
        pair<int, int>, // change type
        null_type,
        less<pair<int, int> >, // change type
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define per(i, start, end) for(int i = (int)start-1; i >= end; --i)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
const double PI = 3.14159265358979323846;
const double eps = (1e-8);

int n, m;
string g[405];
bool visit[405][405];
ll black, white;

int di[] = {-1, 1, 0 ,0};
int dj[] = {0, 0, -1, 1};

bool valid(int i, int j)
{
    if (i < 0 || j < 0 || i >= n || j >= m)
        return 0;
    return 1;
}

void dfs(int i, int j)
{
    visit[i][j] = 1;
    if (g[i][j] == '#')
        black++;
    else
        white++;
    rep(mv, 0, 4)
    {
        int ii = i + di[mv], jj = j + dj[mv];
        if (valid(ii, jj) && g[ii][jj] != g[i][j] && !visit[ii][jj])
        {
            dfs(ii, jj);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
////    freopen("facebook.txt", "w", stdout);
//#endif
    cin >> n >> m;
    rep(i,0,n)
        cin >> g[i];
    ll ans = 0;
    rep(i,0,n)
    {
        rep(j,0,m)
        {
              black = white = 0;
			dfs(i, j);
                ans += black * white;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 18048
#include <stdio.h>
#include <stdlib.h>


int main()
{
    char inputNumbers[5];
    char temp[2];
    int a, b, c, d;
    int sum;
    char symbols[3];
    
    scanf("%s", &inputNumbers);

    temp[1] = '\0';

    temp[0] = inputNumbers[0];
    a = atoi(temp);
    temp[0] = inputNumbers[1];
    b = atoi(temp);
    temp[0] = inputNumbers[2];
    c = atoi(temp);
    temp[0] = inputNumbers[3];
    d = atoi(temp);
    
    for (int i = 0; i < 2; i++)
    {
	for (int j = 0; j < 2; j++)
	{
	    for (int k = 0; k < 2; k++)
	    {
		if (i == 0)
		{
		    sum = a + b;
		    symbols[0] = '+';
		}
		else
		{
		    sum = a - b;
		    symbols[0] = '-';
		}

		if (j == 0)
		{
		    sum = sum + c;
		    symbols[1] = '+';
		}
		else
		{
		    sum = sum - c;
		    symbols[1] = '-';
		}

		if (k == 0)
		{
		    sum = sum + d;
		    symbols[2] = '+';
		}
		else
		{
		    sum = sum - d;
		    symbols[2] = '-';
		}

		if (sum == 7)
		{
		    printf("%d%c%d%c%d%c%d=7\n", a, symbols[0], b, symbols[1], c, symbols[2], d);
		    
		    return 0;
		}
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    ll h[n];
    ll c[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    c[0]=0;
    c[1]=abs(h[0]-h[1]);
    for(ll i=2;i<n;i++){
        c[i]=min(c[i-2]+abs(h[i-2]-h[i]),c[i-1]+abs(h[i-1]-h[i]));
    }
    cout<<c[n-1];
}


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

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

using namespace std;

typedef long long ll;

int main(){
	int n; scanf("%d",&n);
	int cost[100][100];
	rep(u,n) rep(v,n) scanf("%d",cost[u]+v);

	ll ans=0;
	rep(u,n) rep(v,u) ans+=min(cost[u][v],cost[v][u]);
	printf("%lld\n",ans);

	return 0;
}

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

#define rep(a,b) for(ll ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  string s;
  int c=0,max=0;
  cin>>s;
  rep(0,s.length())
  {
     if(s[ii]=='R') c++;
     else
     {
       if(c>max) max=c;
       c=0;
     }
  }
  if(c>0) max=c;
  cout<<max<<endl;
  return 0;
}

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

const int N=100005;
const long long INF=0x3f3f3f3f3f3f3f3f;
int n,m,tot=100000;
long long w[N],v[N];
long long dp[N];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d%d",&w[i],&v[i]);
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=tot;j>=v[i];j--)
		{
			dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
		}
	}
	for(int i=tot;i>=0;i--)
	{
		if(dp[i]<=m)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
    double r, s, l;
    scanf("%lf", &r);
    s = M_PI * pow(r, 2);
    l = 2 * M_PI * r;
    printf("%lf %lf\n", s, l);
    return 0;
}


Measured memory_bytes: 2088
def make_fomula(s, ops):
    f = ''
    for v, op in zip(s, ops):
        f += v + op
    else:
        f += s[-1]
    return f


s = input()
n = len(s) - 1
bit = 0
while bit < (1 << n):
    ops = ['-'] * n
    for i in range(n):
        if bit & 1 << i:
            ops[i] = '+'

    fomula = make_fomula(s, ops)
    if eval(fomula) == 7:
        print(fomula+'=7')
        break

    bit += 1

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

using namespace std;

const int maxn = 2e3 + 23;

int n, dtr, rad, res;
vector<int> adj[maxn];
bool buf;

int dfs(int v, int par, int dist) {
	int ret = (dist < 0);
	for (auto u : adj[v]) {
		if (u != par)
			ret += dfs(u, v, dist-1);
	}
	return ret;
}

inline void solve() {
	res = n-1;
	for (int i = 1; !(dtr&1) and i <= n; i++) {
		res = min(res, dfs(i, -1, rad));
	}
	for (int i = 1; (dtr&1) and i <= n; i++) {
		for (auto u : adj[i]) {
			if (i < u)
				res = min(res, dfs(i, u, rad) + dfs(u, i, rad));
		}
	}
}

int main() {

	buf = scanf("%d %d", &n, &dtr);
	for (int i = 1; i <= n-1; i++) {
		int x, y;
		buf = scanf("%d %d", &x, &y);

		adj[x].emplace_back(y);
		adj[y].emplace_back(x);
	}

	rad = dtr>>1;

	solve();

	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 3928
#include<bits/stdc++.h>
const int N=1e5+7;
using namespace std;
int n,m,tot,head[N],size[N];
vector<int> G[N];
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
inline void addedge(int u,int v){
	G[u].push_back(v);G[v].push_back(u);
}
int cnt=0;
inline int dfs(int u,int f){
	size[u]=1;int cur=0;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];if(v==f)continue;
		cur+=dfs(v,u);size[u]+=size[v];
	}
	if(cur>=2){puts("First");exit(0);}
	if(cur)return 0;
	else return 1;
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		addedge(u,v);
	}
	int ans=dfs(1,0);int cnt=0;
	if(cnt)puts("First");
	if(ans)puts("First");else puts("Second");
}

Measured memory_bytes: 6144
#include<stdio.h>

int f(int a){
	if(a<0){
		return 1;
	}
	switch(a){
		case 0: return 1;
		case 1: return 2;
		case 2: return 3;
		case 3: return 5;
		case 4: return 8;
		case 5: return 13;
		case 6: return 21;
		case 7: return 34;
		default: return 0;
	}
}

int main(){
	long long mod = 1000000007;
	int H, W, K;
	int i, j;
	if(scanf("%d%d%d", &H, &W, &K));
	if(W==1){
		printf("1");
		return 0;
	}
	long long dp[H+1][W+1];
	dp[0][1] = 1;
	for(i=2; i<=W; i++){
		dp[0][i] = 0;
	}
	for(i=1; i<=H; i++){
		dp[i][1] = ((dp[i-1][1]*f(W-2)) + (dp[i-1][2]*f(W-3)))%mod;
		dp[i][W] = ((dp[i-1][W]*f(W-2)) + (dp[i-1][W-1]*f(W-3)))%mod;
		for(j=2; j<=W-1; j++){
			dp[i][j] = ((dp[i-1][j-1]*f(j-3)*f(W-j-1)) + (dp[i-1][j]*f(j-2)*f(W-j-1)) + (dp[i-1][j+1]*f(j-2)*f(W-j-2)))%mod;
		}
	}
	printf("%lld", dp[H][K]);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    lli n, a;
    vector<lli> v;
    cin >> n;
    vector<lli> pref(n + 1, 0);
    input(n, v);
    // vector<vector<vector<lli>>> dp(n + 1,
    //                                vector<lli>(n + 1, vector<lli>(2, 0)));
    lli dp[n + 1][n + 1][2];
    fr(i, 0, n) {
        dp[i][i][0] = v[i];
        dp[i][i][1] = v[i];
    }

    pref[0] = v[0];
    fr(i, 1, n) {
        pref[i] = pref[i - 1] + v[i];
    }

    for (lli i = 2; i <= n; i++) {
        for (lli j = 0; j <= n - i; j++) {
            lli l = j, r = j + i - 1;
            dp[l][r][0] =
                max(v[l] + pref[r] - pref[l] - dp[l + 1][r][1],
                    v[r] + pref[r - 1] - pref[l] + v[l] - dp[l][r - 1][1]);
            dp[l][r][1] =
                max(v[l] + pref[r] - pref[l] - dp[l + 1][r][0],
                    v[r] + pref[r - 1] - pref[l] + v[l] - dp[l][r - 1][0]);
        }
    }

    cout << 2 * dp[0][n - 1][0] - pref[n - 1] << endl;
    rt;
}

Measured memory_bytes: 140928
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
}Node;

typedef Node * NodePointer;

void insert(int);
void inorderPrint(NodePointer);
void preorderPrint(NodePointer);
NodePointer createNode();

NodePointer root = NULL, NIL = NULL;

main(){
  int order, key, i;
  char command[7];

  scanf("%d", &order);

  for( i = 0; i < order; i++){
    scanf("%s", command);

    if( strcmp(command, "insert") == 0 ){
      scanf("%d", &key);
      insert(key);
    }
    else if( strcmp(command, "print") == 0 ){
      inorderPrint(root);
      printf("\n");
      preorderPrint(root);
      printf("\n");
    }
  }

  return 0;

}


void insert(int key){
  NodePointer x = root;
  NodePointer y = NIL;
  NodePointer z = createNode();

  z->key = key;

  while( x != NIL){
    y = x;
    if( z->key < x->key ) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if( y == NIL ) root = z;
  else if( z->key < y->key ) y->left = z;
  else y->right = z;

}


void inorderPrint(NodePointer x){
  
  if( x != NIL ){
    inorderPrint(x->left);
    printf(" %d", x->key);
    inorderPrint(x->right);
  }
  
}


void preorderPrint(NodePointer x){

  if( x != NIL ){
  printf(" %d", x->key);
  preorderPrint(x->left);
  preorderPrint(x->right);
  }

}


NodePointer createNode(){
  NodePointer x;

  x = malloc(sizeof(Node));
  x->key = 0;
  x->parent = NULL;
  x->left = NULL;
  x->right = NULL;

  return x;

}

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

int main() {
  string x,y;
  cin>>x>>y;
  if (x[0]==y[2] and x[1]==y[1] and x[2]==y[0]) {
    cout<< "YES" <<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
n, q = map(int, input().split())


class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


uf = UnionFind(n)
for _ in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        uf.union(x, y)
    else:
        if uf.is_same(x, y):
            print(1)
        else:
            print(0)


Measured memory_bytes: 6044
#include <bits/stdc++.h>
#define MAXN 2050
#define pii  pair<int, int>
#define ss second
#define ff first
 
using ll = long long;
using namespace std;
const int mod = 1e9 + 7;
 

int main(){
    int n, m;

    cin >> n >> m;
    vector<string> s(n);

    for (int i=0; i<n; i++){
        cin >> s[i];
    }
    sort(s.begin(), s.end());

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

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n = 0;
	int m = 0;
	scanf("%d %d", &n, &m);

	int a[100][100] = { 0 };
	int b[100] = { 0 };

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}

	for (int i = 0; i < m; i++) {
		scanf("%d", &b[i]);
	}

	int ans;
	for (int i = 0; i < n; i++) {
		ans = 0;
		for (int j = 0; j < m; j++) {
			ans += a[i][j] * b[j];
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1888
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    A, B = map(int, readline().split())

    print((A+B) % 24)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61868
#include <iostream>
#include <string>
#include <vector>

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

    std::cin >> n >> k;

    std::vector<int> snuke(n, 0);

    for (int i = 0; i < k; i++) {
        int d;
        std::cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            std::cin >> a;
            snuke[a - 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (snuke[i] == 0) {ans++;}
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define task ""
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef vector<int> vi;

const int N = 2e3 + 5;
const int oo = 1e9 + 7;
int n, posb[N], posw[N], f[N][N], b[N][N], w[N][N];
int main() {
    //freopen(task".inp", "r", stdin);
    //freopen(task".out", "w", stdout);
    scanf("%d", &n);
    FOR(i, 1, 2*n) {
        char ch;
        int x;
        scanf(" %c %d", &ch, &x);
        if (ch == 'B') posb[x] = i;
        else posw[x] = i;
    }


    FOR(i, 1, n) {
        FOR(j, 1, i-1) b[i][0] += (posb[j] > posb[i]);
        FOR(j, 1, n) b[i][j] = b[i][j-1] + (posw[j] > posb[i]);
    }
    /*FOR(i, 0, n) {
        FOR(j, 0, n) printf("%5d", b[i][j]);
        cerr << "\n";
    }+*/
    FOR(i, 1, n) {
        FOR(j, 1, i-1) w[i][0] += (posw[j] > posw[i]);
        FOR(j, 1, n) w[i][j] = w[i][j-1] + (posb[j] > posw[i]);
    }
    /*cerr << "\n"
    FOR(i, 0, n) {
        FOR(j, 0, n) printf("%5d", w[i][j]);
        cerr << "\n";
    }*/

    FOR(i, 0, n) FOR(j, 0 + (i == 0), n) {
        f[i][j] = oo;
        if (i) f[i][j] = min(f[i][j], f[i-1][j] + b[i][j]);
        if (j) f[i][j] = min(f[i][j], f[i][j-1] + w[j][i]);
    }
    printf("%d", f[n][n]);
}



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

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double a, b;
    double theta;

    a = 30 * H + 0.5 * M;
    b = 6 * M;
    theta = a - b;
    // cout << theta << endl;

    double ans = sqrt(A*A + B*B - 2*A*B*cos(theta/180*M_PI));
    cout << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 4152
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
      cin>>n;

      int seqb[n-1];
      for(int i=0;i<n-1;i++)
        cin>>seqb[i];

      int seqa[n];

        if(n > 2)
        {
            seqa[0]=seqb[0];
            seqa[1]=seqb[0];

             for(int i=1;i<n-1;i++)
             {
                 if(seqb[i] > seqa[i])
                   seqa[i+1]=seqb[i];

                  else
                  {
                     seqa[i]=seqb[i];
                       seqa[i+1]=seqb[i];
                  }
             }
             long int total=0;
             for(int i=0;i<n;i++)
              total+=seqa[i];

              cout<<total;
        }

       else
       {
         seqa[0]=seqb[0];
         seqa[1]=seqb[0];
          cout<<seqa[0]+seqa[1];
       }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		
		int ans = (a+b) * h /2;
		
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc092_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  int D, X;
  cin >> D >> X;

  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }

  ll ans = X;
  rep(i, N) {
    ans += (D - 1) / c[i] + 1;
  }

  cout << ans << endl;
}

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

int main(void){
    int n ;
    bool ans=false ;
    cin >> n ;
    for (int i=1; i<10; i++){
        for (int j=1; j<10; j++){
            if (i*j==n){
                ans=true ;
            }
        }
    }
    if (ans==true){
        cout << "Yes" << endl ;
    } else {
        cout << "No" << endl ;
    }
}

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

struct Dice{
	int num[6];
};

void move(struct Dice *dice, string str){
	int store[6];

	for(int i=0;i<str.length();i++){
		for(int j=0;j<6;j++){
			store[j] = (*dice).num[j];
		}
		switch(str[i]){
		case 'N':
			(*dice).num[0] = store[1];
			(*dice).num[1] = store[5];
			(*dice).num[5] = store[4];
			(*dice).num[4] = store[0];
			break;
		case 'E':
			(*dice).num[0] = store[3];
			(*dice).num[3] = store[5];
			(*dice).num[5] = store[2];
			(*dice).num[2] = store[0];
			break;
		case 'S':
			(*dice).num[0] = store[4];
			(*dice).num[4] = store[5];
			(*dice).num[5] = store[1];
			(*dice).num[1] = store[0];
			break;
		case 'W':
			(*dice).num[0] = store[2];
			(*dice).num[2] = store[5];
			(*dice).num[5] = store[3];
			(*dice).num[3] = store[0];
			break;
		}
	}
}

void spin(struct Dice *dice, int n){
	for(int i=0;i<n;i++){
		int temp = (*dice).num[1];
		(*dice).num[1] = (*dice).num[3];
		(*dice).num[3] = (*dice).num[4];
		(*dice).num[4] = (*dice).num[2];
		(*dice).num[2] = temp;
	}
}

int check(struct Dice *dice1, struct Dice *dice2){
	bool b = true;
	for(int i=0;i<6;i++)
		if((*dice1).num[i] != (*dice2).num[i])
			b = false;

	if(b)
		return 1;
	else
		return 0;
}

int main(){
	struct Dice dice[2];
	int x = 0;
	string str[6] = {" ", "N", "N", "N", "NE", "EE"};

	for(int j=0;j<2;j++){
		for(int i=0;i<6;i++){
			cin>>dice[j].num[i];
		}
	}

	for(int i=0;i<6;i++){
		move(&dice[1], str[i]);

		for(int j=1;j<5;j++){
			spin(&dice[1], 1);
			x += check(&dice[0], &dice[1]);
		}
	}

	if(x == 0)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 1208
import itertools

n = int(input())
p_list = list(map(int, input().split(' ')))
q_list = list(map(int, input().split(' ')))

if p_list == q_list:
	print(0)
else:
	a, b = 0, 0
	permutation = list(itertools.permutations(range(1,n+1)))
	for i, p in enumerate(permutation):
		pl = list(p)
		if pl == p_list:
			a = i
		elif pl == q_list:
			b = i
	print(abs(a-b))

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

int main() {
				    // *constraint*
  int N;    	// 1<=N<=10＾8
  				    // enter an integer
  
  int sum = 0;
  cin  >> N;
  int i = N;
  while (i > 0) {
   sum +=  i % 10;
   i /= 10;
  }
  
  if((N % sum) == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

using namespace std;

int main() {
    int N;
    cin >> N;
    
    int weights[N];
    for(int i = 0; i < N; i++)
    {
        cin >> weights[i];
    }

    int left_sum = 0, right_sum = weights[N - 1], smallest = 1000000;
    for(int i = 0; i < N - 1; i++)
    {
        left_sum += weights[i];
    }
    if (abs(left_sum - right_sum) < smallest)
    {
        smallest = abs(left_sum - right_sum);
    }

    for(int i = N - 2; i >= 0; i--)
    {
        left_sum -= weights[i];
        right_sum += weights[i];
        if (abs(left_sum - right_sum) < smallest)
        {
            smallest = abs(left_sum - right_sum);
        }
    }

    cout << smallest;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repm(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge;

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

    string s1, s2;
    cin >> s1 >> s2;
    a = stoi(s1 + s2);

    bool is = false;
    rep(i, 1000)
    {
        if (i * i == a)
            is = true;
    }

    if (is)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    n=I()
    ans=0
    for i in range(1,n+1):
        if len(str(i))%2==1:
            ans+=1
    print(ans)

if __name__=='__main__':
    main()

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

using namespace std;

typedef long long  ll;

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

    int n;

    cin >> n;
    n *= 2;
    vector<int> l(n);
    for (int i = 0; i < n; ++i)
        cin >> l[i];

    sort(l.begin(), l.end());
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        ans += min(l[i], l[i + 1]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
int main() {
	int N;
	cin >> N;
	vector<int> v(N);
	unordered_map<int, int> odd, even;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		if (i % 2 == 0) {
			even[v[i]]++;
		}
		else {
			odd[v[i]]++;
		}
	}
	int odd_f = 0, odd_s = 0, even_f = 0, even_s = 0;
	int odd_f_a = 0, odd_s_a = 0, even_f_a = 0, even_s_a = 0;
	for (auto i = odd.begin(); i != odd.end(); i++) {
		auto a = *i;
		if (odd_s < a.second && odd_f >= a.second) {
			odd_s = a.second;
			odd_s_a = a.first;
		}
		else if (odd_f < a.second) {
			odd_s = odd_f;
			odd_s_a = odd_f_a;
			odd_f = a.second;
			odd_f_a = a.first;
		}
	}
	for (auto i = even.begin(); i != even.end(); i++) {
		auto a = *i;
		if (even_s < a.second && even_f >= a.second) {
			even_s = a.second;
			even_s_a = a.first;
		}
		else if (even_f < a.second) {
			even_s = even_f;
			even_s_a = even_f_a;
			even_f = a.second;
			even_f_a = a.first;
		}
	}
	if (even_f_a == odd_f_a) {
		cout << min(N - even_f - odd_s, N - even_s - odd_f) << endl;
	}
	else {
		cout << N - even_f - odd_f << endl;
	}
	return 0;
}

Measured memory_bytes: 4760
#include<bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int n; 
int attack[1005];
int cost[1005];
int dp[10005];
int f(int health){
	int&ret = dp[health];
	if(~ret) return ret;
	ret = INF; 
	for(int i=0; i<n; i++){
		if(attack[i]>=health) ret = min(ret,cost[i]);
		else ret = min(ret,cost[i]+f(health-attack[i]));
	}
	return ret;
}
int main(){
	int h;
	cin>>h>>n;
	for(int i=0; i<n; i++) cin>>attack[i]>>cost[i];
	memset(dp,-1,sizeof(dp));
	dp[0] = 0;
	cout<<f(h);
}

Measured memory_bytes: 4308
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
lint powint(lint x,lint y){
	if(y==0)return 1;
	if(y%2)return x*powint(x,y-1);
	lint a = powint(x,y/2);
	return a*a;
}

int main(){
	int n;
	cin>>n;
	cout<<powint(n,3)<<endl;
}


Measured memory_bytes: 256
def minN(N:int, usable:list, restrict=True):
    usable.sort()
    keta = False
    if restrict:
        for i in usable:
            if i >= N:
                return str(i)
        # 桁が増える
        return '1'+str(usable[0])
    else:
        return str(usable[0])

def rote(N:list, D:set, d:set):
    ans = []
    flag = True
    lenNstr = len(N)
    for i, n in enumerate(N):
        n = int(n)
        keta = 10**(len(N) - i - 1)
        if flag:
            if n in D:
                ans.append(int(minN(n, d)) * keta)
                flag = False
            else:
                ans.append(keta * n)
        else:
            ans.append(keta * min(d))
    return sum(ans)

def main():
    N, K = map(int, input().split())
    D = set(map(int, input().split()))
    numset = set(range(0,10))
    d = list(numset.difference(D))
    d.sort()
    for _ in range(10):
        Nstr = list(str(N))
        ans = rote(Nstr, D, d)
        N = ans    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9252
# coding:utf-8

N = int(input())
X = [el for el in map(int, input().split(' '))]
ans = 2 ** 63 - 1

for point in range(100):
    tmp = 0
    for x in X:
        tmp += (x - point) ** 2
    if ans > tmp:
        ans = tmp

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
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 main()
{
    int N;
    cin >> N;
    vint A(N);
    cin >> A;
    int i=1;
    for(auto a:A){
        if(i == a){
            i++;
        }
    }
    i--;
    if(0 == i){
        i = -1;
    }else{
        i = (int)A.size()-i;
    }
    cout << i << endl;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define fork(i, n) for (ll i = 0; i < (n); i++)
#define forn for (ll i = 0; i < (n); i++)
#define fori(i, k, n) for (ll i = k; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);

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;
}
template <typename T>
void print(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(deque<T> &a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
template <typename T>
void print(vector<vector<T>> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

const int mod = 1e9 + 7;

ll pw(ll b, ll e)
{
	ll res = 1;
	while (e)
	{
		if (e % 2)
			res = (res * b) % mod;
		b = (b * b) % mod;
		e >>= 1; // e/=2;
	}
	return res;
}

ll fact[200005], inv[200005];
ll C(ll n, ll k)
{
	return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

int main()
{
	fast;
	int n, c;
	for (int i = 1; i <= 5; i++)
	{
		cin >> n;
		if (n == 0)
		{
			c = i;
			break;
		}
	}
	cout << c << en;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 
signed main(){
    string s;

    while(cin>>s){
        if(s[0]=='-')break;

        int m;
        cin>>m;
        string now=s;
        while(m--){
            int h;
            cin>>h;
            //dump(now);
            string t=now.substr(0,h);
            //dump(t);
            string tb=now.substr(h,now.size()-h);
            //dump(tb);

            now=tb+t;
            //cerr<<"now="<<now<<endl;

        }
        cout<<now<<endl;

    }

 
}


Measured memory_bytes: 3172
import queue
import sys
input = sys.stdin.readline

N = int(input())
E = {n: set() for n in range(N)}

for _ in range(N - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    E[a].add((b, c))
    E[b].add((a, c))

Q, K = map(int, input().split())
K -= 1
dist = [-1] * N
already = set()
que = queue.Queue()
dist[K] = 0
que.put(K)
while not que.empty():
    now = que.get()
    out = E[now]
    for n, c in out:
        if dist[n] != -1:
            continue
        dist[n] = dist[now] + c        
        que.put(n)

res = ""
for _ in range(Q):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    res += str(dist[x] + dist[y]) + "\n"

print(res)



Measured memory_bytes: 67036
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
int main(){
    int n,m;
    cin>>n>>m;
    int data[101][101];
    rep(i,n)rep(j,m)cin>>data[i][j];
    
    
    rep(i,n){
        data[i][0]  = !data[i][0];
        data[i][m-1]= !data[i][m-1];
    }
    rep(i,m){
        data[0][i] = !data[0][i];
    }
    
    int ans=0;
    rep(i,n){
        int c=0;
        rep(j,m)if(data[i][j]==1)c++;
        if(c==m)ans += c-1;
        else    ans += c+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3128
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		for(int i=1;; i++)
		{		
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			
			if(a==0 && b==0)
			{
				break;
			}
			else if(a > b)
			{
				int buf = a;
				a = b;
				b = buf;
				
			}
			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 36624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

mod = 10**9+7

def dfs(v, Pa=-1):
    white, black = 1, 1
    for u in to[v]:
        if u == Pa: continue
        x, y = dfs(u, v)
        white *= x+y
        black *= x
    return white, black

n = int(input())
to = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)

white, black = dfs(0)
print((white+black) % mod)

Measured memory_bytes: 116400