akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* UnionFind */

struct UnionFind {
  vector<int> data;
  UnionFind(int s): data(s, -1) {}

  int root(int x) {
    if (data[x] < 0) return x;
    return data[x] = root(data[x]);
  }

  bool set(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }

  bool check(int x, int y) {
    return root(x) == root(y);
  }

  int size(int x) {
    return -data[root(x)];
  }
};

int N;
int X[SIZE], Y[SIZE];
pair<int,int> pX[SIZE], pY[SIZE];
set<int> ssX[SIZE], ssY[SIZE];

int main() {

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf("%d%d", X+i, Y+i);
    pX[i] = {X[i], i};
    pY[i] = {Y[i], i};
  }

  sort(pX, pX+N);
  sort(pY, pY+N);

  UnionFind uf(N);

  for (int i=0; i<N-1; i++) {
    if (pX[i].first == pX[i+1].first)
      uf.set(pX[i].second, pX[i+1].second);

    if (pY[i].first == pY[i+1].first)
      uf.set(pY[i].second, pY[i+1].second);
  }


  for (int i=0; i<N; i++) {
    int r = uf.root(i);
    ssX[r].insert(X[i]);
    ssY[r].insert(Y[i]);
  }

  ll ans = 0;

  for (int i=0; i<N; i++) {
    if (i == uf.root(i)) {
      ll num = (ll)ssX[i].size() * ssY[i].size();
      num -= uf.size(i);
      ans += num;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 28288
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    from bisect import bisect
    i = bisect(A, X)
    return min(len(A)-i, i)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    print(solve(N, M, X, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

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

    set<int> s;
    int a, b, c;
    cin >> a >> b >> c;

    s.insert(a);
    s.insert(b);
    s.insert(c);

    if (s.size()==2)        cout << "Yes";
    else                    cout << "No";

    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(N-K+1):
  left = X[i]; right = X[i+K-1]
  if left >= 0:
    ans = min(ans, right)
    break
  elif right <= 0:
    ans = min(ans, -left)
  else:
    t = min(-left, right)*2 + max(-left, right)
    ans = min(ans, t)

print(ans)

Measured memory_bytes: 14384
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

def solve(h, w, k, S):
    ret = float('inf')
    bits = 2 ** (h - 1)
    for b in range(bits):
        tmp = 0
        idx = 0
        groups = []
        for y in range(h):
            groups.append(idx)
            if (1 << y) & b:
                idx += 1
        m = idx + 1
        counts = [[0] * w for _ in range(m)]
        imp = False
        for y in range(h):
            g = groups[y]
            for x in range(w):
                if S[y][x] == 1:
                    counts[g][x] += 1
                    if counts[g][x] > k:
                        imp = True
                        break
        if imp:
            continue

        cuts = 0
        cum = [counts[g][0] for g in range(m)]
        for x in range(1, w):
            cut = False
            for g in range(m):
                cum[g] += counts[g][x]
                if cum[g] > k:
                    cut = True
                    break
            if cut:
                cuts += 1
                cum = [counts[g][x] for g in range(m)]
        ret = min(ret, m - 1 + cuts)
        #print(b, groups, m, cuts, ret)
    print(ret)
    return

def main():
    h, w, k = map(int, input().split())
    s = []
    for i in range(h):
        tmp = str(input())
        s.append([int(j) for j in tmp])
    solve(h, w, k, s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46044
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**5)

N, M = map(int, input().split())
G = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
dp = [-1]*N


def dfs(n):
    global dp
    if dp[n] >= 0:
        return dp[n]

    ma = 0
    for b in G[n]:
        ma = max(ma, dfs(b) + 1)
    dp[n] = ma
    return ma


def main():
    for i in range(N):
        dfs(i)
    print(max(dp))


if __name__ == '__main__':
    main()


Measured memory_bytes: 138204
#include <bits/stdc++.h>
#define f first
#define s second
#define rep(i, l, r) for (long long i = (l); i < (r); i++)
#define repb(i, r, l) for (long long i = (r); i > (l); i--)
#define pb push_back
 
using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef long long int lli;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull; 
const int MAX_CHAR=256;
 
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 
const ll mod = 1e9 + 7;
 
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
} 

ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

bool sortbysec(const pair<ll, ll>& a, 
               const pair<ll, ll>& b) 
{ 
    return (a.second < b.second); 
} 
  
// Function to find maximal disjoint set 
ll maxDisjointIntervals(vector<pair<ll, ll> > list) 
{ 
  
    // Sort the list of intervals 
    sort(list.begin(), list.end(), sortbysec); 
  
    // First Interval will always be 
    // included in set 
    // cout << "[" << list[0].first << ", "
    //      << list[0].second << "]" << endl; 
    ll count=1;
  
    // End point of first interval 
    ll r1 = list[0].second; 
  
    for (ll i = 1; i < list.size(); i++) { 
        ll l1 = list[i].first; 
        ll r2 = list[i].second; 
  
        // Check if given interval overlap with 
        // previously included interval, if not 
        // then include this interval and update 
        // the end point of last added interval 
        if (l1 >= r1) { 
            count++; 
            r1 = r2; 
        } 
    }
    
    return count;
} 

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,k,s;
    
    cin>>n>>k>>s;
    
    vl v;
    
    if(s!=(ll)1e9)
    {
        rep(i,0,k)
            v.pb(s);
        rep(i,k,n)
            v.pb(ll(1e9));
    }
    else
    {
        rep(i,0,k)
            v.pb(s);
        rep(i,k,n)
            v.pb(1);
    }
    
    rep(i,0,n)
        cout << v[i] << " ";
    cout << endl;
}

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

using namespace std;


int main() {
	int n;
	cin >> n;
	int a, b, c;
	a = b = c = 0;
	for (int i = 0; i < n; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		int d = abs(x - b) + abs(y - c);
		int nt = t - a;
		if ((d % 2) != (nt % 2) || nt < d) {
			cout << "No" << endl;
			return 0;
		}
		a = t; b = x; c = y;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
 
if k< b-a:
  print(":(")
elif k< c-a:
  print(":(")
elif k< d-a:
  print(":(")
elif k< e-a:
  print(":(")
elif k< c-b:
  print(":(")
elif k< d-b:
  print(":(")
elif k< e-b:
  print(":(")
elif k< d-c:
  print(":(")
elif k< e-c:
  print(":(")
elif k< e-d:
  print(":(")
else:
  print("Yay!")

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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)
#define rreps(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rreps(v, 0, n - 1)
#define rlep(v, n) rreps(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define debug(x) std::cerr << #x << " = " << (x) << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
  int dp[5][99] = {};
  dp[0][0] = 1;
  lep(i, 4){
    rep(j, 99){
      rep(k, 10){
        if (j - k < 0) continue;
        dp[i][j] += dp[i - 1][j - k];
      }
    }
  }
  int n;
  while (~scanf("%d", &n)){
    printf("%d\n", dp[4][n]);
  }

  return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(ll i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
//const ll MOD = 1000000007ll;
const ll MOD = 998244353ll;
const dou pi=3.141592653589793;

//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう
int main(){
    int n,k;
    std::cin >> n>>k;
    int ans=k;
    rep(i,n-1)ans*=(k-1);
    std::cout << ans << std::endl;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

#define LEN_MAX 200009

bool strcmp_len(char *s1, char *s2, int len)
{
	for (int i = 0; i < len; i++){
		if (s1[i] != s2[i]){
			return false;
		}
	}
	return true;
}

void strcpy_len(char *dst, char *src, int len)
{
	for (int i = 0; i < len; i++){
		dst[i] = src[i];
	}
	return;
}

void solv()
{
	char S[LEN_MAX]; scanf("%s", S);

	int ret = 1;
	char prev[LEN_MAX]; prev[0] = S[0];
	int len_prev = 1, len = strlen(S), tail = 1;
	for (int i = 1; i < len; i++){
		if (i - tail + 1 != len_prev || !strcmp_len(prev, S + tail, len_prev)){
			strcpy_len(prev, S + tail, i - tail + 1);
			len_prev = i - tail + 1;
			ret++;
			tail = i + 1;
		}
	}

	printf("%d", ret);
}

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

	solv();

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

	return 0;
}

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

int main(){
  int n, x, y; cin >> n >> x >> y;
  x--, y--;
  vector<int> ans(n);
  rep(i, n){
    for(int j=i+1; j<n; j++){
      int k = min(j-i, abs(x-i)+abs(y-j)+1);
      ans[k]++;
    }
  }
  
  rep(i, n){
    if(i==0) continue;
    cout << ans[i] << endl;
  }
   
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = int;


int main(){
	fast_io;
	int s,w;
	cin>>s>>w;
	if(w>=s){
		cout<<"unsafe\n";
	}
	else cout<<"safe\n";
}

Measured memory_bytes: 3612
#include <stdio.h>
 
#define MAX 100000
#define N -1
 
struct Node{
  int y; 
  int l; 
  int r; 
};

struct Node T[MAX];

void pre(int uk){
 
  printf(" %d",uk);
  if(T[uk].l!=N) pre(T[uk].l);
  if(T[uk].r!=N) pre(T[uk].r);
 
}
 
void ino(int uk){
 
  if(T[uk].l!=N) ino(T[uk].l);
  printf(" %d",uk);
  if(T[uk].r!=N) ino(T[uk].r);
}
 
void pos(int uk){ 
  
  if(T[uk].l!=N) pos(T[uk].l);
  if(T[uk].r!=N) pos(T[uk].r);
  printf(" %d",uk);
 
}
 
main(){
  int i,j,vo,co,n;
 
  scanf("%d",&n); 
 
  for(i=0;i<n;i++){
    T[i].y=N;
    T[i].l=N;
    T[i].r=N;
  }
 
  for(i=0;i<n;i++){
    scanf("%d",&vo); 
 
    for(j=0;j<2;j++){
      scanf("%d",&co); 
 
      if(j==0){
    T[vo].l=co;  
      } else {
    T[vo].r=co;
      }
    T[co].y=vo;       
    }
  }
 
  for(i=0;i<n;i++){
    if(T[i].y==N){
      vo=i;
      break;
    }
  }
 
  printf("Preorder\n");
  pre(vo);
  printf("\nInorder\n");
  ino(vo);
  printf("\nPostorder\n");
  pos(vo);
  printf("\n");
  
  return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

auto PI = acos(-1);
ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a,b,x;
    cin>>a>>b>>x;
    cout<<setprecision(12);
    if(a*b*a/2.0 <=x){
        cout<<atan(2.0*(a*a*b-x)/(a*a*a))*180.0/PI;
    }
    else{
        cout<<atan(b*b*a/(2.0*x))*180.0/PI;
    }
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

ll solve(V<int> A, int X){
	sort(all(A));
	int N = A.size()-1;
	V<int> maskmax(1<<N);
	rep(s,1<<N){
		rep(i,N) if(s&1<<i) chmax(maskmax[s],A[i]);
	}
	VV<ll> cur(X+1,V<ll>(1<<N));
	cur[A.back()][0] = 1;
	rep(i,X){
		VV<ll> nxt(X+1,V<ll>(1<<N));
		for(int j=i;j<=X;j++) rep(s,1<<N) if(cur[j][s]){
			rep(ds,1<<N) if(!(s&ds)){
				int ns = s|ds;
				int nj = j;
				if(ds) chmax(nj,i+maskmax[ds]);
				chmin(nj,X);
				nxt[nj][ns] += cur[j][s];
			}
		}
		swap(cur,nxt);
	}
	return cur[X][(1<<N)-1];
}

//coef x^{n-1}
template<class T>
T interpolate(vector<T> xs,vector<T> ys){
	int N = xs.size();
	T ret = 0;
	rep(i,N){
		T a = ys[i];
		rep(j,N) if(j!=i) a /= xs[i]-xs[j];
		ret += a;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N,X; cin >> N >> X;
	V<int> A(N); rep(i,N) cin >> A[i];
	V<ll> f(N+1);
	rep1(k,N){
		V<int> AA = A; rep(i,N) AA[i] *= k;
		f[k] = solve(AA,X*k);
		show(f[k]);
	}

	using D = long double;
	V<D> xs(N); rep(i,N) xs[i] = (i+1)*X;
	V<D> ys(N); rep(i,N) ys[i] = D(f[i+1]);
	cout << interpolate(xs,ys) << endl;
}


Measured memory_bytes: 492
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] a_asArgs)
        {
			int[][] l_aaiInput = new int[3][];
			l_aaiInput[0] = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
			l_aaiInput[1] = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
			l_aaiInput[2] = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

			bool l_b =
				l_aaiInput[0][2] - l_aaiInput[0][1] == l_aaiInput[1][2] - l_aaiInput[1][1] &&
				l_aaiInput[0][2] - l_aaiInput[0][1] == l_aaiInput[2][2] - l_aaiInput[2][1] &&
				l_aaiInput[0][1] - l_aaiInput[0][0] == l_aaiInput[1][1] - l_aaiInput[1][0] &&
				l_aaiInput[0][1] - l_aaiInput[0][0] == l_aaiInput[2][1] - l_aaiInput[2][0];
			Console.WriteLine(l_b ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(void){
  const double pi=3.14159265359;
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double ans,answer,angle,angle1,angle2;
  angle1=(2*pi/720)*(h*60+m);
  angle2=(2*pi/60)*m;
  angle=abs(angle1-angle2);
  ans=pow(a,2)+pow(b,2)-2*a*b*cos(angle);
  answer=sqrt(ans);
  printf("%.10lf\n",answer);
  return 0;
}

Measured memory_bytes: 4164
list=Array.new(3001,nil)
r=false
loop do
  a,b=gets.split.map(&:to_i)
  break if a==0 and b==0
  if r then puts ""
  else r=true end
  count=[]
  (a..b).each do |year|
    if list[year]==1
      count<<year
    elsif list[year].nil?
      if year%400==0 or (year%4==0 and year%100!=0)
        count<<year
        list[year]=1
      else
        list[year]=0
      end
    end
  end
  puts count.empty? ? "NA" : count
end

Measured memory_bytes: 8796
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  char A;
  cin >> A;
  int x = A + 0;
  if(x > 96){
    cout << "a";
  }
  else{
    cout << "A";
  }
}

Measured memory_bytes: 3592
//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VVI = vector<VI>;


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


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9

// Main program
void solve(){
    int N,K;
    cin >> N >> K;
    if(K==1){
        cout << 0 << endl;
    }
    else{
        cout << N- K << endl;
    }
}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}

Measured memory_bytes: 256
#include<stdio.h>

char a[50][51],b[50][51];


int main(int argc, char const *argv[]) {
	int n,m,i,j,k,l,f;
	char c;
	scanf("%d %d",&n,&m);
	getchar();
	for(i=0;i<n;i++){
		scanf("%s",a[i]);
	}
	for(i=0;i<m;i++){
		scanf("%s",b[i]);
	}
	for(i=0;i<=n-m;i++){
		for(j=0;j<=n-m;j++){
			f=1;
			for(k=i;k<i+m;k++){
				for(l=j;l<j+m;l++){
					if(a[k][l]!=b[k-i][l-j]) f=0;
				}
			}
			if(f){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

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

    string s;
    cin >> s;

    vs32 ans;
    int pos = n;
    while (pos != 0)
    {
        int i = MIN(pos, m);
        while (pos - i < pos && s[pos - i] == '1') --i;
        if (i == 0)
        {
            cout << "-1\n";
            return 0;
        }
        ans.push_back(i);
        pos -= i;
    }

    for (auto it = ans.rbegin(); it < ans.rend(); ++it)
    {
        if (it > ans.rbegin()) cout << " ";
        cout << *it;
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 1096
<?php
fscanf(STDIN, "%d", $n);
$pow2 = [];
for($i = 0; 2 ** $i <= 100; $i++) {
   $pow2[] = 2 ** $i;
}
rsort($pow2);
//var_dump($pow2);
foreach($pow2 as $v) {
    if($v <= $n) {
        echo $v. "\n";
        break;
    }
}

Measured memory_bytes: 4728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long h = Long.parseLong(sc.next());
        long w = Long.parseLong(sc.next());
        
        if(h == 1 || w == 1){
            System.out.println(1);
        }else if(h%2 == 0 || w%2 == 0){
            System.out.println(h*w/2);
        }else{
            System.out.println((h-1)*(w-1)/2 + h/2 + w/2 +1);
        }
    }
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N / 1000;
  b = N % 1000 / 100;
  c = N % 100 / 10;
  d = N % 10;

  if ((a == b && b == c) || (b == c && c == d)) {
    cout << "Yes" << endl;
  }
  
  else
    cout << "No" << endl;
  
}


Measured memory_bytes: 256
#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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
             1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << A[K - 1] << "\n";
  return 0;
}


Measured memory_bytes: 3648
a,b=input().strip().split(' ')
a,b=[int(a),int(b)]
c=input().strip()
d=0
if c[0]=='R':
  if c[1]=='R':
    d+=1
  
for i in range(1,a-1):
  if c[i]=='L':
    if c[i-1]=='L':
      d+=1
  elif c[i]=='R':
    if c[i+1]=='R':
      d+=1
if c[a-1]=='L':
  if c[a-2]=='L':
    d+=1
d=d+2*b
if d>(a-1):
  print (a-1)
else:
  print(d)
  
  


Measured memory_bytes: 3316
import sys
import math

sx,sy,tx,ty = list(map(int,input().split()))

dy=ty-sy
dx=tx-sx

a=""
a+="U"*dy
a+="R"*dx
a+="D"*dy
a+="L"*dx
a+="L"
a+="U"*(dy+1)
a+="R"*(dx+1)
a+="D"
a+="R"
a+="D"*(dy+1)
a+="L"*(dx+1)
a+="U"

print(a)

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
N,M=map(int,input().split())

L={}
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    d=0
    for j in c:
        d+=2**(N-j)
    if d not in L:
        L[d]=a
    else:
        if L[d]>a:
            L[d]=a
#print(L)

D={}
D[0]=0
C=0
for i in range(N):
    C+=2**(N-1-i)
    E={}
    for j in D:
        for k in L:
            if j>=C:
                if j not in E:
                    E[j]=D[j]
                else:
                    if E[j]>D[j]:
                        E[j]=D[j]
            if j|k>=C:
                if j|k not in E:
                    E[j|k]=D[j]+L[k]
                else:
                    if E[j|k]>D[j]+L[k]:
                        E[j|k]=D[j]+L[k]
    #print(E)
    D=E
if len(D)==0:
    print(-1)
else:
    print(D[2**N-1])

Measured memory_bytes: 44252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
#define enld endl
int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(auto &x:s){
        if(x=='o')cnt++;
    }
    cout<<700+cnt*100<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  
  string res = "Yes";
  int s = S.size();
  
  for (int i = 0; i < s; i++) {
    if (S.at(i) == T.at(i)) {
    
    } else {
      res = "No";
    } 
  }
  
  cout << res << endl;
  
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
#ifdef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
  boost::for_each(vc, [&os](T value) {
#else
  std::for_each(vc.begin(), vc.end(), [&os](T value) {
#endif
    os << value << '\n';
    });
  return os;
    }

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

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  //string S{}; std::cin >> S;
  //ui N{}; cin >> N;

  vector<ui> vc(5);
  rep(0, vc.size()) cin >> vc[i];


  auto ans = boost::accumulate(vc, 0ULL, [](auto res, auto p) {
    return res + (p + (p % 10U ? (10 - p % 10ULL) : 0U));
    });
  
  auto it = boost::min_element(vc, [](auto v1, auto v2) {
    return (v1 % 10 ? v1 % 10 : 10) < (v2 % 10 ? v2 % 10 : 10);
    });

  ans -= (*it % 10U ? (10 - *it % 10ULL) : 0);

  using std::cout;
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[4] = {1,4,7,9};
  int b[4];

  for(int i = 0;i < 4;i++){
	cin >> b[i];
  }

  sort(b, b + 4);

  int flag = 0;
  for(int i = 0;i < 4;i++){
	if(a[i] != b[i]){
	  flag = 1;
	  break;
	}
  }

  if(flag) cout << "NO" << endl;
  else     cout << "YES" << endl;
  
  return 0;
}


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

using namespace std;

using ull = unsigned long long;
using vi = vector<int>;

int N;
int minval, maxval;

int main() {
  scanf("%d", &N);

  minval = 1000000001, maxval = -1;
  int buf;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &buf);
    if (buf < minval) minval = buf;
    if (buf > maxval) maxval = buf;
  }

  printf("%d\n", maxval - minval);  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class c{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        int ans = 0;
        int[] dp = new int[n+1];
        dp[1] = 1;
        CreatePrimeDp(ref dp, n);
        for(int i=1; i<n; i++){
            if(i == 1){
                ans++;
                continue;
            }
            //Console.WriteLine(i + "---------");
            var primes = CreateFastPrime(i, dp);
            var dict = new Dictionary<int, int>();
            foreach(int prime in primes){
                if(dict.ContainsKey(prime)){
                    dict[prime]++;
                }
                else{
                    dict[prime] = 1;
                }
            }
            int add = 1;
            foreach(var set in dict){
                add *= (set.Value+1);
                //Console.WriteLine(set);
            }
            ans += add;
        }
        Console.WriteLine(ans);
    }
    public static void CreatePrimeDp(ref int[] dp, int size){
        for(int i=2; i<=size; i++){
            int t = i;
            while(t <= size){
                if(dp[t] == 0){
                    dp[t] = i;
                }
                t += i;
            }
        }
    }
    public static IEnumerable<int> CreateFastPrime(int n, int[] dp){
        while(n > 1){
            yield return dp[n];
            n /= dp[n];
        }
        //yield return dp[n];
    }
}


Measured memory_bytes: 25344
import java.util.*;
// warm-up
// Have to check the post hyphen string for digit as well.
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt(), i=A+1;
		String s = sc.next();
		boolean ok = s.charAt(A)=='-';
		if (ok) while (i<A+B+1) ok&=Character.isDigit(s.charAt(i++));
		i=0;
		if (ok) while (i<A) ok&=Character.isDigit(s.charAt(i++));
		System.out.println(ok ? "Yes" : "No");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35712
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
TA = [LIST() for _ in range(N)]

T = TA[0][0]
A = TA[0][1]

for t, a in TA[1:]:
	p = max((T+t-1)//t, (A+a-1)//a)
	T = t*p
	A = a*p
	
print(T+A)



Measured memory_bytes: 10520
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

E = lcm(C, D)
count_A = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//E
count_B = B - B//C - B//D + B//E

print(count_B - count_A)

Measured memory_bytes: 5460
from collections import Counter
N,K = map(int, input().split())
a = [int(i) for i in input().split()]
cnt = Counter(a)
mc = cnt.most_common()
j = 0
ans = 0
while j < len(mc)-K:
  obj = mc[len(mc)-1-j]
  ans += obj[1]
  j += 1
print(ans)

Measured memory_bytes: 39288
n,i;ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],R[2<<17];
dfs1(u,p,i,I){
	dp1[u]=1;
	for(i=first[u];I=eb[i];i=next[i])I-p?dfs1(I,u),dp1[u]=dp1[u]*-~dp1[I]%M:0;
}
dfs2(u,p,x,i,I){
	for(make(i=first[u],p);I=eb[i];I-p?dfs2(I,u,R[i]*x%M+1,0,0),x=x*-~dp1[I]%M:0)i=next[i];
	dp2[u]=x%M;
}
make(i,p){
	i?make(next[i],p),R[i]=R[next[i]]*(eb[i]-p?-~dp1[eb[i]]:1)%M:0;
}
main(u,v){
	for(;~scanf("%d%d",&u,&v);)i++?ea[i-1]=eb[i]=u,eb[i-1]=ea[i++]=v:(n=u,M=v);
	for(;--i;first[ea[i]]=i)next[i]=first[ea[i]];
	dfs1(*R=1,0);
	dfs2(1,0,1);
	for(;i++<n;)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 13824
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	res := map[int]int{}
	for i := 1; i < n/2+1; i++ {
		if i != n-i {
			res[i] = n - i
		}
	}
	fmt.Println(len(res))
}


Measured memory_bytes: 40320
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void){
  int a,b;

  while(scanf("%d%d",&a,&b)!=EOF){
  int c=a+b;
  int count=1;
  while(1){
    if(c>=10)c=c/10;
    count++;
    if(c<10)break;
}
  cout<<count<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>

#define INFINITY 2000000000
#define MAX 100000

int cnt=0;

struct card{
    char alp;
    int num;
};

struct card L[MAX/2+2],R[MAX/2+2];

void merge(struct card a[],int n,int left,int mid,int right){
	int n1=mid-left;
	int n2=right-mid;
	for(int i=0;i<n1;i++){
		L[i]=a[left+i];
	}
	for(int i=0;i<n2;i++){
		R[i]=a[mid+i];
	}
	L[n1].num=INFINITY;
	R[n2].num=INFINITY;
	int i=0;
	int j=0;
	for(int k=left;k<right;k++){
		cnt++;
		if(L[i].num<=R[j].num){
			a[k]=L[i];
			i++;
		}else{
			a[k]=R[j];
			j++;
		}
	}
}

void msort(struct card a[],int n,int left,int right){
	if(left+1<right){
		int mid=(left+right)/2;
		msort(a,n,left,mid);
		msort(a,n,mid,right);
		merge(a,n,left,mid,right);
	}
}

int partition(struct card a[],int n,int p,int r){
    int i,j;
    struct card t,x;
    x=a[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(a[j].num<=x.num){
            i++;
            t=a[i];
            a[i]=a[j];
            a[j]=t;
        }
    }
    t=a[i+1];
    a[i+1]=a[r];
    a[r]=t;
    return i+1;
}

void quicksort(struct card a[],int n,int p,int r){
    int q;
    if(p<r){
        q=partition(a,n,p,r);
        quicksort(a,n,p,q-1);
        quicksort(a,n,q+1,r);
    }
}

int main(void){

	int n,v;
    struct card a[MAX],b[MAX];
    char s[10];
    int stable=1;
    
	scanf("%d",&n);

	for(int i=0;i<n;i++){
		scanf("%s %d",s,&v);
        a[i].alp=b[i].alp=s[0];
        a[i].num=b[i].num=v;
	}
	
	msort(a,n,0,n);
	quicksort(b,n,0,n-1);
	
	for(int i=0;i<n;i++){
        if(a[i].alp!=b[i].alp)stable=0;
    }

    if(stable==1)printf("Stable\n");
    else printf("Not stable\n");
    for (int i = 0; i < n; i++){
        printf("%c %d\n",b[i].alp,b[i].num);
    }
    
	return 0;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  for (int i = 0; i < A; i++)
  {
    cin >> s[i];
  }
  for (int i = 0; i < B; i++)
  {
    cin >> t[i];
  }
  s.push_back(INF), s.push_back(-INF);
  t.push_back(INF), t.push_back(-INF);
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  for (int i = 0; i < Q; i++)
  {
    ll x;
    cin >> x;
    int sa, sb, ta, tb;
    sb = upper_bound(s.begin(), s.end(), x) - s.begin();
    sa = sb;
    sa--;
    tb = upper_bound(t.begin(), t.end(), x) - t.begin();
    ta = tb;
    ta--;
    ll res = INF;
    // 最初にsを訪れる
    for (int i = 0; i < 2; i++)
    {
      ll first = (i ? s[sa] : s[sb]);
      for (int j = 0; j < 2; j++)
      {
        ll second = (j ? t[ta] : t[tb]);
        res = min(res, abs(x - first) + abs(second - first));
      }
    }
    // 最初にtを訪れる
    for (int i = 0; i < 2; i++)
    {
      ll first = (i ? t[ta] : t[tb]);
      for (int j = 0; j < 2; j++)
      {
        ll second = (j ? s[sa] : s[sb]);
        res = min(res, abs(x - first) + abs(second - first));
      }
    }
    cout << res << endl;
  }
  return 0;
}

// 二分探索で最も近い西の寺と東の寺，西の神社と東の神社をそれぞれsa, sb, ta, tbとする．これらをどの順番で訪れるかで8通りを全探索する．sa->ta, sa->tb, sb->ta, sb->tbとその逆順．配列外アクセスにならないようにINF, -INFの位置に番兵があるとする．


Measured memory_bytes: 2912
/// Source : https://atcoder.jp/contests/abc043/tasks/abc043_a
/// Author : liuyubobobo
/// Time   : 2020-09-22

#include <iostream>
#include <cstdio>

using namespace std;


/// Mathematics
/// Time Complexity: O(1)
/// Space Complexity: O(1)
class Solution{

public:
    int candy(int N){
        return (1 + N) * N / 2;
    }
};

int main() {

    int N;
    scanf("%d", &N);
    printf("%d\n", Solution().candy(N));
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    set<string> as;
    while (n--)
    {
        string s;
        cin >> s;
        as.insert(s);
    }
    cout << as.size() << '\n';
    return 0;
}

Measured memory_bytes: 19216
#include <bits/stdc++.h>
using namespace std;
long long f[101][100001];
int w[101];
int v[101];
int N,W;
int main()
{
	int i,j,max_v=0,ans=0;
	scanf("%d %d",&N,&W);
	for(i=1;i<=N;i++)
	{
		scanf("%d %d",&w[i],&v[i]);
		max_v=max(max_v,v[i]);	
	}
	max_v=max_v*N;
	memset(f,0x7f,sizeof(f));
	for(i=0;i<=N;i++)
		f[i][0]=0;
	for(i=1;i<=N;i++)
	{
		for(j=1;j<=max_v;j++)
		{
			f[i][j]=f[i-1][j];
			if(j>=v[i])
				f[i][j]=min(f[i][j],f[i-1][j-v[i]]+w[i]);	
		}	
	}
	for(j=1;j<=max_v;j++)
	{
		if(f[N][j]<=W)
			ans=max(ans,j);	
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 79104
#pragma GCC optimize("O3")
#include<stdint.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define VIS(it,con) for(auto it=con.begin();it!=con.end();++it)
#define pob pop_back
#define pf push_front
#define pof pop_front
#define MIN(x,y) (x=min(x,(y)))
#define MAX(x,y) (x=max(x,(y)))
#define mid (l+r>>1)
#define lch (idx*2+1)
#define rch (idx*2+2)
/*****************************************************************************/
#include<bits/stdc++.h>
#define int int_fast64_t
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> VI;
#define REP(i,j,k) for(register int i=(j);i<(k);++i)
#define RREP(i,j,k) for(register int i=(j)-1;i>=(k);--i)
#define ALL(a) a.begin(),a.end()
#define MST(a,v) memset(a,(v),sizeof a)
#define pb push_back
#define F first
#define S second
#define endl '\n'
																#define __debug
#ifdef __debug
	#define IOS (void)0
	#define de(...) cerr<<__VA_ARGS__
	#define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);}
#else
	#define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false)
	#define de(...) (void)0
	#define ar(...) (void)0
#endif
/***********************************default***********************************/
const int maxn=5e5+9,mo=998244353;
int n,m,fac[maxn],res=0;

int qp(int x,int t=mo-2){
	int re=1;
	while(t){
		if(t&1)re=re*x%mo;
		x=x*x%mo,t>>=1;
	}
	return re;
}

int c(int x,int y){
	if(x==y)return 1;
	else if(y>x||y<0)return 0;
	else return fac[x]*qp(fac[y])%mo*qp(fac[x-y])%mo;
}

main(){
	IOS;
	fac[0]=1;REP(i,1,maxn)fac[i]=fac[i-1]*i%mo;
	cin>>n>>m;
	REP(i,0,min(n,m)+1){
		(res+=(i%2?-1:1)*c(n,i)*c(m,i)%mo*fac[i]%mo*qp(m+1,n-i)%mo*qp(n+1,m-i)%mo)%=mo;
	}
	cout<<(mo+res%mo)%mo<<endl;
}

Measured memory_bytes: 4224
use std::collections::{HashMap, VecDeque};
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
struct Main {
    k: usize,
    a: Vec<Vec<i64>>,
}
impl Main {
    fn invoke(&mut self) {
    }
}

fn main() {
    let n: u64 = read();
    let mut sum = 0 as u64;
    for n_one in 1..n+1 {
        if !(n_one % 3 == 0 || n_one % 5 == 0) {
            sum += n_one;
        }
    }
    println!("{}", sum);

//    Main {
//        k: k,
//        a: vec![(1..10).collect::<Vec<i64>>(); 10],
//    }
//    .invoke()
}


Measured memory_bytes: 2152
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,sum = 0,m = 1000,c;
  cin >> n;
  vector<int> a(n);
  cin >> a[0];
  for (int i = 1; i < n; i++){
    a[i] = a[i-1] + 1;
  }
  for (int i = 0; i < n; i++){
    if (m > abs(0 - a[i])){
      m = abs(0 - a[i]);
      c = i;
    } 
  }
  for (int i = 0; i < n; i++){
    if (i != c){
      sum += a[i];
    }
  }
  cout << sum << '\n';
  return 0;
}

Measured memory_bytes: 256
import sys
def main():
    s=sys.stdin.readline().strip()
    x=[0 for _ in [0]*2020]
    x[0],c=1,0
    m,d=0,1
    for i in reversed(s):
        m+=(int(i)*d)
        x[m%2019]+=1
        d=(d*10)%2019
    for v in x:c+=v*(v-1)//2
    print(c)
if __name__=='__main__':main()

Measured memory_bytes: 9196
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,Z,W;

int main(){
    cin>>N>>Z>>W;
    int a[N];
    rep(i,N)cin>>a[i];
    if(N==1){
        out(abs(a[0]-W));
    }
    else if(N==0){
        out(abs(Z-W));
    }
    else{
        out(max(abs(a[N-1]-W),abs(a[N-2]-a[N-1])));
    }
}


Measured memory_bytes: 256
#include"stdio.h"
#include"iostream"
using namespace std;
int main(void) {
	int a, b;
	cin >> a;
	cin >> b;

	if (a == 1 && b == 2) cout << "3";
	else if (a == 1 && b == 3) cout << "2";
	else if (a == 2 && b == 3) cout << "1";
	else if (a == 2 && b == 1) cout << "3";
	else if (a == 3 && b == 1) cout << "2";
	else if (a == 3 && b == 2) cout << "1";

}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

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

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> a(m);
    vector<int> p(m);
    for(int i = 0; i < m; ++i){
        int k;
        cin >> k;
        a[i] = vector<int>(k);
        for(int j = 0; j < k; ++j){
            cin >> a[i][j];
            --a[i][j];
        }
    }
    for(int i = 0; i < m; ++i){
        cin >> p[i];
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); ++i){
        int cnt_l = 0;
        for(int j = 0; j < m; ++j){
            int cnt_s = 0;
            for(auto && k : a[j]){
                if((i >> k) & 1) ++cnt_s;
            }
            if(cnt_s % 2 == p[j]) ++cnt_l;
        }
        if(cnt_l == m) ++ans;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384