akhauriyash/Code-Regression huggingface dataset:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n = I()
xyh = LI(n)

xyh = mysort(xyh,2,True)
# pprint(xyh)

for i in range(101):
    for j in range(101):
        flag = True
        for k in range(n):
            x = xyh[k][0]
            y = xyh[k][1]
            h = xyh[k][2]
            if k==0: 
                H = h + abs(x-i) + abs(y-j)
            elif k==(n-1):
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    ans = [i,j,H]
                else:
                    flag = False
            else:
                l = max( H - abs(x-i) - abs(y-j), 0 )
                if l==h:
                    pass
                else:
                    flag = False
        if flag:
            myoutput(ans,True)
            exit()
        else:
            continue
exit()

Measured memory_bytes: 49136
#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;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)2e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int freq[N];

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int n;
    cin>>n;
    int a[n];
    f(i, n) {
        cin>>a[i];
        freq[a[i]]++;
    }
    int ans = 0;
    f(i, N) {
        ans += (freq[i] * (freq[i] - 1)) / 2;
    }
    f(i, n) {
        if(freq[a[i]] > 1) {
            int cans = ans - (freq[a[i]] * (freq[a[i]] - 1)) / 2;
            freq[a[i]]--;
            cans += (freq[a[i]] * (freq[a[i]] - 1)) / 2;
            freq[a[i]]++;
            cout<<cans<<"\n";
        }
        else cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h> 
#define int long long
using namespace std;
signed main()
{
    int N; cin >> N;
    vector<int> a(N+1); for(int i = 1; i <= N; i++) cin >> a[i];
    vector<int> in(N+1, 0);
    for(int i = N; i >= 1; i--)
    {
        int s = 0;
        for(int j = i; j <= N; j += i) s += in[j];
        if(s % 2 != a[i]) in[i]++;
    }
    int c = 0; for(int i = 1; i <= N; i++) if(in[i] > 0) c++;
    cout << c << endl;
    for(int i = 1; i <= N; i++) if(in[i] > 0) cout << i << " ";
    cout << endl;
}

Measured memory_bytes: 3968
num1, num2 = map(int, input().split())

matrix = []

for i in range(num1):
    rows = list(map(int, input().split()))
    sum_rows = sum(rows)
    rows.append(sum_rows)
    matrix.append(rows)

#print(matrix[0][5])

row = []
for j in range(num2 + 1):
    sum_columns = 0
    for k in range(num1):
        sum_columns += matrix[k][j]
    row.append(sum_columns)

matrix.append(row)

for row in matrix:
    print(*row)


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

public class Main{
	public static int maxTreesInEst(int[][] map, int W_est, int H_est){
		int max=0;
		int trees;
    	for(int i=0; i+W_est<= map.length ; i++){
      	 for(int j=0; j+H_est<= map[0].length ; j++){
      		trees=0;
      		for(int x=0; x<W_est; x++){
      		 for(int y=0; y<H_est; y++){
      			trees+= map[i+x][j+y];
      		 }
      		}
      		if( max<trees ){ max= trees; }
      	 }
      	}
    	return max;
	}
    public static void main(String args[]) throws Exception{
    	Scanner sc= new Scanner(System.in);
    	int N,W_map,H_map,W_est,H_est;
    	int x,y;
    	while( (N= sc.nextInt()) != 0 ){
    		W_map= sc.nextInt();
    		H_map= sc.nextInt();
        	int[][] map= new int[W_map][H_map];
        	for(int i=0;i<N;i++){
        		x= sc.nextInt()-1;
        		y= sc.nextInt()-1;
        		map[x][y]= 1;
        	}
        	W_est= sc.nextInt();
        	H_est= sc.nextInt();
        	System.out.println( maxTreesInEst(map,W_est,H_est) );
    	}
    }
}

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

N = int(input())
a = list(map(int, input().split()))
m, n = max(a), min(a)
if m - n > 1 or m >= N:
    print('No')
elif m - n == 0:
    print('Yes' if n == N - 1 or n * 2 <= N else 'No')
else:
    print('Yes' if 1 <= m - a.count(n) <= a.count(m) // 2 else 'No')

Measured memory_bytes: 52764
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main()
{
    int A[4];
    int N;
 
    for(int i = 0; i < 4; i++) cin >> A[i];
    cin >> N;
 
    N *= 4;
 
    int now = 0;
    int sum = A[0] * N;  //暫定
    for(int i = 1; i < 4; i++) {
        int val = 1 << i;
        int sa = N / val * val * A[now] / (1 << now) - N / val * A[i];
        if(sa > 0) {
            sum -= sa;
            now = i;
        }
    }
 
    cout << sum << endl;
 
    return (0);
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		HashMap<Long, Long> a = new HashMap<>();
		long aa=0;
		for(i=0;i<n;i++) {
			aa = parseLong(sc.next());
			if(a.get(aa) == null) {
				a.put(aa, 1L);
			} else {
				a.put(aa, a.get(aa)+1);
			}
		}
		sc.close();
		long ans=0;
		for(Long ll:a.keySet()) {
			if(a.get(ll)>ll) {
				ans+=a.get(ll)-ll;
			} else if(a.get(ll)<ll) {
				ans+=a.get(ll);
			}
		}
		out.println(ans);
	}
}

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

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

		int ans = 0;
		for( int i = 0; i < n - 1; ++i ){
			for( int j = 0; j < n - 1 - i; ++j ){
				if( a[ j ] > a[ j + 1 ] ){
					int t = a[ j + 1 ];
					a[ j + 1 ] = a[ j ];
					a[ j ] = t;
					++ans;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define  deb(x) cout << #x << " - " << x << "\n";

const int N = 105;

int n, m, q, ans = 0;
int a[N], b[N], c[N], d[N];
int cur[N];

void gen(int idx)
{
    if(idx>n){
        int temp = 0;
        for(int i=1;i<=q;++i){
            if(cur[b[i]] - cur[a[i]] == c[i]) temp += d[i];
        }
        ans = max(ans,temp);
        return;
    } 
    for(int i = cur[idx-1];i<=m;++i){
        cur[idx] = i;
        gen(idx+1);
    }
}

int32_t main()
{
	IOS;
	cin >> n >> m >> q;
	for(int i = 1; i <= q; i++)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	cur[0] = 1;
	gen(1);
	cout << ans;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct UnionFind{
  VI par,sizes; // par[i]:iの親の番号
  UnionFind(int n) : par(n), sizes(n,1){ // 最初は全てが根であるとして初期化
    rep(i,n) par[i] = i;
  }
  int root(int x){
    if(par[x]==x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x); int ry = root(y);
    if(rx==ry) return;
    if(sizes[rx]<sizes[ry]) swap(rx,ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }
  bool same(int x, int y){
    return root(x)==root(y);
  }
  int size(int x){
    return sizes[root(x)];
  }
};

signed main(){
  ll n,m; cin>>n>>m;
  UnionFind tree(n);
  int a[m],b[m];
  ll ans[m];
  rep(i,m){cin>>a[i]>>b[i]; a[i]--; b[i]--;}

  ans[m-1] = n*(n-1)/2;
  REPS(i,m-1){
    int l,r; l=a[i]; r=b[i];
    ans[i-1] = ans[i];
    if(tree.same(l,r)) continue;
    ans[i-1] -= tree.size(l)*tree.size(r);
    tree.unite(l,r);
  }
  rep(i,m) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
int h, w;
char gr[2005][2005];
int u[2005][2005], l[2005][2005], d[2005][2005], r[2005][2005];
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> gr[i][j];
    }
  }
  for (int i = 0; i < h; i++) {
    int cnt = 0;
    for (int j = 0; j < w; j++) {
      if (gr[i][j] == '.') cnt++;
      else cnt = 0;
      l[i][j] = cnt;
    }
    cnt = 0;
    for (int j = w-1; j >= 0; j--) {
      if (gr[i][j] == '.') cnt++;
      else cnt = 0;
      r[i][j] = cnt;
    }
  }
  for (int j = 0; j < w; j++) {
    int cnt = 0;
    for (int i = 0; i < h; i++) {
      if (gr[i][j] == '.') cnt++;
      else cnt = 0;
      u[i][j] = cnt;
    }
    cnt = 0;
    for (int i = h-1; i >= 0; i--) {
      if (gr[i][j] == '.') cnt++;
      else cnt = 0;
      d[i][j] = cnt;
    }
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (gr[i][j] == '.') {
        ans = max(ans, u[i][j]+l[i][j]+d[i][j]+r[i][j]-4);
      }
    }
  }
  cout << ans+1 << el;
  return 0;
}

Measured memory_bytes: 66944
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.end());
	cout << a[0] + a[1] << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return true;
}
int n;

int main(){
	cin >> n;
	int i = 11;
	while (n) {
		if (prime(i)) {
			cout << i << " ";
			n--;
		}
		i += 5;
	}
	cout << endl;
	return 0;
}

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

zorome_max = 0
zorome_now = 0
for i in range(n):
  d1, d2 = map(int, input().split())
  if d1 == d2:
    zorome_now += 1
  else:
    zorome_now = 0
  zorome_max = max(zorome_max, zorome_now)

print("Yes" if zorome_max >= 3 else "No")

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 100100


vector<int>ad[N];
int ans=0;
int a[N];
bool vis[N];

void dfs(int sr)
{
    int sum=0;
    vis[sr]=true;
    for(auto s : ad[sr])
    {
        if(vis[s]==false)dfs(s);
        sum=max(sum,a[s]);
    }
    a[sr]=1+sum;
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        ad[x].pb(y);
    }
    int u=0;
    for(int i = 1;i<=n;i++)if(!vis[i])dfs(i);
    for(int i = 1;i<=n;i++)u=max(u,a[i]);
    cout<<u-1<<endl;
}


