akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
ll S[50][50];
vector<ll> XOR(vector<ll> a, vector<ll> b) {
    vector<ll> ret(a.size());
    for(int i = 0; i < a.size(); i++) {
        ret[i] = (a[i] ^ b[i]);
    }
    return ret;
}
int H, W, D;

void print(vector<ll> v) {
    return;
    for(auto tmp : v) {
        cout << bitset<64>(tmp) << " ";
    }
    cout << endl;
}

int solve() {
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            cin >> S[h][w];
        }
    }
    vector<vector<ll>> base(H * W);
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            vector<ll> v;
            ll num = 0;
            for(int h1 = 0; h1 < H; h1++) {
                for(int w1 = 0; w1 < W; w1++) {
                    if(num == 0) v.push_back(0);
                    int d = abs(h-h1) + abs(w-w1);
                    if(d == 0 or d == D) v.back() |= (1LL << num);
                    num++;
                    num %= 62;
                }
            }
            print(v);
            for(int i = 0; i < h*W+w; i++) {
                chmin(v, XOR(v, base[i]));
            }
            base[h*W+w] = v;
        }
    }
    sort(base.begin(), base.end(), greater<vector<ll>>());
    vector<ll> V;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            ll num = h * W + w;
            if(num % 62 == 0) V.push_back(0);
            num %= 62;
            V.back() += (S[h][w] * (1LL << num));
        }
    }
    for(auto q : base) {
        chmin(V, XOR(V, q));
    }
    int ans = 1;
    for(auto tmp : V) {
        if(tmp) ans = 0;
    }
    cout << ans << endl;
    return 0;
}

int main() {
    while(cin >> W >> H >> D) {
        if(W == 0) break;
        solve();
    }
}


Measured memory_bytes: 3108
/**********************************************************
* @Author: 			   Kirito
* @Date:   			   2020-07-25 20:06:53
* @Last Modified by:   Kirito
* @Last Modified time: 2020-07-25 20:10:01
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

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

const int maxn=111111;


int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(k&&b<=a){
		b<<=1;
		k--;
	}
	while(k&&c<=b){
		c<<=1;
		k--;
	}
	if(b>a&&c>b)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

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

void solve(void){
  
  long long int x,k;
  cin >> x >> k;
  
	x=x%k;
  
  if(k-x>x) cout << x << endl;
  else cout << k-x <<endl;
  return;
/*
	int n,m;
  cin >> n >> m;
	
  int i;
  long long int A[n],total=0;
  rep(i,n){
    cin >> A[i];
	total+=A[i];
  }
  
  int mmax=0;

  sort(A,A+n);
  
  if(A[n-m]*4*m>total){
  
    if(n==m){
      
      cout << "Yes" <<endl;
     return; 
    }else if(n!=m&&A[n-m]!=A[n-m-1]){
    cout << "Yes" <<endl;
   return; 
  }}
    
  cout << "No" << endl;
  
  return;
  */
}

int main(void){
  
	solve();
	return 0; 
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
L = []
for i in range(N):
  L.append(int(input()))
def Base_10_to_n(X,n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n),n)+str(X%n)
  return str(X%n)
n = 4
ans = float('inf')
for X in range(n**N):
  STR = Base_10_to_n(X,n).zfill(N)
  cur = 0
  TAKEA = 0
  TAKEB = 0
  TAKEC = 0
  for i in range(len(STR)):
    if STR[i] == '1':
      TAKEA += L[i]
      cur += 10
    elif STR[i] == '2':
      TAKEB += L[i]
      cur += 10
    elif STR[i] == '3':
      TAKEC += L[i]
      cur += 10
  if TAKEA != 0 and TAKEB != 0 and TAKEC != 0:
    cur += abs(TAKEA-A)+abs(TAKEB-B)+abs(TAKEC-C)
    cur -= 30
    if cur <= ans:
      ans = cur
print(ans)

Measured memory_bytes: 3064
# coding: utf-8
# Your code here!

S=list(map(int,input()))
ans=0
for i in range(2**(len(S)-1)):
    bin_str=format(i,"0{}b".format(len(S)-1))
    ans+=S[-1]
    k=1
    for j in range(len(S)-1):
        if bin_str[-j]=="1":
            k=0
        ans+=S[-(2+j)]*(10**k)
        k+=1

