akhauriyash/Code-Regression huggingface dataset:
from collections import Counter
import numpy as np

hw = input().split()
h = int(hw[0])
w = int(hw[1])

# print(h,w)
a_all = ""
for i in range(h):
    a_all += input()
    
count = Counter(a_all)

four_num = (w//2) * (h//2)
two_num = (w%2) * (h//2) + (h%2) * (w//2)
one_num = (w%2) * (h%2)

# print("test:",four_num,two_num,one_num)
nums = list(count.values())

nums_array = np.array(nums)

check=0

# print(nums_array)
for i in range(four_num):
    if len(nums_array[nums_array>=4])>=1:
        nums_array[np.where(nums_array>=4)[0][0]] -= 4
#         print(nums_array)
    else:
        check = 1
        break

for i in range(two_num):
    if len(nums_array[nums_array>=2])>=1:
        nums_array[np.where(nums_array>=2)[0][0]] -= 2
#         print(nums_array)
    else:
        check = 1
        break

if check == 1:
    print("No")
else:
    print("Yes")

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

using namespace std;

int searchIndex(const vector<int>& vec, int item) {
    int answer = -1;
    for (int i = 0; i < vec.size(); ++i) {
        if (vec.at(i) == item) {
            answer = i;
            break;
        }
    }
    return answer;
}

int main() {
    int n;
    cin >> n;
    vector<int> vec;
    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            vec.push_back(i * j);
        }
    }
    if (searchIndex(vec, n) != -1) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def main():
	n, k = map(int, input().split())
	win_per = 0
	for i in range(n):
		count = 0
		score = i + 1
		if score <= k:
			while True:
				if score >= k:
					break
				score *= 2
				count += 1
			win_per += (1 / n) * (1 / 2)**count
		else:
			win_per += 1 / n
	print(win_per)

if __name__ == "__main__":
	main()


Measured memory_bytes: 3060
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def digit_sum(num:int, base:int) -> int:

    if num < base:
        return num
    else:
        return digit_sum(int(num/base), base) + (num % base)

n = ni()
s = ni()

ans = -1

if s > n:
    ans = -1
  
elif s == n:
    ans = n+1
    
else:
    base = 2
    exist = False
    while base*base <= n:
        ds = digit_sum(n,base)
        if ds == s:
            ans = base
            exist = True
            break
        
        base += 1
        
    
    if not exist:
        for p in range(base,0,-1):
            if (n-s+p)%p == 0 and s-p >= 0:
                b = (n-s+p)//p
                if b > p and b > s-p:
                    ans = b
                    exist = True
                    break
            
print(ans)

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        if (i / j == j)
          ans++;
        else
          ans += 2;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    ll p= tx-sx, q= ty-sy; 
    REP(i,p+q){
        if(i<q){
            cout << "U";
        }else{
            cout << "R";
        }
    }
    cout << "R";
    REP(i,p+q+2){
        if(i<q+1){
            cout << "D";
        }else{
            cout << "L";
        }
    }
    cout << "U";
    
    REP(i,p+q){
        if(i<p){
            cout << "R";
        }else{
            cout << "U";
        }
    }
    cout << "U";
    REP(i,p+q+2){
        if(i<p+1){
            cout << "L";
        }else{
            cout << "D";
        }
    }
    cout << "R" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  string s;
  cin>>s;

  string day[8]={"SUN","MON","TUE","WED","THU","FRI","SAT","SUN"};
  rep(i,0,8){
    if(s==day[i]){
      cout<<7-i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 256
/*
{
######################
#       Author       #
#        Gary        #
#        2020        #
######################
*/
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int n;
int main(){
	fastio;
	int cnt=0;
	R(n);
	rb(i,1,n){
		int ai;
		R(ai);
		cnt+=(ai)&1;
	}
	cout<<(cnt&1? "NO":"YES");
	return 0;
}
/** 程序框架：
  *
  *
  *
  *
  **/


Measured memory_bytes: 3616
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,node[10000],a,b,c[10000],key,st,ans;
vector<ll>v[10000];
queue<ll>que;
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
        node[a]++;
        node[b]++;
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
        if(node[i]==1)key=i;
        node[i]=0;
    }
    sort(c,c+n);
    reverse(c,c+n);
    que.push(key);
    node[key]=c[st];
    st++;
    while(!que.empty()){
        ll q=que.front();
        que.pop();
        for(auto x:v[q]){
            if(node[x]==0){
                que.push(x);
                node[x]=c[st];
                st++;
            }
        }
    }
    for(int i=1;i<n;i++)ans+=c[i];
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
        cout<<node[i]<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
pair <int,pii> dp[3005][3005];
void solve()
{
  //code begins from here//
  string s,t;
  cin>>s>>t;
  s='1'+s,t='1'+t;
  lop1(i,sz(s)-1)
  {
      lop1(j,sz(t)-1)
      {
          if(s[i]==t[j])
          {
             dp[i][j].F=1+dp[i-1][j-1].F;
             dp[i][j].S={i-1,j-1};
          }
          else
          {
              dp[i][j].F=max(dp[i-1][j].F,dp[i][j-1].F);
              if(dp[i][j].F==dp[i-1][j].F) dp[i][j].S={i-1,j};
              else dp[i][j].S={i,j-1};
          }
      }
  }
  string ans;
  int i=sz(s)-1,j=sz(t)-1;
  while(i!=0 && j!=0)
  {
     int ii=i,jj=j;
    if(dp[i][j].S.F==i-1 && dp[i][j].S.S==j-1) ans.pb(s[i]);
    i=dp[ii][jj].S.F,j=dp[ii][jj].S.S;
  }
  reverse(all(ans));
  cout<<ans<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
    //cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 109296
#include<stdio.h>
#include<string.h>
  
#define M 1046527
#define L 14
  
char H[M][L];
  
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
  
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
  
int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }
  
int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}
     
  
int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
  
}
  
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
      
    scanf("%d", &n);
      
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
      
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
  
    return 0;
}

