akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

int main() {

	long N, K, Q; cin >> N >> K >> Q;
	//初期ポイントは K -Q;
	vector<long> point(N , K - Q);

	for (int i = 0; i < Q; i++) {
		long a; cin >> a; a--;
		point[a]++;
	}

	for (int i = 0; i < N; i++) {
		if (point[i] > 0) cout << "Yes" << endl; else cout << "No" << endl;
	}

}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,m; cin >> n >> m;
    priority_queue<int> ne;
  	rep(i,n) {
    	int x;
    	cin >> x;
    	ne.push(x);
  	}
  	rep(i,m) {
    	int x = ne.top(); ne.pop();
    	ne.push( x/2 );
  	}
  	int ans = 0;
  	rep(i,n) {
    	ans += ne.top(); ne.pop();
  	}
  	cout << ans << endl;
  	
    
    return 0;
}

Measured memory_bytes: 1400
from collections import deque
N = int(input())
T = list(set([int(input()) for _ in range(N)]))
ret = T[0]

def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b)

for t in T[1:]:
  ret = ret * t // gcd(ret, t)
  
print(ret)

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

int main(){
    int N;
    cin >> N;
    int W[N];
    for(int i = 0; i < N; i++){
        cin >> W[i];
    }
    int min = 1<<30;
    for(int t =0; t < N; t++){
        int s1 = 0;
        int s2 = 0;
        for(int i =0; i < t; i++){
            s1 += W[i];
        }
        for(int i = t; i < N; i++){
            s2 += W[i];
        }
        if(abs(s1 - s2) < min) min = abs(s1 - s2);
    }
    cout << min << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	
	static int d , g ;
	static int []p;
	static int []c;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		d = sc.nextInt();
		g = sc.nextInt();
		
		p = new int [d];
		c = new int [d];
		
		for(int i = 0 ; i < d ; i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		
		sc.close();
		
		solve();
	}
	
	static void solve() {
		Set<Integer>hs = new HashSet<Integer>();
		
		int min = 1000000000;
		int n = (int)Math.pow(2, d);
		
		for(int i = 0 ; i < n ;i++) {
			int sum = 0;
			int cnt = 0;
			for(int j = 0 ; j < d ;j++) {
				if((1 & i >> j) == 1) {
					sum += ((j+1) * 100 * p[j]) + c[j];
					cnt += p[j];
					hs.add(j);
				}
				
			}
			f:if(sum < g) {
			for(int k = d-1 ; k >= 0 ; k--) {
				if(!hs.contains(k)) {
					int temp = 0;
					while(true) {
						sum += (k+1) * 100;
						temp++;
						if(sum >= g || temp == p[k]) {
							cnt += temp;
							break;
						}
					}
					
					break f;
				}
			}			
		}	
			if(sum >= g) {
			min = Math.min(cnt, min);
			}
			hs.clear();
	}
		
		System.out.println(min);
		
		
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    int n;
    cin >> n;
    vector<double> t(n), v(n);
    int T = 0;
    rep(i, n){
        cin >> t[i];
        T += t[i];
    }
    rep(i, n) cin >> v[i];

    const int INF = 1e9;
    vector<double> maxv(2*T+1, INF);

    int now = 0;
    rep(i, n){
        rep(j, t[i]){
            int t1 = now + 2*j;
            int t2 = now + 2*j + 1;
            maxv[t1] = min(maxv[t1], v[i]);
            maxv[t2] = min(maxv[t2], v[i]);
        }
        now += t[i] * 2;
        maxv[now] = min(maxv[now], v[i]);
    }

    maxv[0] = 0;
    maxv[2*T] = 0;

    for(int i=1; i<=2*T; i++){
        maxv[i] = min(maxv[i], maxv[i-1]+0.5);
    }

    for(int i=2*T-1; i>=0; i--){
        maxv[i] = min(maxv[i], maxv[i+1]+0.5);
    }

    double ans = 0;
    for(int i=0; i<=2*T; i++){
        ans += 0.25 * (maxv[i] + maxv[i+1]);
    }

    cout << fixed << setprecision(9) << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  bool bo = false;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    if (a.at(i) == 0) {
      bo = true;
    }
  }
  
  long long ans = 1;
  if (bo) {
    cout << 0 << endl;
  }
  else {
    for (int i = 0; i < n; i++) {
      if (10000000000000000000 / ans < a.at(i)) {
        cout << -1 << endl;
        break;
      }
      else if (ans * a.at(i) > 1000000000000000000) {
        cout << -1 << endl;
        break;
      }
      else {
        ans *= a.at(i);
      }
      
      if (i == n - 1) {
        cout << ans << endl;
      }
    }
  }
}


