akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){

            int k = Integer.parseInt(sc.next());
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());

            boolean isNg = true;
            int i = 0;
            while(k <= b){
                k += i;
                if(i == 0) i = k;
                if(a <= k && k <= b){
                    System.out.println("OK");
                    isNg = false;
                    break;
                }
            }

            if(isNg) System.out.println("NG");

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}


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

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

  int s = 1;
  int count = 0;
  for (int i=0; i<n; ++i) {
    if (an[i] == s) {
      ++s;
      ++count;
    }
  }

  if (count == 0) {
    cout << "-1\n";
  } else {
    cout << n - count << "\n";
  }
}



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

int main() {
    int N, L;   cin >> N >> L;
    vector<int> apple(N);
    int sum = 0;

    for (int i = 0; i < N; ++i) {
        apple[i] = L + i;
        sum += apple[i];
    }

    if((L<0)&&(abs(L)>=N)){
        cout << sum - apple[N-1] << endl;
    } else if ((L>0)) {
        cout << sum - apple[0] << endl;
    } else {
        cout << sum << endl;
    }
    return 0;
}

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

int main(){
    ll a; string x; cin >> a >> x;
    int d1 = x[0]-'0';
    int d2 = x[2]-'0';
    int d3 = x[3]-'0';
    ll A = d1,B = d2,C = d3;
    a = a*(100*d1+10*d2+d3);
    ll ans = a/100;
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

i64 sqr(i64 x) { return x * x; }

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

    int N; read(N);

    vector<i64> X(N);
    rep(i, N) {
        read(X[i]);
    }

    i64 ans = LINF;
    reps(p, 0, 101) {
        i64 sum = 0;
        rep(i, N) sum += sqr(p - X[i]);
        chmin(ans, sum);
    }

    print(ans);

    return 0;
}


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

#define ll long long

using namespace std;

int pmod(int x, int y, int p){ int res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; }  
ll pmod(ll x, ll y, ll p){ ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1)  res = (res*x) % p;  y = y>>1; x = (x*x) % p; } return res; } 

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

	string s;
	cin >> s;
	if(s == "ABC")
		cout << "ARC";
	else
		cout << "ABC";
	return 0;
}

Measured memory_bytes: 3652
n  = int(input())
m = n
factors = set()
q = 2
while n>1 and q*q<=n:
	if n % q == 0:
		factors.add(q)
		n //= q
	else:
		q += 1
if n>1:
	factors.add(n)

for p in factors:
	m *= p-1
	m //= p

print(m)


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

using ll = long long;

ll arr[100];
int n;


int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
    //sort(arr, arr + n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            for(int k = j + 1; k < n; k++){
                if(arr[i] != arr[j] and arr[i] != arr[k] and arr[j] != arr[k] and (arr[i] + arr[j] > arr[k]) and (arr[i]  + arr[k] > arr[j]) and (arr[j] + arr[k] > arr[i]))
                    ans++;
            }
        }
    }
    cout << ans << endl;
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if((N%1000)%111==0 || (N/10)%111==0) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22100
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.ArrayDeque;
import java.awt.Point;
 
class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] P = new int[N];
        
        for(int i=0; i<N; i++){
            P[i] = sc.nextInt();
        }

        Arrays.sort(P);

        int min = 0;

        for(int i=0; i<K; i++){
            min += P[i];
        }

        System.out.println(min);
    } 
}

Measured memory_bytes: 38616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long N;
	cin >> N;
  	long Array[N];
  	int idx = 0;
  	while(cin >> Array[idx]) idx++;
  	int count = 0;
  	for(int i = 0; i< N;i++)
    {
      int min_idx = i;
      for(int j=i;j<N;j++)
      {
        if(Array[j] < Array[min_idx])
        {
          min_idx = j;
        }
      }
      if(i != min_idx)
      {
        long tmp = Array[i];
        Array[i] = Array[min_idx];
        Array[min_idx] = tmp;
        count++;
      }
    }
	for(int i=0;i<N-1;i++)
    {
      cout << Array[i] << " ";
    }
  	cout << Array[N-1] << endl;
  	cout << count << endl; 
  	return 0;
}