Measured memory_bytes: 16052
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

class UnionFind {
public:
  VI par, s;
  UnionFind(int n=1e5) { init(n); }
  void init(int n=1e5) { par.resize(n); s.assign(n, 1); REP(i, n) par[i] = i; }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
    else par[y] = x, s[x] = s[x] + s[y];
  }
  bool same(int x, int y) { return find(x) == find(y);}
};

int x[40010], y[40010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, h, w;
  cin >> n >> w >> h;
  bool flag=false;
  REP(i, n) {
    cin >> x[i] >> y[i];
    x[i]--, y[i]--;
    if(x[i]==0 || x[i]==w-1 || y[i]==0 || y[i]==h-1) flag = true;
  }

  UnionFind uf(n);
  REP(i, n) FOR(j, i+1, n) {
    if(x[i] == x[j] || y[i] == y[j]) {
      uf.unite(i, j);
    }
  }

  int ret = 0, cnt = 0;
  REP(i, n) {
    if(i == uf.find(i)) {
      ret += uf.s[uf.find(i)] - 1;
      cnt++;
    }
  }
  // cout << ret << " " << cnt << endl;
  if(cnt >= 2) ret += cnt + cnt - 1 - (flag?1:0);

  cout << ret << endl;

  return 0;
}



Measured memory_bytes: 4060
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int a = Integer.parseInt(str2[0]);
    int b = Integer.parseInt(str2[2]);
    String op = str2[1];
    String plus = "+";
    String minus = "-";
    String product = "*";
    String division = "/";

      if(op.equals(plus))
        System.out.println(a + b);
      else if(op.equals(minus))
        System.out.println(a - b);
      if(op.equals(product))
        System.out.println(a * b);
      else if(op.equals(division))
        System.out.println(a / b);
      else if(op.equals("?")){
        break;
      }
    }
  }
}

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

using namespace std;

const int N = 1e5 + 5;

int n, a, m;
map<int, int> mp;

main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a;
        mp[a]++;
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a;
        if (mp[a]) {
            mp[a]--;
        } else {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}


Measured memory_bytes: 9600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {

    int n,m;
    cin>>n>>m;
    vi v(n+1),w(m+1);
    rep(i,n)cin>>v[i];
    rep(i,m)cin>>w[i];
    ll dp[2][n+10][m+10];
    rep(i,n+10)rep(j,m+10){
        dp[0][i][j]=0;
        dp[1][i][j]=0;
    }

    dp[0][0][0]=1;

    rep(i,n+1)rep(j,m+1){
        dp[0][i+1][j] += dp[0][i][j];
        dp[0][i+1][j] %= MOD;
        dp[1][i][j] += dp[0][i][j];
        dp[1][i][j] %= MOD;
        dp[1][i][j+1] += dp[1][i][j];
        dp[1][i][j+1] %= MOD;
        if(v[i]==w[j]) {
            dp[0][i+1][j+1] += dp[1][i][j];
            dp[0][i+1][j+1] %= MOD;
        }
    }
    cout<<dp[1][n][m]<<endl;
    
}