Measured memory_bytes: 4052
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	string a,b,c;
	cin >> a >> b >> c;
	int count=0;

	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			if(b[i]==c[i])
				continue;
			else
				count++;
		}
		else
		{
			if(b[i]==c[i] or a[i]==c[i])
				count++;
			else
				count+=2;
		}
	}

	cout << count << endl;
}

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

bool is_kaibun(string s) {
	string t = s;
	reverse(all(t));
	if(t == s) return true;
	else return false;
}

int main() {
	string s;
	cin >> s;
	string ans = "Yes";
	if(!is_kaibun(s)) {
		cout << "No" << endl;
		return 0;
	}
	string s1, s2;
	int n = s.size();
	for(int i = 0; i < (n-1)/2; i++) {
		s1 += s[i];
	}
	if(!is_kaibun(s1)) {
		cout << "No" << endl;
		return 0;
	}
	for(int i = (n+3)/2-1; i < n; i++) {
		s2 += s[i];
	}
	if(!is_kaibun(s2)) {
		cout << "No" << endl;
		return 0;
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
    int aa[20] ,b=1,bb=0,c=0;
    cin>> bb;
    cin >> aa[0];
for (int i=1;i<=bb-1;i++){
    cin >> aa[i];
    for (int j= 0; j<i;j++){
        if(aa[j]>aa[i]  ){
            c=1;
        }
    }
    if(c==0){
        b++;
    }else {
        c=0;
    }
}
cout << b;
}

Measured memory_bytes: 256
_ = input()
L = [int(i) for i in input().split()]

if len(L) < 3:
  print(0)
  exit()

cnt = 0

for i in range(len(L) - 2):
  for j in range(i + 1, len(L) - 1):
    if i == j:
      continue
    for k in range(j + 1, len(L)):
      if k == i or k == j:
        continue
      if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
        continue
      if (L[i] + L[j] > L[k] and 
          L[j] + L[k] > L[i] and
          L[k] + L[i] > L[j]):
        cnt += 1

print(cnt)

Measured memory_bytes: 9252
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

int n, m, vt[100001];
vector<int> adj[100001];
queue<int> q;

int main() {
    scanf("%d%d", &n, &m);
    while (m-- > 0) {
        int a, b;
        scanf("%d%d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    q.push(1);
    vt[1] = -1;
    while (!q.empty()) {
        int cur = q.front();
        q.pop();
        for (int i = 0, j ; i < adj[cur].size() ; i++) {
            j = adj[cur][i];
            if (vt[j]) continue;
            vt[j] = cur;
            q.push(j);
        }
    }
    for (int i = 2 ; i <= n ; i++) {
        if (!vt[i]) {
            printf("No");
            return 0;
        }
    }
    printf("Yes\n");
    for (int i = 2 ; i <= n ; i++) printf("%d\n", vt[i]);
}


Measured memory_bytes: 10032
#include<bits/stdc++.h>
using namespace std;
int l,r,n,m,pos1=0,pos2=100010;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i) {
		scanf("%d%d",&l,&r);
		if(l>pos1)
			pos1=l;
		if(r<pos2)
			pos2=r;
	}
	printf("%d",max(pos2-pos1+1,0));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    int a = 0, b = 0, i = 0,j = 0, k =0;
    for(k=0 ;; k++){
        cin >> a >> b;
        if((a==0)||(b==0))break;

        for(i = 0; i < a; i++){
            for(j = 0; j < b; j++){
               if(j==0 || j==b-1 || i==0 | i ==a-1)
               cout << '#';
               else cout<<'.';
            }
            cout << endl;
        }

        cout << endl;
    }

}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 1000000007;
int main() {
  long long int  H,W;
  cin >> H >> W;
  // tt
  long long int ans = INF;
  for(int i = 1; i <= W-1; i++) {
    long long int ma = i * H;
    long long int mi = i * H;
    int j = floor((W - i) / 2) + i;
    if(j == 0 || j >= W || j == i) continue;
    ma = max((j - i) * H,ma);
    mi = min((j - i) * H,mi);
    ma = max((W - j) * H,ma);
    mi = min((W - j) * H,mi);
    ans = min(ans,ma - mi);
  }
  // ty
  for(int i = 1; i <= W-1; i++) {
    int j = floor(H/2);
    long long int ma = i * H;
    long long int mi = i * H;
    ma = max((W - i) * j,ma);
    mi = min((W - i) * j,mi);
    ma = max((W - i) * (H - j),ma);
    mi = min((W - i) * (H - j),mi);
    ans = min(ans,ma - mi);
  }

  for(int i = 1; i <= H-1; i++) {

    long long int ma = i * W;
    long long int mi = i * W;
    int j = floor((H - i) / 2) + i;
    if(j == 0 || j >= H || j == i) continue;
    ma = max((j - i) * W,ma);
    mi = min((j - i) * W,mi);
    ma = max((H - j) * W,ma);
    mi = min((H - j) * W,mi);
    ans = min(ans,ma - mi);
  }
  // ty
  for(int i = 1; i <= H-1; i++) {
    int j = floor(W/2);
    long long int ma = i * W;
    long long int mi = i * W;
    ma = max((H - i) * j,ma);
    mi = min((H - i) * j,mi);
    ma = max((H - i) * (W - j),ma);
    mi = min((H - i) * (W - j),mi);
    ans = min(ans,ma - mi);
  }


  cout << ans << endl;






}


Measured memory_bytes: 256
#include <stdio.h>
int dp[1001][1001]={0};
int main(void)
{
	int n=0,i=0,m=0,d[1001]={0},c[1001]={0},j=0,x=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	for(j=0;j<m;j++){
		scanf("%d",&c[j]);
	}
	for(i=0;i<n+1;i++){
		for(j=i;j<m+1;j++){
			x=d[i]*c[j];
			if(dp[i][j]+x<dp[i+1][j+1] || dp[i+1][j+1]==0){
				dp[i+1][j+1]=dp[i][j]+x;
			}
			if(dp[i][j+1]>dp[i][j] || dp[i][j+1]==0){
				dp[i][j+1]=dp[i][j];
			}
		}
	}
		printf("%d\n",dp[n][m]);
	return 0;
}



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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;



int main()
{

    SPEED;
    int a,b,k;
    cin >> k >> a >> b;

    for(int i=a;i<=b;i++)
    {
        if(i%k == 0)
        {
            cout << "OK" << endl;
            R 0;
        }
    }
    cout << "NG" << endl;

    R 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int M, N;

int judge(string in, int n){
  string s;
  if(n % 5 == 0 && n % 3 == 0) return in == "FizzBuzz";
  if(n % 5 == 0) return in == "Buzz";
  if(n % 3 == 0) return in == "Fizz";
  if(!isdigit(in[0])) return false;
  return n == atoi(in.c_str());
}

int main(){
  while(scanf("%d%d", &M, &N) && M+N){
    vector<int>p(M);
    rep(i, M) p[i] = i+1;

    int pos = 0, w = -1;
    REP(i, 1, N+1){
      string s;
      cin >> s;
      if(w != -1) continue;
      if(!judge(s, i)){
	p.erase(p.begin()+pos);
      }else{
	pos++;
      }
      pos = pos%p.size();
      if(p.size() == 1) w = p[0];
    }
    rep(i, p.size()) printf(i?" %d":"%d", p[i]); puts("");
  }
  return 0;
}

Measured memory_bytes: 1288
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define INF (1LL<<60)
#define int long long
#define ll long long
#define mod 1000000007


signed main(){

	int N, oN;
	cin >> N;
	oN = N;

	if (N == 3){
		cout << "2 3 25" << endl;
		return 0;
	}

	vector<int> v = {};
	v.push_back(2);
	v.push_back(4);
	v.push_back(3);
	v.push_back(9);

	N -= 4;
	if (N % 2 == 1){
		v.push_back(6);
		N--;
	}

	int n = 1;
	while (N > 0 && 2 * (3 * n + 2) <= 30000){
		v.push_back(2 * (3 * n + 1));
		v.push_back(2 * (3 * n + 2));
		N -= 2;
		n++;
	}
	n = 1;
	while (N > 0 && 3 * (4 * n + 3) <= 30000){
		v.push_back(3 * (4 * n + 1));
		v.push_back(3 * (4 * n + 3));
		N -= 2;
		n++;
	}
	for (int i = 1; v.size()<oN; i++){
		if ((i % 2 == 0 || i%3==0) && find(v.begin(), v.end(), i) == v.end())
			v.push_back(i);
	}



	for (int i = 0; i < v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 640
import sys


if __name__ == "__main__":
    N = raw_input()
    S = raw_input()

    bra = 0
    ket = 0
    pair = 0
    # ket = 0
    for s in S:
        if s == '(':
            bra += 1
        else:
            if bra > 0:
                bra -= 1
                pair +=1
            else:
                ket += 1
    print '(' * ket + S + ')'*bra


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


def convert(n, b):
    if n == 0:
        return "0"
    out = []
    while n != 0:
        n, rem = divmod(n, b)
        if rem < 0:
            n += 1
            rem -= b
        out.append(rem)
    return "".join(map(str, out[::-1]))


print(convert(N, -2))


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define All(a) a.begin(), a.end()
int main(){
    string S;
    cin >> S;
    string t;
    for(int i = 0 ;i < S.size(); i++){
        t += 'x';
    }
    cout << t << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

using namespace std;
typedef long long ll;

const long long MOD = 2;

int result[200001];
void solve(long long N, std::vector<long long> a){
  vector<int> out;
  for (int i = N; i >= 1; i--) {
    int sum = 0;
    for (int j = i * 2; j <= N; j += i) {
      sum += result[j];
    }
    if (sum % 2 != a[i]) {
      result[i] = 1;
      out.push_back(i);
    }
  }

  printf("%d\n", (int)out.size());
  for (int i = 0; i < out.size(); i++) {
    if (i != out.size() - 1) {
      printf("%d ", out[i]);
    } else {
      printf("%d\n", out[i]);
    }
  }
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N+1);
  a[0] = 0;
  for(int i = 1 ; i <= N ; i++){
    scanf("%lld",&a[i]);
  }
  solve(N, std::move(a));
  return 0;
}


Measured memory_bytes: 3704
using System;

namespace ABC_049_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            if (s == "a" || s == "e" || s == "i" || s == "o" || s == "u")
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define forn(i, n) for(int i=0;i<(n);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int main() {
	fastio;
	int n, r;
	cin >> n >> r;
	// out = inner - 100*(10-n)
	// inner = out + 100*(10-n)
	cout << r + 100*max(0, 10-n);
}

Measured memory_bytes: 256
N = input()

A = N[0:2]
C = N[2:-1]
M = N[-1]


if A[0] == "A":
    if A[1].islower():
        if C.find("C") != -1:
            c = list(C)
            c[C.find("C")] = "s"
            C = "".join(c)
            if C.islower():
                if M.islower():
                    print("AC")
                else:
                    print("WA")
            else:
                print("WA")
        else:
            print("WA")
    else:
        print("WA")       
else:
    print("WA")

Measured memory_bytes: 3064
# n, m = [int(x) for x in input().split()]
n,m = map(int, input().split())
a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
# b = []

for i in range(n):
    a[i] = [int(x) for x in input().split()]
    # a.append(list(map(int, input().split())))
for i in range(m):
    # b.append(int(input()))
    b[i] = int(input())
    
for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j]*b[j]
    print(sum)


Measured memory_bytes: 5984
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

typedef long long ll;
const int N = 5e5 + 10;
const int MOD = 1e9;

char s[55][55];

int main(){
	int h, w;
	int sum = 0;
	scanf("%d %d", &h, &w);
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++){
			cin >> s[i][j];
			if(s[i][j] == '#')
				sum++;
		}
	int flag = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(s[i][j] == '#'){
				if( i == 0 && j == 0){
					if(s[i + 1][j] == '#' || s[i][j + 1] == '#')
						flag++;
				}
				else if(i == 0){
					if(s[i + 1][j] == '#' || s[i][j - 1] == '#' || s[i][j + 1] == '#')
						flag++;
				}
				else if(j == 0){
					if(s[i + 1][j] == '#' || s[i - 1][j] == '#' || s[i][j + 1] == '#')
						flag++;
				}
				else{
					if(s[i + 1][j] == '#' || s[i - 1][j] == '#' || s[i][j + 1] == '#' || s[i][j - 1] == '#')
						flag++;
				}
			}
		}
	}
	if(flag == sum)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

A, B, C = sorted(map(int, input().split()))

ans = 0
if C % 2 == 0:
    if A % 2 == 0 and B % 2 == 1:
        ans += 1
        A += 1
        C += 1
    elif A % 2 == 1 and B % 2 == 0:
        ans += 1
        B += 1
        C += 1
    elif A % 2 == 1 and B % 2 == 1:
        ans += 1
        A += 1
        B += 1
else:
    if A % 2 == 0 and B % 2 == 1:
        ans += 1
        B += 1
        C += 1
    elif A % 2 == 1 and B % 2 == 0:
        ans += 1
        A += 1
        C += 1
    elif A % 2 == 0 and B % 2 == 0:
        ans += 1
        A += 1
        B += 1

while C > A:
    A += 2
    ans += 1

while C > B:
    B += 2
    ans += 1

print(ans)

Measured memory_bytes: 9404
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <array>
#include <bitset>
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
// #include <fstream>//ifstream/ofstream
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <list>
#include <queue>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <tuple>
#include <utility>//pair
#include <valarray>
#include <vector>

#define PRIME_SHORT 10007
#define PRIME 1000000007

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef pair<ull, int> puli;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pllll;
typedef pair<ull, ull> pulul;
typedef pair<double, double> pdd;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;

const bool debug = false;

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

    vector<int> arr;
    for (size_t i = 0; i < n; ++i) {
        int temp; cin >> temp;
        arr.push_back(temp);
    }

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

    int mine = arr[0];
    int maxe = arr[n-1];

    vector<int> counter(maxe+1, 0);

    for (size_t i = 0; i < n; ++i) {
        ++counter[arr[i]];
    }

    int totalcount = 0;

    for (size_t i = 0; i <= maxe; ++i) {
        if (counter[i] > 1) {
            totalcount += counter[i] - 1;
        }
    }

    if (debug)
    {
        //1D
        cout << "arr" << endl;
        for (int i = 0; i <= maxe; ++i)
        {
            cout << counter[i] << "\n";
        }
    }

    if (totalcount % 2) {
        ++totalcount;
    }
    int result = n - totalcount;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 1272
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	string str;
	cin>>str;
	if(str=="SUN")
		cout<<7<<"\n";
	if(str=="MON")
		cout<<6<<"\n";
	if(str=="TUE")
		cout<<5<<"\n";
	if(str=="WED")
		cout<<4<<"\n";
	if(str=="THU")
		cout<<3<<"\n";
	if(str=="FRI")
		cout<<2<<"\n";
	if(str=="SAT")
		cout<<1<<"\n";
	return 0;
}
	

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1234567;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
// o o o o o o o o o o o o
// ↑           ↑
// i - - - - - j
signed main() {
    int N;
    cin >> N;
    vector<int>A(N);
    map<int,int>Mp;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        Mp[A[i]+i+1]++;
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans+=Mp[i+1-A[i]];
    }
    cout << ans << endl;
}