Measured memory_bytes: 3212
#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 trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e5+5;
const int MOD=1e9+7;

int n;
string first;

map<string, string> opp;

string get_expected(int k)
{
	if((k-0)%2)
		return opp[first];
	else
		return first;
}

int check(int k)
{
	cout<<k<<endl;
	string cur;
	cin>>cur;
	string expected=get_expected(k);
	if(cur=="Vacant")
		exit(0);
	if(cur==expected)
		return 1;
	else
		return 0;
}

int binsearch(int lo, int hi)
{
	while(lo<hi)
	{
		int mid=(lo+hi)>>1;
		if(check(mid))
			lo=mid+1;
		else
			hi=mid-1;
	}
	check(lo);
}

int32_t main()
{
    IOS;
    opp["Male"]="Female";
    opp["Female"]="Male";
    cin>>n;
    cout<<"0"<<endl;
    cin>>first;
    if(first=="Vacant")
    	return 0;
    int ans=binsearch(1, n-1);
    return 0;
}

Measured memory_bytes: 980
#include<cstdio>
#include<vector>
#include<iostream>
#include<climits>
typedef long long ll;
using namespace std;
int main() {
  int n = 0;
  cin >> n;
  vector<ll> len(n, 0);
  for(int i = 0; i < n; ++i) {
    cin >> len[i];
  }
  ll sum = 0;
  for(int i = 0; i < n; ++i) {
    sum += len[i];
  }
  ll answer = LLONG_MAX;
  ll current = 0;
  for(int i = 0; i < n; ++i) {
    current += len[i];
    ll diff = abs(sum - 2 * current);
    if(diff < answer) {
      answer = diff;
    }
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int A[100000];
int partition(int p, int r){
	int i,j,t,x;
	x = A[r];
	i = p-1;
	for(j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			t = A[i];
			A[i] = A[j];
			A[j] = t;
		}
	}
	t = A[i+1];
	A[i+1] = A[r];
	A[r] = t;
	return i+1;
}

int main(){
	int n, i, q;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++) scanf("%d",&A[i]);
	q = partition(0, n-1);
	for(i = 0; i < n; i++){
		if(i == q) printf("[");
		printf("%d",A[i]);
		if(i == q) printf("]");
		if(i != n-1) printf(" ");
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2156
n = int(input())
A = list(map(int, input().split()))
L = [i+x for i, x in enumerate(A)]
R = [i-x for i, x in enumerate(A) if i-x > 0]

from collections import Counter
P = Counter(L)
Q = Counter(R)
 
ans = 0
for k, v in P.items():
  if k in Q:
    ans += v*Q[k]
print(ans)    
  


Measured memory_bytes: 45316
#abc 167
a, b, c, k = map(int, input().split())
# 1≤K≤A+B+C
if 1<= k<=  a:
    print(k)
elif a+1<= k<=  a+b:
    print(a)
elif a+b+1<= k<=  a+b+c:
    print(a-(k-a-b))

Measured memory_bytes: 9180
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scanf("%d %d", &a, &b)
	for i := 1; i <= 3; i++ {
		if (a*b*i)%2 != 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

Measured memory_bytes: 512
l, r = map(int,input().split())

ans = 2019
for i in range(l, r):
    for j in range(i+1, r+1):
        tmp = i*j % 2019
        if ans > tmp:
            ans = tmp
        if ans == 0:
            print(ans)
            exit(0)
print(ans)


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int S, W; cin >> S >> W;
  if(S <= W){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}

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

typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int n;
	std::cin >> n;
	if (n % 1000 == 0)
		std::cout << 0 << '\n';
	else
		std::cout << 1000 - n % 1000 << '\n';
	return (0);
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1ll;while(b){if(b&1)ans=ans*a%MOD;a=a*a%MOD;b>>=1;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int fa[maxn];
int n,m;
ll num[maxn];
void init()
{
	repd(i,0,n)
	{
		fa[i]=i;
		num[i]=1;
	}
}
struct node
{
	int f;
	int t;
}b[maxn];
ll cnt[maxn];
int findpar(int x)
{
	if(x==fa[x])
	{
		return x;
	}else
	{
		fa[x]=findpar(fa[x]);
		num[x]=max(num[x],num[fa[x]]);
		num[fa[x]]=max(num[x],num[fa[x]]);
		return fa[x];
	}
	// return x==fa[x]?x:fa[x]=findpar(f[x]);
}
void Merg(int x,int y)
{
	x=findpar(x);
	y=findpar(y);
	if(x!=y)
	{
		fa[x]=y;
		num[y]+=num[x];
	}
}
int main()
{
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\in.txt.txt","r",stdin);
	//    freopen("C:\\Users\\DH_M\\Desktop\\code_io\\out.txt.txt","w",stdout);
	gbtb;
	cin>>n>>m;
	init();
	repd(i,1,m)
	{
		cin>>b[i].f>>b[i].t;
	}
	ll v;
	for(int i=m;i>=1;i--)
	{

		if(findpar(b[i].t)!=findpar(b[i].f))
		{
		    v=num[b[i].t]*num[b[i].f];
		    Merg(b[i].t,b[i].f);
			cnt[i]=v;
		}
	}
	ll ans=0;
	repd(i,1,m)
	{
		ans+=cnt[i];
		cout<<ans<<endl;
	}


    return 0;
}

inline void getInt(int* p) {char ch;do {ch = getchar();}
while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');
while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}
else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9')
{*p = *p * 10 + ch - '0';}}}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n;
int dfs(string s) {
  if (stol(s) > n) return 0;
  string t = "753";
  int res = 1, cnt[3] = {0};
  rep(i, 0, s.size()) {
    rep(j, 0, 3) if (s[i] == t[j]) cnt[j]++;
  }
  rep(i, 0, 3) if (cnt[i] == 0) {
    res = 0;
    break;
  }
  rep(i, 0, 3) {
    res += dfs(s + t.substr(i, 1));
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    cout << dfs(to_string(0)) << endl; 
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <tuple>
#include <numeric>
#include <iomanip>

using namespace std;

int main()
{
    double l;
    cin >> l;

    double ret = (l/3) * (l/3) * (l/3);
    // cout << ret << endl;
    cout << fixed << setprecision(12) << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){

  int a,b,i,count,n=0;


  
  while (1){

    count=0;
    
    scanf("%d %d",&a,&b);

    if(a==0 && b==0)break;
    else if(n!=0) printf("\n");

    n++;
    
    for(i=a;i<=b;i++){

      if(i%4==0){
	if(i%400==0){

	  printf("%d\n",i);
	  count++;
	  
	}else if(i%100==0){

	  continue;

	}else{

	  printf("%d\n",i);
	  count++;
	}
      }
    }
   
    if(count==0) printf("NA\n");
  }

  return 0;

}
      

Measured memory_bytes: 616
import sys

n = int(input())
r0 = int(input())
r1 = int(input())

mx = r1-r0
mn = min(r1,r0)
l = map(int,sys.stdin.readlines())
for i in l:
    if mx < i - mn:
        mx = i - mn
    elif mn > i:
        mn = i

print(mx)

Measured memory_bytes: 21868
def sort_str(str):
  return ''.join(sorted(list(str)))

n = int(input().rstrip())
s = [sort_str(input().rstrip()) for _ in range(n)]

ans = 0
pool = {}
for i in range(n):
  if not s[i] in pool.keys():
    pool[s[i]] = 0
  else:
    pool[s[i]] += 1
    ans += pool[s[i]]
print(ans)

Measured memory_bytes: 19472
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    string ans = "NO";
    if(a*b*c*d == 9*7*4 && (a+b+c+d)==(1+9+7+4))ans = "YES";

    PUTS(ans);
}

Measured memory_bytes: 256
import math
N,K = map(int,input().split())
A_s = list(map(int,input().split()))
S = sum(A_s)
divs = []
for i in range(1, round(math.sqrt(S)+1) ):
    if S%i==0:
        divs.append(i)
        divs.append(S//i)
answer = 1
for div in divs:
    r_s = []
    for A in A_s:
        r_s.append(A%div)
    r_s.sort()
    if sum(r_s[:-sum(r_s)//div]) <= K and answer < div:
        answer = div
    # for i,r in enumerate(r_s[-sum(r_s)//div:]):
    #     r_s[i] = 

print(answer)

Measured memory_bytes: 41580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);

   ll a;
   cin>>a;
   for(ll i=0;i<a;i++)
   {
       cout<<"ACL";
   }
   cout<<endl;

   return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<tuple<string,int,int>> data(n);
  for(int i=0;i<n;i++){
    string s;
    int p;
    cin>>s>>p;
    data[i]=make_tuple(s,100-p,i+1);
  }
  sort(data.begin(),data.end());
  for(int i=0;i<n;i++)cout<<get<2>(data[i])<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from itertools import accumulate
from bisect import bisect
n = int(input())
a = list(map(int, input().split()))
s = [0] + list(accumulate(a))
m = s[-1] // 2
r = bisect(s, m)
l = r - 1
ans = min(abs(s[-1] - s[l] * 2), abs(s[-1] - s[r] * 2))
print(ans)


Measured memory_bytes: 25768
#include<iostream>
#include<map>
using namespace std;
int n;
int a[1000005];
int mp[1000005];
int main(){
	cin >> n;
	for(int i = 2; i <= n; i++){
		cin >> a[i];
		mp[a[i]]++;
	}
	for(int i = 1; i <= n; i++)
		cout << mp[i] << endl;
}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 998244353
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
//#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   

int main() 
{ 
    fastio
    ll x, y;
    cin>>x>>y;
    if(4*x - y < 0) {
        cout<<"No"<<endl;
    }
    else if((4*x - y) % 2 !=0) {
        cout<<"No"<<endl;
    }
    else if((4*x-y)/2 > x) {
        cout<<"No"<<endl;
    }
    else {
        cout<<"Yes"<<endl;
    }
} 

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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 INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

string s,t,u;
cin >> s >> t;
int a,b;
cin >> a >> b;
cin >> u;

if(u == s) cout << a-1 << ' ' << b << endl;
else cout << a << ' ' << b-1 << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;


int main(){
  int n;
  cin >> n;
  ll ans=0;
  repi(i,1,n+1){
    if(i%3!=0 && i%5!=0){
      ans+=i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
	int n,l1,l2,i;
	string a, b;
	char ans[80];
	int ia,ib,sum;
	cin>>n;
	while(n--){
		cin>>a>>b;
		if(a.length()>80 || b.length()>80){
			cout<<"overflow"<<endl;
			continue;
		}
		if(a.length()==80 || b.length()==80){
			if((int)a[0]-'0'+(int)b[0]-'0'>9){
				cout<<"overflow"<<endl;
				continue;
			}
		}
		if(a.length()<b.length()){
			swap(a,b);
		}
		l1=a.length();
		l2=b.length();
		for(i=0;i<80;i++)ans[i]=0;
		for(i=1;i<l2+1;i++){
			ia=(int)a[l1-i]-(int)'0';
			ib=(int)b[l2-i]-(int)'0';
			sum=ia+ib;
			ans[80-i]+=sum+'0';
		}
		for(i=l2+1;i<l1+1;i++){
			ans[80-i]=a[l1-i];
		}
		for(i=79;i>=0;i--){
			if(ans[i]-'0'>9 && ans[i]!=0){
				ans[i]=ans[i]-10;
				if(ans[i-1]==0)ans[i-1]+=49;
				else ans[i-1]+=1;
			}
		}
		for(i=0;i<80;i++){
			if(ans[i]!=0){
				cout<<(int)ans[i]-'0';
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int m;
    cin >> m;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    rep(i, m) {
        if (!binary_search(all(a), b[i])) {
            puts("0");
            return 0;
        }
    }
    puts("1");
}



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

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

ll dp[2001][2001];

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

	int n;
	cin >> n;

	vector<pii> a(n);

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

	sort(a.begin(), a.end(), [](const pii& a, const pii& b) {
		return a.first > b.first;
	});

	for (int sum = 0; sum < n; sum++) {
		for (int l = 0; l <= sum; l++) {
			int r = sum - l;

			dp[l + 1][r] = max(dp[l + 1][r], dp[l][r] + 1LL * abs(l - a[sum].second) * a[sum].first);
			dp[l][r + 1] = max(dp[l][r + 1], dp[l][r] + 1LL * abs(n - r - 1 - a[sum].second) * a[sum].first);
		}
	}

	ll res = 0;

	for (int i = 0; i <= n; i++) {
		res = max(res, dp[i][n - i]);
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 26184
#include <bits/stdc++.h>
#define int long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 200005
using namespace std;

int tab[N];
int n, ans = 0;
int ile[20];

bool bad() {
    for(int i = 0; i < 20; ++i) if(ile[i] > 1) return true;
    return false;
}

main() {
    ios_base::sync_with_stdio(false);
    cin >> n; for(int i = 0; i < n; ++i) cin >> tab[i];


    for(int i = 0; i < 20; ++i) ile[i] = 0;

    int l = 0;

    for(int i = 0; i < n; ++i) {
        for(int x = 0; x < 20; ++x) {
            if(tab[i] & (1 << x)) ile[x]++;
        }
        while(l < n and bad()) {
            for(int x = 0; x < 20; ++x) {
                if(tab[l] & (1 << x)) ile[x]--;
            }
            l++;
        }

        if(l == n) break;

        ans += max(0ll,(i-l+1));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
n, m = map(int, input().split())
a = list(map(int, input().split()))

ans = "Yes"
vote = sum(a)

a_sort = sorted(a, reverse=True)

# print(vote, a_sort)

if a_sort[m-1] < vote * 1/(4*m):
  ans = "No"

print(ans)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  bool correct = true;
  int n, mod = int(1e9 + 7), ans = 1;
  cin >> n;
  int a[n];
  int b[n];
  for (int i = 0; i < n; ++i) b[i] = 0;
  for (int i = 0; i < n; ++i) cin >> a[i];
  if (n & 1) {
    for (int i = 0; i < n; ++i) b[a[i]] += 1;
    if (b[0] == 0) correct = false;
    for (int i = 2; i < n; i += 2) if (b[i] != 2) correct = false;
    if (correct) {
      for (int i = 0; i < n / 2; ++i) ans = (ans * 2) % mod; 
      cout << ans << '\n';
    } else cout << 0 << '\n';
  } else {
    for (int i = 0; i < n; ++i) b[a[i]] += 1;
    if (b[0] != 0) correct = false;
    for (int i = 1; i < n; i += 2) if (b[i] != 2) correct = false;
    if (correct) {
      for (int i = 0; i < n / 2; ++i) ans = (ans * 2) % mod;
      cout << ans << '\n';
    } else cout << 0 << '\n';
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 1e4+5;
const int maxn = 1e9+5;
const dd eps = 1e-6;
const ll mod = 1e9+7;

struct point{
  dd x,y;
}a[10];

int n,p[10];
dd down=1,up;

dd dis(point p1,point p2){
  dd dx = p1.x - p2.x,dy = p1.y - p2.y;
  return sqrt(dx*dx + dy*dy);
}

int main(){
  // freopen("input.txt","r",stdin);
  cin>>n;
  for(int i = 1;i <= n;i++) cin>>a[i].x>>a[i].y;
  for(int i = 1;i <= n;i++) p[i] = i;
  do{
    for(int i = 1;i < n;i++){
      up += dis(a[p[i]],a[p[i+1]]);
    }
  }while(next_permutation(p+1,p+1+n));
  for(int i = n;i >= 2;i--) down *= (dd)i;
  printf("%.10f\n",up/down);
  return 0;
}


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

using namespace std;

int main() {
	int N, Y;
	cin >> N >> Y;
	int x = -1;
	int y = -1;
	int z = -1;
	for (int i = 0;i<=N;++i) {
		for (int j = 0;j<=N-i;++j) {
			if (Y == 10000*i+5000*j + 1000*(N-i-j)) {
				x = i;
				y = j;
				z = N - i - j;
			}
		}
	}
	cout<< x << " " << y << " " << z << " " << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(void){
	int c[3],i,l,a,b,f;
	
	while(scanf(" %d %d %d",&c[0],&c[1],&c[2])!=EOF){
	f=0;
	for(i=1;i<=10;i++){
		if(c[0]+c[1]+i<=20 && i!=c[0] && i!=c[1] && i!=c[2])f++;
	}
	if(f>=4)printf("YES\n");
	else printf("NO\n");
	}
	
	return 0;
}
	

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

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


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

  string s;
  cin >> s;
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }else if(s == "Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int a;
  cin >> a;
  cout << a/3 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
int main(){
    ll n, ans=0, check = 1;
    string s;
    map<char, ll> S;
    char march[] = {'M', 'A', 'R', 'C', 'H'};
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> s;
        S[s[0]]++; 
    }
    for(ll i=0;i<5;i++){
        for(ll j=i+1;j<5;j++){
            for(ll k=j+1;k<5;k++){
                check = S[march[i]] * S[march[j]] * S[march[k]];
                ans += check;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

rooms = [
    [
        [0] * 10 for f in range(3)
    ] for b in range(4)
]


def print_rooms():
    for i, building in enumerate(rooms):
        if i != 0:
            print('#' * 20)
        for floor in building:
            print(' ' + ' '.join(map(str, floor)))


lines = int(sys.stdin.readline())
for _ in range(lines):
    b, f, r, v = map(int, sys.stdin.readline().strip().split())
    rooms[b-1][f-1][r-1] += v


print_rooms()



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<typename V> struct ConvexHull {
	deque<pair<V,V>> Q;
	V calc(pair<V,V> p, V x) {
		return p.first*x+p.second;
	}
	int dodo(pair<V,V> A,pair<V,V> B, pair<V,V> C) { // max or min
		return ((A.second-C.second)*(B.first-A.first)<=(A.second-B.second)*(C.first-A.first));
	}
	void add(V a, V b) { // add ax+b
		Q.push_back({a,b});
		int v;
		while((v=Q.size())>=3 && dodo(Q[v-3],Q[v-2],Q[v-1]))
			Q[v-2]=Q[v-1], Q.pop_back();
	}
	V query(V x) {
		int L=-1,R=Q.size()-1;
		while(R-L>1) {
			int M=(L+R)/2;
			(((calc(Q[M],x)>=calc(Q[M+1],x)))?L:R)=M;
		}
		return calc(Q[R],x);
	}
};

int N;
ll C,H[202020],R[202020];
ConvexHull<ll> cht;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>C;
	FOR(i,N) {
		cin>>H[i];
		if(i) {
			R[i]=cht.query(H[i])+H[i]*H[i];
		}
		cht.add(-2*H[i],H[i]*H[i]+R[i]+C);
	}
	
	cout<<R[N-1]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
  int n,i;
  ll a,b=0,res=0;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a;
    res+=max(b-a,(ll)0);
    b=max(a,b);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3596
[X,K,D]=[int(i) for i in input().split()]
X=abs(X)
H=X//D
if abs(H+1)<K:
	if (K-H)%2==0:
		print(abs(X-H*D))
	else:
		print(abs(X-H*D-D))
else:
	print(abs(X-K*D))

Measured memory_bytes: 61748
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main()
{
  int N, M;
  while (cin >> N >> M && N != 0) {
    vector<vector<int> > g(N);
    for (int i = 0; i < M; i++) {
      int s, t;
      cin >> s >> t;
      --s;  --t;
      g[s].push_back(t);
      g[t].push_back(s);
    }
    unsigned init = 0;
    for (int i = 0; i < N; i++) {
      int x;
      cin >> x;
      init |= (x<<i);
    }
    vector<vector<int> > switches(N);
    for (int i = 0; i < N; i++) {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int r;
        cin >> r;
        --r;
        switches[i].push_back(r);
      }
      sort(switches[i].begin(), switches[i].end());
    }

    queue<pair<int,unsigned> > q;
    static const int INF = 10000000;
    vector<vector<int> > dist(N, vector<int>(1<<N, INF));
    q.push(make_pair(0, init));
    dist[0][init] = 0;
    vector<vector<pair<int,unsigned> > > prev(N, vector<pair<int,unsigned> >(1<<N));
    while (!q.empty() && dist[N-1][1<<(N-1)] == INF) {
      int n = q.front().first;
      unsigned s = q.front().second;
      q.pop();

      for (vector<int>::const_iterator it = g[n].begin(); it != g[n].end(); ++it) {
        if (s & (1<<*it) && dist[n][s] + 1 < dist[*it][s]) {
          dist[*it][s] = dist[n][s] + 1;
          prev[*it][s] = make_pair(n, s);
          q.push(make_pair(*it, s));
        }
      }

      for (vector<int>::const_iterator it = switches[n].begin(); it != switches[n].end(); ++it) {
        if (*it != n) {
          unsigned t = s ^ (1<<*it);
          if (dist[n][s] + 1 < dist[n][t]) {
            dist[n][t] = dist[n][s] + 1;
            prev[n][t] = make_pair(n, s);
            q.push(make_pair(n, t));
          }
        }
      }
    }
    if (dist[N-1][1<<(N-1)] != INF) {
      cout << "You can go home in " << dist[N-1][1<<(N-1)] << " steps." << endl;
      int n = N-1;
      unsigned s = 1<<(N-1);
      vector<string> logs;
      for (int i = 0; i < dist[N-1][1<<(N-1)]; i++) {
        const int m = prev[n][s].first;
        const unsigned t = prev[n][s].second;
        ostringstream oss;
        if (n == m) {
          const unsigned u = s ^ t;
          int r;
          for (r = 0; r < N; r++) {
            if (u & (1<<r)) {
              break;
            }
          }
          oss << "Switch " << (s & (1<<r) ? "on" : "off") << " room " << r+1 << ".";
        } else {
          oss << "Move to room " << n+1 << ".";
        }
        logs.push_back(oss.str());
        n = m;
        s = t;
      }
      for (vector<string>::const_reverse_iterator it = logs.rbegin(); it != logs.rend(); ++it) {
        cout << *it << endl;
      }
    } else if (*min_element(dist[N-1].begin(), dist[N-1].end()) == INF) {
      cout << "Help me!" << endl;
    } else {
      cout << "You can not switch off all lights." << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

L,R,d=nm()
if(L%d==0):
    ans=R//d-L//d+1
else:
    ans=R//d-L//d

print(ans)

Measured memory_bytes: 10456
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  char x, y;
  cin >> x >> y;
  cout << (x < y ? '<' : x == y ? '=' : '>') << endl;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(int(1e6))

N, M = list(map(int, input().split()))

base = int(1e9 + 7)
ans = 0
if abs(N -M) > 1:
  pass
else:
  fact = 1
  for i in range(1, min(N+1, M+1)):
    fact = (fact * i) % (base)
  
  if N == M:
    ans = 2 * fact * fact
  else:
    ans = fact * fact * max(N, M)
    
ans = ans % base
print(ans)


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n;cin>>n&&n;){
		vi a(3*n);
		rep(i,3*n) cin>>a[i];
		sort(all(a));
		ll sum=0;
		rep(i,n) sum+=a[n+2*i];
		cout<<sum<<endl;
	}
}


Measured memory_bytes: 1408
import sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a = collections.Counter(a)
    t = 0
    for k, v in a.items():
        t += abs(v - 1)
    print(len(a) if t % 2 == 0 else len(a) - 1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62124
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      Set<Integer> set = new HashSet<Integer>();
      int n = sc.nextInt();
      for(int i = 0;i < n;i++){
      	int a = sc.nextInt();
        if(set.contains(a))set.remove(a);
        else set.add(a);
      }
      System.out.println(set.size());
    }
}


Measured memory_bytes: 62624
#include<stdio.h>
#include<stdlib.h>
#define N 100
#define white 0
#define black 2
#define gray 1

int A[N][N],color[N],d[N],f[N];
int t;

void visit(int u,int n){
  int i;
  color[u] = gray;
  d[u] = ++t;
  for(i=0;i<n;i++){
    if(A[u][i] == 0){
      continue;
    }
    if(color[i] == white){
      visit(i,n);
    }
  }
  color[u] = black;
  f[u] = ++t;
}

void dfs(int n){
  int u;
  for(u=0;u<n;u++){
    color[u] = white;
  }
  t = 0;
  for(u=0;u<n;u++){
    if(color[u] == white){
      visit(u,n);
    }
  }
}

int main(){
  int n,i,u,k,j,v;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = 0;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      A[u][v] = 1;
    }
  }

  dfs(n);

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
}
  
  



Measured memory_bytes: 2108
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if(a<b&&b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  int x[N], y[N], a[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }

  int l = 0, r = W, u = H, d = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] == 1) {
      if (l <= x[i]) {
        l = x[i];
      }
    }

    if (a[i] == 2) {
      if (r >= x[i]) {
        r = x[i];
      }
    }

    if (a[i] == 3) {
      if (d <= y[i]) {
        d = y[i];
      }
    }

    if (a[i] == 4) {
      if (u >= y[i]) {
        u = y[i];
      }
    }
  }

  int width = (r - l);
  int height = (u - d);

  if (width <= 0) width = 0;
  if (height <= 0) height = 0;
  cout << width * height << endl;
  return 0;
}

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

int main()
{
	int n,a,b,c,copy;

	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b>>c;
		if(b>a)
		{
			copy=a;
			a=b;
			b=copy;
		}
		if(c>a)
		{
			copy=a;
			a=c;
			c=copy;
		}
		if(a*a==b*b+c*c)
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;

	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}

bool d[3][3][4005];

int main(){
    vector<string> s(3);
    for(int i=0;i<3;i++) cin >> s[i];
    sort(s.begin(),s.end());
    int ans=6010;
    do{
        for(int i=0;i<3;i++){
            for(int j=0;j<3;j++){
                if(i>=j) continue;
                for(int k=0;k<s[i].size();k++){
                    bool ok=true;
                    for(int ni=k;ni<s[i].size();ni++){
                        int nj=ni-k;
                        if(nj>=s[j].size()) continue;
                        if(s[i][ni]=='?'||s[j][nj]=='?') continue;
                        if(s[i][ni]!=s[j][nj]) ok=false;
                    }
                    d[i][j][k]=ok;
                }
            }
        }
        auto f = [&](int i, int j, int k) {
            if (k >= s[i].size()) return true;
            return d[i][j][k];
        };
        for(int i=0;i<2005;i++){
            for(int j=0;j<2005;j++){
                if(!f(0,1,i)) continue;
                if(!f(1,2,j)) continue;
                if(!f(0,2,i+j)) continue;
                int now=0;
                now=max(now,i+(int)s[1].size());
                now=max(now,i+j+(int)s[2].size());
                now=max(now,(int)s[0].size());
                ans=min(ans,now);
            }
        }
    } while(next_permutation(s.begin(),s.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int getAllCase(vector<int> &a,int n){
  int retVal = 0;
  for(int t:a){
    if(t>=n){
      retVal++;
    }
  }
  return retVal;
}

int main() {
    ll N;
    cin >> N;
    Sieve sieve = Sieve(N);
    map<ll,ll> mp;
    for(int i=2;i<=N;i++){
      vector<P> factors = sieve.factor(i);
      for(P p:factors){
        mp[p.first] += p.second;
      }
    }
    vector<int> num;
    for(auto itr = mp.begin();itr != mp.end();++itr){
      if(itr->second>=2){
        num.push_back(itr->second);
      }
    }
    ll ans =0;
      
      int n3 = getAllCase(num,2);
      int n5 = getAllCase(num,4);
      int n15 = getAllCase(num,14);
      int n25  = getAllCase(num,24);
      int n75 = getAllCase(num,74);
      //3,5,5の場合
      ans += ((n5*(n5-1))/2)*(n3-2);
      //3,25の場合
      ans += n25*(n3-1);
      //5,15の場合
      ans += n15*(n5-1);
      //75の場合
      ans += n75;
      cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A.reverse()
B.reverse()

cnt = 0
for i in range(n):
    if A[i] <= B[i]:
        cnt += A[i]
        B[i] -= A[i]
        A[i] = 0
        if A[i+1] >= B[i]:
            cnt += B[i]
            A[i+1] -= B[i]
        else:
            cnt += A[i+1]
            A[i+1] = 0
    else:
        cnt += B[i]
        B[i] = 0
#print(A)
#print(B)
print(cnt)


Measured memory_bytes: 82148
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
   
using namespace std;
typedef long long int ll;
  
int main()
{
	int a, b, h;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &h);
  
    printf("%d\n", (a+b)*h/2);
  
    return 0;
}

Measured memory_bytes: 256