Measured memory_bytes: 63360
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <numeric>
#include <climits>
#include <cfloat>

int main() {
	while (true) {
		int n, m, cap; std::cin >> n >> m >> cap;
		if (n == 0 && m == 0) break;
		std::map<std::string, int> to_int;
		std::string source, destination; std::cin >> source >> destination; to_int.emplace(source, 0); to_int.emplace(destination, 1);
		std::vector<std::vector<std::pair<int, int>>> nodes(2);
		{
			std::string from, to; int distance;
			for (auto i = 0; i < n; ++i) {
				std::cin >> from >> to >> distance;
				if (distance > cap * 10) continue;
				auto f = to_int.emplace(from, to_int.size());
				auto t = to_int.emplace(to, to_int.size());
				if (to_int.size() > nodes.size()) nodes.resize(to_int.size());
				nodes[f.first->second].emplace_back(t.first->second, distance); nodes[t.first->second].emplace_back(f.first->second, distance);
			}
		}
		std::vector<bool> has_lpg_station(to_int.size(), false);
		{
			std::string station;
			for (auto i = 0; i < m; ++i) {
				std::cin >> station; has_lpg_station[to_int[station]] = true;
			}
		}
		auto comparator = [](const std::pair<std::pair<int, int>, int>& a, const std::pair<std::pair<int, int>, int>& b) {return a.second > b.second; };
		std::priority_queue<std::pair<std::pair<int, int>, int>, std::vector<std::pair<std::pair<int, int>, int>>, decltype(comparator)> queue(comparator);
		std::vector<std::vector<int>> min_length(to_int.size(), std::vector<int>(cap * 10 + 1, INT_MAX));
		min_length[0][cap * 10] = 0; queue.emplace(std::make_pair(0, cap * 10), 0);
		while (!queue.empty()) {
			auto top = queue.top();
			if (top.first.first == 1) break;
			queue.pop();
			if (min_length[top.first.first][top.first.second] == top.second) {
				for (const auto& next : nodes[top.first.first]) if (has_lpg_station[top.first.first]) {
					if (min_length[next.first][cap * 10 - next.second] > top.second + next.second) {
						min_length[next.first][cap * 10 - next.second] = top.second + next.second;
						queue.emplace(std::make_pair(next.first, cap * 10 - next.second), top.second + next.second);
					}
				}
				else if (top.first.second >= next.second) {
					if (min_length[next.first][top.first.second - next.second] > top.second + next.second) {
						min_length[next.first][top.first.second - next.second] = top.second + next.second;
						queue.emplace(std::make_pair(next.first, top.first.second - next.second), top.second + next.second);
					}
				}
			}
		}
		if (queue.empty()) std::cout << -1 << std::endl;
		else std::cout << queue.top().second << std::endl;
	}
}



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

int main(){
  int n;
  cin >> n;
  int h[n];
  int dp[n+1];
  dp[0] = 0;
  for(int i = 0; i < n; i++) cin >> h[i];
  for(int i = 1; i < n; i++){
    dp[i] = dp[i-1] + abs(h[i-1] - h[i]);
    if(i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i-2] - h[i]));
  }
  cout << dp[n-1] << endl;
}

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

using namespace std;
using ll = long long;

const int N = int(1.1e5);
const int M = 13;
int dp[N][M];
const int mod = int(1e9 + 7);

