akhauriyash/Code-Regression huggingface dataset:
S = input()

n = len(S)

l = [0]*n
current_run = 'R'
R_start = 0

for i in range(n-1):
    if current_run == 'R':
        if S[i+1] == 'L':
            R_len = i+1 - R_start
            current_run = 'L'
            L_start = i+1
            if i == n-2:
                placeR = L_start - 1
                placeL = L_start
                L_len = 1
                D_len = (R_len + L_len) // 2
                l[placeR] = D_len
                l[placeL] = D_len
                if (R_len + L_len) % 2 == 0:
                    continue
                if R_len > D_len:
                    if R_len % 2 == 0:
                        l[placeL] += 1
                    else:
                        l[placeR] += 1

    else:
        if S[i+1] == 'R' or i == n-2:
            L_len = i+1 - L_start
            if i == n-2: L_len += 1
            current_run = 'R'
            R_start = i+1
            placeR = L_start - 1
            placeL = L_start
            D_len = (R_len + L_len) // 2
            l[placeR] = D_len
            l[placeL] = D_len
            if (R_len + L_len) % 2 == 0:
                continue
            if R_len > D_len:
                if R_len % 2 == 0:
                    l[placeL] += 1
                else:
                    l[placeR] += 1
            elif L_len > D_len:
                if L_len % 2 == 0:
                    l[placeR] += 1
                else:
                    l[placeL] += 1

print(" ".join([str(_) for _ in l]))

Measured memory_bytes: 83480
def main():
    N,M = map(int, input().split())
    l=-100000
    r=1000000
    for i in range(M):
        L,R =map(int,input().split())
        if l<L:
            l=L
        if R<r:
            r=R
    a = r-l+1
    if a<0:
        a=0
    print(a)