Measured memory_bytes: 27528
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int A,B,M;
    cin >> A>> B >> M;
    vector<int> a(A), b(B);
    REP(i, A) cin >> a[i];
    REP(i, B) cin >> b[i];
    int min_cost = MOD;
    REP(i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        min_cost = min(min_cost, a[x-1]+b[y-1]-c);
    }
    min_cost = min(*min_element(ALL(a))+*min_element(ALL(b)), min_cost);
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 1152
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=(ll)(1e9+7);
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

const ll MAX_N = (ll)(1e5 + 100);

map<ll,ll> cnt;
ll ans = 1;


class CombinationModula {
public: 
  ll fact[MAX_N];
  ll inv[MAX_N];
  ll fact_inv[MAX_N];
 
  CombinationModula(ll n) {
    init(n);
  }
 
  void init(ll n) {
    inv[1] = fact[0] = fact_inv[0] = 1;
  	for (int i = 2; i <= n; i++) inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD;
  	for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD;
  	for (int i = 1; i <= n; i++) fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
  }
 
  ll comb(ll n, ll r) {
    if (r > n) return 0;
  	return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
  }
};

//素因数分解
map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i] += 1;
      n /= i;
    }
  } 
  if (n != 1) res[n] = 1;
  return res;
}


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

  cnt = prime_factorization(m);
  
  CombinationModula comb_mod(n + 100);

  for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
    ans *= comb_mod.comb(n - 1 + itr->second, n - 1);
    ans %= MOD;
  }

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