const int MOD = mod;
inline int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; }
inline int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; }
inline int mul(int a) { return a; }
template<typename... T> inline int mul(int a, T... b) { return (int) ((ll) a * (ll) mul(b...) % MOD); }
inline int power(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

int n;
string s;

int rec(int i, int m) {
  if(i == n) {
    return int(m == 5);
  }
  if(dp[i][m] != -1) return dp[i][m];
  dp[i][m] = 0;
  if(s[i] != '?') {
    dp[i][m] = rec(i + 1, (10 * m + int(s[i] - '0')) % M); 
  } else {
    for(int d = 0; d < 10; ++d) {
      dp[i][m] = add(dp[i][m], rec(i + 1, (10 * m + d) % M));
    }
  }
  return dp[i][m];
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s;
  n = int(s.length());
  // reverse(s.begin(), s.end());
  memset(dp, -1, sizeof dp);
  cout << rec(0, 0) << '\n';
  return 0;
}


Measured memory_bytes: 10704
#include <iostream>
int main(){
int A,B;
std::cin >> A >> B;
if(A!=1 && B!=1){
if(A>B)
std::cout << "Alice" << std::endl;
else if(A<B)
std::cout << "Bob" << std::endl;
else
std::cout << "Draw" << std::endl;
}
else{
if(A==1 && B!=1)
std::cout << "Alice" << std::endl;
else if(A!=1 && B==1)
std::cout << "Bob" << std::endl;
else
std::cout << "Draw" << std::endl;
}
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    if (i % 2 == 0) continue;
    if (a % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
#define PB push_back
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int n;
int arr[100005];
int dp[100005];

int f(int indx)
{
    if(indx>=n-1)
        return 0;

    if(dp[indx]!=-1)
        return dp[indx];
    if(indx+1 <=n-1 && indx+2 <=n-1)
           return dp[indx]=min(abs(arr[indx]-arr[indx+1])+f(indx+1), abs( arr[indx]-arr[indx+2])+f(indx+2));
    else if(indx+1 <= n-1)
        return dp[indx]=abs( arr[indx]-arr[indx+1])+f(indx+1);
}

int main()
{
    optimize();
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    cout<<f(0)<<endl;
    return 0;
}


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

int main (){
    int x, a, b;
    cin >> x >> a >> b;
    if(b <= a){
        cout << "delicious" << endl;
    }else if(b <= (a+x)){
        cout << "safe" << endl;
    }else {
        cout << "dangerous" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int h, w, k;
  cin>>h>>w>>k;
  vector<string> c(h);
  REP(i, h) cin>>c[i];
  int ans = 0;
  REP(s, 1<<h){
    REP(t, 1<<w){
      int grid[h][w];
      REP(i, h){
        REP(j, w){
          if(c[i][j] == '.'){
            grid[i][j] = 0;
          }else{
            grid[i][j] = 1;
          }
        }
      }
      REP(i, h) REP(j, w) if(s>>i&1 || t>>j&1) grid[i][j] = 2;
      int cnt = 0;
      REP(i, h) REP(j, w) if(grid[i][j] == 1) cnt++;
      if(cnt == k) ans++;
    }
  }
  
  cout << ans << endl;   
  return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
  int d;
  string s;
  cin >> s >> d;
  bool a[10];
  memset(a, true, sizeof(a));
  for(int i = 0; i < d; i++){
    int x;
    cin >> x;
    a[x] = false;
  }
  int carry = 0;
  char ch;
  for(int i = 1; i < 10; i++){
    if(a[i]){
      ch = i + 48;
      break;
    }
  }
  for(int i = s.size() - 1; i >= 0; i--){
    int m = s[i] - 48;
    m = (m + carry) % 10;
    int m1 = m;
    if(m < s[i] - 48)
      carry = 1;
    else
      carry = 0;
    //cout << m << " " << carry << endl;
    bool flag = false;
    while(!a[m]){
      m = (m + 1) % 10;
      flag = true;
    }
    if(flag){
      for(int j = i + 1; j < s.size(); j++){
        s[j] = min(s[j], ch);
      }
    }
    if(m < m1 || carry > 0)
      carry = 1;
    else
      carry = 0;
    s[i] = m + 48;
  }
  
  if(carry > 0)
    s = ch + s;
  cout << s;
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

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

		char[] arr = sc.nextLine().toCharArray();

		Deque<Integer> posStack = new ArrayDeque<Integer>();
		Deque<Area> areaStack = new ArrayDeque<Area>();

		int tmp_start, tmp_end, tmp_S, sum = 0;

		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == '\\') {
				posStack.addFirst(i);
			} else if (arr[i] == '/') {
				if (posStack.isEmpty()) {
					continue;
				}

				tmp_start = posStack.removeFirst();
				tmp_end = i;

				tmp_S = tmp_end - tmp_start;
				sum += tmp_S;

				while (areaStack.isEmpty() == false && areaStack.getFirst().getStart() > tmp_start
						&& areaStack.getFirst().getEnd() < tmp_end) {
					tmp_S += areaStack.getFirst().getS();
					areaStack.removeFirst();
				}

				areaStack.addFirst(new Area(tmp_start, tmp_end, tmp_S));

			} else {
			}

		}

		System.out.println(sum);

		StringBuilder ans = new StringBuilder();

		ans.append(Integer.toString(areaStack.size()));

		while (!areaStack.isEmpty()) {
			ans.append(" ").append(Integer.toString(areaStack.getLast().getS()));
			areaStack.removeLast();
		}

		System.out.println(ans.toString());

		sc.close();
	}
}

class Area {
	private int start;
	private int end;
	private int S;

	public Area(int start, int end, int S) {
		this.start = start;
		this.end = end;
		this.S = S;
	}

	public int getStart() {
		return this.start;
	}

	public int getEnd() {
		return this.end;
	}

	public int getS() {
		return this.S;
	}
}


Measured memory_bytes: 29444
#include <iostream>

using namespace std;

int main() {
   int i,a,b,c,d;
   cin>> a >> b >>c;
   d=0;
   for(i=a;i<=b;i++)      
   {
    if(c%i==0)
    d++;
    
   }
       cout<< d << endl;
}
       


Measured memory_bytes: 3116
from sys import stdin, setrecursionlimit
from collections import defaultdict
from heapq import heapify, heappush, heappushpop


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(n)]

    dic = defaultdict(list)
    for a, b in ab:
        dic[a].append(b)

    q = []
    heapify(q)

    for i in sorted(dic.keys(), reverse=True):
        for j in sorted(dic[i], reverse=True):
            if len(q) <= m - i:
                heappush(q, j)
            elif q and q[0] < j:
                heappushpop(q, j)

    print(sum(q))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 84060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define FI first