main()

Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int n,i,semi[300];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&semi[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,semi[i]);
    if(i!=1){
      printf("parent key = %d, ",semi[i/2]);
    }
    if(2*i<=n){
      printf("left key = %d, ",semi[2*i]);
    }
    if(2*i+1<=n){
      printf("right key = %d, ",semi[2*i+1]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2056
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int limit = 100005;
using edge = struct {int to; long long cost;};

int n;
vector<edge> tree[limit];
vector<long long> dist;

void dfs(int v, long long d = 0, int p = -1){
    dist[v] = d;
    for(auto &e : tree[v]) {
        if(e.to == p) continue;
        dfs(e.to, d + e.cost, v);
    }
}

vector<long long> calcDist(int s){
    dist = vector<long long>(n);
    dfs(s);
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
	int u, v;
	cin >> u >> v;
	--u; --v;
    for(int i = 0; i < n-1; i++){
        int a, b, c;
        cin >> a >> b;
        a--, b--;
        c = 1;
        tree[a].push_back({b, c});
        tree[b].push_back({a, c});
    }
	vector<ll> distT = calcDist(u);
	vector<ll> distA = calcDist(v);
	ll ans = 0;
	rep(i,n){
		if(distA[i] >= distT[i]){
			chmax(ans, distA[i] - 1);
		}
	}
	chmax(ans, 0LL);
	cout << ans << endl;
    return 0;
}


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

using namespace std;

int main() {
    // Literally fibo except broken stairs you just set to 0
    int N, M;
    cin >> N >> M;
    
    int current_broken = 0;
    long long int dp[N];
    int broken[M];
    for (int i = 0; i < M; i++)
    {
        cin >> broken[i];
    }

    dp[0] = 1;
    dp[1] = 2;
    
    for (int i = 0; i < 2; i++)
    {
        if (broken[i] - 1 == 0)
        {
            dp[0] = 0;
            dp[1] = 1;
            current_broken++;
        } else if (broken[i] - 1 == 1)
        {
            dp[1] = 0;
            current_broken++;
        }
    }

    for(int i = 2; i < N; i++)
    {
        if (i == broken[current_broken] - 1)
        {
            dp[i] = 0;
            current_broken++;
        } else {
            dp[i] = (((dp[i - 2] % 1000000007) + (dp[i - 1] % 1000000007)) % 1000000007);
        }
    }

    cout << (long long int)(dp[N - 1] % 1000000007);
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define M_PI_2 1.57079632679489661923
#define ll long long int
#define endl '\n'
using namespace std;

void solve()
{
  int k;
  string s;
  cin>>k;
  cin>>s;
  if(s.size()<=k)
    cout<<s<<endl;
  else
    cout<<s.substr(0,k)<<"..."<<endl;

}    

int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

int main(){
    int h, w; cin >> h >> w;

    vector <string> a;
    for (int i = 0; i < h; i ++){
        string _a; cin >> _a;
        a.push_back(_a);
    }

    int right_index = 0;
    string ans = "Possible";
    for (int i = 0; i < h; i ++){
        int now_right = 0;
        bool check = false;
        bool check2 = false;
        bool break_flag = false;
        for (int j = 0; j < w; j ++){
            if (!check && a[i][j] == '#'){
                check = true;
                if (right_index > j) {ans = "Impossible"; break_flag = true; break;}
            }

            if(check && a[i][j] != '#') check2 = true;
            if(check2 && a[i][j] == '#') {ans = "Impossible"; break_flag = true; break;}

            if (a[i][j] == '#') now_right = j;
        }
        right_index = now_right;
        if (break_flag) break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
int h,w,i,j,b,c,max=0,min=100000000;
int a[50][50];
scanf("%d %d\n",&h,&w);
for(i=0;i<h;i++){
for(j=0;j<w;j++){
scanf("%d",&a[i][j]);
}
scanf("\n");
}
for(c=0;c<h;c++){
for(b=0;b<w;b++){
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(i<c && j<b && c-i>b-j){
max=max+(b-j)*a[i][j];
}
else if(i<c && j<b && c-i<=b-j){
max=max+(c-i)*a[i][j];
}
else if(i<c && j>b && c-i>j-b){
max=max+(j-b)*a[i][j];
}
else if(i<c && j>b && c-i<=j-b){
max=max+(c-i)*a[i][j];
}
else if(i>c && j<b && i-c>b-j){
max=max+(b-j)*a[i][j];
}
else if(i>c && j>b && i-c>j-b){
max=max+(j-b)*a[i][j];
}
else if(i>c && j<b && i-c<=b-j){
max=max+(i-c)*a[i][j];
}
else if(i>c && j>b && i-c<=j-b){
max=max+(i-c)*a[i][j];
}
}
}
if(min>max){
min=max;
}
max=0;
}
}
printf("%d\n",min);
return 0;
}


Measured memory_bytes: 1992
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

    int num;
    cin >> num;

    cout << 1000 * (num / 500) + (num % 500) / 5 * 5 << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using CompLib.Util;

public class Program
{
    int N;
    long[] A;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.LongArray();

        // A[i]が大きいやつはたくさん移動させたい

        // iまで見る、左埋まってる数-右+N
        var dp = new long[N + 1, 2 * N + 1];
        for (int i = 0; i <= N; i++)
        {
            for (int j = 0; j <= 2 * N; j++)
            {
                dp[i, j] = long.MinValue;
            }
        }

        dp[0, N] = 0;
        var sortedByA = new int[N];
        for (int i = 0; i < N; i++)
        {
            sortedByA[i] = i;
        }

        Array.Sort(sortedByA, (l, r) => A[r].CompareTo(A[l]));


        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j <= 2 * N; j++)
            {
                if (dp[i, j] == long.MinValue) continue;
                int d = j - N;
                long l = (i + d) / 2;
                long r = i - l;

                // 左に移動
                dp[i + 1, j + 1] = Math.Max(dp[i + 1, j + 1], dp[i, j] + A[sortedByA[i]] * (sortedByA[i] - l));
                // 右に移動
                dp[i + 1, j - 1] = Math.Max(dp[i + 1, j - 1], dp[i, j] + A[sortedByA[i]] * (N - 1 - r - sortedByA[i]));
            }
        }

        long ans = long.MinValue;
        for (int i = 0; i <= 2 * N; i++)
        {
            ans = Math.Max(ans, dp[N, i]);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 91084
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    S.sort()
    SS = set(S)
    if len(SS)==2 and S[0]==S[1] and S[2]==S[3]:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> dP;

const int INF = 100000000;
const double EPS = 1e-10;

int s, n, t, p, m;
string str_weekday, str_time;

string wd[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
string tm[] = {"Day", "Night"};

int check(int starttime){
	int cnt = 0;
	int totaltime;
	totaltime = starttime;

	for(int i = 0; i < m; i++){
		int bweekday, btime;
		bweekday = totaltime/(60*24)%7; // 0-> Sun ... 6-> Sat
		btime = totaltime%(60*24);	// 0-359 || 1080-2359 -> Night 360-1079 -> Day 
		btime = !(btime >= 360 && btime < 1080);

		totaltime+=s;

		int eweekday, etime;
		eweekday = totaltime/(60*24)%7; // 0-> Sun ... 6-> Sat
		etime = totaltime%(60*24);	// 0-359 || 1080-2359 -> Night 360-1079 -> Day 
		etime = !(etime >= 360 && etime < 1080);

		bool dok = false, tok =false;
		if(str_weekday == "All" || (str_weekday == wd[bweekday] && bweekday == eweekday)) dok = true;
		if(  str_time == "All"	 || ( str_time	  == tm[btime]	  &&    btime == etime))	tok = true;

		if(dok && tok) cnt++;

		totaltime += t-s;

		//cout << "From:" << wd[btime] << ' ' << tm[btime];
		//cout << "  To:" << wd[etime] << ' ' << tm[etime];
		//cout << endl;
	}

	return cnt;
}

int main(){

	while(1){
		cin >> s >> n >> t >> str_weekday >> str_time >> p >> m;
		if(!s)break;
		int best = 0;
		rep(i, 60*24*7){
			//cout << check(i) << endl;
			best = max(best, check(i));
		}
		double dp = 1.0/p;
		double ps = 1;
		rep(i, best*n){
			ps*=(1-dp);
		}
		ps = 1-ps;
		
		printf("%.9lf\n", ps);
	}

	return 0;
}

Measured memory_bytes: 1272
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for i in range(N):
    A = list(map(int,input().split()))
    X = []
    for j in range(M):
        X.append(A[j]*B[j])
    if sum(X) + C > 0:
        ans += 1

print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h> 
using namespace std;
int main()
{
    int ans=0,i;
  string str;
    cin>>str;
    for(i=0;i<str.size();i++)
    {
      ans+=str[i]-'0';
    }
  if(ans%9==0)
    cout<<"Yes";
  else
  cout<<"No";
    return 0;
}

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

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

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

const int MAXN = 505;

int n;
int t[MAXN];

bool cmp(const int &a, const int &b) {
  return t[a] < t[b];
}

int sol[MAXN * MAXN];

vector<int> avaliable;
vector<int> event[MAXN * MAXN];

int uk[MAXN];

bool check() {
  REP(i, n * n) {
    uk[sol[i]] ++;
    if(t[sol[i]] == i && uk[sol[i]] != sol[i]) {
      cout << "No";
      exit(0);
    }
  }
}

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

  cin >> n;

  vector<int> v;

  FOR(i, 1, n + 1) {
    int x; cin >> x;

    t[i] = x - 1;
    REP(j, i - 1) {
      v.push_back(i);
    }

    event[x].push_back(i);
    sol[x - 1] = i;
  }

  sort(v.begin(), v.end(), cmp);

  for(int i = 0, j = 0; i < v.size(); ++i) {
    while(sol[j]) {
      j ++;
    }
    sol[j] = v[i];
  }

  REP(i, n * n) {
    for(auto x: event[i]) {
      REP(j, n - x) {
        avaliable.push_back(x);
      }
    }

    if(!sol[i]) {
      if(avaliable.empty()) {
        cout << "No";
        return 0;
      }
      sol[i] = avaliable.back();
      avaliable.pop_back();
    }
  }

  check();

  cout << "Yes\n";
  REP(i, n * n) {
    cout << sol[i] << " ";
  }
}


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

//関数
class union_find{
    vector<long> parent, tree_size;
    public:
    union_find(long n) : parent(n), tree_size(n,1){
        for(int i=0;i<n;i++) parent.at(i)=i;
    }
    long find(long x){
        while(parent.at(x)!=x) x=parent.at(x)=parent.at(parent.at(x));
        return x;
    }
    bool marge(long a,long b){
        a=find(a);
        b=find(b);
        if(a==b) return false;
        if(tree_size.at(a)<tree_size.at(b)) swap(a,b);
        tree_size.at(a)+=tree_size.at(b);
        parent.at(b)=a;
        return true;
    }
};


int main() {
    //入力
    long N,M;
    cin>>N>>M;
    vector<long> X(M),Y(M),Z(M);
    for(int i=0;i<M;i++){
        cin>>X.at(i)>>Y.at(i)>>Z.at(i);
    }
    //計算
    union_find uf(N);
    long ans=N;
    for(int i=0;i<M;i++){
        ans-=uf.marge(X.at(i)-1,Y.at(i)-1);
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 4224
#include <iostream>
#define INF 1e+9
using namespace std;

int main(){
	int h,w,cnt[3][50] = {};
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			char c;
			cin >> c;
			if(c == 'W') cnt[0][i]++;
			else if(c == 'B') cnt[1][i]++;
			else cnt[2][i]++;
		}
	}
	int mi = INF;
	for(int i = 0;i < h;i++){
		for(int j = i + 1;j < h - 1;j++){
			int sum = 0;
			for(int k = 0;k <= i;k++) sum += cnt[1][k] + cnt[2][k];
			for(int k = i + 1;k <= j;k++) sum += cnt[0][k] + cnt[2][k];
			for(int k = j + 1;k < h;k++) sum += cnt[0][k] + cnt[1][k];
			mi = min(mi,sum);
		}
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 3080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

	public static void main(String... args) throws IOException {

		// 標準入力を取得
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		int n = Integer.parseInt(line.split(" ")[0]);
		line = br.readLine();
		String[] strs = line.split(" ");
		int[] as = new int[strs.length];
		long aSum = 0;
		for (int i = 0; i < as.length; i++) {
			as[i] = Integer.parseInt(strs[i]);
			aSum += as[i];
		}
		line = br.readLine();
		strs = line.split(" ");
		int[] bs = new int[strs.length];
		long bSum = 0;
		for (int i = 0; i < as.length; i++) {
			bs[i] = Integer.parseInt(strs[i]);
			bSum += bs[i];
		}

		// どうしようもない
		if (bSum > aSum) {
			System.out.println("-1");
			return;
		}

		// 変更不要
		for (int i = 0; i < as.length; i++) {
			if (as[i] < bs[i]) {
				break;
			}
			if (i == as.length - 1) {
				System.out.println("0");
				return;
			}
		}

		// A と Bの差分
		long diff = aSum - bSum;
		int count = 0;

		for (int i = 0; i < as.length; i++) {

			// 同じやつは何もしない
			if (as[i] == bs[i]) {
				count++;
			}
		}

		List<Integer> diffs = new ArrayList<Integer>();
		for (int i = 0; i < as.length; i++) {

			// Bがおおきいやつは仕方ない
			if (as[i] < bs[i]) {
				continue;
			}

			// 同じやつは何もしない
			if (as[i] == bs[i]) {
				continue;
			}

			diffs.add(as[i] - bs[i]);
		}

		Collections.sort(diffs);

		for (int d : diffs) {
			if (diff > d) {
				diff -= d;
				count++;
			}else {
				break;
			}
		}

//		while (true) {
//			int minDiff = 0;
//			int index = -1;
//			for (int i = 0; i < as.length; i++) {
//
//				// Bがおおきいやつは仕方ない
//				if (as[i] < bs[i]) {
//					continue;
//				}
//
//				// 同じやつは何もしない
//				if (as[i] == bs[i]) {
//					continue;
//				}
//
//				int d = as[i] - bs[i];
//				if (minDiff == 0 || minDiff > d) {
//					minDiff = d;
//					index = i;
//				}
//			}
//
//			if (index == -1) {
//				break;
//			} else if (minDiff > diff) {
//				break;
//			} else {
//				diff -= minDiff;
//				bs[index] = as[index];
//				count++;
//			}
//		}

		System.out.println(n - count);

	}
}


Measured memory_bytes: 49676
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  std::vector<int> A(3);
  int even = 0;
  int odd = 0;
  for (auto& ai: A) {
    scanf("%d", &ai);
    ++((ai % 2 > 0)? odd:even);
  }

  int res = 0;
  if (even == 2) {
    for (auto& ai: A)
      if (ai % 2 == 0) ++ai;
    ++res;
  } else if (odd == 2) {
    for (auto& ai: A)
      if (ai % 2 == 1) ++ai;
    ++res;
  }

  std::sort(A.begin(), A.end());
  res += (A[2]-A[1]) / 2;
  res += (A[2]-A[0]) / 2;
  printf("%d\n", res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <list>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 100000007;
using Graph = vector<vector<int>>;


int main(){
    string S;
    cin >> S;
    string Sp;
    Sp = S;
    reverse(Sp.begin(),Sp.end());
    S.reserve(300100);
    Sp.reserve(300100);
    bool reversed = false;
    int Q;
    cin >> Q;
    REP(i,Q){
        int t;
        cin >> t;
        if(t==2){
            int f;
            cin >> f;
            char c;
            cin >> c;
            if(f==1){
                if(reversed){
                    S.push_back(c);
                    Sp.insert(Sp.begin(),c);
                }
                else{
                    Sp.push_back(c);
                    S.insert(S.begin(),c);
                }
            }
            else{
                if(!reversed){
                    S.push_back(c);
                    Sp.insert(Sp.begin(),c);
                }
                else{
                    Sp.push_back(c);
                    S.insert(S.begin(),c);
                }
            }
        }
        else{
            if(reversed) reversed = false;
            else reversed = true;
        }
    }
    if(reversed) cout << Sp << endl;
    else cout << S << endl;
}

Measured memory_bytes: 3936
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

float averageTemperature(int t, int height)
{
    return ((float)t - height * 0.006f);
}

int main()
{
    int n,t,a;
    cin >> n >> t >> a;

    int height[n];
    float min = 999999.0f;
    int ansNum = 0;
    for (int i = 0; i < n; i++)
    {
       cin >> height[i];

        float temp = fabs(averageTemperature(t, height[i]) - a);
        if (min > temp)
        {
            min = temp;
            ansNum = i + 1;
        }
    }

    cout << ansNum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int a[105][105],b[105][105],G[205],to[20405],cap[20405],nxt[20405],sz=-1,d[205],cur[205],id[105][105],n,tmp[105];
bool used[105][105];
queue<int> Q;
inline void adde(int u,int v,int c){
	to[++sz]=v;cap[sz]=c;nxt[sz]=G[u];G[u]=sz;
	to[++sz]=u;cap[sz]=0;nxt[sz]=G[v];G[v]=sz;
}
inline bool bfs(){
	int i,u,v;
	memset(d,0x3f,sizeof(d));
	d[0]=0;Q.push(0);
	while(!Q.empty()){
		u=Q.front();Q.pop();
		for(i=G[u];i!=-1;i=nxt[i])if(cap[i]&&d[v=to[i]]==0x3f3f3f3f){
			d[v]=d[u]+1;
			Q.push(v);
		}
	}
	return d[n<<1|1]!=0x3f3f3f3f;
}
int dfs(int u,int a){
	if(u==(n<<1|1)||!a)return a;
	int v,flow=0,f;
	for(int &i=cur[u];i!=-1;i=nxt[i])if(d[v=to[i]]==d[u]+1&&(f=dfs(v,min(a,cap[i])))){
		flow+=f;
		cap[i]-=f;cap[i^1]+=f;
		if(!(a-=f))break;
	}
	return flow;
}
inline void dinic(){
	while(bfs()){
		memcpy(cur,G,sizeof(cur));
		dfs(0,0x3f3f3f3f);
	}
}
int main(){
	int m,i,j,k;
	scanf("%d%d",&n,&m);
	memset(G,-1,sizeof(G));
	for(i=1;i<=n;++i){adde(0,i,0);adde(i+n,n<<1|1,0);}
	for(i=1;i<=n;++i)
		for(j=1;j<=m;++j){
			scanf("%d",&a[i][j]);
			id[i][j]=sz+1;
			adde(i,(a[i][j]+m-1)/m+n,1);
		}
	for(i=1;i<=m;++i){
		for(j=0;j<(n<<2);j+=4){++cap[j];++cap[j+2];}
		dinic();
		for(j=1;j<=n;++j)
			for(k=1;k<=m;++k)if(!used[j][k]&&!cap[id[j][k]]){
				b[j][i]=a[j][k];
				used[j][k]=1;
				cap[id[j][k]^1]=0;
			}
	}
	for(i=1;i<=n;++i){
		for(j=1;j<=m;++j)printf("%d ",b[i][j]);
		putchar('\n');
	}
	for(j=1;j<=m;++j){
		for(i=1;i<=n;++i)tmp[i]=b[i][j];
		sort(tmp+1,tmp+n+1);
		for(i=1;i<=n;++i)b[i][j]=tmp[i];
	}
	for(i=1;i<=n;++i){
		for(j=1;j<=m;++j)printf("%d ",b[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 768
n, k = map(int, input().split())
ns = list(map(int, input().split()))
c = [None] * n
for i in range(min(k,n)):
    c[i] = abs(ns[0]-ns[i])
if k < n:
    for i in range(k, n):
        c[i] = min([c[i - (k - j)] + abs(ns[i] - ns[i - (k - j)]) for j in range(k)])
print(c[-1])


Measured memory_bytes: 53600
N, K=gets.split.map(&:to_i)

points = $<.map{|l|l.split.map(&:to_i)}

area = Float::INFINITY

#ext = [4, N].min
ext = [4, K].min

points.combination(ext) {|point|
  xs = point.map{|p|p[0]}
  ys = point.map{|p|p[1]}
  maxx = xs.max
  minx = xs.min
  maxy = ys.max
  miny = ys.min
  count=points.select{|x,y| minx<=x && x<=maxx && miny<=y && y<=maxy}.size
  if count>=K
    temp = (maxx - minx) * (maxy - miny)
    area = temp if area > temp
  end
}

p area

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define vp vector <pi>
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1n(x,n) for(int x = 1; x <= n ;++ x)
#define forn1(x,n) for(int x = 1; x < n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#pragma GCC optimize ("Ofast")
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	ll n;
	cin>>n;

	ll minmove = 1e18;
	for(ll i = 1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			minmove = min(minmove, (n/i)+i);
		}
	}
	cout<<minmove-2;

 
	return 0;	
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[] args) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		int n = s.nextInt();
		int sum =0;
		if(n>=10) {
			sum+=9;
			if(n>=1000) {
				sum+=900;
				if(n>=100000) {
					sum+=90000;
				}
				else {
					if(n>=10000) {
						sum+=n-10000+1;
					}
				}
			}else {
				if(n>=100) {
					sum+=n-100+1;
				}
			}
		}else {
			sum=n;
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23508
def inpl(): return list(map(int, input().split()))
x, y = inpl()
ans = 1e10
if x == y:
    ans = 0
elif abs(x) == abs(y):
    ans = 1
elif x == 0:
    if y > 0:
        ans = y - x
    else:
        ans = x - y + 1
elif x * y > 0:
    if x < y:
        ans = y - x
    else:
        ans = abs(y-x) + 2 - (y == 0)
else:
    if x < y:
        ans = abs(abs(y) - abs(x)) + 1 - (y == 0)
    else:
        ans = abs(abs(y) - abs(x)) + 1

print(ans)

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;

static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var k = nk[1];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        bool[] dp = new bool[k + 1];
        for (int i = 0; i < dp.Length; i++) dp[i] = a.Any(x => 0 <= (i - x) && !dp[i - x]);
        Console.WriteLine(dp[k] ? "First" : "Second");
    }
}


Measured memory_bytes: 17500
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;

int main() {
  int n, m; cin >> n >> m;
  vector<int> x(m, 0);
  for(int i=0; i<n; i++) {
    int k; cin >> k;
    vector<int> a(k);
    for(int j=0; j<k; j++){
      cin >> a[j];
      x[a[j]-1]++;
    }
  }
  int cnt = 0;
  for(int i=0; i<m; i++){
    if(x[i] == n) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


//


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

int main(){

int a,b,c,d,s,e,f;
cin >>a>>b>>c>>d;

s=max(a, c);
e=min(b, d);

 f=e-s;
    if(f>=0)
    {
        cout<<f<<endl;
    }
    else
    {
        cout<<0<<endl;
    }

}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#include<tuple>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<tuple<string,int,int>> a;
  for (int i=1; i<=N; i++) {
    string S;
    int P;
    cin >> S >> P;
    P=-P;
    a.push_back(tie(S,P,i));
  }
  sort(a.begin(),a.end());
  for (int i=0; i<N; i++) {
    cout << get<2>(a[i]) << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    long a = scanner.nextLong();
    long b = scanner.nextLong();
    long x = scanner.nextLong();
    b = b / x;
    a = a > 0 ? (a - 1) / x : -1;
    System.out.println(b - a);
  }
}


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

namespace CompetitiveProgramming
{
  class Solve
  {

    const double eps = 1e-15;

    public Solve()
    {
      bool[] red = new bool[100001];
      int[] num = new int[100001];

      string[] input = Console.ReadLine().Split(' ');

      int N = int.Parse(input[0]);
      int M = int.Parse(input[1]);

      red[0] = true;
      for (int i = 0; i < N; i++)
      {
        num[i] = 1;
      }

      for (int i = 0; i < M; i++)
      {
        input = Console.ReadLine().Split(' ');
        int x = int.Parse(input[0]) - 1;
        int y = int.Parse(input[1]) - 1;
        if (red[x]) 
        {
          red[y] = true;
        }
        num[x]--;
        num[y]++;
        if (num[x] == 0) 
        {
          red[x] = false;
        }
      }
      int Count = 0;
      for (int i = 0; i < N; i++)
      {
        if (red[i])
        {
          Count++;
        }
      }
      Console.WriteLine(Count);
    }
  }

  class Program
  {
    static void Main(string[] args)
    {
      new Solve();
    }
  }
}

Measured memory_bytes: 7256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int dp[100010];

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n+10);
    for(int i = 0; i < n; i++) cin >> h[i];

    for(int i = 0; i < 100010; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
d=["a"]*n
ans=""
if n==1 and m==0:
    print(0)
    exit()
for i in range(m):
    s,c=map(str,input().split())
    if s=="1" and c=="0" and n==1:
        print(0)
        exit()
    s=int(s)
    if d[s-1]=="a" or d[s-1]==c:
        d[s-1]=c #置き換え
    else:
        ans="-1"
        print(ans)
        break
if d[0]!="0" and ans!="-1":
    if d[0]=="a" or d[0]=="0":
        print("".join(["1"]+d[1:]).replace("a","0"))
    else:
        print(("".join(d)).replace("a","0"))
elif d[0]=="0":
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
// }}} End Header


int main() {
	int n, cnt = 0;
	cin >> n;
	rep(i,n){
		int a, b;
		cin >> a >> b;
		if(a == b){
			cnt++;
			if(cnt >= 3){
				cout << "Yes" << endl;
				return 0;
			}
		}else{
			cnt = 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
void chmax(int & a, int b) { if (a < b) a = b; }

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

	int res = 0, tmp = 0, pre = 0, h;
	for (int i = 0; i < n; i++) {
		scanf("%d", &h);
		if (pre >= h) tmp++;
		else tmp = 0;

		res = max(res, tmp);
		pre = h;
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void sort(int data1[], int data2[], int, int);
void change(int data1[], int data2[], int, int);

main(){
  int n, m;
  int data1[201], data2[201];
  int l[201];
  int p[201];
  int max, i, temp, j, c, k,a;

  while(1){
    data1[0]=data2[0]=-1;
    l[0]=0;
    p[0]=-1;
    scanf("%d", &n);
    if(n==0) break;

    for(i=1;i<=n;i++){
      scanf("%d %d", &data1[i], &data2[i]);
    }
    
    scanf("%d", &m);

    for(i=n+1;i<=n+m;i++){
      scanf("%d %d", &data1[i], &data2[i]);
    }

    sort(data1, data2, 0, n+m);
    /*for(i=0;i<n+m;i++){
      printf("%d %d\n", data1[i], data2[i]);
      }*/
    
    for(i=1;i<=n+m;i++){
      max=-1;
      temp=-1;
      for(j=0;j<i;j++){
	if(data1[i]>data1[j] && data2[i]>data2[j]){
	  if(l[j]>max){
	    max=l[j];
	    temp=j;
	  }
	}
      }
      p[i]=temp;
      l[i]=l[temp]+1;
    }


    max=-2;
    for(i=0;i<=n+m;i++){
      if(l[i]>max) max=l[i];
    }
    
    printf("%d\n", max);
  }
  return 0;
}

void sort(int data1[], int data2[], int h, int t){
  int i, j;
  int temp;
  int p;

  temp=(h+t)/2;
  p=data1[temp];
  i=h;
  j=t;

  while(1){
    while(data1[i]<p) i++;
    while(p<data1[j]) j--;
    if(i>=j) break;
    change(data1,data2,i,j);
    i++;
    j--;
  }
  if(h<i-1) sort(data1,data2,h,i-1);
  if(j+1<t) sort(data1,data2,j+1,t);
}

void change(int data1[], int data2[], int i, int j){
  int temp;

  temp=data1[i];
  data1[i]=data1[j];
  data1[j]=temp;

  temp=data2[i];
  data2[i]=data2[j];
  data2[j]=temp;
}

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

using namespace std;

int main(){

  string S, T;
  int cnt;
  cin >> S >> T;

  for(int i=0; i<3; ++i){
    if(S[i] == T[i])
      ++cnt;
  }

  cout<< cnt <<endl;
  return 0;
}


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

const int mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) {
			x -= mod;
		}
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

int main() {
	int N, K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(A.begin(), A.end());

	// nCk[i] = (K+i)C(i), 0<=i<=N-K
	vector<mint> nCk(N - K + 1);
	nCk[0] = 1;
	for (int i = 1; i < N - K + 1; i++) {
		mint a = nCk[i - 1];
		a *= K + i - 1;
		a /= i;
		nCk[i] = a;
	}

	mint max_sum = 0;
	for (int i = 0; i <= N - K; i++) {
		mint a = A[K - 1 + i];
		a *= nCk[i];
		max_sum += a;
	}

	mint min_sum = 0;
	for (int i = 0; i <= N - K; i++) {
		mint a = A[N - K - i];
		a *= nCk[i];
		min_sum += a;
	}

	max_sum -= min_sum;
	cout << max_sum.x << endl;

}

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

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

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

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

  vector<vector<int>> G(n);
  rep(i,m) {
    int u,v;
    cin >> u >> v;
    u--, v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    int maxv = a[i];
    bool flag = true;
    for (auto to : G[i]) {
      if(a[to] >= maxv) flag = false;
    }
    if(flag) ans++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 9800
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h;
        h = S / 3600;
        int m;
        m = (S % 3600)/60;
        int s;
        s = (S % 3600)%60;
        
        System.out.println(h + ":" + m + ":" + s);
    }
}



Measured memory_bytes: 26272
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

x = INT()
up = x//100
down = x%100

count5 = down//5
if down %5 == 0:
    count5 -= 1
if count5+1 <= up:
    print(1)
else:
    print(0)

Measured memory_bytes: 65900
#include <iostream>
#include <vector>
#include <set>
#include <queue>

using namespace std;

#define INF (1000000000)

typedef pair<int,int> P;

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

    vector<int> C;
    vector<int> R;
    for(int i=0; i<N; ++i) {
        int a,b;
        cin >> a >> b;
        C.push_back(a);
        R.push_back(b);
    }

    vector<int> PA[N];
    for(int i=0; i<K; ++i) {
        int a,b;
        cin >> a >> b;
        PA[a-1].push_back(b-1);
        PA[b-1].push_back(a-1);
    }

    priority_queue<P,vector<P>,greater<P> > q;
    set<int> check;
    vector<int> cst(N,INF);

    q.push(P(0,0));
    while(!q.empty()) {
        P p=q.top(); q.pop();
        if(check.count(p.second)!=0) continue;
        cst[p.second]=p.first;
        check.insert(p.second);
        if(p.second==N-1) break;

        queue<P> qtemp;
        set<int> stemp;
        qtemp.push(P(p.second,R[p.second]));
        while(!qtemp.empty()) {
            P ptemp=qtemp.front(); qtemp.pop();
            for(auto x : PA[ptemp.first]) {
                if(stemp.count(x)!=0) continue;
                stemp.insert(x);
                if(ptemp.second>1) qtemp.push(P(x,ptemp.second-1));
            }
        }
        for(auto x : stemp) {
            if(check.count(x)!=0 || cst[x]<p.first+C[p.second]) continue;
            cst[x]=p.first+C[p.second];
            q.push(P(p.first+C[p.second],x));
        }
    }

    cout << cst[N-1] << endl;

    return 0;
}


Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[100005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",a+i);
        if(a[i]%2){puts("first");return 0;}
    }
    puts("second");
    return 0;
}


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

using namespace std;

int main(){
	long long a,b,c,k;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
	unsigned long long ans=abs(a-b);
	if(ans>1e18) printf("Unfair");
	else printf("%lld",k&1 ? b-a:a-b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
typedef long long ll;
ll N, Y, arr[3];


void solve() {
  ll x, y;
  for(x = 0; x <= N; x++) {
    for(y = 0; y <= N - x; y++) {
      if(10000*x + 5000*y + 1000*(N-x-y) == Y) {
        arr[0] = x, arr[1] = y, arr[2] = N - x - y;
        return;
      }
    }
  }
}

int main() {
  cin >> N >> Y;
  memset(arr, -1, sizeof(arr));
  solve();
  cout << arr[0] << ' ' << arr[1] << ' ' << arr[2] << endl;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
char s[55],s1[55];
int main()
{
    scanf("%s",s+1);
    scanf("%s",s1+1);
    int len = strlen(s+1);
    int len1 = strlen(s1+1);
    if(len > len1){ 
        for(int i = 1; i <= len1; i++)
            printf("%c%c",s[i],s1[i]);
        for(int i = len1+1; i <= len; i++)
            printf("%c",s[i]);
        printf("\n");
    }
    else if(len == len1)
    {
        for(int i = 1; i <= len; i++)
            printf("%c%c",s[i],s1[i]);
        printf("\n");
    }
    else {
        for(int i = 1; i <= len; i++)
            printf("%c%c",s[i],s1[i]);
        for(int i = len + 1; i <= len1; i++)
            printf("%c",s1[i]);
        printf("\n");
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);

  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  ll sum=0;
  for(int i=62;i>=0;i--){
    ll x=0;
    for(int j=0;j<N;j++){
      x+=(A[j]>> i &1);
    }
    if(N>2*x && (sum|(1LL<<i))<=K){
      sum|=1LL<<i;
    }
  }
  ll ans=0;
  for(int i=0;i<N;i++){
    ans+=sum^A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key=lambda i:i[2], reverse=True)
x0, y0, h0 = xyh[0]

for i in range(101):
    for j in range(101):
        H = h0 + abs(i - x0) + abs(j - y0)
        for x, y, h in xyh:
            if h > 0:
                if H != h + abs(i - x) + abs(j - y):
                    break
            else:
                if H - abs(i - x) - abs(j - y) > 0:
                    break
        else:
            print(i, j, H)
            exit()

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

#define N_MAX 100000

void solv()
{
	int d[3];
	scanf("%d%d%d", d, d + 1, d + 2);
	sort(d, d + 3);
	printf("%d", d[0] + d[1]);
	
	return;
}

int main()
{
	FILE *fin = NULL, *fout = NULL;
	//fin = freopen("input.txt", "r", stdin);
	//fout = freopen("output.txt", "w", stdout);

	solv();

	//finalize
	if (NULL != fin) fclose(fin);
	if (NULL != fout) fclose(fout);

	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	r, _ := strconv.Atoi(nextLine())
	return r
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextInt(), nextInt()

	if a > 8 || b > 8 {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int               long long
#define endl              "\n"
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define ff                first
#define ss                second
#define pii               pair<int,int>
#define vi                vector<int>
#define vpi               vector<pair<int,int>>
#define mii               map<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define repe(i,a,b)        for(int i=a;i<=b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define INF 100000000000
#define mod 1000000007
#define esp 10e-7
const int mx=100005;

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    //freopen("error.txt" , "w" , stderr);
    #endif
    IOS
     int x;
     cin>>x;
     cout<<(x^1)<<endl;
    


return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define pb push_back
#define long long long
#define pll pair < long , long >
#define vll vector < pll >
#define ml map < long , long >
#define mll map < pll , long >
#define x first
#define y second
#define vl vector < long >
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main()
{
    io
    long n,i,v[100005]={0},c=0,cur=0,ans=0;
    string s,b;
    cin>>s;
    n=s.length();
    for(i=0;i<n;++i)
    if(s[i]!='x')
    b.push_back(s[i]);
    for(i=0;i<b.length();++i)
    if(b[i]!=b[b.length()-1-i]) {cout<<-1;return 0;}
    for(i=0;i<n;++i)
    if(s[i]!='x')
    {
        v[c]=cur;
        ++c;
        cur=0;
    }
    else cur++;
    v[c]=cur;
    for(i=0;i<=b.length()/2;++i)
    ans+=abs(v[i]-v[b.length()-i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1360
//void _(){
//    int n,k,l;
//    cin >> n >> k >> l;
//    DSU d1(n),d2(n);
//    vpii e1(k),e2(l);
//    cin >> e1 >> e2;
//    for(auto _ : e1) d1.unite(_.X,_.Y);
//    for(auto _ : e2) d2.unite(_.X,_.Y);
//    map<pii,int> cnt;
//    vpii names;
//    rep(i,1,n)
//        names.pb(mp(d1.getpar(i),d2.getpar(i)));
//    for(auto x : names)
//        ++cnt[x];
//    vi ans;
//    for(auto x : names)
//        ans.pb(cnt[x]);
//    print(ans);
//}
#include <map>
#include <numeric>
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define pb push_back
#define mp make_pair
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define X first
#define Y second
#define T1 template<typename T> static
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template <typename F, typename S> static
istream& operator>>(istream& stream, pair<F, S>& t){
    return stream >> t.first >> t.second;
}
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
struct DSU{
    vi par;
    int n;
    DSU(int _n):n(_n){
        par.resize(n + 1);
        iota(all(par), 0);
    }
    int getpar(int u){
        if(par[par[u]] == par[u])
            return par[u];
        return par[u] = getpar(par[u]);
    }
    bool unite(int u, int v){
        u = getpar(u);
        v = getpar(v);
        if(u == v)
            return false;
        par[u] = v;
        return true;
    }
};
T1 ostream& print(T b, T e, string sep = " ", ostream& stream = cout){
    for(T it = b; it != e; ++it){
        stream << *it;
        if(it + 1 != e)
            stream << sep;
    }
    return stream;
}
T1 void print(vector<T> arr, string sep = " "){
    if(arr.empty()){
        return;
    }
    print(arr.begin(), arr.end(), sep);
    cout << '\n';
}
void _(){
    int n,k,l;
    cin >> n >> k >> l;
    DSU d1(n),d2(n);
    vpii e1(k),e2(l);
    cin >> e1 >> e2;
    for(auto _ : e1) d1.unite(_.X,_.Y);
    for(auto _ : e2) d2.unite(_.X,_.Y);
    map<pii,int> cnt;
    vpii names;
    rep(i,1,n)
        names.pb(mp(d1.getpar(i),d2.getpar(i)));
    for(auto x : names)
        ++cnt[x];
    vi ans;
    for(auto x : names)
        ans.pb(cnt[x]);
    print(ans);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        _();
}


Measured memory_bytes: 18416
n = int(input())
a =[int(d) for d in input().split()]
d = {}

for i in a:
    if i in d:
        d[i]+=1
    else:
        d[i]= 1

keys = sorted(d)
l= sorted(keys,reverse=True)
cnt =0
lenght=[]
found = False
for i in l:
    if d[i]>=4 and cnt <2:
        lenght.append(i)
        lenght.append(i)
        cnt+=2
    elif d[i]>=2 and cnt<2:
        lenght.append(i)
        cnt+=1
    else:
        found = True
        

if cnt>=2:
    print(lenght[0]*lenght[1])
else:
    print(0)
    
        
        
        


Measured memory_bytes: 17936