print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    if(c > a && c > b && b > a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll n,m,k;
    cin >> n >> m >> k;
    vector <ll> a(n);
    vector <ll> b(m);
    for (ll i =0; i< n ; i++) cin >> a[i];
    for (ll i =0; i< m; i++) cin >> b[i];
    int ans = 0;
    ll c[m];
    c[0] = 0;
    for (int i = 0; i < m; i++) {
        c[i+1] = c[i] + b[i];
    }
     ll t = 0;
    for (int i = 0; i <= n; i++) {
        if (i != 0) {
            t += a[i - 1];
        }
        if (t > k) break;
        int l = -1;
        int r = m + 1;
        while (r - l > 1) {
            int d = (l + r) / 2;
            if (t + c[d] <= k) {
                l = d;
            } else {
                r = d;
            }
        }
        ans = max(ans, i + l);
    }

    cout << ans << endl;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

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

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int H,W,h,w;
	cin >> H >> W >> h >> w;
	ANS(H * W - h * W - H * w + h * w);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main(){
    string str;
    string word;
    int num =0;
    cin >> word;
    for(int i=0;i<word.size();i++){
        if('A'<=word[i] && 'Z'>= word[i]) word[i] += 'a' - 'A';
    }
    cin >> str;
    while(str != "END_OF_TEXT"){
        for(int i=0;i<str.size();i++){
            if('A'<=str[i] && 'Z'>= str[i])str[i] += 'a' - 'A';
        }
        if(word == str) num++;
        cin >> str;
    }
    cout << num << endl;
    
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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;
}

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    string S; cin >> S;

    int l=0, r=S.size()-1;
    int ans=0;

    while(l<r){
        //cout << "l= " << l << " r= " << r << endl;
        if(S[l]==S[r]){
            ++l, --r;
        }else{
            if(S[l]=='x'){
                ++l;
                ++ans;
            }else if(S[r]=='x'){
                --r;
                ++ans;
            }else{
                cout << -1 << endl;
                return 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cmath>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;

int main() {
    long long A;
    long long B;
    long long C;

    cin >> A >> B >> C;

    // A + 2*sqrt(A*B) + B < C
    // 2*sqrt(*A*B) < (C-B-A)
    // 4*A*B < (C-B-A)^2
    long long diff = C-B-A;
    if (4*A*B < diff*diff && diff > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

int main(void) {
    string s;
    cin >> s;
    if (s.find('A') != string::npos && s.find('B') != string::npos) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/
i32 dp[3010][3010];  // dp[i][j]: i個目までの料理からj分以内に食べきる時のおいしさの合計の最大値

/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n, t; cin >> n >> t;
    vec<PII> ab(n);
    rep(i,n) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(all(ab));

    rep(i,n) rep(j,t) {
        if(j-ab[i].first >= 0) chmax(dp[i+1][j], dp[i][j-ab[i].first] + ab[i].second);
        chmax(dp[i+1][j], dp[i][j]);
    }

    i32 answer = -1;
    rep1(i,n) {
        i32 tmp = 0;
        for(i32 j = i; j < n; ++j) {
            chmax(tmp, ab[j].second);
        }
        tmp += dp[i][t-1];
        chmax(answer, tmp);
    }

//    // Debug
//    rep(i,n)rep(j,t) cout << dp[i][j] << (j==t-1 ? '\n' : ' ');


    cout << answer << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll M, N;
    cin >> N >> M;
    VL A(N);
    ll sum = 0;
    rep(i, 0, N){
        cin >> A[i];
        sum += A[i];
    }
    sort(ALL(A), greater<ll>());
    rep(i, 0, M){
        if(4*M*A[i] < sum){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
  int a[32]={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;
  scanf("%d",&k);
  printf("%d",a[k-1]);
  return 0;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
# define ll long long int
# define ld long double
# define pb push_back
# define mp make_pair
# define mod 1000000007
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#else
// online submission
	#endif
	IOS
	int r,c,k;
	cin >> r >> c >> k;
	char arr[r+1][c+1] = {'a'};
	int row[r][c+1] = {0}, col[r+1][c] = {0};
	int tot = 0;
	for(int i = 0; i < r; i++){
		for(int j = 0; j < c; j++){
			cin >> arr[i][j];
			if(arr[i][j] == '#')
				tot++;
		}
	}
	for(int i = 0; i < r; i++){
		row[i][0] = (arr[i][0] == '#');
		for(int j = 1; j <= c; j++){
			row[i][j] = row[i][j - 1] + (arr[i][j] == '#');
		}
	}
	for(int j = 0; j < c; j++){
		col[0][j] = (arr[0][j] == '#');
		for(int i = 1; i <= r; i++){
			col[i][j] = col[i - 1][j] + (arr[i][j] == '#');
		}
	}
	int ways = 0;
	for(int i = 0; i < (1 << r ); i++){	//Change was made here: (1 << r + 1) --> (1 << r)
		int x = 0;
		vector<int> tempx;
		for(int j = 0; j < r; j++){
			if((i & (1 << j))){
				tempx.pb(j);
				x += row[j][c];
			}
		}
		for(int j = 0; j < (1 << c); j++){	//Change was made here: (1 << c + 1) --> (1 << c)
			int y = 0;
			vector<int> tempy;	
			for(int t = 0; t < c; t++){
				if((j & (1 << t))){
					y += col[r][t];
					tempy.pb(t);
				}
			}
			if(tempx.size() > 0 && tempy.size() > 0){
				for(int a : tempx){
					for(int b : tempy){
						y -= (arr[a][b] == '#');
					}
				}
			}
			if(tot - x - y == k){
				// if(tempx.size() > 0 && tempy.size() > 0){
				// 	for(int a : tempx){
				// 		for(int b : tempy){
				// 			cout << a << " " << b << endl;
				// 		}
				// 	}
				// }
				ways++;
				// cout << ways << " --------------XXX--------------\n";
			}
		}
	}
	cout << ways;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>




struct UnionFind
{

  vector<int> par;
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    rep(i,n) par[i] = i;
  }

  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]); 
  }

  bool unite(int x, int y) {

    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (sizes[x] < sizes[y]) swap(x, y);

    par[y] = x;
    sizes[x] += sizes[y];

    return true;
  }

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

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

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

  int n,m;
  cin>>n>>m;
  int res=n*(n-1)/2;
  UnionFind uf(n);
  vector<P> v;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    v.PB(P(a,b));
  }

  reverse(all(v));
  vi ans;
  rep(i,m){
    ans.PB(res);
    //cout<<res<<endl;
    int a=v[i].F,b=v[i].S;
    if(uf.find(a,b)) continue;
    res-=uf.size(a)*uf.size(b);
    //cout<<uf.size(a)<<' '<<uf.size(b)<<endl;
    uf.unite(a,b);
  }

  rep(i,m){
    cout<<ans[m-i-1]<<endl;
  }

}

Measured memory_bytes: 6256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
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;}

int dp[1010101];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
 
    for(auto t : a){
        for(int i=1;i*t<=a.back();i++){
            dp[i*t]++;
        }
    }
    int ans = 0;
    for(auto t : a){
        if(dp[t] == 1) ans++;
    }
    cout<<ans<<endl;
    return 0;

}

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

using namespace std;

int x, k;
long long f[105][4];

long long call (int l, int last) {
  if (l < 0) return 0;
  if (l == 0) return last;
  if (f[l][last] != -1) return f[l][last];
  f[l][last] = call(l - 1, last ^ 1);
  if (last == 0) f[l][last] += call(l - k, 1);
  return f[l][last];
}

int main() {
  cin >> x >> k;
  memset(f, -1, sizeof f);
  long long ans = 0;
  for (int i = 1; i <= x; ++i) {
    ans += call(i, 0);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
using pll = pair<long long, long long>;

int main() {
    int N; cin >> N;
    vector<pll> pos(N);
    for (int i = 0; i < N; ++i) cin >> pos[i].first >> pos[i].second;
    
    int par = (abs(pos[0].first) + abs(pos[0].second)) % 2;
    for (int i = 0; i < N; ++i) {
        int par2 = (abs(pos[i].first) + abs(pos[i].second)) % 2;
        pos[i] = pll(pos[i].first + pos[i].second, pos[i].first - pos[i].second);
        if (par2 != par) {
            cout << -1 << endl;
            return 0;
        }
    }
    
    vector<long long> d;
    for (int i = 30; i >= 0; --i) d.push_back(1LL<<i);
    if (par % 2 == 0) d.push_back(1);
    cout << d.size() << endl;
    for (int j = 0; j < d.size(); ++j) cout << d[j] << " ";
    cout << endl;
    
    for (int i = 0; i < N; ++i) {
        int xdir, ydir;
        long long xsum = 0, ysum = 0;
        for (int j = 0; j < (int)d.size(); ++j) {
            if (xsum <= pos[i].first) xdir = 1, xsum += d[j];
            else xdir = -1, xsum -= d[j];
            if (ysum <= pos[i].second) ydir = 1, ysum += d[j];
            else ydir = -1, ysum -= d[j];
            
            if (xdir == 1 && ydir == 1) cout << "R";
            else if (xdir == 1 && ydir == -1) cout << "U";
            else if (xdir == -1 && ydir == -1) cout << "L";
            else cout << "D";
        }
        cout << endl;
    }
}


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

int main(){
  int n; cin >> n;
  vector<int> p(n);
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  int a = 0, b = 0, out=0;
  for(int i = 1; i < n- 1; i++){
    if(p.at(i) > p.at(i-1)){
      a=1;
    }else{
      b=1;
    }
    if(a==1){
      if(p.at(i) < p.at(i+1)){
        out++;
      }
    }
    if(b==1){
      if(p.at(i) > p.at(i+1)){
        out++;
      }
    }
    a=0;b=0;
  }
  cout << out;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
cnt = [[0,0] for _ in range(N)]
for i,a in enumerate(A):
    for j,b in enumerate(A):
        if a > b:
            if i < j:
                cnt[i][1] += 1
            if i > j:
                cnt[i][0] += 1

ans = 0
mod = 10**9 + 7
for c in cnt:
    ans += c[0]*(K-1)*K//2
    ans += c[1]*K*(K+1)//2
    ans %= mod
print(ans)


Measured memory_bytes: 3308
N = int(input())
A = list(map(int, input().split()))
A.sort()
s = set()
count = 0
for x in A:
    if x not in s:
        s.add(x)
    else:
        count += 1

if count % 2 == 0:
    print(len(s))
else:
    print(len(s) - 1)


Measured memory_bytes: 14208
S = input()
chars = []
res = True
for i in range(len(S)):
  if len(chars) == 0:
    chars += [S[i]]
  elif len(chars) == 1:
    if S[i] == chars[0]:
      continue
    else:
      chars += [S[i]]
  elif len(chars) == 2:
    if S[i] == chars[0] or S[i] == chars[1]:
      continue
    else:
      res = False
print('Yes' if res and len(chars) == 2 else 'No')


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <iomanip>
#include <sstream>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 1LL << 60;
const int inf = 1 << 30;

int main() {
    string S; ll K;
    cin >> S >> K;
    int cnt = 0;
    char c;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] != '1') {
            c = S[i];
            break;
        }
        ++cnt;
    }
    if (K <= (ll)cnt) {
        cout << 1 << endl;
    }
    else {
        cout << c << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn=1, Kr=1, Knr=1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int hand[200005];

int main()
{
	int P, Q, R;
	cin >> P >> Q >> R;

	int x = max(max(P, Q), R);

	cout << P + Q + R - x;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	long long i, N, SUM;

	scanf("%lld", &N);
	SUM = 0;

	for(i = 0; i <= N; i++){
		if(i % 3 == 0||i % 5 == 0)
			SUM = SUM;
		else
			SUM = SUM + i;
		
	}

	printf("%lld", SUM);

	return 0;

}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);    
#define f(i,j,k)  for(int i=j;i<k;i++)
#define fr(i,j,k) for(int i<=k-1;i>=j;i--)
#define ll long long
#define ld long double
#define pi 3.14159265359
using namespace std;

int main()
{
	fio
	int TC;
	// cin>>TC;
	TC=1;
	while(TC--)
	{
		long double r;
		cin>>r;
		cout<<2*pi*r<<endl;
		
	}
	return 0;
}


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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
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; }
//lambda: [&](int x, int y){return x<y;}

signed main(void){
    string s;cin>>s;
    ll n=s.size(),sum=0;
    rep(tmp,1<<(n-1)){
        ll t=0;
        rep(i,n){
            t+=s[i]-'0';
            if(i==n-1||tmp&(1<<i)){
                sum+=t;
                t=0;
            }else{
                t*=10;
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
import math
from functools import reduce
from operator import add
from operator import sub


def round_up(x, y):

    if x % 10 == 0:
        return x
    else:
        roundup = int((x / y) + 1) * y
        return roundup


# int型
cook_time = [int(input()) for i in range(5)]
# 1の位を0へ
cook_time_round = list(map(lambda x: round_up(x, 10), cook_time))
# cook_time - cook_time_round
cook_time_difference = list([sub(x, y) for x, y in zip(cook_time_round, cook_time)])
# 合計時間
total_time = reduce(add, cook_time_round)

print(total_time - reduce(max, cook_time_difference))


Measured memory_bytes: 3572
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long		
int a[214514];
int b[214514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	int sum=0;
	rep(0,i,n){
		if(a[i]!=i+1){
			sum++;
		}
	}
	if(sum<=2){
		c("YES")
	}
	else{
		c("NO")
	}
} 					

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)
 
template <typename T>
void debug_out(T t) {
  cerr << t;
}
 
template <typename A, typename B>
void debug_out(pair<A, B> u) {
  cerr << "(" << u.first << " " << u.second << ")";
}
 
template <typename T>
void debug_out(vector<T> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << ", ";
  }
}
 
template <typename T>
void debug_out(vector<vector<T>> t) {
  int sz = t.size();
  for(int i = 0; i < sz; i++) {
    debug_out(t[i]);
    if(i != sz - 1) cerr << endl;
  }
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:" << endl, debug_out(__VA_ARGS__), cerr << endl;
 
struct edge {
  int u, v;
  edge(){};
  edge(int _u, int _v) : u(_u), v(_v) {};
};
 
void debug_out(edge a) {
  debug_out(make_pair(a.u, a.v));
}
 
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  vector<edge> edges;
  range(i, 0, m) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--; v--;
    g[u].push_back(i);
    g[v].push_back(i);
    edges.emplace_back(u, v);
  }
  vector<int> used(m);
  int cnt = 0;
  int easy = 0;
  int foo = 0;
  range(i, 0, n) {
    int sz = g[i].size();
    if(sz & 1) {
      cout << "No";
      return 0;
    }
    if(sz == 4) foo++;
    easy = max(easy, sz);
  }
  if(easy > 4 || foo > 2) {
    cout << "Yes";
    return 0;
  }

  vector<int> cur;
  set<pair<int, int>> to;
  vector<int> was(n);
  vector<int> pas(n);
  function<void(int, int)> dfs = [&](int v, int par) {
    if(!to.empty()) return;
    cur.push_back(v);
    was[v] = 1;
    pas[v] = 1;
 
    int s = -1;
    for(int p : g[v]) {
      if(used[p]) continue;
      int u = (edges[p].u == v ? edges[p].v : edges[p].u);
      if(u == par) continue;
      if(was[u]) s = u;
    }
 
    if(~s) {
      reverse(cur.begin(), cur.end());
      while(cur.back() != s) cur.pop_back();
      range(i, 0, (int) cur.size()) to.insert(make_pair(cur[i], cur[(i + 1) % cur.size()]));
      return;
    }
 
    for(int p : g[v]) {
      if(used[p]) continue;
      int u = edges[p].u == v ? edges[p].v : edges[p].u;
      if(u == par) continue;
      if(!pas[u]) dfs(u, v);
      if(!to.empty()) return;
    }
 
    was[v] = 0;
    cur.pop_back();
  };
  dfs(0, -1);
  assert(to.size());
  int bug = 0;
  
  A:;
  bug += cur.size();
  cnt++;
  range(i, 0, m) {
    pair<int, int> s = make_pair(edges[i].u, edges[i].v);
    if(to.find(s) != to.end()) used[i] = 1;
    swap(s.first, s.second);
    if(to.find(s) != to.end()) used[i] = 1;
  }
  
  if(*min_element(used.begin(), used.end()) == 1) {
    cout << "No";
    return 0;
  }
  
  if(cnt == 2) {
    assert(bug < m);
    cout << "Yes";
    return 0;
  }
  
  range(i, 0, m) {
    if(!used[i]) {
      int u = edges[i].u;
      cur.clear(); to.clear();
      fill(was.begin(), was.end(), 0);
      fill(pas.begin(), pas.end(), 0);
      dfs(u, -1);
      goto A;
    }
  }
  return 0;
}


Measured memory_bytes: 17652
#include <bits/stdc++.h>
using namespace std;
 
int a[105];
int main(){
  int n;
  cin>>n;
  double sum = 0;
  for(int i=0;i<n;i++){
  	cin>>a[i];
    sum+=(1.0/a[i]);
  }
  cout<<fixed<<setprecision(10)<<(1.0/sum)<<endl;
}

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

#define rin(i,a,b) for(int i=(a);i<=(b);++i)
#define irin(i,a,b) for(int i=(a);i>=(b);--i)
#define trav(i,a) for(int i=head[a];i;i=e[i].nxt)
#define Size(a) (int)a.size()
#define pb push_back
#define mkpr std::make_pair
#define fi first
#define se second
#define lowbit(a) ((a)&(-(a)))
typedef long long LL;

using std::cerr;
using std::endl;

inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

const int MAXN=100005;

int n,fullmark;
LL B,sum[MAXN];

struct subj{
	int b,l,r;LL tot;
	inline friend bool operator < (subj x,subj y){
		return x.tot<y.tot;
	}
}s[MAXN];

bool check(LL mid){
	LL cnt=mid/fullmark,rem=mid-fullmark*cnt;
	if(!rem)return sum[n]-sum[n-cnt]>=B;
	rin(i,1,n){
		LL ext=0;
		if(i<=n-cnt)ext=sum[n]-sum[n-cnt];
		else ext=sum[n]-sum[n-cnt-1]-s[i].tot;
		if(rem<=s[i].b)if(rem*s[i].l+ext>=B)return true;
		if(rem>s[i].b)if(1ll*s[i].b*s[i].l+(rem-s[i].b)*s[i].r+ext>=B)return true;
	}
	return false;
}

int main(){
	n=read(),fullmark=read();
	rin(i,1,n){
		s[i].b=read();
		s[i].l=read();
		s[i].r=read();
		s[i].tot=1ll*s[i].b*s[i].l+1ll*(fullmark-s[i].b)*s[i].r;
		B+=1ll*s[i].b*s[i].l;
	}
	std::sort(s+1,s+n+1);
	rin(i,1,n)sum[i]=sum[i-1]+s[i].tot;
	LL l=0,r=1ll*fullmark*n,ans=0;
	while(l<=r){
		LL mid=((l+r)>>1);
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;

deque<ll> dque;
vector<ll> ans;

int main(void) {
  // Here your code !
  scanf("%lld", &n);

  for (int i = 1; i <= n; ++i) {
    int tmp;
    scanf("%lld", &tmp);

    if (i % 2 == 0) {
      dque.push_front(tmp);
    }
    else {
      dque.push_back(tmp);
    }
  }

  while (!dque.empty()) {
    ans.push_back(dque.front());
    dque.pop_front();
  }

  if (n % 2 == 1) {
    reverse(ans.begin(), ans.end());
  }

  for (auto e: ans) {
    printf("%lld ", e);
  }

  printf("\n");

  return 0;
}


Measured memory_bytes: 5488
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>

using namespace std;

int main(){
    int x_1, y_1, x_2, y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    int x_3, y_3, x_4, y_4;
    int temp_x,temp_y;

    temp_x = x_2 - x_1;
    temp_y = y_2 - y_1;

    x_3 = x_2 - temp_y;
    y_3 = y_2 + temp_x;

    temp_x = x_3 - x_2;
    temp_y = y_3 - y_2;

    x_4 = x_3 - temp_y;
    y_4 = y_3 + temp_x;

    printf("%d %d %d %d\n",x_3, y_3, x_4, y_4);
}

Measured memory_bytes: 256
import java.util.Scanner
import scala.collection.Searching._

import scala.annotation.tailrec

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {

  def solve(sc: => Scanner): Unit = {
    val N, M = sc.nextInt
    val A = Array.fill[Set[Int]](N)(Set[Int]())
    for (i <- 0 until N) {
      A(i) = A(i) ++ Set(i)
    }
    val B = Array.fill(M)((sc.nextInt, sc.nextInt)).sorted
    for (i <- 0 until M) {
      A(B(i)._2) = A(B(i)._2) ++ A(B(i)._2 - 1)
      A(B(i)._2 - 1) = A(B(i)._2) ++ A(B(i)._2 - 1)
    }
    println(A.map(x=>x.size).mkString(" "))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}

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

int m, n;
char a[100][100], b[100][100];

int main(){
  cin >> n >> m;
  rep(i, n){
    cin >> a[i];
    //cerr << a[i] << endl;
  }
  rep(i, m){
    cin >> b[i];
  }
  string res = "No";
  rep(i, n - m + 1){
    rep(j, n - m + 1){
      bool flag = true;
      for(int k = 0; k < m; k++){
        for(int l = 0; l < m; l++){
          if(a[i + k][j + l] != b[k][l]){
            flag = false;
            cerr <<k <<" "<< l<<endl;
          }
        }
      }
      if(flag){
        res = "Yes";
      }
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n, 100007);
  for (ll i = 0; i < n - 1; i++) {
    ll tmp;
    cin >> tmp;
    a.at(i) = tmp;
  }
  for (ll i = 0; i < n - 1; i++) {
    ans += min(a.at(i), a.at(i + 1));
  }
  ans += a.at(0);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chkmax(T& a,T b){return a<b?a=b,1:0;}
template<class T> inline bool chkmin(T& a,T b){return a>b?a=b,1:0;}
template<typename T> inline T& read(T& x){
    static char c; bool flag=0;
    while(!isdigit(c=getchar())) if(c=='-') flag=1;
    for(x=c-'0';isdigit(c=getchar());(x*=10)+=c-'0');
    if(flag) x=-x;
    return x;
}
int n,m,k;
int main(){
#ifdef xffyjq
    freopen("exec.in","r",stdin);
    freopen("exec.out","w",stdout);
#endif
    read(n); read(m); read(k);
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++) if(i*m+j*n-i*j*2==k) puts("Yes"),exit(0);
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    double ans=0;
    ll N,K;
    cin >> N >> K;
    double fw = 0;
    if (N > K-1) {
        fw = double(N - (K-1))/N;
        ans += fw;
    }
    if (K > 1) {
        double p = 0;
        for (ll n=1; n<=min(K-1,N); ++n) {
            ll d = 1;
            ll m = n;
            while (m < K) {
                m *= 2;
                d *= 2;
            }
            p += 1.0/d;
        }
        p /= min(K-1,N);
        ans += (1.0 - fw)*p;
    }
    printf("%.10f\n", ans);
}

Measured memory_bytes: 3740
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

n = int(input())
a = [int(i) for i in input().split()]

def solve(a):
    if a[0] > 0:
        status_pos = True
    elif a[0] < 0:
        status_pos = False

    tmp = 0
    ans = 0
    for i in range(n):
        tmp += a[i]
        if tmp == 0:
            ans += 1
            if status_pos:
                tmp = -1
            else:
                tmp = 1

        elif status_pos and tmp < 0:
            ans += 1+abs(tmp)
            tmp = 1
        elif status_pos == False and tmp > 0:
            ans += 1+abs(tmp)
            tmp = -1
        status_pos = not(status_pos)
    return ans

if a[0] == 0:
    a[0] = 1
    ans = 1
    ans += solve(a)

    a[0] = -1
    ans2 = 1
    ans2 += solve(a)
    ans = min(ans,ans2)
else:
    ans = solve(a)
    #値反転
    ans3 = abs(a[0])+1
    if a[0] > 0:
        a[0] = -1
    else:
        a[0] = 1
    ans3 += solve(a)
    ans = min(ans,ans3)

print(ans)


Measured memory_bytes: 16740
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	for(int i=b-a+1;i<=b+a-1;i++)printf("%d ",i);
	printf("\n");
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int cnt[4];//nwse
main(){
    string s;
    cin >> s;
    for(char c:s){
        if(c=='N')cnt[0] = 1;
        if(c=='W')cnt[1] = 1;
        if(c=='S')cnt[2] = 1;
        if(c=='E')cnt[3] = 1;
    }
    if(!((cnt[0]^cnt[2])|(cnt[1]^cnt[3])))cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////

int main(){
    int k;
    cin >> k;
    int a[32] = {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};

    cout << a[k-1] << endl;
}

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

#define MAX 1000000

int main()
{
  int triangle,tetra[MAX];
  int i,j,T;
  int dp[MAX],dpOdd[MAX];
  int n;
  T=0;
  tetra[0]=1;
  tetra[1]=4;
  triangle=1;
  for(i=2;triangle<MAX;i++){
    triangle+=i;
    tetra[i-1]=tetra[i-2]+triangle;
    T++;
  }

  for(i=0;i<MAX;i++)dp[i]=dpOdd[i]=INT_MAX;
  dp[0]=dpOdd[0]=0;
  for(i=0;i<T;i++){
    for(j=tetra[i]; j<MAX; j++){
      if(dp[j-tetra[i]]+1 < dp[j])
	dp[j]=dp[j-tetra[i]]+1;
      if(tetra[i]&1 && dpOdd[j-tetra[i]]+1 < dpOdd[j])
	dpOdd[j]=dpOdd[j-tetra[i]]+1;
    }
  }

  while(cin>>n,n){
    cout<<dp[n]<<" "<<dpOdd[n]<<endl;
  }
}

Measured memory_bytes: 8568
#include<iostream>

int main(){
	int A,B,ans(0);
  	std::cin >> A >> B;
  	for(int i = 0 ; i < 2 ; i ++){
    	if(A < B){ 
          	ans += B;
          	B --;
        } else {
          	ans += A;
          	A --;
        }
    }
  	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
/* cpp file
 * kanzo
 * @2020
 * */
#include<bits/stdc++.h>
#include "string"
using namespace std;

#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define pi pair<int,int>

int main()
{
		boost;
		int D=0,T=0,S=0;
		cin >> D >> T >> S;
		
		if(((float)(D)/(float)(T)) <= float(S))
			cout << "Yes";
		else
			cout << "No";		
		return 0;
}




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

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

typedef pair<int, int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<P> zero;
	int x1, y1,h1;
	while (N > 0) {
		cin >> x1 >> y1 >> h1;
		N--;
		if (h1 != 0)break;
		zero.push_back(P(x1, y1));
	}
	vvi H(101, vi(101, 1));
	REP(x, 101) {
		REP(y, 101) {
			H[x][y] =  h1 + abs(x - x1) + abs(y - y1);
		}
	}

	REP(i, N) {
		int x, y, h;
		cin >> x >> y >> h;
		if (h == 0) {
			zero.push_back(P(x, y));
			continue;
		}
		REP(ix, 101) {
			REP(iy, 101) {
				if(h+abs(x-ix)+abs(y-iy) != H[ix][iy])H[ix][iy] = -1;
			}
		}
	}

	REP(x, 101) {
		REP(y, 101) {
			if (H[x][y] == -1)continue;
			for (P p: zero) {
				if (H[x][y] - abs(p.first - x) - abs(p.second - y) > 0) {
					H[x][y] = -1;
					break;
				}
			}
		}
	}
	int ans = -1;
	REP(x, 101) {
		REP(y, 101) {
			if (H[x][y] != -1) {
				cout << x << " " << y << " ";
				assert(ans == -1);
				ans = H[x][y];
			}
		}
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
def popcount(n):
    bit_count = bin(n).count('1')
    n = n % bit_count 
    return n

if __name__ == "__main__":
    import sys 

    readline = sys.stdin.readline 

    N = int(input())
    X = readline()
    bit_count = X.count('1')
    mod1 = int(X, 2) % (bit_count + 1)
    mod2 = int(X, 2) % (bit_count - 1) if (bit_count - 1) != 0 else 0

    for i in range(N):
        if X[i] == '0':
            X_rest = (mod1 + pow(2, N - 1 - i, bit_count + 1)) % (bit_count + 1)
        else:
            if bit_count - 1 != 0:
                X_rest = (mod2 - pow(2, N - 1 - i, bit_count - 1)) % (bit_count - 1)
            else:
                print(0)
                continue

        counter = 1
        while X_rest != 0:
            X_rest = popcount(X_rest)
            counter += 1
        print(counter)






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

int main() {
 int N, M;
  cin >> N >> M;
  map<int, int> height;
  for (int i = 0; i < N; i++) {
    int h;
    cin >> h;
    height[i + 1] = h;
  }
  vector<bool> vec(N, true);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (height[a] > height[b])  vec.at(b - 1) = false;
    if (height[a] == height[b]) vec.at(a - 1) = false, vec.at(b - 1) = false;
     if (height[a] < height[b])  vec.at(a - 1) = false;
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (vec.at(i) == true) count++;
  }
  cout << count << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  map<ll, int> cnt;
  rep(j, n) {
    if (j >= a[j]) ans += cnt[j - a[j]];
    cnt[j + a[j]]++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 17544
def resolve():
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    mod = 998244353
    modinv = pow(2, mod - 2, mod)
    dp = [0] * (s + 1)
    dp[0] = pow(2, n, mod)
    for i in a:
        for j in range(s - i, -1, -1):
            dp[j + i] += dp[j] * modinv
            dp[j + i] %= mod
    print(dp[-1])


if __name__ == '__main__':
    resolve()


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

int main(){
  int n,m; cin>>n>>m;
  vector<ll> dp(n+1, -1);
  dp[0]=1;
  dp[1]=1;
  rep(i,m){
    int a; cin>>a;
    dp[a]=0;
  }
  for (int i=2; i<=n; i++){
    if(dp[i] != 0) dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 4020
import numpy as np

def main():
    n = int(input())
    a = list(map(int, input().split()))
    a = np.array(a)
    sa = sum(a)
    half = int(sa/2)
    tmp = 0
    ans = 0
    flag = 0

    for i in range(n):
        tmp = tmp + a[i]
        if tmp >= half:
            if 2*tmp - sa < sa - 2*(tmp-a[i]):
                break
            else:
                tmp = tmp - a[i]
                flag = 1
                break
    
    if flag == 0:
        ans = 2*tmp - sa
    else:
        ans = sa - 2*tmp
        
    print(int(ans))



if __name__ == "__main__":
    main()

Measured memory_bytes: 34232