#define SE second
#define PB(a) push_back(a)
#define DEBUG(x) cerr << __LINE__ << ":" << #x << ": " << x << "\n";
#define SZ(x) ((int)(x).size())
#define SO(x) sizeof((x)) / sizeof((x)[0])
//#define int long long
using namespace std;
using lint = long long;
struct Fast{Fast(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};} fast;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
inline void co(int a[], int n) {REP(i, n) cout << a[i] << " "; cout << "\n";}
//if (IO > 1e5){lint a;	scanf(%lld, &a);	printf("%lld\n", a);}

signed main(){
	int n;
	cin >> n;
	int x[n], y[n], h[n];
	REP(i,n){
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] == 0){
			i--;
			n--;
		}
	}
	
	if (n == 1){
		cout << x[0] << " " << y[0] << " " << h[0] << endl;
		return 0;
	}
	
	bool a;
	int cx, cy, ansh, anshh;
	for(cx = 0; cx <= 100; cx++){
		for(cy = 0; cy <= 100; cy++){
			a = true;
			REP(i,n-1){
				ansh = abs(x[i]-cx) + abs(y[i]-cy) + h[i];
				anshh= abs(x[i+1]-cx) + abs(y[i+1]-cy) + h[i+1];
				if ( ansh != anshh){
					a = false;
					break;
				}
			}
			if (a == true) goto out;
		}
	}
	
	out:
	cout << cx << " " << cy << " " << ansh << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    double ans = a[0];
    loop(i,1,n)ans = (ans+a[i])/2;
    cout << shosu(10) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	cout << a * b / 2 << endl;
}


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


def dfs(current, judge, count):
    if current > N:
        return
    if judge == 0b111:
        count.append(1)

    dfs(current * 10 + 7, judge | 0b100, count)
    dfs(current * 10 + 5, judge | 0b010, count)
    dfs(current * 10 + 3, judge | 0b001, count)


cnt = []
dfs(0, 0, cnt)
print(sum(cnt))

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

