akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

int part(int y) {
    // how many pairs of (a,b) where a+b=y
    if (y < 0) return 0;
    if (y <= 1000) return y+1;
    if (y > 2000) return 0;
    // 1??? (???,1000) ~ (1000,???)
    return 2001-y;
}

void solve96(int n) {
    int cnt = 0;
    REP(i,1001) {
        REP(j,1001) {
            cnt += part(n - i - j);
        }
    }
    cout << cnt << endl;
}

int main() {
    int n;
    while(cin >> n) {
        solve96(n);
    }
    return 0;
}

Measured memory_bytes: 1160
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

for a in A:
    if a % 2 == 0 and a % 3 != 0 and a % 5 != 0:
        print('DENIED')
        exit()
print('APPROVED')


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	static long mod = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long sum = 0;
		COMinit(n);
		for (int i = 1; i < n; i++) {
			sum += COM(n - i, k - 1) * (a[n - i] - a[i - 1]) % mod;
			sum %= mod;
		}
		if (sum < 0) {
			sum += mod;
		}
		System.out.println(sum);
	}

	static long[] fac;
	static long[] finv;
	static long[] inv;

	static void COMinit(int n) {
		fac = new long[n + 1];
		finv = new long[n + 1];
		inv = new long[n + 1];
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for (int i = 2; i < n; i++) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - inv[(int) (mod % i)] * (mod / i) % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
	static long COM(int n, int k) {
		if (n < k || (n < 0 || k < 0)) {
			return 0;
		}
		return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 26956
//by xiqiao
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
typedef long long ll;
vector <int> v[maxn];
vector <int> g[maxn];
int n,m,flag;
int vis[maxn];
ll ans;
int cnt[4],ge;
int next(int x){if(x==3)return 1;return x+1;}
int next2(int x){if(x==1)return 3;if(x==2)return 1;return 2;}
void dfs(int x,int c){
	cnt[c]++;vis[x]=c;
	for(int i=0;i<(int)v[x].size();i++){
		if(v[x][i]==x)flag=1;
		ge++;
		if(!vis[v[x][i]]){
			dfs(v[x][i],next(c));
		}
		else if(vis[v[x][i]]!=next(c)){
			flag=1;
		}
	}
	for(int i=0;i<(int)g[x].size();i++){
		ge++;
		if(!vis[g[x][i]]){
			dfs(g[x][i],next2(c));
		}
		else if(vis[g[x][i]]!=next2(c)){
			flag=1;
		}	
	}
}
int main(){
//	freopen("table.in","r",stdin);
	//freopen("table.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int x,y;scanf("%d%d",&x,&y);
		v[x].push_back(y);g[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			flag=0;cnt[1]=0;cnt[2]=0;cnt[3]=0;ge=0;
			dfs(i,1);
			int sum=cnt[1]+cnt[2]+cnt[3];
			if(flag){
				ans+=1ll*sum*sum;
			}
			else if(cnt[1] && cnt[2] && cnt[3]){
				ans+=1ll*cnt[1]*cnt[2];
				ans+=1ll*cnt[2]*cnt[3];
				ans+=1ll*cnt[3]*cnt[1];
			}
			else ans+=ge/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19328
n = int(input())

cnt = [[0]*10 for i in range(10)]

for i in range(1,n+1):
    s = str(i)
    cnt[int(s[0])][int(s[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    System.out.println(A[N - 1] - A[0]);
  }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+5;
typedef long long ll;
ll dp[N],sum[N],a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(i==1)
            sum[i]=a[i];
        else
            sum[i]=sum[i-2]+a[i];
    }
    for(int i=2;i<=n;i++)
    {
        if(i&1)
            dp[i]=max(dp[i-1],dp[i-2]+a[i]);
        else
            dp[i]=max(dp[i-2]+a[i],sum[i-1]);
    }
    printf("%lld\n",dp[n]);
    return 0;
}

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

const int N = 300000;
vector<int> mon_sat, prime;
  
int main(){
  for(int i=2;i<=N;i++){
    if(i%7==1 || i%7==6)mon_sat.push_back(i);
  }

  for(int i=0;i<mon_sat.size();i++){
    bool f = true;
    for(int j=0;j<prime.size();j++){
      if(mon_sat[i] % prime[j] == 0){
	f = false;
	break;
      }
    }
    if(f)prime.push_back(mon_sat[i]);
  }

  int n;
  while(cin >> n, n!=1){
    cout << n << ":";
    for(int i=0;i<prime.size();i++){
      if(n % prime[i] == 0)cout << " " << prime[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1720
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

vector<pair<int, int>> pvec;

inline bool isOverlap(pair<int,int>& _ix1, const pair<int,int> _ix2) {
	if (_ix1.second < _ix2.first) {
		_ix1 = _ix2;
		return false;
	}
	else {
		_ix1.first = _ix2.first;
		if (_ix1.second > _ix2.second) {
			_ix1.second = _ix2.second;
		}
	}
	return true;
}

int main() {
	cin.tie(0);
	int N, M;
	cin >> N >> M;

	REP(i, M) {
		pair<int, int> p;
		cin >> p.first >> p.second;
		p.second -= 1;
		pvec.push_back(p);
	}

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

	ll ans = 0;

	pair<int, int> overlap_ix = pvec[0];
	REPS(i, 1, M) {
		if (!isOverlap(overlap_ix, pvec[i])) {
			ans++;
		}
	}
	ans++;
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 1400
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n = int(input())
r=0
for i in range(0,n):
  xs,u = input().split()
  x=float(xs)
  if u == 'BTC':
    r=r+380000.0*x
  else:
    r=r+x
print(r)


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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
template <typename T> using VVV = vector<vector<vector<T>>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

void solve() {
    lint N, W;
    cin >> N >> W;

    vector<lint> w(N);
    vector<lint> v(N);

    rep(i, N) {
        lint a, b;
        cin >> a >> b;
        w[i] = a;
        v[i] = b;
    }

    unordered_map<lint, lint> dp;

    rep(i, N) {
        unordered_map<lint, lint> next_dp = dp;
        repu(j, 1, N + 1, 1) {
            rep(k, j * 3 + 1) {
                lint now_w = w[0] * j + k;
                if(now_w - w[i] >= 0) {
                    next_dp[now_w] = max(dp[now_w], dp[now_w - w[i]] + v[i]);
                }
            }
        }
        dp = next_dp;
    }

    lint ans = 0;
    for(auto &&it : dp) {
        if(it.first <= W) {
            ans = max(ans, it.second);
        }
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
 
int main() {
	string s;
	int B = 0;
	long long ans = 0;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == 'B') B++;
		else  ans += B;
	}
	cout << ans << endl;
	return 0;
}

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

const ll MOD = 1E9+7;
int n, a[100001], aa;
ll ans;

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

    bool flag = true;
    if(n% 2 == 0){
        for(int i = 1; i < n; i+= 2){
            if(a[i] != 2){
                flag  = false;
                break;
            }
        }
    }
    else{
        if(a[0] != 1)   flag = false;
        for(int i = 2; i < n; i+= 2){
            if(a[i] != 2){
                flag = false;
                break;
            }
        }
    }

    ans = 1;
    if(!flag){
        cout << "0\n";
        return 0;
    }
    else{
        for(int i = 0; i < n/2; i++){
            ans = ans * 2 % MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

//Kannondou
public class Main{

	public static void main(String[] args) {
		int[][] dp = new int[31][31];
		dp[0][0] = 1;
		for(int i=1;i<=30;i++){
			for(int j=1;j<=30;j++){
				for(int k=1;k<=3;k++){
					if(j-k<0)continue;
					dp[i][j] += dp[i-1][j-k];
				}
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int t = 0;
			for(int i=1;i<=n;i++)t+=dp[i][n];
			System.out.println((t/10-1)/365+1);
		}
	}
}

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

int main() {
  ll a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k%2==0) cout<<a-b<<endl;
  else cout<<b-a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

struct FT {
	int n;
	vector<int> v;
	FT(int n) : n(n), v(vector<int>(n + 1, 0)) {}
	void update(int i, const int a) {
		for (++i; i < v.size(); i += i & -i)
			v[i] += a;
	}
	int query(int i) const { // sum from 0 ... i
		assert(i >= -1 && i < n);
		int sum = 0;
		for (++i; i; i -= i & -i)
			sum += v[i];
		return sum;
	}
};

// numb of subarrays with median at most m
ll f(vector<int> a, const int m) {
	for (int &x : a)
		x = x <= m ? 1 : -1;

	a.insert(a.begin(), a.size());
	partial_sum(a.begin(), a.end(), a.begin());

	FT ft(a.size() << 1 | 1);

	ll res = 0;
	for (int i = 0; i < a.size(); ++i) {
		assert(a[i] >= 0 && a[i] < ft.n);
		res += ft.query(a[i] - 1);
		ft.update(a[i], 1);
	}
	return res;
}

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

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

	int lo = 1;
	int hi = 1 << 30;
	const ll total = (n + 1LL)*n / 2;

	while (lo < hi) {
		const int mid = (0LL + lo + hi) >> 1;
		if (f(a, mid) >= total / 2 + 1)
			hi = mid;
		else
			lo = mid + 1;
	}
	cout << lo << '\n';
	return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            ////入力した値を数値変換する
            string str = Console.ReadLine();
            int intNumFirst = int.Parse(Console.ReadLine());

            string[] strArray = new string[str.Length];

            //1文字目の文字を取得する
            char c1 = str[0];
            //あ

            //forを使って1文字ずつ列挙する
            for (int i = 0; i < str.Length; i++)
            {
                strArray[i] = str[i].ToString(); ;
            }

            int intMax = strArray.Length;
            string strResult = string.Empty;

            for (int i=0;i< intMax;i=i+intNumFirst)
            {
                strResult = strResult + strArray[i];
            }

            Console.WriteLine(strResult);

        }
    }

}

Measured memory_bytes: 27784
import java.io.*;
import java.util.StringTokenizer;
public class Main {

	public static void main(String[] args) throws Exception{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer tok = new StringTokenizer(in.readLine());
		int a = Integer.parseInt(tok.nextToken());
		int b = Integer.parseInt(tok.nextToken());
		if(a > 0 && b > 0) System.out.println("Positive");
		else if( a==0 || b == 0 ) System.out.println("Zero");
		else if(a < 0 && b < 0){
			int c = Math.abs(Math.abs(a) - Math.abs(b));
			System.out.println(c%2==0? "Negative" : "Positive");
		}
		else System.out.println("Zero");
	}
}


Measured memory_bytes: 22996
#include <iostream>

using namespace std;

bool Binary_search(int S[], int n, int key)
{
	int left = 0, right = n, mid;
	while(left < right)
	{
		mid = (left + right) / 2;
		if(S[mid] > key)
		{
			right = mid;
		}
		else if(S[mid] < key)
		{
			left = mid + 1;
		}
		else
		{
			return true;
		}
	}
	return false;
}

int main()
{
	int S[100005];
	int i, j, n, q, key, cnt = 0;
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> S[i];
	}
	cin >> q;
	for(j = 0; j < q; j++)
	{
		cin >> key;
		if(Binary_search(S,n,key))
		{
			cnt++;
		}
	}
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 3472
#include <stdio.h>
int main(){
    int m,n;
    char a[105][105];
    scanf("%d%d",&m,&n);
    getchar();
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            scanf("%c",&a[i][j]);
        }
        getchar();
    }
    for(int i=0;i<m+2;i++){
        for(int j=0;j<n+2;j++){
            if(i==0||i==m+1||j==0||j==n+1) printf("#");
            else printf("%c",a[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define len(s) s.length()
#define all(v) v.begin(),v.end()
const ll INF = INT_MAX;
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

int main() {


	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;
	// cin >> tc;
	while (tc--) {

		ll n, m, l, r;
		ll i, j;
		ll x, y;
		// cin >> n;

		ll h1, m1, h2, m2, k;

		cin >> h1 >> m1 >> h2 >> m2 >> k;

		ll totmin1 = h1 * 60 + m1;
		ll totmin2 = h2 * 60 + m2;

		totmin2 = totmin2 - k;

		ll ans = totmin2 - totmin1;
		cout << ans << endl;
	}
}

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

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

    vector<int> dp(N);
    dp[0] = 0, dp[1] = abs(H[1] - H[0]);
    for (int i = 2; i < N; i++) {
        dp[i] = min(dp[i - 1] + abs(H[i] - H[i - 1]), dp[i - 2] + abs(H[i] - H[i - 2]));
    }

    cout << dp[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int y,m,d;
	int i;
	int ans;
	
	y=2004;
	
	for(;;)
	{
		scanf("%d%d",&m,&d);
		if(m==0)
			break;
		
		ans=0;
		
		ans=(y-1)*365+y/4-y/100+y/400;
		
		for(i=1;i<m;i++)
		{
			if(i==2 && (y/4==0 && y/100!=0) || y/400==0)
				ans+=29;
			else if(i==2)
				ans+=28;
			else if(i<8 && i%2==0)
				ans+=30;
			else if(i<8 && i%2!=0)
				ans+=31;
			else if(i>7 && i%2==0)
				ans+=31;
			else
				ans+=30;
		}
		
		ans+=d;
		
		if(m<3 && ((y%4==0 && y%100!=0) || y%400==0))
			ans-=1;
		
		switch(ans%7)
		{
			
			case 0:
				printf("Sunday\n");
				break;
			case 1:
				printf("Monday\n");
				break;
			case 2:
				printf("Tuesday\n");
				break;
			case 3:
				printf("Wednesday\n");
				break;
			case 4:
				printf("Thursday\n");
				break;
			case 5:
				printf("Friday\n");
				break;
			case 6:
				printf("Saturday\n");
				break;
		}
	}
		
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(10);
    rep(i,n){
        int k = a[i]/400;
        if(k <= 7) cnt[k]++;
        else cnt[8]++;
    }
    int ans = 0;
    rep(i,8){
        if(cnt[i]) ans++;
    }
    cout << (ans > 0?ans:1) << " " << ans+cnt[8] << endl;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    unordered_map<int, int> odd, even;
    rep(i, n) {
        int v;
        cin >> v;
        if(i&1) odd[v]++;
        else even[v]++;
    }

    int a = 0, b = 0;
    int ma = 0, mb = 0;
    for(P x: odd) {
        if(a < x.second) {
            a = x.second;
            ma = x.first;
        }
    }
    for(P x:even) {
        if(b < x.second) {
            b = x.second;
            mb = x.first;
        }
    }



    if(ma == mb) {
        odd.erase(ma);
        even.erase(ma);
        int a_ = 0, b_ = 0;
        for(P x: odd) {
            a_ = max(a_, x.second);
        }
        for(P x:even) {
            b_ = max(b_, x.second);
        }
        a = max(a+b_, b+a_);
        b = 0;
    }

    cout << n-a-b << endl;
}

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

#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repn(i, n) for(int i = 1; i < n; ++i)
#define repm(i, n, m)  for(int i = n; i <= m; i++)
#define mod 1000000000+7

int main(){
    int n; cin >> n;
    long long k; cin >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    long long ans = 0;
    rep(i, n){
        for(int j = i+1; j < n; ++j){
            if(a[i] < a[j]){
                ans += k*(k-1)/2;
                ans %= mod;
                
            }else if(a[i] > a[j]){
                ans += k*(k+1)/2;
                ans %= mod;
            }
        }
    }

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


Measured memory_bytes: 764
i = 0
a = Array.new()
b = Array.new()
a[0], b[0] = gets.split.map(&:to_i)
while a[i] != 0 || b[i] != 0 do
	i = i + 1
	a[i], b[i]= gets.split.map(&:to_i)
end
i = 0
while a[i] != 0 || b[i] != 0 do
	if a[i] <= b[i] then
		puts "#{a[i]} #{b[i]}"
	else
		puts "#{b[i]} #{a[i]}"
	end
	i += 1
end

Measured memory_bytes: 8780
import sys
def input(): return sys.stdin.readline().strip()

class UnionFind():
    """
    https://note.nkmk.me/python-union-find/
    DFSの上位互換と考えて良い
    ２要素x, yがpath-connectedかどうかをlogオーダーで判定する（螺旋本の14.1節参照）
    さらに連結成分の要素数がO(1)で取得可能なように改造してある
    """
    def __init__(self, n):
        """
        要素数をnとして、各ノードを0,1,...,(n-1)の番号で管理する
        parentsは各ノードの属する木の根を表す
        ただし根ノードのparentには(その木のノード数)*(-1)を格納する
        """
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        """
        xの属する木の根を返す
        このとき同時に経路圧縮して、探索途中のノードを全て根に繋ぎ直す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        x, yのそれぞれ属する木Tx, Tyの根同士を繋ぐ
        このとき木の要素数が小さい方を大きい方に繋ぐ（rankではなくsizeを用いる）
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        """
        xの属する木の要素数を返す
        根の親を要素数の(-1)倍で定めておいたおかげでO(1)で取得可能
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        xとyがpath-connectedかを判定する
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        xの属する木の要素を列挙する
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        連結成分の代表元のリストを返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        連結成分の個数を返す
        """
        return len(self.roots())

    def all_group_members(self):
         """
         連結成分およびそれぞれの代表元をまとめた辞書を返す
         代表元がキーになってる
         """
         return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        連結成分およびその代表元を出力
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 


def main():
    N, M = map(int, input().split())
    edge = []
    for _ in range(M):
        a, b = map(int, input().split())
        edge.append((a-1, b-1))

    bridge = 0
    for i in range(M):
        tree = UnionFind(N)
        for j in range(M):
            if j == i: continue
            tree.union(edge[j][0], edge[j][1])
        if tree.group_count() != 1:
            bridge += 1
    print(bridge)

if __name__ == "__main__":
    main()


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

int value[20];

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

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

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

	int sum = 0;
	for(int i = 0; i < n; ++i){
		if(value[i] > 0){
			sum += value[i];
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
f=lambda a:any(all(b)for b in a)|all(a[i][i]for i in(0,1,2))
*t,=map(int,open(0).read().split())
a=t[:9]
s=eval('[0]*3,'*3)
for b in t[10:]:
  if b in a:
    i=a.index(b)
    s[i//3][i%3]=1
print('NYoe s'[f(s)|f([t[::-1]for t in zip(*s)])::2])

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

int kaibun(string T){
    int count=0;
    for(int i=0; i<T.size()/2; i++){
        if(T.at(i) == T.at(T.size()-1-i)) count++;
    }
    if(count == T.size()/2){
        return 1;
    }
    else return 0;
}

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

    string zen = "";
    string kou = "";

    int N = S.size();
    for(int i=0; i<N/2; i++){
        zen += S.at(i);
        kou += S.at((N+1)/2 + i);
    }

    if(kaibun(S) + kaibun(zen) + kaibun(kou) == 3){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 100005;
LL n , ara[N],d[N];
int main()
{
    cin >> n;
    FOR(i,1,n)cin >> ara[i];
    LL s = 0;FOR(i,1,n)s += ara[i];

    for(int i = 1;i + 1 < n;i++)d[i] = ara[i + 1] - ara[i];
    LL k = (2 * s)/((n + 1) * n);
    if((2 * s) % ((n + 1) * n) != 0){
        cout << "NO\n";
        return 0;
    }
    for(int i = 1;i + 1 < n;i++)d[i] = d[i] - k;

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

        if(ABS(d[i]) % n != 0 or d[i] > 0){
            cout << "NO" << "\n";
            return 0;
        }
        cnt += ABS(d[i])/n;
    }
    if(cnt <= k)cout << "YES\n";
    else cout << "NO\n";
}



Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

#素因数分解
def factorization(n):
	arr = []
	tmp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if tmp%i == 0:
			cnt = 0
			while tmp%i == 0:
				cnt += 1
				tmp //= i
			arr.append([i, cnt])
	if tmp != 1:
		arr.append([tmp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr
	
N = INT()

if N == 1:
	print(1)
	exit()

dic = defaultdict(int)
for i in range(2, N+1):
	for key, value in factorization(i):
		dic[key] += value

#print(dic)
ans = 1
for value in dic.values():
	ans = ans*(value + 1)%mod

print(ans)


Measured memory_bytes: 5460
h, w = map(int, input().split())
f = [input() for _ in range(h)]

inf = 10 ** 18
d = [[inf for _ in range(w)] for _ in range(h)]
d[0][0] = 0

for j in range(1, w):
    if f[0][j] == f[0][j-1]:
        d[0][j] =  d[0][j-1]
    else:
        d[0][j] =  d[0][j-1] + 1

for i in range(1, h):
    if f[i][0] == f[i-1][0]:
        d[i][0] =  d[i-1][0]
    else:
        d[i][0] =  d[i-1][0] + 1

for i in range(1, h):
    for j in range(1, w):
        costi = int(f[i][j] != f[i-1][j])
        costj = int(f[i][j] != f[i][j-1])
        d[i][j] = min(d[i-1][j] + costi, d[i][j-1] + costj)

if f[0][0] == '.':
    print((d[h-1][w-1]+1)//2)
else:
    print(d[h-1][w-1]//2 + 1)

Measured memory_bytes: 3188
#include<stdio.h>
int main(void)
{
    int n,m,i,a[200],b[200],flg[200],j,w;
	scanf("%d",&n);
	for(i=0;i<n;i++){
	    scanf("%d %d",&a[i],&b[i]);
	}
	scanf("%d",&m);
	for(i=n;i<m+n;i++){
	    scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<200;i++) flg[i]=1;
	for(i=0;i<n+m-1;i++){
	    for(j=i+1;j<n+m;j++){
		    if(a[i]>a[j]){
			    w=a[i];
				a[i]=a[j];
				a[j]=w;
				w=b[i];
				b[i]=b[j];
				b[j]=w;
			}
			else if(a[i]==a[j]&&b[i]>b[j]){
			    w=a[i];
				a[i]=a[j];
				a[j]=w;
				w=b[i];
				b[i]=b[j];
				b[j]=w;
			}
		}
	}
	for(i=0;i<n+m;i++){
	    if(a[i]==a[i+1]&&b[i]==b[i+1]) flg[i+1]=0;
	}
	for(i=0;i<n+m;i++){
	    if(flg[i]==1&&i==0) printf("%d:%02d",a[i],b[i]);
		else if(flg[i]==1) printf(" %d:%02d",a[i],b[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2756
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,X[101010],Y[101010];
vector<pll> xyv;
ll num[101010],mk[101010];
ll i,j,k,ans;

struct UnionFind{
    vector<int> nxt;
    UnionFind(int x){
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};


int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld%lld", &X[i], &Y[i]);
        //Xl[X[i]]++;
        //Yl[Y[i]]++;
        xyv.push_back({X[i], Y[i]});
        //yxv.push_back({Y[i], X[i]});
    }
    sort(xyv.begin(), xyv.end());
    //sort(yxv.begin(), yxv.end());
    UnionFind uf(100500);

    j = 0;
    fornum(i,0,N){
        auto xy = xyv[i];
        if(j!=xy.first){
            j = xy.first;
            k = 0;
        }
        if(k!=0){
            uf.unite(k, xy.second);
        }
        k = xy.second;
    }
    fornum(i,0,100100){
        num[uf.find(i)]++;
    }
    j = 0;
    fornum(i,0,N){
        auto xy=xyv[i];
        if(j!=xy.first){
            j = xy.first;
        }
        ll g = uf.find(xy.second);
        if(mk[g]!=j){
            mk[g] = j;
            ans += num[g];
        }
        ans--;
    }
    printf("%lld", ans);
    return 0;
}

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

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

	std::vector<int> d(n);
	for(int i = 0; i < n; ++i){
		std::cin >> d.at(i);
	}
	
	std::sort(d.begin(), d.end(), std::greater<int>());
	int prev = d.at(0);
	int kind = 1;
	for(int i = 0; i < n; ++i){
		if(d.at(i) != prev){
			++kind;
		}
		prev = d.at(i);
	}

	std::cout << kind << std::endl;

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

vector<vector<bool> > graph(9, vector<bool>(9));

int check(vector<int> v){
	for (int i = 0; i < v.size()-1; i++){
		if (graph[v[i]][v[i+1]] == false){
			return 0;
		}
	}
	return 1;
}

int main(){
	int n, m, ans = 0;
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		graph[a][b] = true;
		graph[b][a] = true;
	}
	vector<int> v;
	for (int i = 1; i <= n; i++){
		v.push_back(i);
	}

	do{
		ans += check(v); 
	}while(next_permutation(v.begin()+1, v.end()));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
using namespace std;

int main() {
	vector<int> a{ 1,2,3 };
	int A, B; cin >> A >> B;

	for (int i = 0; i < 3; i++) {
		if (a[i] != A && a[i] != B) cout << a[i] << endl;
	}
}

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

namespace CColoringColorfully
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var colors = Console.ReadLine().ToCharArray().Select(x => x - '0').ToArray();

            // 奇数番目が黒、偶数番目が白というルールを満たす数Xを数える
            // 上記ルールを満たすものが半分より多いならば N - X が解答
            // もし半分以下ならば X が解答
            var n = colors.Length;
            var oddBlackRule = colors.Where((c, i) => i % 2 == c).Count();
            var answer = n / 2 < oddBlackRule ? n - oddBlackRule : oddBlackRule;

            // 解答の出力
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13152
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <queue>
using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

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

    int ans[N], s, c;
    REP(i, 3){
        ans[i] = 10;
    }

    REP(i, M){
        cin >> s >> c;
        if(ans[N-s] > 9){
            ans[N-s] = c;
        } else if(ans[N-s] < 10 & ans[N-s] != c){
            ans[N-s] = -1;
        }
    }

    // REP(i, N){
    //     cout << "-----" << ans[i] << endl;
    // }

    int b = 0;
    REP(i, N){
        if(ans[i] < 0){
            b = -1;
            break;
        } else if(ans[i] == 0){
            // if(i == 0 & N != 1){
            //     b = -1;
            //     break;
            // }
        } else if(ans[i] < 10){
            b += int(pow(10, i))*ans[i];
        } else {
            if(i == N-1){
                b += int(pow(10, N-1));
            }
        }
    }

    // cout << b << endl;

    if(N ==3){
        if(b < 100){
            b = -1;
        }
    } else if(N == 2){
        if(b < 10 || 99 < b){
            b = -1;
        }
    } else {
        if(b > 10){
            b = -1;
        }
    }

    if(N == 1 & M == 0) b = 0;

    cout << b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())

int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
        int n;
        cin >> n;
        vector<int> vec(n);
        REP(i,n){
            cin >> vec[i];
        }

        int m,ans=1;
        m = vec[0];

        FOR(i,1,n){
            if(m > vec[i]){
                ans++;
                m = vec[i];
            }
        }
        cout << ans << endl;
}





Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
	char d;
	
	scanf("%c", &d);
	
	if(d == 'A')
		d = 'T';
	else if(d == 'C')
		d = 'G';
	else if(d == 'G')
		d = 'C';
	else if(d == 'T')
		d = 'A';
	
	putchar(d);
	
	return 0;
}

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

using namespace std;
using lint = long long;

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

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

    int m = distance(a.begin(), max_element(a.begin(), a.end()));
    int n = distance(a.begin(), min_element(a.begin(), a.end()));
    
    if (a[n] >= 0) {
        cout << N - 1 << endl;
        for (int i = 0; i < N - 1; i++) {
            cout << i + 1 << ' ' << i + 2 << endl;
            a[i + 1] += a[i];
        }
    } else if (a[m] <= 0) {
        cout << N - 1 << endl;
        for (int i = N - 1; i > 0; i--) {
            cout << i + 1 << ' ' << i << endl;
            a[i - 1] += a[i];
        }
    } else if (a[m] >= abs(a[n])) {
        cout << 2*N - 2 << endl;
        for (int i = 0; i < N; i++) {
            if (i != m) {
                cout << m + 1 << ' ' << i + 1 << endl;
                a[i] += a[m];
            }
        }
        for (int i = 0; i < N - 1; i++) {
            cout << i + 1 << ' ' << i + 2 << endl;
            a[i + 1] += a[i];
        }
    } else if (a[m] < abs(a[n])) {
        cout << 2*N - 2 << endl;
        for (int i = 0; i < N; i++) {
            if (i != n) {
                cout << n + 1 << ' ' << i + 1 << endl;
                a[i] += a[n];
            }
        }
        for (int i = N - 1; i > 0; i--) {
            cout << i + 1 << ' ' << i << endl;
            a[i - 1] += a[i];
        }
    }

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> c(n-1),s(n-1),f(n-1);
    REP(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }
    ll res;
    REP(i,n-1){
        res=s[i]+c[i];
        REAP(j,i+1,n-1){
            if(res<=s[j])res+=(s[j]-res);
            else if(res%f[j]==0);
            else res+=(f[j]-res%f[j]);
            res+=c[j];
        }
        cout << res << endl;
    }
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,K;
    int a,j;
    int sum=0;
    int number[1000];
    int i;
    scanf("%d %d",&N, &K);
    for(i=0; i<N; i++){
        scanf("%d",&number[i]);
    }
    for (i = 0; i < N; ++i)
        {

            for (j = i + 1; j < N; ++j)
            {

                if (number[i] > number[j])
                {

                    a =  number[i];
                    number[i] = number[j];
                    number[j] = a;

                }

            }

        }
    for (i = 0; i < K; ++i){
        sum =sum+number[i];
    }
    printf("%d",sum);

    }


Measured memory_bytes: 1696
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())
if d1+1 == d2:
    print("0")
else:
    print("1")
"""
if d1 == 31:
    if m1 == 1 or m1 == 3 or m1 == 5 or m1 == 7 or m1 == 8 or m1 == 10 or m1 == 12:
        print(1)
elif d1 == 30:
    if m1 == 4 or m1 == 6 or m1 == 9 or m1 == 11:
        print(1)
elif d1 == 28:
    if m1 == 2:
        print(1)
else:
    print(0)
"""

Measured memory_bytes: 38384
import numpy as np

S = input()
n = len(S)
li = []
tmp = 'R'
cnt = 1
for i in range(1,n):
    if S[i] != tmp:
        li.append(cnt)
        cnt = 1
        tmp = S[i]
    else: cnt += 1
li.append(cnt)

ans = []
for i in range(0,len(li),2):
    r_c,l_c = 0,0
    r,l = li[i],li[i+1]
    r_c += r//2
    l_c += r//2
    if r%2 == 1: r_c += 1

    r_c += l//2
    l_c += l//2
    if l%2 == 1: l_c += 1

    ans += list(np.zeros(r-1,dtype=int))+[r_c,l_c]+list(np.zeros(l-1,dtype=int))

for i in ans:
    print(i,end=' ')
print()


Measured memory_bytes: 18100
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    string str;
    cin >> str;
    int ans = 1000;
    for(int i = 0; i <= str.size()-3; i++){
        int s = (str[i] - '0')*100 + (str[i+1] - '0')*10 + (str[i+2] - '0');
        ans = min(ans, abs(753 - s));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class Point
  attr_reader :x, :y
  def initialize(x, y)
    @x, @y = [x, y].map(&:to_f)
  end
  def distance(p)
    Math::hypot(@x - p.x, @y - p.y)
  end
end

def bfs(*vertex)
  edge = Hash.new{|h, k| h[k] = Hash.new}
  vertex.each do |u|
    vertex.each do |v|
      if u == vertex.first || v == vertex.first
        edge[u][v] = true if u.distance(v) <= 10.0
      else
        edge[u][v] = true if u.distance(v) <= 50.0
      end
    end
  end

  visited = Hash.new
  q = Array.new
  q.push([vertex.first, 0])
  until q.empty?
    current, depth = q.shift
    next if visited[current]
    visited[current] = depth
    vertex.each do |v|
      q.push([v, depth + 1]) if edge[current][v]
    end
  end
  visited.values.max
end

gets.to_i.times do
  n, x, y = gets.split.map(&:to_i)
  natsume = Point.new(*gets.split)
  customer = n.times.map{Point.new(*gets.split)}
  number = bfs(natsume, *customer)
  puts (x > y && number > 1) ? "You're always welcome!" : number * x
end

Measured memory_bytes: 138640
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int MAXN = 55;

int n, p; LL C[MAXN][MAXN];

int main(){
	int i, t, cnt[2], j;
	LL ans = 0LL;
	cnt[0] = cnt[1] = 0;
	scanf("%d%d", &n, &p);
	for(i = 1; i <= n; ++ i){
		scanf("%d", &t);
		++ cnt[t & 1];
	}
	for(i = 0; i <= n; ++ i)
		for(j = C[i][0] = 1; j <= i; ++ j)
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
	for(i = p; i <= cnt[1]; i += 2)
		ans += C[cnt[1]][i];
	cout << (ans << cnt[0]) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int x = scan.nextInt();
    String A = scan.next();
    String B;
    String C;
    String ans = "No";
    int l;
    l = A.length();
    B = A.substring(0, l/2);
    C = A.substring(l/2, l);
    if (B.equals(C)) {
      ans = "Yes";
    }
    System.out.println(ans);
    scan.close();
  }
}

Measured memory_bytes: 21844
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

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

signed main()
{
    fastio;
    string s;
    cin>>s;
    int sum=0;
    for(int i=0;i<s.size();i++)
    {
        sum+=s[i]-'0';
    }
    //cout<<sum<<endl;
    if(sum%9==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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


int main() {
	// your code goes here
	ll n;
	cin>>n;
	int arr[n];
	ll brr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	//	brr[i]=0;
	}
	if(n!=0)
	{
	brr[0]=0;
	brr[1]=abs(arr[1]-arr[0]);
	for(ll i=2;i<n;i++)
	{
		brr[i]=min(brr[i-1]+abs(arr[i]-arr[i-1]),brr[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<brr[n-1];
}
else
cout<<"0";
	return 0;
}

Measured memory_bytes: 1408
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    
    long a, b;
    long ans;

    void run(){
	while(sc.hasNext()){
	    a = sc.nextInt();
	    b = sc.nextInt();
	    if(a!=0 && b!=0)
		solve();
	}
    }

    void solve(){
	if(a>b){
	    long tmp = a;
	    a = b;
	    b = tmp;
	}
	/*
	  a < b ??即???????????????
	  a*b == GCD*LCM ??則?????????
	 */
	long lcm = b;	
	while(lcm%a!=0) {
	    lcm+=b;
	    //System.out.println(a+" "+b+" "+lcm);
	}
	ans = a*b/lcm;

	System.out.println(ans);
    }
}

Measured memory_bytes: 18680
A,B,C,D=[int(x) for x in list(input())]

def p_or_m(a,b,op):
    if op==0:
        return a+b
    else:
        return a-b
      
out_list=[]

for op1 in range(2):
    out_1=p_or_m(A,B,op1)
    for op2 in range(2):
        out_2=p_or_m(out_1,C,op2)
        for op3 in range(2):
            out_3=p_or_m(out_2,D,op3)
            if out_3==7:
                out_list.append([op1,op2,op3,out_3])
                
out=out_list[0]

L=[B,C,D]
out_str=str(A)
for i in range(len(out)-1):
    if out[i]==0:
        out_str+='+'
    elif out[i]==1:
        out_str+='-'
    out_str+=str(L[i])
        
out_str+='=7'

print(out_str)

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

    int cnt=0;

    cin>>n;

    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
    {
        if(i*j==n)
            cnt++;
    }

    if(cnt!=0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> a(5);
  for(int i = 0; i < 5; i++)
    cin >> a.at(i);
  int ans = 10000000,sum = 0;
  for(int i = 0; i < 5; i++){
    for(int i = 0; i < 5; i++){
      sum += a.at(i);
      if(sum % 10 != 0 and i != 4){
        sum += 10 - sum % 10;
      }
    }
    ans = min(sum,ans);
    sum = 0;
    int x = a.at(0);
    a.erase(a.begin());
    a.push_back(x);
  }
  cout << ans;
}

Measured memory_bytes: 3556
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

n,k=map(int,input().split())
s=input()
l =[]
cnt=0

for i in range(len(s)-1):
	if s[i]==s[i+1]: 
		cnt+=1
		
d=len(s)-1-cnt
while d>1 and k>0:
	cnt+=2
	d-=2
	k-=1
if d==1 and k>0:
	cnt+=1
	d-=1
	
print(cnt)		



Measured memory_bytes: 3316