akhauriyash/Code-Regression huggingface dataset:
from itertools import *
import copy
from collections import *


N=int(input())
A=list(map(int,input().split()))
idle_max=10**9
peki2=[]
for i in range(1,100):
    a=2**i
    if a<=2*idle_max:
        peki2.append(a)
peki2.sort(reverse=True)
lst=[[],[]]
for a in A:
    if a%2:
        lst[1].append(a)
    else:
        lst[0].append(a)

lst[0].sort(reverse=True)
lst[1].sort(reverse=True)
setlst=[set(lst[0]),set(lst[1])]
Counerlst=[Counter(lst[0]),Counter(lst[1])]

count=0
for l in range(2):
    for n in lst[l]:
        if n in setlst[l]:
            for p in peki2:
                a=p-n

                if a in setlst[l]:
                    if n==a:
                        if Counerlst[l][n]>=2:
                            count+=1
                            Counerlst[l][n]-=2
                            if Counerlst[l][n]==0:
                                setlst[l].remove(n)
                    else:

                        count+=1
                        Counerlst[l][a]-=1
                        Counerlst[l][n]-=1
                        if Counerlst[l][a]==0:
                            setlst[l].remove(a)
                        if Counerlst[l][n]==0:
                            setlst[l].remove(n)
                    break
print(count)


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


int main()
{
  int count=0,N,M,*H,A,B;
  bool *best;
  cin>>N>>M;
  
  H=new int[N];
  best=new bool[N];
  for(int i=0;i<N;i++)
  {
    cin>>H[i];
    best[i]=true;
  }
  for(int i=0;i<M;i++)
  {
    cin>>A>>B;
    A--;
    B--;
    if(H[A]>=H[B])
      best[B]=false;
    if(H[A]<=H[B])
      best[A]=false;
  }
  for(int i=0;i<N;i++)
    if(best[i])
      count++;
  
  cout<<count;
  
  delete[] H;
  delete[] best;
}

Measured memory_bytes: 3408
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector< vector<long long>>
#define mi map<int,int>
#define pi pair<int,int>

#define Fori(i,a,b) for(int i=a; i<b; i++)
#define Ford(i, a, b) for(int i=a; i>=b; i--)

#define pb push_back
#define mp make_pair