int main(void){
    int N;
    cin>>N;
    vector<int> a(N);
    for (int i=0;i<N;i++) cin>>a[i];

    int ans=10000000;
    for (int i=-100;i<=100;i++){
        int swap=i;
        int cost=0;
        for (int j=0;j<N;j++){
            cost+=pow(swap-a[j],2);
        }
        if (ans>cost) ans=cost;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using ll=long long;
using namespace std;

int main(){
    string S;
    int Q;
    cin>>S>>Q;

    int T,F;
    char C;
    vector<char> front;
    vector<char> back;
    int rev=1;
    for(int i=0;i<Q;i++){
        cin>>T;
        if(T==1){
            rev*=-1;
        }else{
            cin>>F>>C;
            if(rev==1){
                if(F==1){
                    front.push_back(C);
                }else{
                    back.push_back(C);
                }
            }else{
                if(F==2){
                    front.push_back(C);
                }else{
                    back.push_back(C);
                }
            }
        }
    }

    string ans;
    for(int i=front.size()-1;i>=0;i--){
        ans.push_back(front[i]);
    }
    for(int i=0;i<S.size();i++){
        ans.push_back(S[i]);
    }
    for(int i=0;i<back.size();i++){
        ans.push_back(back[i]);
    }
    if(rev==-1){
        reverse(ans.begin(),ans.end());
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4340
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int d = sc.nextInt();

		int[] c = new int[27];
		for ( int i=1; i<27; i++ ) {
			c[i] = sc.nextInt();
		}

		int[][] s = new int[d][27];
		for ( int i=0; i<d; i++ ) {
		for ( int j=1; j<27; j++ ) {
			s[i][j] = sc.nextInt();
		}
		}

		long man = 0L;
		int[] last = new int[27];
		for ( int i=0; i<d; i++ ) {
			int t = sc.nextInt();
			last[t] = i+1;
			man += (long)s[i][t];

			for ( int j=1; j<27; j++ ) {
				man -= (long)(c[j]*((i+1)-last[j]));
			}

			System.out.println(man);
		}

	}
}

Measured memory_bytes: 47004
#include<stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
        if(x-r>=0&x+r<=W&y+r<=H&y-r>=0){
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}

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

int d,score,i,j,k,pscore,cscore,id;
int c[26],s[365][26],last[26],t[365];
int day1,day2,v1,v2,csize,f;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> d;
  for(i=0;i<26;i++) {
    cin >> c[i];
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      cin >> s[i][j];
    }
  }
  for(i=0;i<d;i++) {
    for(j=0;j<26;j++) {
      int tscore=s[i][j];
      for(int k=0;k<26;k++) {
        if(k==j) continue;
        tscore-=c[k]*(i+1-last[k]);
      }
      if(j==0) score=tscore;
      else if(tscore>score) {
        score=tscore;
        t[i]=j;
      }
    }
    last[t[i]]=i+1;
  }
  int cnt=200000;
  while(cnt--) {
    day1=rand()%d;
    v1=rand()%26;
    day2=rand()%d;
    v2=rand()%26;
    if(t[day1]==v1) continue;
    int check[4];
    check[0]=t[day1];
    check[1]=v1;
    csize=2;
    f=0;
    if(cnt%4==0&&day1!=day2&&t[day2]!=v2) {
      f=1;
      if(t[day1]!=t[day2]&&v1!=t[day2]) {
        check[csize++]=t[day2];
      }
      if(t[day1]!=v2&&v1!=v2) {
        check[csize++]=v2;
      }
    }
    pscore=0;
    cscore=0;
    for(i=0;i<csize;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      pscore+=s[i][t[i]];
      last[t[i]]=i+1;
      for(j=0;j<csize;j++) {
        int id=check[j];
        pscore-=c[id]*(i+1-last[id]);
      }
    }
    for(i=0;i<2;i++) last[check[i]]=0;
    for(i=0;i<d;i++) {
      if(day1==i) {
        cscore+=s[i][v1];
        last[v1]=i+1;
      }
      else if(f&&day2==i) {
        cscore+=s[i][v2];
        last[v2]=i+1;
      }
      else {
        cscore+=s[i][t[i]];
        last[t[i]]=i+1;
      }
      for(j=0;j<2;j++) {
        id=check[j];
        cscore-=c[id]*(i+1-last[id]);
      }
    }
    if(pscore<cscore) {
      t[day1]=v1;
      t[day2]=v2;
    }
  }
  for(i=0;i<d;i++) {
    printf("%d\n",t[i]+1);
  }
}

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

int main(){
while(1){
	int w,h,dp[102][102][2][2]={0};
	scanf("%d%d",&w,&h);
	if(w==0&&h==0)break;
	dp[1][3][0][0]=1; dp[2][2][1][0]=1; dp[2][2][0][1]=1; dp[3][1][1][1]=1;
	for(int i=1;i<=w;i++){
		for(int j=1;j<=h;j++){
			if(i+j>4){
				dp[i][j][0][0]=(dp[i][j-1][0][0]+dp[i][j-1][1][0])%100000;
				dp[i][j][0][1]=(dp[i-1][j][0][0])%100000;
				dp[i][j][1][0]=(dp[i][j-1][1][1])%100000;
				dp[i][j][1][1]=(dp[i-1][j][0][1]+dp[i-1][j][1][1])%100000;
			}
			//printf("(%d %d %d %d) ",dp[i][j][0][0],dp[i][j][0][1],dp[i][j][1][0],dp[i][j][1][1]);
		}
		//printf("\n");
	}
	printf("%d\n",(dp[w][h][0][0]+dp[w][h][0][1]+dp[w][h][1][0]+dp[w][h][1][1])%100000);
}
}

Measured memory_bytes: 1340
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