Measured memory_bytes: 2560
// g++ -std=c++14
#include<bits/stdc++.h>
typedef long long int lli;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x);
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z);

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) c.begin(),c.end()

#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
vector<vector<int> >ans;
void func(int ind,int n1,int n2){
  // cout << ind << " " << n1 << " " << n2 << "\n";
  for(int i=5;i>=0;i--){
    ans[ind][i] = n1%10;
    n1/=10;
  }
  for(int i=11;i>5;i--){
    ans[ind][i] = n2%10;
    n2/=10;
  }
}
int main(){
  _
  int n,m;
  cin >> n >> m;
  vector<vector<pair<int,int> > >vec(n+1);
  ans.resize(m+1,vector<int>(12,0));
  for(int i=1;i<=m;i++){
    int x,y;
    cin >> x >> y;
    vec[x].pb(mp(y,i));
  }
  for(int i=1;i<=n;i++){
    sort(vec[i].begin(),vec[i].end());
    for(int j=0;j<vec[i].size();j++){
      int ind = vec[i][j].se;
      func(ind,i,j+1);
    }
  }
  for(int i=1;i<=m;i++){
    for(int j=0;j<12;j++){
      cout << ans[i][j];
    }cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 15616
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n; cin >> n;
    int a[100001]; INITA(a, 0, 100000, 0);
    REP(i, n) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }
    int res = 0;
    FOR(i, 1, 99999) {
        res = max(res, a[i-1] + a[i] + a[i+1]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ull N, M;
  cin >> N >> M;
  if (N == 1 && M == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (N == 1) {
    cout << max(0ULL, M - 2) << endl;
    return 0;
  }
  if (M == 1) {
    cout << max(0ULL, N - 2) << endl;
    return 0;
  }
  // corner
  ull front = 4;
  if (N > 1) {
    front += (M - 2) * 2;
  }
  if (M > 2) {
    front += (N - 2) * 2;
  }

  cout << N * M - front << endl;

  return 0;
}


Measured memory_bytes: 256
import Data.List
import Data.Array.IO
import Data.Ratio
import Data.Fixed
import Control.Monad
import Numeric

main = do
  (n:a:b:_) <- getLine >>= return . map read . words :: IO [Int]
  vs <- getLine >>= return . map read . words :: IO [Integer]

  dp <- newArray ((0,0),(n,n)) (0,1) :: IO (IOArray (Int,Int) (Ratio Integer, Integer))

  forM_ [1..n] $ \i -> do
    forM_ [1..n] $ \j -> do
      (a1,c1) <- readArray dp (i-1,j-1) >>= \(a,c) -> return ((a*(fromIntegral $ j-1)+(fromIntegral $ vs!!(i-1)))/(fromIntegral j), c)
      (a2,c2) <- readArray dp (i-1,j)

      if a1 == a2 then
        writeArray dp (i,j) (a1,c1+c2)
        else
        writeArray dp (i,j) (if a1>a2 then (a1,c1) else (a2,c2))
        
  result <- forM [a..b] $ \i -> readArray dp (n,i)

  let (mx,_) = maximumBy (\x y -> compare (fst x) (fst y)) result
  let count = sum . map snd $ filter ((==mx) . fst) result

  putStrLn $ showFFloat Nothing (fromRational mx) ""
  print $ count


Measured memory_bytes: 1276
#include <iostream>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
	int n;cin>>n;
	long long x;cin>>x;
	vector<ll> lp(n+1),lm(n+1),ln(n+1);
	lp[0]=1;
	lm[0]=1;
	ln[0]=1;
	for(int i=1;i<n+1;i++){
		lp[i]=lp[i-1]*2+1;
		lm[i]=ln[i-1]+2;
		ln[i]=ln[i-1]*2+3;
	}
	ll ans=0;
//	for(auto x:lm){
//		cout<<x<<endl;
//	}
	while(n){
		if(lm[n]==x){
			ans+=lp[n-1]+1;
			break;
		}
		if(x==1){
			break;
		}
		if(x==ln[n]){
			ans+=lp[n-1]*2+1;
			break;
		}
		if(x>lm[n]){
			x-=lm[n];
			ans+=lp[n-1]+1;
		}else{
			x-=1;
		}
		n-=1;
//		cout<<n<<' '<<x<<' '<<ans<<endl;
		if(n==0){
			ans++;
			break;
		}

	}
	cout<<ans<<endl;

	return 0;
}

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

int main()
{
    long long X;
    cin >> X;

    for (int a = -120; a <= 120; a++) {
        for (int b = -120; b <= 120; b++) {
            if (powl(a, 5) - powl(b, 5) == X) {
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3592
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> >vvi;
const ll MOD=1000000007LL;
int main(){
  ll n,m;
  cin>>n>>m;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  map<int,int>ma;
  rep(i,n){
    ma[a[i]]++;
  }
  vector<ll>b(m),c(m);
  rep(i,m)cin>>b[i]>>c[i];
  rep(i,m){
    ma[c[i]]+=b[i];
  }
  int k=ma.size();
  vector<pair<ll,ll>>p(k);
  int q=0;
  for(auto t:ma){
    p[q].first=t.first;
    p[q].second=t.second;
    q++;
    
  }
  reverse(p.begin(),p.end());
  ll ans=0;
  ll count=0;
  for(ll i=0;i<n;i++){
    if(count+p[i].second>n){
      ans+=(n-count)*p[i].first;
      break;
    }
    else{
    ans+=p[i].first*p[i].second;
    count+=p[i].second;
    }
  }
  cout<<ans<<endl;
}
    
  

Measured memory_bytes: 15104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << ", " << p.second << "}";
}
template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
  os << "{";
  rep(i, v.size()) { if(i) os << ", "; os << v[i]; }
  return os << "}";
}
// template<class t> ostream& operator<<(ostream& os, const set<t>& se) {
//   os << "{";
//   auto itr = se.begin();
//   rep(i, se.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
// template<class t, class u>
// ostream& operator<<(ostream& os, const map<t, u>& mp) {
//   os << "{";
//   auto itr = mp.begin();
//   rep(i, mp.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<string> S(H);
  rep(i, H) cin >> S[i];
  vector<vector<int> > ans(H, vector<int>(W));
  int tmp = 1;
  vector<set<int> > cnt(H);
  rep(i, H) rep(j, W) if(S[i][j] == '#') cnt[i].insert(j+1);
  int pre = -1;
  vector<bool> done(H);
  rep(i, H) {
    if(cnt[i].size() == 0) {
      if(pre != -1) {
        rep(j, W) ans[i][j] = ans[pre][j];
        done[i] = true;
        pre = i;
      }
    } else {
      int prev = 0;
      for(int c: cnt[i]) {
        REP(j, prev, c) ans[i][j] = tmp;
        prev = c;
        tmp++;
      }
      tmp--;
      REP(j, prev, W) ans[i][j] = tmp;
      tmp++;
      pre = i;
      done[i] = true;
    }
  }
  pre = H-1;
  rrep(i, H) {
    if(!done[i]) {
      rep(j, W) ans[i][j] = ans[pre][j];
      done[i] = true;
    } else {
      pre = i;
    }
  }
  rep(i, H) {
    rep(j, W) cout << ans[i][j] << ' ';
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

// 後ろから期待値を求めるときの dfs

int main() {
  int n, m; cin >> n >> m;
  vector<vector<int>> to(n);
  for(int i = 0; i < m; i++) {
    int s, t; cin >> s >> t;
    s--;
    t--;
    to[s].push_back(t);
  }
  vector<double> dp(n);
  // dp[n - 1] = 0;
  for(int v = n - 2; v >= 0; v--) {
    double now = 0;
    for(int u : to[v]) {
      now += dp[u];
    }
    now /= to[v].size();
    now += 1;
    dp[v] = now;
  }
  double ans = dp[0];

  for(int nv = 0; nv < n - 1; nv++) {
    if(to[nv].size() == 1) continue;
    int nu = to[nv][0];
    // 行き先の dp の値が最も大きい頂点をさがす
    for(int u : to[nv]) {
      if(dp[nu] < dp[u]) nu = u;
    }
    double now = [&]{
      vector<double> dp(n);
      // dp[n - 1] = 0;
      for(int v = n - 2; v >= 0; v--) {
        double now = 0;
        for(int u : to[v]) {
          if(v == nv and u == nu) continue;
          now += dp[u];
        }
        int deg = to[v].size();
        if(v == nv) deg--;
        now /= deg;
        now += 1;
        dp[v] = now;
      }
      return dp[0];
    }();
    ans = min(ans, now);
  }

  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 1408
def check_baisuu(K, A, B):
  if (A % K == 0) or (B % K == 0):
    return True
  elif (A // K) < (B // K):
    return True
  else:
    return False

K, A, B = map(int, open(0).read().split())
if check_baisuu(K, A, B):
  print("OK")
else:
  print("NG")

Measured memory_bytes: 9192
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include <cstdio>

using namespace std;

int s[8];

int main()
{
    map<string,int> vis;
    queue<string> q;
    queue<int> qstep;

    string target = "01234567";
    q.push(target);
    qstep.push(0);
    vis[target] = 0;
    while(!q.empty()){
        string tmp1 = q.front(); q.pop();
        int step = qstep.front(); qstep.pop();
        for(int i=0;i<8;++i){
            if(tmp1[i]=='0'){
                if(i!=3&&i!=7){
                    string tmp = tmp1;
                    char t = tmp[i];
                    tmp[i] = tmp[i+1];
                    tmp[i+1] = t;
                    if(vis.count(tmp)==0){
                        q.push(tmp);
                        qstep.push(step+1);
                        vis[tmp] = step+1;
                    }
                }
                if(i!=0&&i!=4){
                    string tmp = tmp1;
                    char t = tmp[i];
                    tmp[i] = tmp[i-1];
                    tmp[i-1] = t;
                    if(vis.count(tmp)==0){
                        q.push(tmp);
                        qstep.push(step+1);
                        vis[tmp] = step+1;
                    }
                }
                if(i>3){
                    string tmp = tmp1;
                    char t = tmp[i];
                    tmp[i] = tmp[i-4];
                    tmp[i-4] = t;
                    if(vis.count(tmp)==0){
                        q.push(tmp);
                        qstep.push(step+1);
                        vis[tmp] = step+1;
                    }
                }
                if(i<4){
                    string tmp = tmp1;
                    char t = tmp[i];
                    tmp[i] = tmp[i+4];
                    tmp[i+4] = t;
                    if(vis.count(tmp)==0){
                        q.push(tmp);
                        qstep.push(step+1);
                        vis[tmp] = step+1;
                    }
                }
                break;
            }
        }
    }

    string tmp="";
    while(scanf("%d",&s[0]) != EOF){
        for(int i=1;i<8;++i) scanf("%d",&s[i]);
        tmp = "";
        for(int i=0;i<8;++i) tmp += ('0'+s[i]);
        printf("%d\n",vis[tmp]);
    }
    return 0;
}



Measured memory_bytes: 5504
from fractions import Fraction
def main():
    N = int(input())

    for h in range(1, 3501):
        for n in range(h,3501):
            a = N*h*n
            b = 4*n*h - N*n - N*h 
            if a >= b and b >  0 and a%b == 0:
                w = Fraction(N*h*n, 4*n*h - N*n - N*h)
                if Fraction(4, N) == Fraction(1, h) + Fraction(1, n) + Fraction(1, w):
                    print(h,n,w)
                    exit()
            else:
                continue

if __name__ == "__main__":
    main()


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

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

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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 (b<a) { a=b; return 1; } return 0; }



i64 n;
void solve(){
	cin >> n;
	
	cout << (n-1)*n/2 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define BIGINT_SIZE (1000)

class BigInt {
private:
    unsigned int _num[BIGINT_SIZE]{};

    void carry_up() {
        for (int i = 0; i < BIGINT_SIZE - 1; ++i) {
            if (_num[i] >= 10) {
                _num[i + 1] += _num[i] / 10;
                _num[i] %= 10;
            }
        }
    }

public:
    BigInt() {
        for (unsigned int &i : _num) {
            i = 0;
        }
    }

    void add(int num) {
        _num[0] += num;
        carry_up();
    }

    string to_string() {

        int i = BIGINT_SIZE - 1;
        for (; i >= 0; --i) {
            if (_num[i] != 0) break;
        }
        if (i < 0) {
            return "0";
        }

        string ret;
        while (i >= 0) {
            ret += ::to_string(_num[i]);
            i--;
        }

        return ret;
    }
};

int main() {
    string s, t;
    cin >> s >> t;

    BigInt count;
    int prev_pos = -1;
    for (char c : t) {
        if (++prev_pos >= s.length()) {
            prev_pos = 0;
            count.add(s.length());
        }

        int pos_from_prev_pos = s.find(c, prev_pos);

        if (pos_from_prev_pos != string::npos) {
            prev_pos = pos_from_prev_pos;
            continue;
        }

        count.add(s.length());
        int pos_from_top = s.find(c);
        if (pos_from_top == string::npos) {
            cout << "-1" << endl;
            return 0;
        }

        prev_pos = pos_from_top;
    }

    count.add(prev_pos + 1);

    string answer = count.to_string();
    cout << answer << endl;
}


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

using namespace std;

#define L long long int
#define in(x) L x; cin>>x;
#define vi vector<L>
#define pb push_back
#define re(i,n) for(L i=0; i<n; i++) 
#define mp make_pair
#define pi(v) vector<pair<L,L>> v;
#define bi begin();3

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 

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

L power(L b,L e,L m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    in(n);
    set <L> s;
    map <L,L> m;
    L ans=0;
    re(i,n)
    {
        in(z);
        m[z]++;
        s.insert(z);
    }
    for(auto i=s.begin();i!=s.end();i++)
    {
        if(m[*i]<*i)
            ans+=m[*i];
        else if(m[*i]>*i)
            ans+=(m[*i]-*i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 14036
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>

#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








template <typename T>
class Bellmanford {
private:
    struct edge {
        int to;
        T cost;
    };
    int n;
    vector<vector<edge>> g;
    vector<T> dist;
    
public:
    Bellmanford(int n) : n(n){
        g.resize(n);
    }
    
    void add_edge(int v1, int v2, T cost){
        g[v1].push_back({ v2, cost });
    }
    
    // 負の閉路があるときfalseを返す
    bool run(int s){
        dist = vector<T>(n, INF);
        dist[s] = 0;    //開始点の距離は0
        
        for (int i = 0; i < n; i++) {
            for (int v = 0; v < n; v++) {
                for (auto& e : g[v]) {
                    if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        if (i == n - 1) {
                            // return false;
                            dist[e.to] = -INF;
                        }
                    }
                }
            }
        }
        return true;
    }
    
    T get_distance(int v){
        return dist[v];
    }
};


int main(){
    ll n, m;
 
	cin >> n >> m;
 
	Bellmanford<ll> bell(n);
 
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--;
 
		bell.add_edge(a, b, -c);
	}
 
	bell.run(0);
 
	if (bell.get_distance(n - 1) > -INF) {
		cout << -bell.get_distance(n - 1) << endl;
	}
	else {
		cout << "inf" << endl;
	}
}

Measured memory_bytes: 384
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
count = 0
for i in range(N):
    A = list(map(int,input().split()))
    S = C
    for j in range(M):
        S += A[j]*B[j]
    if S>0:
        count+=1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define INF 1234567890ll
#define PI (acos((ld)-1.0))
#define ll long long int 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
typedef pair <int, int> pi;
typedef pair <ll, ll> pl;
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;


int main()
{
	IAMSPEED
	double n; cin >> n;
	double odd = 0;
	FOR(i, 1, n) {
		if (i % 2 == 1) ++odd;
	}
	cout << odd/n;
}

Measured memory_bytes: 256