#define read(a, n) for(int i=0; i<n; i++) cin >> a[i];
#define print(x) cout << "X: == " << x << endl;
#define printMap(a) for(auto it=a.begin() ; it!= a.end() ; it++) {cout << it->first << "  " << it->second << endl; }
#define printVector(a) for(auto it = a.begin() ; it!= a.end() ;it++) {cout << *it << endl;}
#define M 1000000007
using namespace std;
int main() {
    IOS
    ll n, k;
    cin >> n >> k;
    vl a(n);
    ll positive=0, negative = 0, zero=0;
    Fori(i, 0, n) {
        cin >> a[i];
        if(a[i] > 0){
            positive++;
        } else if(a[i] == 0) {
            zero++;
        } else {
            negative++;
        }
    }
    sort(a.begin(), a.end());
    int i=0, j=n-1;
    vl b;
    ll temp = k;
    while(k--) {
        if(negative == n) {
            if(temp % 2) {
                b.push_back(a[j--]);
                continue;
            } else {
                b.push_back(a[i++]);
                continue;
            }
        }  else if(positive == n) {
            b.push_back(a[j--]);
            continue;
        }
        if(k == 0) {
            b.push_back(a[j--]);
            continue;
        }
        // if(k == 2) {
        //     b.push_back(a[i++]);
        //     b.push_back(a[i++]);
        //     k--;
        //     continue;
        // }
        ll prod1=1,prod2=1;
        prod1 = a[j] * a[j-1];
        prod2 = a[i] * a[i+1];
        if(prod1 > prod2) {
            b.push_back(a[j--]);
            // b.push_back(a[j--]);
            // k--;
        } else {
            b.push_back(a[i++]);
            b.push_back(a[i++]);
            k--;
        }
    }
    sort(b.begin(), b.end());
    ll ans = 1;
    ll cond = b.size();
    for(ll i=0; i<cond; i++) {
        ans *= b[i];
        ans = ans % M;
    }
    if(ans < 0) {
        ans = M + ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6824
#include <stdio.h>

int main(void) {
    int n, m, l, r, i, c = 0;
    int ml = 0, mr = 100000;
    scanf("%d%d", &n, &m);

    for (i = 0; i < m; i++) {
        scanf("%d%d", &l, &r);
        if (ml < l) ml = l;
        if (mr > r) mr = r;
    }
 
    for (i = 0; i < n; i++) {
        c += (i + 1 >= ml && i + 1 <= mr);
    }

    printf("%d\n", c);
    return 0;
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    vector<ll> sum(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + A[i];

    ll ans = (ll)INF * INF;
    int l = 1, r = 3;
    for (int i = 2; i < N - 1; ++i) {
        ll P = sum[l], Q = sum[i] - sum[l];
        while (l + 1 < i && abs(sum[l + 1] - (sum[i] - sum[l + 1])) < abs(P - Q)) {
            l++;
            P = sum[l], Q = sum[i] - sum[l];
        }
        r = max(r, i + 1);
        ll R = sum[r] - sum[i], S = sum[N] - sum[r];
        while (r + 1 < N && abs((sum[r + 1] - sum[i]) - (sum[N] - sum[r + 1])) < abs(R - S)) {
            r++;
            R = sum[r] - sum[i], S = sum[N] - sum[r];
        }
        ans = min(ans, max({P, Q, R, S}) - min({P, Q, R, S}));
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
/*
 * Author: RainAir
 * Time: 2019-10-27 21:12:58
 */
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define fi first
#define se second
#define U unsigned
#define P std::pair
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
#define int LL
const int MAXN = 2e5 + 5;
int n,k;
int a[MAXN],f[MAXN];

struct Node{
    int a,f,v;

    Node(int a=0,int f=0,int v=0) : a(a),f(f),v(v) {}

    bool operator < (const Node &t) const {
        return v < t.v;
    }
};

std::vector<Node> q;

inline bool chk(int k){
    int ans = 0;
    for(auto x:q){
        if(x.v <= k) break;
        ans += std::ceil(1.0*(x.v-k)/x.f);
    }
    return ans <= ::k;
}

signed main(){
    scanf("%lld%lld",&n,&k);
    FOR(i,1,n) scanf("%lld",a+i);
    FOR(i,1,n) scanf("%lld",f+i);
    std::sort(a+1,a+n+1);std::sort(f+1,f+n+1);std::reverse(f+1,f+n+1);
    FOR(i,1,n) q.pb(Node(a[i],f[i],a[i]*f[i]));
    std::sort(all(q));std::reverse(all(q));
    int l = 0,r = 1e18,ans = -1;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(chk(mid)) r = mid-1,ans = mid;
        else l = mid+1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 11632
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  int d1 = abs(x - a);
  int d2 = abs(x - b);
  cout << (d1 < d2 ? "A" : "B") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int N;
  cin>>N;
  int a[N];
  int count[N];
  REP(i, N) count[i]=0;
  REP(i, N){
    cin>>a[i];
    ++count[a[i]];
  }
  if(N==1){
    cout<<1<<endl;
    return 0;
  }

  if(N%2==0){
    for(int i=1; i<N; i=i+2){
      if(count[i] !=2){
        cout<<0<<endl;
        return 0;
      }
    }
  }
  else{
    if(count[0]!=1){
      cout<<0<<endl;
      return 0;
    }
    for(int i=2; i<N; i=i+2){
      if(count[i]!=2){
        cout<<0<<endl;
        return 0;
      }
    }
  }

  LL r = N/2;
  LL ans=1;
  REP(i, r) ans = ans * 2%MOD;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[][] graph = new int[n][n];
      String[] vInfo;
      int degree;

      for(int i=0; i<n; i++) {
        vInfo = br.readLine().split(" ");
        degree = Integer.parseInt(vInfo[1]);
        for(int j=0,k=2,v=0; j<degree; j++) {
          v = Integer.parseInt(vInfo[k++]);
          graph[i][v-1] = 1;
        }
      }

      StringBuilder buf = new StringBuilder();
      for (int[] i : graph) {
        for (int v : i) {
          buf.append(v).append(" ");
        }
        buf.setLength(buf.length()-1);
        buf.append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }
}


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

int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    for (ll& e : p) cin >> e;
    for (ll& e : q) cin >> e;
    for (ll& e : r) cin >> e;
    sort(p.rbegin(), p.rend());
    while (p.size() > x) p.pop_back();
    sort(q.rbegin(), q.rend());
    while (q.size() > y) q.pop_back();
    sort(r.rbegin(), r.rend());
    while (r.size() > x + y) r.pop_back();
    multiset<ll> s;
    for (ll& e : p) {
        s.insert(e);
        if (s.size() > x + y) s.erase(s.begin());
    }
    for (ll& e : q) {
        s.insert(e);
        if (s.size() > x + y) s.erase(s.begin());
    }
    for (ll& e : r) {
        s.insert(e);
        if (s.size() > x + y) s.erase(s.begin());
    }
    ll ans = 0;
    for (ll e : s) ans += e;
    cout << ans << endl;
}

Measured memory_bytes: 11008
import sys
from collections import Counter

h, w = map(int, input().split())
s_list = [list(input()) for i in range(h)]

def check_mine(v):
    if v == '#':
        return 1
    else:
        return 0

for i in range(h):
    for j in range(w):
        if s_list[i][j] == '.':
            tmp = 0
            if i != 0:
                if j != 0:
                    tmp += check_mine(s_list[i-1][j-1])
                if j != w-1:
                    tmp += check_mine(s_list[i-1][j+1])
                tmp += check_mine(s_list[i-1][j])

            if i != h-1:
                if j != 0:
                    tmp += check_mine(s_list[i+1][j-1])
                if j != w-1:
                    tmp += check_mine(s_list[i+1][j+1])
                tmp += check_mine(s_list[i+1][j])

            if j != 0:
                tmp += check_mine(s_list[i][j-1])

            if j != w-1:
                tmp += check_mine(s_list[i][j+1])
            
            s_list[i][j] = str(tmp)

for i in s_list:
    print(''.join(i))


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

int main(void){
	int N, K;
	cin >> N >> K;
	int p[N];
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	sort(p,p+N);

	int tot = 0;
	for (int i = 0; i < K; i++) {
		tot += p[i];
	}

	cout << tot << endl;

	return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll dp[200005][2];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    if(s.size()==1)
    {
    	cout<<1<<"\n";
    	return 0;
    }
    dp[0][1]=1;
    dp[1][2]=1;
    if(s[1]!=s[0])
    	dp[1][1]=2;
    rep(i,2,sz(s))
    {
    	if(dp[i-1][2])
    	dp[i][1]=1+dp[i-1][2];
    	if(dp[i-1][1]&&s[i]!=s[i-1])
    		dp[i][1]=max(dp[i][1],1+dp[i-1][1]);
    	dp[i][2]=1+dp[i-2][1];
    	if(dp[i-2][2]&&!(s[i-3]==s[i-1]&&s[i-2]==s[i]))
    		dp[i][2]=max(dp[i][2],1+dp[i-2][2]);
    }
    cout<<max(dp[sz(s)-1][1],dp[sz(s)-1][2]);
}


Measured memory_bytes: 3732
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n, a) for(int i = a; i < n; ++i)

int main(void) {
  int n, i, j, ans = 0;
  scanf("%d", &n);
  int a[n];
  rep(i, n) scanf("%d", &a[i]);
  int flag = 1;
  while(flag) {
    flag = 0;
    for(j = n - 1; j > 0; --j) {
      if(a[j] < a[j - 1]) {
        int t;
        t = a[j], a[j] = a[j - 1], a[j - 1] = t;
        flag = 1;
        ++ans;
       }
    }
  }
  rep(i, n) {
    if(i) printf(" %d", a[i]);
    else printf("%d", a[i]);
  }
  printf("\n%d\n", ans);
  return 0;
}


Measured memory_bytes: 2728
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<ctype.h>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<math.h>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<stdio.h>
#include<stdlib.h>
#include<streambuf>
#include<string.h>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
char s[100010];
bool dp[100010];
int l;
bool can1(int i){
	if (i+4>l) return 0;
	if (s[i]!='e') return 0;
	if (s[i+1]!='r') return 0;
	if (s[i+2]!='a') return 0;
	if (s[i+3]!='s') return 0;
	if (s[i+4]!='e') return 0;
	return 1;
}
bool can2(int i){
	if (i+5>l) return 0;
	if (s[i]!='e') return 0;
	if (s[i+1]!='r') return 0;
	if (s[i+2]!='a') return 0;
	if (s[i+3]!='s') return 0;
	if (s[i+4]!='e') return 0;
	if (s[i+5]!='r') return 0;
	return 1;
}
bool can3(int i){
	if (i+4>l) return 0;
	if (s[i]!='d') return 0;
	if (s[i+1]!='r') return 0;
	if (s[i+2]!='e') return 0;
	if (s[i+3]!='a') return 0;
	if (s[i+4]!='m') return 0;
	return 1;
}
bool can4(int i){
	if (i+6>l) return 0;
	if (s[i]!='d') return 0;
	if (s[i+1]!='r') return 0;
	if (s[i+2]!='e') return 0;
	if (s[i+3]!='a') return 0;
	if (s[i+4]!='m') return 0;
	if (s[i+5]!='e') return 0;
	if (s[i+6]!='r') return 0;
	return 1;
}

int main(void){
	char c=getchar();
	while(c!=10&&c!=32&&~c){
		s[++l]=c;
		c=getchar();
	}
	if (can1(1)) dp[5]=1;
	if (can2(1)) dp[6]=1;
	if (can3(1)) dp[5]=1;
	if (can4(1)) dp[7]=1;
	for (int i=2;i<l;i++){
		if (!dp[i]) continue;
		if (can1(i+1)) dp[i+5]=1;
		if (can2(i+1)) dp[i+6]=1;
		if (can3(i+1)) dp[i+5]=1;
		if (can4(i+1)) dp[i+7]=1;
	}
	if (dp[l]){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, t, l;
    cin >> n >> l >> t;
    vector<pll> ant(n);
    rep(i,n){
        ll x, w;
        cin >> x >> w;
        ant[i] = mp(x, w);
    }
    vll res(n);
    rep(i,n){
        ll move = t;
        if (ant[i].S==2)
            move *= -1;
        move = (move % l + l) % l;
        res[i] = (ant[i].F + move) % l;
    }
    ll cnt = 0;
    if (ant[0].S==1){
    repf(i,1,n){
        if (ant[i].S==ant[0].S)
            continue;
        if (2*t<ant[i].F-ant[0].F)
            continue;
        cnt += max(0ll, 1 + (2 * t - (ant[i].F - ant[0].F)) / l);
    }}
    else{
        repf(i,1,n){
            if (ant[i].S==ant[0].S)
                continue;
            if (2*t<(l+ant[0].F-ant[i].F))
                continue;
            cnt -= max(0ll, 1 + (2 * t - (ant[0].F + l - ant[i].F)) / l);
        }
    }
    cnt = (cnt % n + n) % n;
    vll ans(n);
    ll zero = res[0];
    ll reres = 0;
    sort(all(res));
    rep(i,n){
        if (i<n-1 && res[i]==zero && res[i+1]==zero){
            if (ant[0].S==1)
                reres = i + 1;
            else
                reres = i ;
            break;
        }
        else if (res[i]==zero){
            reres = i;
            break;
        }
    }
    ans[cnt] = reres;
    repf(i,1,n){
        ans[(cnt + i) % n] = (reres + i) % n;
    }
    rep(i, n) cout << res[ans[i]] << ENDL;
    //res:蟻のいる位置。
    //0の蟻がいる位置にcntの番号がある
    //ans：res[i]にいる蟻の番号？
}

Measured memory_bytes: 4352
#include<stdio.h>
#define N 25
#define NIL -1
int Pre(int t),In(int t),Post(int t);
struct Node{
  int p,l,r;
};
struct Node A[N];

int main(){
  int i,j,n,id,h,d;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p=NIL;
    A[i].l=NIL;
    A[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&h,&d);
    A[h].p=id;
    A[d].p=id;
    A[id].l=h;
    A[id].r=d;
  }
  for(i=0;i<n;i++){
    if(A[i].p==NIL)
      break;
  }
  printf("Preorder\n");
  Pre(i);
  printf("\n");
  printf("Inorder\n");
  In(i);
  printf("\n");
  printf("Postorder\n");
  Post(i);
  printf("\n");
  return 0;
  }
  int Pre(int t){
    printf(" %d",t);
    if(t!=NIL){
      if(A[t].l!=NIL)Pre(A[t].l);
      if(A[t].r!=NIL)Pre(A[t].r);
    }
    return 0;
  }
  int In(int t){
    if(t!=NIL){
      if(A[t].l!=NIL)
        In(A[t].l);
      printf(" %d",t);
      if(A[t].r!=NIL)
        In(A[t].r);
    }
    return 0;
  }

  int Post(int t){
    if(t!=NIL){
      if(A[t].l!=NIL)
        Post(A[t].l);
      if(A[t].r!=NIL)
        Post(A[t].r);
    }
    printf(" %d",t);
    return 0;
  }



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
//char a[100][100];

int main(){
    string s[3];
    for(int i=0;i<3;i++){
        cin>>s[i];
    }
    cout<<s[0][0]<<s[1][0]<<s[2][0]<<'\n';
    return 0;
}


Measured memory_bytes: 256
import fractions


def calc(x1, y1, x2, y2):
    return 2 * (x2 - x1), 2 * (y2 - y1), x2 ** 2 + y2 ** 2 - x1 ** 2 - y1 ** 2


n = int(input())
for _ in range(n):
    x1, y1, x2, y2, x3, y3 = map(float, input().split())
    cx1, cy1, z1 = calc(x1, y1, x2, y2)
    cx2, cy2, z2 = calc(x1, y1, x3, y3)
    gcd = fractions.gcd(cx1, cx2)
    r1, r2 = cx2 // gcd, cx1 // gcd
    dcy = r1 * cy1 - r2 * cy2
    dz = r1 * z1 - r2 * z2
    y = dz / dcy
    try:
        x = (z1 - cy1 * y) / cx1
    except ZeroDivisionError:
        x = (z2 - cy2 * y) / cx2
    r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
    print(*map(lambda x: '{:.3f}'.format(round(x, 3)), (x, y, r)))

Measured memory_bytes: 10188
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""
各マスのdp
下から来たものと左から来たものを足す
その後、重なっているところを引く
"""
MOD = 998244353
A, B, C, D = lr()  # Cは縦
dp = [[0] * (D+1) for _ in range(C+1)]   # 1-indexed
dp[A][B] = 1
for i in range(A, C+1):
    for j in range(B, D+1):
        dp[i][j] += dp[i-1][j] * j + dp[i][j-1] * i
        dp[i][j] -= dp[i-1][j-1] * (i-1) * (j-1)
        dp[i][j] %= MOD

answer = dp[C][D]
print(answer%MOD)


Measured memory_bytes: 136576
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) vc<vc<T>> xs(n, vc<T>(m)); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    Sort(a);
    Unique(a);
    CoutYN(a.size() == n);
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
long long n, f[45];
void fibonacci() {
	f[0] = f[1] = 1;
	for (int i = 2; i < 45; i++)
		f[i] = f[i - 1] + f[i - 2];
}
int main() {
	fibonacci();
	cin >> n;
	cout << f[n] << endl;
}


Measured memory_bytes: 3084
def main():
    a, b, k = map(int, input().split())
    count = 0
    for i in range(max(a, b), 0, -1):
        if a % i == 0 and b % i == 0:
            count += 1
        if count == k:
            print(i)
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;

int main(){
    int ans=10000000;
    int n,l;
    cin >> n >> l;
    int sum=n*l+n*(n-1)/2;
    for(int i=0;i<n;i++){
        int summ = sum-(l+i);
        int a=abs(sum-summ);
        ans=min(ans,a);
    }
    for(int i=0;i<n;i++)
    if(ans==abs(l+i)) cout << sum-(l+i);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int n;
  cin >> n;
  lvec a(n);
  ll sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  ll x = 0;
  ll y = sum;
  ll minDiff = INF;
  ll diff = INF;
  REP(i, n - 1) {
    x += a[i];
    y = sum - x;
    diff = abs(x - y);
    minDiff = min(minDiff, diff);
  }
  cout << minDiff << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=0;
    int cr=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
        cr++;
    }

    for(int i=cr;i<n;i++)
    {
        if(s[i]=='R')
        c++;
    }

    cout<<c;
    return 0;
}

Measured memory_bytes: 3740
from bisect import bisect_right

N = int(input())
P = list(map(int, input().split()))
X = [0] + list(map(int, input().split()))

C = [[] for _ in range(N+1)]
for i in range(N-1):
    C[P[i]].append(i+2)
W = [(-1, -1)] * (N+1)

def solve(v):
    if not C[v]:
        return (X[v], 0)
    A = []
    total = 0
    for u in C[v]:
        A.append(W[u])
        total += sum(W[u])
    n = len(A)
    dp = [set() for _ in range(N+1)]
    dp[0].add(0)
    for i in range(n):
        x, y = A[i]
        for z in dp[i]:
            dp[i+1].add(x + z)
            dp[i+1].add(y + z)
    B = sorted(dp[n])
    idx = bisect_right(B, X[v]) - 1
    if idx == -1:
        print("IMPOSSIBLE")
        exit()
    x, y = X[v], total - B[idx]
    return (x, y)

def rec(v, prex):
    for u in C[v]:
        rec(u, v)
    W[v] = solve(v)

rec(1, 0)
print("POSSIBLE")


Measured memory_bytes: 108508
var s:String;i:Longint;f:boolean;
begin
	readln(s);
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='a' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('a');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='b' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('b');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='d' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('d');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='f' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('f');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='i' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('i');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='p' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('p');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='y' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('y');
		exit;
	end;
	f:=false;
	for i:=1 to length(s) do begin
		if s[i]='z' then begin
			f:=true;
			break;
		end;
	end;
	if not f then begin
		writeln('z');
		exit;
	end;
	writeln('None');
end.


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    if(a <= 999 && a >= 100){
    System.out.println("ABC" + a);
    }else{
    System.out.println("ABCの回数が違反しています");
    }
  }
}

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

typedef long long ll;

int N;
ll K;
vector<bool> visited;
vector<int> dic;
vector<int> A;

int dfs(int cur){
    K--;
    if(visited[cur]) return cur;
    if(K == 0) return cur;
    visited[cur] = true;
    dic.push_back(cur);
    return dfs(A[cur]);
}

int main(){
    cin>>N>>K;
    A.resize(N);
    visited.resize(N);
    fill(visited.begin(),visited.end(),false);    

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

    visited[0] = true;
    dic.push_back(0);

    int cur = dfs(A[0]);
    ll idx = 0;
    vector<int> last;

    int i;  
    for(i=0; i<(int)dic.size(); i++){
        if(dic[i] == cur){
            idx = i;
            last.push_back(dic[i]);
            break;
        } 
    }

    for(int j=i+1; j<(int)dic.size(); j++){
        last.push_back(dic[j]);
    }

    idx = (ll)dic.size() - idx;

    if(K == 0) cout<<(cur+1)<<endl;
    else cout<<(last[K%idx]+1)<<endl;

    return 0;

}

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

int main(){
    string S,T,U;
    int A,B;
    cin>>S>>T>>A>>B>>U;
    if (U==S){
        --A;
    }else if(U==T){
        --B;
    }
    cout<<A<<" "<<B<<endl;
}


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


int main() {
  long n,k;
  cin>>n>>k;
  vector<long>a(n),d(n);
  vector<long>c(n+2);
  rep(i,n){
    cin>>a.at(i);
    d.at(i)=a.at(i);
  }
  
  if(k<100){
  while(k--){
    rep(i,n+2){
      c.at(i)=0;
    }
  rep(i,n){
    c[max(0L,i-d.at(i))]++;
    c[min(n,i+d.at(i))+1]--;
  }
  rep2(i,1,n+2){
    c.at(i)+=c.at(i-1);
  }
  
  rep(i,n){
    d.at(i)=c.at(i);
  }
  }
    rep(i,n){
      cout<<c.at(i)<<" ";
    }
  
  }
  else{
    rep(i,n){
      cout<<n<<" ";
    }
  }
}



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

int main(){
    int N;
    cin >> N;
    for(long double x = 0; x <= N; x++){
        if(floor(x*1.08) == N){
            cout << x << endl;
            return 0;
        }
    }

    cout << ":(" << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, X, L[110];

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

    std::cin >> N >> X;

    for(int i=0;i<N;++i){
        std::cin >> L[i];
    }

    int t = 1, cur = 0;
    for(int i=0;i<N;++i){
        cur += L[i];
        
        if(cur <= X){
            t += 1;
        }
    }

    std::cout << t << std::endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N;
vector<ll> A;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<ll> cum_sum(N + 1, 0);
  vector<ll> cum_xor(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cum_sum[i + 1] = cum_sum[i] + A[i];
    cum_xor[i + 1] = cum_xor[i] ^ A[i];
  }

  ll ans = 0;
  ll r = 1;
  for (ll l = 0; l < N; l++) {
    ll sum = cum_sum[r] - cum_sum[l];
    ll xr = cum_xor[r] ^ cum_xor[l];
    while (r <= N && sum == xr) {
      ans += (r - l);
      r++;
      sum = cum_sum[r] - cum_sum[l];
      xr = cum_xor[r] ^ cum_xor[l];
    }
  }

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

Measured memory_bytes: 4992
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
    
    int k;
    cin>>k;
    cout<<(k/2)*(k-k/2)<<endl;
    
}

Measured memory_bytes: 256
'use strict';
process.stdin.on('data', function(chunk) {
   
  var inputs = chunk.toString().trim().split('\n');
  var cols = inputs.filter(function(v) {
    return v !== '0 0';
  })
  .map(function(v) {
    return v.split(' ')
          .map(Number)
          .sort(function(a ,b) {
            return a - b;
          })
          .join(' ');
  })
  .join('\n');
   
  console.log(cols);
   
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

int main() {
  int N, H, W, A, B;
  cin >> N >> H >> W;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    if (H <= A && W <= B)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/

inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
int k[206]={0,300000,200000,100000,0};
/*======================================================================*/
int main()
{
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int a,b;
  cin>>a>>b;
  cout<<k[a]+k[b]+(a==1&&b==1?400000:0);
  return 0;
}


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



int main(){
    int i, j, k;
    long long int Items;
    long long int maxWeight;
    scanf("%lld %lld",&Items, &maxWeight);
    int weight[Items+100], value[Items+100];
    for(i = 1; i <= Items; i++)
    {
        scanf("%lld %lld",&weight[i],&value[i]);
    }
    long long int DP[Items+100][maxWeight+100];
    memset(DP, 0, sizeof(DP));

    for(i = 1; i <= Items; i++)
    {
        for(j = 0; j <= maxWeight; j++)
        {
            //SKIP
            DP[i][j] = DP[i-1][j];

            //Take
            if(weight[i] <= j)
            {
                DP[i][j] = max( DP[i][j], value[i] + DP[i-1][j - weight[i]] );
            }
        }
    }
    printf("%lld\n",DP[Items][maxWeight]);


    return 0;
}



Measured memory_bytes: 156672
/*
Author : N_o_o_B
Created : April 22 2020 15:49:12 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;
    
    int a,b,c;
    cin >> a >> b >> c;

    set<tuple<int,int,int>> s;
    int ans = 0;
    while(s.count(make_tuple(a,b,c))==0)
    { 
        s.insert(make_tuple(a,b,c));
        if(a%2 or b%2 or c%2){
            cout << ans << endl;
            return 0;
        }
        ans++;
        int na = (b+c)/2;
        int nb = (a+c)/2;
        int nc = (a+b)/2;
        a = na,b = nb,c = nc;
    }

    cout << -1 << endl;

    time_taken();
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc011.contest.atcoder.jp/tasks/agc011_a>
問題文============================================================
 高橋空港には，毎日飛行機で N 人の乗客が到着します． i 番目の乗客は時刻 Ti に到着します．
 
 高橋空港に到着する乗客は全員バスで市内へ移動します．
 どのバスも定員は C 人であり，C 人以下の乗客を乗せることができます．
 飛行機の乗客は，飛行機の到着時刻よりも早く出発するバスには乗ることができません．
 また，飛行機の到着時刻から K の時間が経過した後にもバスに乗れていないと，怒り出してしまいます．
 そのため，i 番目の乗客は，出発時刻が Ti 以上 Ti+K 以下であるようなバスに乗れるようにしないといけません．
 
 この条件のもとで，うまくバスの出発時刻を定めるとき，必要なバスの数の最小値を求めてください．
 ただし，バスの出発時刻は必ずしも整数である必要はなく，同じ時刻に出発するバスが複数あってもかまいません．
=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,C,K; cin >> N >> C >> K;
    vector<ll> T(N);
    for(auto &in:T) cin >> in;
    sort(T.begin(),T.end());
    ll ans = 1;
    ll c = 0;
    ll from = 0;
    for(int i = 0; i < N;i++){
        if(c == C){
            ans++;
            c = from = 0;
        }
        
        if(c == 0){
            c++;
            from = T[i];
        }else{
            if(T[i] - from<=K){
                c++;
            }else{
                ans++;
                c = 1;
                from = T[i];
            }
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import heapq
from collections import defaultdict

class PriorytyQueue(object):

    def __init__(self, arr, target='min'):
        self.arr = arr
        self.target = target
        self._heapify()
    
    def _heapify(self):
        if self.target == 'max':
            self.arr = list(map(lambda x:x*(-1), self.arr))
        heapq.heapify(self.arr)
    
    def push(self, x):
        if self.target == 'max':
            x *= -1
        heapq.heappush(self.arr, x)

    def pop(self):
        res = heapq.heappop(self.arr)
        if self.target == 'max':
            return res*(-1)
        else:
            return res
    
    def get_arr(self):
        if self.target == 'max':
            return list(map(lambda x:x*(-1), self.arr))
        else:
            return self.arr
    
    def is_empty(self):
        return len(self.arr) == 0

n, m = map(int, input().split())
jobs = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    if a > m:
        continue
    jobs[a].append(b)

res = 0
candidates = PriorytyQueue(arr=[],
                           target='max')
for d in range(1, m+1):
    if d in jobs.keys():
        for m in jobs[d]:
            candidates.push(m)
    if not(candidates.is_empty()):
        res += candidates.pop()
print(res)

Measured memory_bytes: 27652
N = int(input())
h = list(map(int, input().split()))
dp = [0 for i in range(N)]
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[N - 1])

Measured memory_bytes: 13980
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 10000000
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;

int h,w;
int ans;
int f[10],stage[10][10000];

int counter(void){
  int tmp, res = 0;
  rep(j,w){
    tmp = 0;
    rep(i,h)if(f[i] && !stage[i][j] || !f[i] && stage[i][j])tmp++;
    if(tmp < h - tmp)res += h - tmp;
    else res += tmp;
  }
  return res;
}

void solve(int x){
  int res;
  if(x == h){
    res = counter();
    if(ans < res) ans = res;
    return;
  }
  f[x] = 0;
  solve(x+1);
  f[x] = 1;
  solve(x+1);
}

int main(){
  while(scanf("%d%d",&h,&w) && h|w){
    rep(i,h)rep(j,w)scanf("%d",&stage[i][j]);
    ans = 0;
    solve(0);
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1576
// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(0);  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x);
#define rep(i,a,n) for(int ( i ) = ( a ) ;( i ) <( n );( i )++)
 
 
int main()
{
    fast_io
    
    int h,w;
    cin >> h >> w ;

    int c[11][11] ;
    rep(i,0,10) rep(j,0,10) cin >> c[i][j];

    int a[h+1][w+1] ;
    rep(i,1,h+1) rep(j,1,w+1) cin >> a[i][j] ;

    rep(k,0,10) rep(i,0,10) rep(j,0,10) c[i][j] = min(c[i][j],c[i][k]+c[k][j]);

    /*
    rep(i,0,10)
    {
        rep(j,0,10) cout << c[i][j] << " ";
        cout << endl;
    }
    */

    int sum = 0 ;
    rep(i,1,h+1) rep(j,1,w+1) sum += (a[i][j]>=0?c[a[i][j]][1]:0);

    cout << sum << endl;


    return 0;
}


 

Measured memory_bytes: 3768
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

int comp(const void* a, const void* b){
	return *(int*)a - *(int*)b;
}

int main() {
	string s;
	int ans = 0;
	cin >> s;
	rep(i, 4){
		if(s[i] == '+'){
			++ans;
		}else{
			--ans;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(){
    int x,y,a,b,c; cin>>x>>y>>a>>b>>c;
    long long d=0;
    vector<int> p(a),q(b),r(c);
    rep(i,a) cin>>p[i]; rep(i,b) cin>>q[i]; rep(i,c) cin>>r[i];
    sort(p.rbegin(),p.rend()); sort(q.rbegin(),q.rend());
    rep(i,x) r.push_back(p[i]); rep(i,y) r.push_back(q[i]);
    sort(r.rbegin(),r.rend());
    rep(i,x+y) d+=r[i]; cout<<d;
}

Measured memory_bytes: 5640
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

lli gcd(lli x, lli y)
{
        if (y == 0) {
                return x;
        } else {
                return gcd(y, x % y);
        }
}

lli lcm(lli x,lli y){
	return ((x/gcd(x,y))*y);
}

/*aまでの数でcで割り切れない数*/
lli func(lli a,lli c){
	return a-a/c;
}

/*a以上bまでの数でcで割り切れない数*/
lli calc(lli a,lli b,lli c){
	return func(b,c)-func(a-1,c);
}

signed main(){
 
 	lli a,b,c,d;
 	cin>>a>>b>>c>>d;

 	lli e=lcm(max(c,d),min(c,d));

 	if(DEBUG){
 		cout<<calc(a,b,c)<<endl;
 		cout<<calc(a,b,d)<<endl;
 		cout<<calc(a,b,e)<<endl;
 	}

 	cout<<calc(a,b,c)+calc(a,b,d)-calc(a,b,e)<<endl;

	return 0;
}

Measured memory_bytes: 256