ll k, a, b;
main()
{
    scanf("%lld%lld%lld", &k, &a, &b);
  if(a>=k){puts("1");return 0;}
    if (a <= b)
    {
        puts("-1");
        return 0;
    }
    printf("%lld\n", (k - b - 1) / (a - b) * 2 + 1);
    return 0;
}

Measured memory_bytes: 128
# coding: utf-8
N = int(input())
a = list(map(int, input().split()))
cnt = 0
half = 0
for i in range(N):
    if a[i] % 4 == 0:
        cnt += 1
    elif a[i] % 2 == 0:
        half += 1
cnt += half // 2
if cnt >= N//2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line: Vec<u64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = line[0] as f64;
    let m = line[1] as f64;
    let d = line[2];

    let ans = if d==0 {
        (m - 1.0) / n
    } else {
        2.0 * (n - (d as f64)) * (m - 1.0) / (n * n)
    };

    println!("{:.9}", ans);
}


Measured memory_bytes: 4352
//Author- VMAX


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//最小公倍数を求める
   return a * b / gcd(a, b);
}
/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/

//ll ss[2][(1<<22)+10];
       int main()
       {
       
        fast
        
        ll z;
        cin>>z;
        if(z%1000==0)
        {
            o("0")
        }
        else
        {
            ll p=z/1000;
            o((p+1)*1000-z)
        }
       









          re
}


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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        int N;
        cin >>N;
        vector<int> A(10001, 0);
        Rep1(x, 100)
                Rep1(y, 100)
                        Rep1(z, 100) {
                                int S=x*x+y*y+z*z+x*y+y*z+z*x;
                                if (S<=10000)
                                        A.at(S)++;
                        }
        Rep1(i, N)
                cout <<A.at(i) <<endl;
        return 0;
}

Measured memory_bytes: 3552
import math
def plot(x,y):
    print(f'{x:.8f} {y:.8f}')
def Koch(n, x1,y1,x2,y2):
    if n==0:
        plot(x1,y1)
        return
    sx=(2*x1+x2)/3
    sy=(2*y1+y2)/3
    tx=(x1+2*x2)/3
    ty=(y1+2*y2)/3
    ux=(tx-sx)*(1/2)-(ty-sy)*(math.sqrt(3)/2)+sx
    uy=(tx-sx)*(math.sqrt(3)/2)+(ty-sy)*(1/2)+sy
    
    Koch(n-1, x1,y1, sx,sy)
    Koch(n-1, sx,sy, ux,uy)
    Koch(n-1, ux,uy, tx,ty)
    Koch(n-1, tx,ty, x2,y2)
    
n=int(input())
Koch(n, 0,0, 100,0)
plot(100,0)


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

def f(m, a):
    return sum([m % i for i in a])

def gcd(a, b):
    while b > 0:
        if a < b: a, b = b, a
        r = a % b
        a = b
        b = r
    return a

lcm = arr[0]
for i in range(1, len(arr)):
    lcm = lcm * arr[i] // gcd(lcm, arr[i])

print(f(lcm -1, arr))