Measured memory_bytes: 8320
import java.util.*;

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

    int a1 = sc.nextInt();
    int a2 = sc.nextInt();
    int a3 = sc.nextInt();
    String ans = "win";

    if(a1 + a2 + a3 >= 22){
      ans = "bust";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 19924
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>
#include <iomanip>
#include <stdio.h>
#include <bitset>
#include <queue>
#include <set>

constexpr long long INFLL = 1e18;

using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> L(n);
    for (int i = 0; i < n; i++)
    {
        cin >> L.at(i);
    }
    sort(L.begin(), L.end());

    int a, b, c;
    int ans = 0;
    for (int i = L.size() - 1; i >= 0; i--)
    {
        for (int k = i - 1; k >= 0; k--)
        {
            for (int j = k - 1; j >= 0; j--)
            {
                if (L.at(i) != L.at(k) && L.at(k) != L.at(j) && L.at(j) != L.at(i))
                {
                    if (L.at(i) + L.at(k) > L.at(j) && L.at(i) + L.at(j) > L.at(k) && L.at(j) + L.at(k) > L.at(i))
                    {
                        ans++;
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3196
#include<iostream>
#include<queue>
#include<cstdio>

using namespace std;

const int MAX = 1000001;
int S[MAX];

struct data{
  int num,score;
  data(){}
  data(int n, int s):num(n),score(s){}
  bool operator < (const data& d) const {
    if(score != d.score) return score < d.score;
    return num > d.num;
  }
};

int main(){

  int n,m;
  scanf("%d %d",&n,&m);

  priority_queue<data> Q;
  Q.push(data(0,0));

  while(m--){
    int a,b;
    scanf("%d %d",&a,&b);
    S[a] += b;
    
    Q.push(data(a,S[a]));

    while(1){
      data now = Q.top();
      if(now.score == S[now.num]){
	printf("%d %d\n",now.num,now.score);
	break;
      } 
      Q.pop();
    }
  }
  return 0;
}

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

#define int long long

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

const int mod = 1e9+7;

int N;
auto dp = vectors(111, 9, 9, 9, 0);

bool isAGC(vector<int> C) {
  return C[0] == 0 and C[1] == 1 and C[2] == 2;
}


signed main() {
  cin >> N;
  int M = 4;

  // 初期化
  for (int i = 0; i < 5; i++) {
    dp[0][i][i][i] = 1;
  }

  for (int i = 0; i < N; i++) {
    for (int c3 = 0; c3 < M; c3++) { // iの3文字前
      for (int c2 = 0; c2 < M; c2++) { // iの2文字前
        for (int c1 = 0; c1 < M; c1++) { // iの1文字前
          for (int now = 0; now < M; now++) { // 新しく選ぶ文字
            // AGC文字列になるかどうかの判定
            bool ok = true;
            vector<int> t = {c3, c2, c1, now};
            if (isAGC({c3, c2, c1}) or isAGC({c2, c1, now})) ok = false;

            for (int j = 0; j < t.size()-1; j++) {
              vector<int> tt = t;
              swap(tt[j], tt[j+1]);
              if (isAGC({tt[0], tt[1], tt[2]}) or isAGC({tt[1], tt[2], tt[3]})) ok = false;
            }

            // AGC文字列にならないなら遷移させる
            if (ok) {
              Add(dp[i+1][c2][c1][now], dp[i][c3][c2][c1]);
            }
          }
        }
      }
    }
  }

  int ans = 0;
  for (int c3 = 0; c3 < M; c3++) {
    for (int c2 = 0; c2 < M; c2++) {
      for (int c1 = 0; c1 < M; c1++) {
        Add(ans, 1LL*dp[N-1][c3][c2][c1]); // なんかN-1でやるとACする。
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> C(N);
    vector<int> V(N);

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (V[i] > C[i]) ans += V[i] - C[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

s = input()
if s == 'ABC':
    print('ARC')
else:
    print('ABC')


Measured memory_bytes: 68640
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int[] A = new int[N+1];
        for (int i=0; i<N+1; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve2(N, A));
    }

    private static long solve2(int N, int[] A) {
        long[] maxNode = new long[N+1];
        maxNode[0] = 1;
        for (int i=1; i<N+1; i++) {
            maxNode[i] = Math.min((maxNode[i-1]-A[i-1])*2, Long.MAX_VALUE/2);

            // System.err.println("check i=" + i + ", max=" + maxNode[i]);
            if (maxNode[i] < 0) return -1;
        }


        long count = A[N];
        long childNode = A[N];
        // System.err.println("i=" + N + ", count=" + count + ", max=" + maxNode[N] + ", leaf=" + A[N] + ", child=" + childNode);
        for (int i=N-1; i>=0; i--) {
            int minNode = A[i+1]/2 + A[i+1]%2;
            if (maxNode[i] < A[i] + minNode) {
                return -1;
            }

            count += A[i];
            count += Math.min(maxNode[i]-A[i], childNode);
            childNode = Math.min(maxNode[i]-A[i], childNode) + A[i];

            // System.err.println("i=" + i + ", count=" + count + ", max=" + maxNode[i] + ", leaf=" + A[i] + ", child=" + childNode);
        }

        if (childNode != 1) return -1;

        return count;
    }
}

Measured memory_bytes: 58908
def main2():
    N = int(input())
    a = [int(i) for i in input().split()]

    a.sort()
    n = a[-1]
    m = n / 2
    tmp = 10**10
    for i in a:
        if abs(m - i) < tmp:
            tmp = abs(m - i)
            r = i

    print(n, r)


if __name__ == "__main__":
    main2()

Measured memory_bytes: 14052
n, k = map(int, input().split())
arr = list(map(int, input().split()))

if n == 1:
    if k % 2:
        print(*arr)
    else:
        print(*[])
    exit()

table = {}
original_table = {}
move = {}

for i, a in enumerate(arr):
    if a not in table:
        table[a] = i
        original_table[a] = i
    else:
        move[table[a]], move[i] = i + 1, original_table[a] + 1
        table[a] = i

res = {}
idx = 0

for i in range(1, k + 1):
    while idx in move and move[idx] > idx:
        idx = move[idx]

    res[i] = idx
    if idx == len(arr):
        k %= len(res)
        if not k:
            k = len(res)
        break

    if idx in move:
        idx = move[idx]
    else:
        idx += 1

idx = res[k]
response = []

while idx < len(arr):
    while idx in move and move[idx] > idx:
        idx = move[idx]
    if idx < len(arr):
        response.append(arr[idx])
    idx += 1

print(*response)


Measured memory_bytes: 77480
# include<iostream>
using namespace std;
int main ()
{
	int a,b;
	cin>>a>>b;
//	int c  = (int)(a*1.0/b+0.5);
//	cout<<c<<endl;
	if(a%b==0)
	{
		cout<<a/b<<endl;
	 } 
	else
	{
		cout<<a/b+1<<endl;
	}
}

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

#define int long long

using namespace std;

signed main(void){
    int N;cin>>N;
    vector<int>A(N),B(N),C(N);
    for(int i=0;i<N;i++)cin>>A[i];
    for(int i=0;i<N;i++)cin>>B[i];
    for(int i=0;i<N;i++)cin>>C[i];
    cerr<<endl;

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    for(int i=0;i<N;i++)cerr<<A[i]<<(i==N-1?'\n':' ');
    for(int i=0;i<N;i++)cerr<<B[i]<<(i==N-1?'\n':' ');
    for(int i=0;i<N;i++)cerr<<C[i]<<(i==N-1?'\n':' ');
    cerr<<endl;

//    A.erase(unique(A.begin(),A.end()),A.end());
//    B.erase(unique(B.begin(),B.end()),B.end());
//    C.erase(unique(C.begin(),C.end()),C.end());

   vector<int>v1(B.size()),v2(A.size());
   for(int i=0;i<v1.size();i++){
       v1[i]=N-distance(C.begin(),upper_bound(C.begin(),C.end(),B[i]));
   }
   for(int i=0;i<N;i++)cerr<<v1[i]<<(i==N-1?'\n':' ');
   

   int ans(0);

   for(int i=v1.size()-1;i>0;i--)v1[i-1]+=v1[i];
   for(int i=0;i<N;i++)cerr<<v1[i]<<(i==N-1?'\n':' ');
   cerr<<endl;

   for(int i=0;i<A.size();i++){
      int x = distance(B.begin(),upper_bound(B.begin(),B.end(),A[i]));
      cerr<<x<<" "<<v1[x]<<endl;
      ans += v1[x];
  }

  cout<<ans<<endl;
      
          
}


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

bool isEven(std::string str, int len) {
  if (len % 2 != 0)
    return false;
  for (int i = 0; i < len / 2; ++i) {
    if (str[i] != str[len / 2 + i])
      return false;
  }
  return true;
}
  

int main() {
  std::string str;
  std::cin >> str;
  for (int i = (int)str.size() - 2; i >= 0; i -= 2) {
    if(isEven(str, i)) {
      std::cout << i << std::endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0].split(' ')[0])
    const X = parseInt(input[0].split(' ')[1])
    const ms = input.slice(1, N + 1).map(i => parseInt(i))
    const msCount = ms.length
    const sum = ms.reduce((p, v) => p + v)
    const rest = X - sum
    const min = Math.min(...ms)
    const count = Math.floor(rest / min)
    console.log(msCount + count)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;
using namespace std;

inline int max(int a, int b){
	return a > b ? a : b;
}

inline int min(int a, int b){
	return a < b ? a : b;
}

int n;
char a[110], b[110];

int main(){

	cin >> n >> a >> b;
	for(int i = 1; i <= n; i++)
		cout << a[i - 1] << b[i - 1];

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;
  if(a<3200)cout<<"red"<<endl;
  else cout << s << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = a; i < b; i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

ll n, k;
inline ll mink(ll c) {
	return c*(c-1)/2;
}

inline ll maxk(ll c){
	return c*(2*n+1-c)/2;
}

int main() {
    fast_io;
    cin >> n >> k;
    ll ans = 0;
    for(ll c=k;c<=n+1;c++) {
        ans += maxk(c) - mink(c) + 1;
        ans %= MOD;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    ll h,w,n;
    cin>>h>>w>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<vector<ll>> board(h,vector<ll>(w,0));
    pair<ll,ll> nowc=make_pair(0,0);
    ll nowi=0,cnt=0;
    while(nowc.second<h){
        board[nowc.second][nowc.first]=nowi+1;
        cnt++;
        if(cnt==a[nowi]){
            nowi++;
            cnt=0;
        }
        if(w==1) nowc.second++;
        else if(nowc.first==w-1){
            if(nowc.second%2) nowc.first--;
            else nowc.second++;
        }else if(nowc.first==0){
            if(nowc.second%2) nowc.second++;
            else nowc.first++;
        }else{
            if(nowc.second%2) nowc.first--;

            else nowc.first++;
        }
    }
    rep(i,h){
        rep(j,w) cout<<board[i][j]<<' ';
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int h, w;
	int s[50][50] = { 0 };
	int i , j , cnt;
	char str[50][50];

	scanf("%d %d", &h, &w);
	for (i = 0; i < h; i++) {
		scanf("%s", str[i]);
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (str[i][j] == '#') {
				s[i][j] = 1;
			}
			 //printf("%2d", s[i][j]);
		}
		//printf("\n");
	}

	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (s[i][j]) {
				//printf("h:%d %d %d %d ",h,i,j,s[i+1][j]);
				cnt = 0;
				if (i) {
					cnt += s[i - 1][j];
				}
				if (j) {
					cnt += s[i][j - 1];
				}
				if (i + 1 < h) {
					cnt += s[i + 1][j];
					//printf("\n%d", s[i + 1][j]);
				}
				if (j + 1 < w) {
					cnt += s[i][j + 1];
				}
				if (!cnt) {
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w,k = LI()
    dp = [[0]*w for _ in range(h+1)]
    dp[0][0] = 1
    k -= 1
    f = [1,1]
    for i in range(w):
        f.append(f[-1]+f[-2])

    for i in range(h):
        ni = i+1
        for j in range(w):
            dpj = dp[i][j]
            nj = j+1
            if nj < w:
                l = f[j]
                r = f[w-1-nj]
                dp[ni][nj] += l*r*dpj%mod
            l = f[j]
            r = f[w-1-j]
            dp[ni][j] += l*r*dpj%mod
            nj = j-1
            if nj >= 0:
                l = f[nj]
                r = f[w-1-j]
                dp[ni][nj] += l*r*dpj%mod
    print(dp[h][k]%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string w,t;
    cin >> w;
    int cnt=0;
    while(cin >> t){
        if(t=="END_OF_TEXT"){
            break;
        }
        for(int i=0;i<t.size();i++){
            if('A'<=t.at(i)&&t.at(i)<='Z'){
                t.at(i)+='a'-'A';
            }
        }
        if(w==t){
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  cout << 48 - n << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define forn(i,n) for(ll i=0;i<(n);i++)
#define maxx ((ll)1e6+5)
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	  ll n,k;
	  cin>>n>>k;
	  cout<<min(n%k,min(n,abs(n%k-k)));
	   return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,S[100000],q,T[50000],c=0,i,i2,toread,cnt;
	cin>>n;
	for(i=0;i<n;i++)cin>>S[i];
	cin>>q;
	for(i=0;i<q;i++)cin>>T[i];
	/*for(i=0;i<n;i++){
		for(i2=0;i2<n;i2++){
			if(S[i]<S[i2]){
				toread=S[i];
				S[i]=S[i2];
				S[i2]=toread;
			}
		}
	}*/
	sort(S,S+n);
	for(i=0;i<q;i++){
		cnt=0;
		toread=n;
		while(toread>1){
			if(toread%2==0)toread/=2;
			else toread=(toread+1)/2;
			if(S[(toread-1)+cnt]<T[i])cnt+=toread;
			else if(S[(toread-1)+cnt]==T[i]){
				c++;
				break;
			}
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3680
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  int N = sc.nextInt();
  int Y = sc.nextInt();
  int x = -1; int y = -1; int z = -1;
  out:
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= N-i;j++){
      for(int k = 0;k <= N-i-j;k++){
        if(10000*i + 5000*j + 1000*k == Y && i+j+k == N){
          x = i;y = j;z = k;
          break out;
        }
      }
    }
  }
  System.out.println(x+" "+y+" "+z);
}}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
#define all(V) V.begin(),V.end()
 
int V, E, R, s, t, d = 0, x = 0;
 
vector<vector<int>> G(100000);
vector<int> ord(100000, -1), low(100000, -1);
vector<pair<int,int>> Es;
 
int dfs(int c, int p) {
    low[c] = ord[c] = x;
    x++;
    for (int i : G[c]) {
        if (i == p)
            continue;
        if (ord[i] < 0)
            low[c] = min(low[c], dfs(i, c));
        else {
            low[c] = min(low[i], low[c]);
        }
    }
    return low[c];
}
 
int main() {
    cin >> V >> E;
    for (int i = 0;i < E;i++) {
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        G[t].push_back(s);
        Es.push_back({ min(s,t),max(s,t) });
    }
    sort(all(Es));
    dfs(0, -1);
    for (int i = 0;i < E;i++) {
        s = Es[i].first;
        t = Es[i].second;
        if (ord[s] < ord[t]) {
            if (ord[s] < low[t])
                d++;
        }
        else {
            if (ord[t] < low[s])
                d++;
        }
    }
    cout << d << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

struct UnionFind {
  vector<int> par;
  UnionFind(int size) : par(size, -1) {}
  bool unite(int u, int v) {
    if ((u = root(u)) == (v = root(v))) return false;
    if (par[u] > par[v]) swap(u, v);
    par[u] += par[v], par[v] = u;
    return true;
  }
  bool same(int u, int v) { return root(u) == root(v); }
  int root(int u) { return par[u] < 0 ? u : par[u] = root(par[u]); }
  int size(int u) { return -par[root(u)]; }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    uf.unite(--A, --B);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) ans = max(ans, uf.size(i));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3976
#include <stdio.h>

#define MAX 10000

int parent(int);
int left(int);
int right(int);

int main()
{
  int H,i,a[MAX+1];

  scanf("%d",&H);

  for(i=0;i<H;i++){
    scanf("%d",&a[i+1]);
  }

  for(i=0;i<H;i++){
    printf("node %d: ",i+1);
    printf("key = %d, ",a[i+1]);
    if(parent(i+1) >= 1) printf("parent key = %d, ",a[parent(i+1)]);
    if(left(i+1) <= H) printf("left key = %d, ",a[left(i+1)]);
    if(right(i+1) <= H) printf("right key = %d, ",a[right(i+1)]);

    printf("\n");

  }

  return 0;

}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}



Measured memory_bytes: 2044
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
a, b = LI()
print((a+b+1)//2)


Measured memory_bytes: 3316
#include<stdio.h>
#include<algorithm>
using namespace std;
struct st
{
    int num,people;
}a[100005];
bool cmp(st a,st b)
{
    return a.people<b.people;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i].people);
        a[i].num=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        printf("%d",a[i].num);
        if(i!=n)
        {
            printf(" ");
        }
    }
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
int n,q; 
ll solve(ll a, ll b)
{
	if(n==1) return min(a,b);
	vector<ll> vec;
	while(a>0)
	{
		vec.pb(a);
		a=(a-1)/n;
	}
	vec.pb(0);
	sort(vec.begin(),vec.end());
	while(b>0)
	{
		if(binary_search(vec.begin(),vec.end(),b)) return b;
		b=(b-1)/n;
	}
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>q;
	for(int i=0;i<q;i++)
	{
		ll u,v; cin>>u>>v; u--; v--;
		cout<<solve(u,v)+1<<'\n';
	}
}	


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template <typename T> constexpr bool chmax(T &a, const T b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

using Real = double;
using Point = complex<Real>;
const Real EPS = 1e-8, PI = acos(-1);

inline bool eq(Real a, Real b) { return fabs(b - a) < EPS; }

istream &operator>>(istream &is, Point &p) {
    Real a, b;
    is >> a >> b;
    p = Point(a, b);
    return is;
}

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

    int n, h, w;
    cin >> h >> w >> n;
    vector<pair<Point, int>> vec;
    double r = h / 2.0, c = w / 2.0;
    Point p(r, c);
    rep(i, n) {
        Point a, b;
        cin >> a >> b;
        if(real(a) != 0 && real(a) != h && imag(a) != 0 && imag(a) != w)
            continue;
        if(real(b) != 0 && real(b) != h && imag(b) != 0 && imag(b) != w)
            continue;
        vec.push_back(make_pair(a - p, i));
        vec.push_back(make_pair(b - p, i));
    }
    stack<int> x;
    sort(ALL(vec), [&](pair<Point, int> a, pair<Point, int> b) {
        return atan2(a.first.imag(), a.first.real()) <
               atan2(b.first.imag(), b.first.real());
    });
    for(auto i : vec) {
        if(!x.empty() && x.top() == i.second)
            x.pop();
        else
            x.push(i.second);
    }
    cout << (x.size() ? "NO" : "YES") << endl;

    return 0;
}

Measured memory_bytes: 8304
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 998244353;
const int n_max = 1e5+10;

const int MAX = 3e5 + 10;
// const int MOD = 1e9+7;

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    ll n; cin >> n;
    ll a,b,k; cin >> a >> b >> k;
    // bool ok = false;
    COMinit();
    ll ans = 0;
    rep(i,n+1){
        ll r = k - a*i;
        if(r < 0)break;
        if(r % b != 0)continue;
        r /= b;
        // debug(i);debug(r);
        // rep(G,min(i,r)+1){
        //     if(n < r+i-G)continue;
        //     ll A = i-G, B = r-G;
        //     ans = (ans + ((COM(n,A) * COM(n-A,B)) % MOD) * COM(n-A-B,G) % MOD) % MOD;
        // }
        ans = (ans + (COM(n,i) * COM(n,r) % MOD)) % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 7296
def main():
    n,x,y = tuple([int(t)for t in input().split()])

    dmin = [[n]*n for _ in [0]*n]

    nlist = list(range(n))

    for i in range(n):
        for j in range(i,n):
            dmin[i][j] = j-i
            dmin[j][i] = j-i

    for i in range(x):
        for j in range(y-1,n):
            dmin[i][j] -= y-x-1
            dmin[j][i] -= y-x-1


    for i in range(n):
        for j in range(x,(x+y)//2):
            t = dmin[j][x-1]+dmin[x-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

        for j in range((x+y)//2,y):
            t = dmin[j][y-1]+dmin[y-1][i]
            if dmin[i][j]>t:
                dmin[i][j] = t
                dmin[j][i] = t

    res = [0]*(n+1)
    for dmin_ in dmin:
        for d in dmin_:
            res[d] += 1

    for r in res[1:n]:
        print(r//2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 77916
#import sys
#input = sys.stdin.readline
#from numpy import matrix, eye, dot
def productMatrix(N, A, B):
    Ret = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            for k in range(N):
                Ret[i][j] += A[i][k]*B[k][j]
    return Ret
def modMatrix(N, A, Q): #N×N行列のmod
    for i in range(N):
        for j in range(N):
            A[i][j] %= Q
#            A[i,j] %= Q
    return

def powOfMatrix(N, X, n, Q): #N×N行列のn乗
#    Ret = eye(N)
    Ret = [[1,0,0],[0,1,0],[0,0,1]]
    power = '{:060b}'.format(n)[::-1] #log2(pow(10,18)) < 60
    for p in power:
        if p == "1":
            Ret = productMatrix(N,Ret, X)
#            Ret = dot(Ret, X)
            modMatrix(N, Ret, Q)
        X = productMatrix(N,X,X)
#        X = dot(X,X)
        modMatrix(N, X, Q)
#        print(Ret)
    return Ret

def main():
    L, A, B, M = map( int, input().split())
    s = A
    ANS = [[1,0,0],[0,1,0],[0,0,1]]
    for i in range(1, 37):
#        print(i, ANS)
        if s >= pow(10,i):
            continue
        P = [[pow(10, i, M), 0, 0], [1,1,0], [0,B,1]]
#        P = matrix([[pow(10, i, M), 0, 0], [1,1,0], [0,B,1]])
#        print((pow(10,i)-1-s)//B+1)
        step = (pow(10,i)-s+B-1)//B
        if L <= step:
            ANS = productMatrix(3,ANS,powOfMatrix(3,P,L,M))
#            ANS = dot(ANS,powOfMatrix(3,P,L,M))
            modMatrix(3,ANS,M)
            break
#        print(powOfMatrix(3,P, (pow(10,i)-1-s)//B + 1,M))
        ANS = productMatrix(3,ANS, powOfMatrix(3,P, step,M))
#        ANS = dot(ANS, powOfMatrix(3,P, (pow(10,i)-1-s)//B + 1,M))
#        print( (ANS[1][0]*A + ANS[2][0])%M, (pow(10,i)-1-s)//B + 1)
        modMatrix(3,ANS, M)
        L -= step
        s += step*B
    print( (ANS[1][0]*A + ANS[2][0])%M)
#    print( int((ANS[1,0]*A + ANS[2,0])%M))
        
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <queue>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; in(N);

  int A[N], B[N];
  rep(i, N) in(A[i]);
  rep(i, N) in(B[i]);
  int ans = 0;
  ll lack = 0;
  priority_queue<int> q;
  rep(i, N) {
    if (A[i] < B[i]) {
      lack += B[i] - A[i];
      ++ans;
    } else {
      q.push(A[i] - B[i]);
    }
  }
  while (!q.empty() && lack > 0) {
    int p = q.top(); q.pop();
    lack -= p;
    ++ans;
  }
  if (lack > 0)
    out(-1);
  else
    out(ans);

  return 0;
}


Measured memory_bytes: 1660