Measured memory_bytes: 3316
#include<stdio.h>
void selection_sort(int value[],int array_size);
void swap(int *x,int *y);
int main(){
  int n;
  scanf("%d",&n);
  int value[n];
  for(int i=0;i<n;i++){
    scanf("%d",&value[i]);
  }
  selection_sort(value,n);
  /*double sum=(value[0]+value[1])/2;
  for(int j=2;j<n;j++){
    sum=(sum+value[j])/2;
  }*/
  double sum=value[0];
  for(int j=1;j<n;j++){
    sum=(sum+value[j])/2;
  }

  printf("%f\n",sum);
  
}
void swap(int *x,int *y){
  int temp;

  temp=*x;
  *x=*y;
  *y=temp;
}
void selection_sort(int value[],int array_size){
  int i,j,min_index;
  for(i=0;i<array_size-1;i++){
    min_index=i;
    for(j=i+1;j<array_size;j++){
      if(value[j]<value[min_index]){min_index=j;}
    }
    swap(&value[min_index],&value[i]);
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
 {
	int t, n, k;
	cin>>t;
  int flag=0;
  
  while(t){
    int k=t%10;
    if(k==7){cout<<"Yes"<<endl;flag=1;break;}
    t=t/10;}
  if(flag==0)cout<<"No"<<endl;}


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

int main() {
    while(true){
        int n , m;
        cin >> n>>m;
        vector<int>list(n,0);
        if(n==0&&m==0){break;}
        for(int i =0;i<n;i++){
        cin >>list.at(i);
        }
        int cost = 0;
        for(int i = 0;i<n;i++){
            for(int k = 0;k<n;k++){
                if(list.at(i)+list.at(k)>cost&&list.at(i)+list.at(k)<=m){
                    if(k!=i){
                        cost = list.at(i)+list.at(k);
                        }
                    }
                }
        }
        if(cost==0){cout << "NONE" << endl;}
        else cout << cost << endl;
    }
}



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

using namespace std;

using int64 = long long;

int main()
{
  int64 X, Y;
  cin >> X >> Y;

  // X+2^1 X+2^2 X+2^3 X

  int64 mult = 1;
  int ret = 1;
  while(mult * 2 * X <= Y) {
    mult *= 2;
    ++ret;
  }
  cout << ret << endl;
}



Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int a = int.Parse(ReadLine());
        int b = int.Parse(ReadLine());
        int c = int.Parse(ReadLine());
        int d = int.Parse(ReadLine());
        int e = int.Parse(ReadLine());
        int k = int.Parse(ReadLine());

        if (e - a > k)
        {
            WriteLine(":(");
        }
        else
        {
            WriteLine("Yay!");
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}
int n,q;
hei(ll) seg, lazy;

void aaa(int k) {
	if (lazy[k] == 0)return ;
	if (k < n - 1) {
		lazy[k * 2 + 1] += lazy[k];
		lazy[k * 2 + 2] += lazy[k];
	}
	seg[k] += lazy[k];
	lazy[k] = 0;
}

void update(int a, int b, ll x,int k,int l,int r) {
	aaa(k);
	if (a<=l && b>=r) {
		lazy[k] += x;
		aaa(k);
	}
	else if(a<r&&l<b){
		update(a, b, x, k * 2 + 1, l, (l + r) / 2);
		update(a, b, x, k * 2 + 2, (l + r) / 2, r);
		seg[k] = seg[k * 2 + 1]+seg[k * 2 + 2];
	}
}

ll query(int a,int b,int k,int l,int r){
	aaa(k);
	if (l >= b || r <= a)return 0;
	if (a <=l  && b >= r) {
		return seg[k];
	}
	ll v1 = query(a, b, k*2+1, l, (l + r) / 2);
	ll v2 = query(a, b, k*2+2, (l + r) / 2, r);
	return v1 + v2;
}

int main() {
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	int x = 0;
	rep(i, 1, n + 1) {
		if (s.substr(n - i, i) == t.substr(0, i))x = i;
	}
	int ans = (2 * n) - x;
	cout << ans << endl;
	return 0;
}

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

int N;
const int MAX_N = 50 + 10; 
double v[MAX_N];

int main() {
    cout << fixed << setprecision(10);

    cin >> N;
    for (int i = 0; i < N; i++) cin >> v[i];

    for (int i = N; i >= 2; i--) {
        sort(v, v+i, greater<>());

        v[i-2] = (v[i-1] + v[i-2])/ 2.0;
    }

    cout << v[0] << endl;
    

    return 0;
}


Measured memory_bytes: 256
from collections import deque


def main():

    N, M = map(int, input().split())
    G = [set() for _ in range(N)]
    for _ in range(M):
        A, B = map(lambda x: int(x) - 1, input().split())
        G[A].add(B)
        G[B].add(A)

    q = deque([0])
    side = [-1] * N
    side[0] = 0
    while q:
        v = q.pop()
        for n in G[v]:
            if side[n] != -1:
                # if not bipartite graph
                if side[n] != (side[v] + 1) % 2:
                    print(int(N * (N - 1) / 2) - M)
                    exit()
                continue
            q.appendleft(n)
            side[n] = (side[v] + 1) % 2

    # bipartite graph
    side = sum(side)
    print(side * (N - side) - M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 76652
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int dfs(int node,vector<vector<int>> &edge,vector<int> &visited){
	visited[node]=1;
	int ans=1;
	for(int i=0;i<edge[node].size();i++){
		if(visited[edge[node][i]])
			continue;
		ans+=dfs(edge[node][i],edge,visited);
	}
	return ans;
}

int main(){
	int n,m,i,a,b,ans=1;
	cin>>n>>m;
	vector<vector<int>> edge(n);
	for(i=0;i<m;i++){
		cin>>a>>b;
		edge[a-1].push_back(b-1);
		edge[b-1].push_back(a-1);
	}
	vector<int> visited(n,0);

	for(i=0;i<n;i++){
		if(visited[i])
			continue;
		ans=max(ans,dfs(i,edge,visited));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 24372