akhauriyash/Code-Regression huggingface dataset:
<?php

fscanf(STDIN, "%d", $n);
$L = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($L);

$cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    for ($j = $i + 1; $j < $n; ++$j) {
        $target = $L[$i] + $L[$j];

        $l = $j + 1;
        $r = $n;
        while ($r - $l >= 1) {
            $mid = floor(($l + $r) / 2);

            if ($L[$mid] >= $target) {
                $r = $mid;
            } else {
                $l = $mid + 1;
            }
        }

        /* echo "i: $i, j: $j, l: $l, r: $r", PHP_EOL; */
        $cnt += max(0, $r - ($j + 1));
    }
}

echo $cnt;


Measured memory_bytes: 4604
N = int(input())
As = list(map(int, input().split()))

dp = [[0] * (N-k+1) for k in range(N+1)]

s = 0
for i, A in sorted(enumerate(As), key = lambda t:t[1], reverse=True):
    s += 1
    for x in range(s+1):
        y = s - x
        if x > 0 and y > 0:
            dp[x][y] = max(dp[x-1][y] + A * (i - x + 1), dp[x][y-1] + A * ((N-y) - i))
        elif x == 0:
            dp[x][y] = dp[x][y-1] + A * ((N-y) - i)
        else:
            dp[x][y] = dp[x-1][y] + A * (i - x + 1)
ans = max((dp[x][N-x] for x in range(N+1)))

print(ans)

Measured memory_bytes: 108992
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = ll;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

Int solve(Int n){
    Int m = sqrt(n);
    Int x = INF;
    for(int a = 1; a <= m; a++){
        if(n % a == 0){
            Int b = n / a;
            x = min(x, a + b);
        }
    }
    return x - 2;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    Int n;
    cin >> n;
    cout << solve(n) << "\n";

    return 0;
}


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

ll gcd(ll n,ll m){
  if(n>m) return gcd(m,n);
  else if(n==0) return m;
  else return gcd(m-n*(m/n),n);
}

int main(){
  ll t,a,b,c,d,g;
  cin>>t;
  fr(i,t){
    cin>>a>>b>>c>>d;
    if(b>a||b>d){
      cout<<"No"<<endl;
      continue;
    }
    if(c>=b){
      cout<<"Yes"<<endl;
      continue;
    }
    a%=b;
    d%=b;
    if(d==0){
      if(a>c){
        cout<<"No"<<endl;
        continue;
      }
      else{
        cout<<"Yes"<<endl;
        continue;
      }
    }
    g=gcd(b,d);
    if(a%g-g+b>c){
      cout<<"No"<<endl;
      continue;
    }
    else{
      cout<<"Yes"<<endl;
      continue;
    }
  }
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;

long long s[200005];

int main(){
	long long n,t,sum = 0;
	scanf("%lld %lld",&n,&t);
	for(int i = 1;i <= n;i++){
		scanf("%lld",&s[i]);
	}
	for(int i = 2;i <= n;i++){
		if(s[i] - s[i - 1] > t){
			sum += t;
		}
		else{
			sum += s[i] - s[i - 1];
		}
	}
	printf("%lld",sum + t);
}

Measured memory_bytes: 1792
from numpy import int64, bitwise_xor

N, *A = map(int, open(0).read().split())
A = int64(A)

x = bitwise_xor.reduce(A)
A &= ~x

res = 0
while any(A):
    ma = A.max()
    msb = 1 << (int(ma).bit_length() - 1)

    A[(A & msb) > 0] ^= ma

    res ^= ma * (not res & msb)

print(x + 2 * res)

Measured memory_bytes: 24028
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, X[19] = {}, XX[37] = {};
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			X[i + j]++;
		}
	}
	for (int i = 0; i <= 18; i++) {
		for (int j = 0; j <= 18; j++) {
			XX[i + j] += X[i] * X[j];
		}
	}
	while (cin >> N) {
		if (N > 36) cout << 0 << endl;
		else cout << XX[N] << endl;
	}
}


Measured memory_bytes: 3060
info = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())

for i in range(n):
    b,f,r,v = (int(x) for x in input().split())
    info[b-1][f-1][r-1] += v

for b in range(4):
    for f in range(3):
        for r in range(10):
            print(" " + str(info[b][f][r]), end="")
        print()
    if b == 3:
        break
    print("####################")


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

int main(){
    int n,q,sum,key;
    cin>>n;int A[n];
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    cin>>q;
    sum=0;
    for(int i=0;i<q;i++){
        scanf("%d",&key);
        if(*lower_bound(A,A+n,key)==key)sum++;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb emplace_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> ostream& operator<<(ostream &os,const vector<vector<T>> &v) {
    ITR(u,begin(v),end(v))ITR(w,begin(*u),end(*u))os<<*w<<(w==end(*u)-1?"\n":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed << setprecision(10) << val;

string s;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> s;
  if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) 
    cout << "Bad" << endl;
  else 
    cout << "Good" << endl;
  return 0;
}




Measured memory_bytes: 256
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t,r,a,b,i;(t=s.nextInt())>0;System.out.println(a+" "+b))for(a=0,b=999;t-->0;a=a>r?a:r,b=b<r?b:r)for(r=0,i=5;i-->0;)r+=s.nextInt();}}

Measured memory_bytes: 12000
#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
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; }

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
ll dp[10010];

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string S; cin >> S;

    REP(i,S.size()) cout << "x";
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  int i;
  int c=0;
  for(i=0;i<n;i++){
    cin>>a[i];
  }
  for(i=0;i<n;i++){
    if(i%2==0){
      if(a[i]%2!=0) c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;cin>>N;
  queue<int>A;
  for(int i=1;i<10;i++)A.push(i);
  for(int i=1;i<N;i++){
    int a=A.front();
    A.pop();
    if(a%10!=0)A.push(a*10+a%10-1);
    A.push(a*10+a%10);
    if(a%10!=9)A.push(a*10+a%10+1);
  }
  cout<<A.front()<<endl;
}

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

using namespace std;

using i64 = long long int;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(a) a.begin(), a.end()

struct IoSetup {
    IoSetup() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    i64 n;
    cin >> n;
    vector<double> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    double ans = 0;
    rep(i, n - 1){
        rep(j, i + 1, n){
            double cd = a[j] - a[i];
            double ab = 0;
            i64 cnt = 0;
            for(i64 k = n - 1; k >= 0; --k){
                if(cnt == 2) break;
                if(k != i && k != j){
                    ab += a[k];
                    ++cnt;
                }
            }
            ans = max(ans, ab / cd);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

struct bracket{
    ll open,close;
};
bool comp(bracket &a,bracket &b){
    return a.open-a.close>b.open-b.close;
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    vector<string> vv(n);
    for(auto &s:vv)cin>>s;
    ll open=0,close=0;
    vector<bracket> v;
    for(int i=0;i<n;i++){
        string s=vv[i];
        ll open1=0,open2=0,close1=0,close2=0;
        for(int j=0;j<s.size();j++){
            if(s[j]=='(')open1++;
            else{
                if(open1==0)close1++;
                else open1--;
            }
        }
        for(int j=s.size()-1;j>=0;j--){
            if(s[j]==')')close2++;
            else{
                if(close2==0)open2++;
                else close2--;
            }
        }
        if(open2==0&&close1==0)continue;
        else if(open2==0)close+=close1;
        else if(close1==0)open+=open2;
        else {
            bracket a;
            a.open=open2;
            a.close=close1;
            v.push_back(a);
        }
    }
    sort(v.begin(),v.end(),comp);
    for(int i=0;i<v.size();i++){
        open-=v[i].close;
        if(open<0){cout<<"No";return 0;}
        open+=v[i].open;
    }
    if(open==close)cout<<"Yes";
    else cout<<"No";
}


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

ll divide(ll a, ll b, ll ans){
	for(int i = 1; i <= b-1; i++)
	{	
		vector<ll> area(3);
		area[0] = i * a;

		ll remB = b - i;
		if(remB % 2 == 0){
			area[1] = a * remB / 2;
			area[2] = area[1];
		}else
		{
			area[1] = a * (remB+1) /2;
			area[2] = a * (remB / 2);
		}
		sort(area.begin(), area.end());
		ans = min(ans, area[2]-area[0]);
		vector<ll> area2(3);
		area2[0] = i * a;

		remB = b - i;
		if(a % 2 == 0){
			area2[1] = remB * a / 2;
			area2[2] = area2[1];
		}else
		{
			area2[1] = remB * (a+1) / 2;
			area2[2] = remB * (a / 2);
		}
		sort(area2.begin(), area2.end());
		ans = min(ans, area2[2]-area2[0]);

	}
	return ans;
}


int main(){
	ll h, w;
	cin >> h >> w;
	ll ans = 1e5+7;

	ans = divide(h, w, ans);
	ans = divide(w, h, ans);

	cout << ans << endl;	

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {

        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        static void SolveA(string[] args)
        {
            int.Parse(Console.ReadLine());
            int[] a = Array.ConvertAll(Console.ReadLine().Split(' '),  int.Parse);

            int[] b = new int[a.Length];
            CountingSort(a, b, 10001);
            Console.WriteLine(string.Join(" ", Array.ConvertAll(b, i=>i.ToString())));
        }
        private static void CountingSort(int[] a , int[] b, int k)
        {
            int[] c = new int[k];
            for(int i=0;i<a.Length;++i)
            {
                c[a[i]]++;
            }

            // 累積
            for(int i=1;i<k;++i)
            {
                c[i] += c[i - 1];
            }

            for(int i=a.Length-1;i>=0;--i)
            {
                b[c[a[i]]-1] = a[i];
                c[a[i]]--;
            }
        }
    }

}



Measured memory_bytes: 265412
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

// ceil of a/b
inline int ceil(int a, int b) { return (a+b-1)/b; }


signed main() {
	int n,k;
	std::cin >> n >> k;
	std::vector<int> a(n);
	rep(i,n) std::cin >> a[i];
	std::vector<int> plus;
	std::vector<int> minus;
	int zero = 0;
	rep(i,n) {
		if(a[i]>0) plus.emplace_back(a[i]);
		if(a[i]<0) minus.emplace_back(-a[i]);
		if(a[i]==0) zero++;
	}
	std::sort(all(plus));
	std::sort(all(minus));
	int l=-1e18-1,r=1e18+1;
	while(r-l>1) {
		debug(l,r);
		int mid = (r+l)/2;
		if(mid>=0) {
			int x = plus.size()*minus.size()+zero*plus.size()+zero*minus.size()+(zero-1)*zero/2;
			if(plus.size()) for(auto it=plus.begin();(it+1)!=plus.end();it++) {
				auto ub = std::upper_bound(it+1,plus.end(),mid/(*it));
				x+=(ub-it)-1;
			}
			if(minus.size()) for(auto it=minus.begin();(it+1)!=minus.end();it++) {
				auto ub = std::upper_bound(it+1,minus.end(),mid/(*it));
				x+=(ub-it)-1;
			}
			debug(mid,x,k);
			if(x>=k) r=mid;
			else l=mid;
		} else {
			int x = 0;
			if(plus.size()!=0 && minus.size()!=0) for(auto it=plus.begin();(it)!=plus.end();it++) {
				auto lb = std::lower_bound(all(minus),ceil(-mid,(*it)));
				debug(minus.end()-lb,*it,*lb);
				x+=minus.end()-lb;
			}
			debug(mid,x,k);
			if(x>=k) r=mid;
			else l=mid;
		}
	}
	print(r);
	return 0;
}


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		int[][] a=new int[n<<1][];
		bool[] b=new bool[n];
		for(int i = 0;i<n;i++) {
			int[] e=sc.Ia;
			a[i]=new int[3]{e[0],i,0};
			a[i+n]=new int[3]{e[1],i,1};
		}
		a=a.OrderBy(x=>x[0]).ToArray();
		bool c=false;
		int d=0;
		long ans=0;
		for(int i = 0;i<n;i++) {
			if(b[a[i][1]]){c=true;}
			b[a[i][1]]=true;
			d+=a[i][2];
			ans+=a[i][0];
		}
		if(!c&&d!=0&&d!=n){
			if(a[n-1][1]!=a[n][1]){ans+=a[n][0]-a[n-1][0];}
			else{ans+=Min(a[n+1][0]-a[n-1][0],a[n][0]-a[n-2][0]);}
		}
		Console.WriteLine(ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return (Console.ReadLine()+" 0").Split();}}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 37432
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)
    {
        var res = MyUtil.ReadIntArray();
        int a = res[0];
        int b = res[1];
        int c = res[2];

        if (a == b && b == c)
            WriteLine(1);
        else if (a == b || b == c || c == a)
            WriteLine(2);
        else
            WriteLine(3);
        ReadKey();
    }
}

static class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    /// <summary>
    /// <see cref="IEnumerable{T}"/>の各要素を並べてコンソールに出力します。各要素の間には半角スペースが一つ入ります。
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="ts"></param>
    public static void WriteToConsole<T>(this IEnumerable<T> ts)
    {
        StringBuilder stringBuilder = new StringBuilder();
        foreach (T t in ts)
        {
            stringBuilder.Append(t.ToString());
            stringBuilder.Append(" ");
        }
        stringBuilder.Remove(stringBuilder.Length - 1, 1);
        Console.WriteLine(stringBuilder.ToString());
    }
}


Measured memory_bytes: 11348
#include <cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long s[300005];
int main()
{
    long long n,h,i,a,b,ans=0,sum=0;
    scanf("%lld%lld",&n,&h);
    for(i=0;i<n;i++)
    {
        scanf("%lld%lld",&a,&b);
        s[i]=a*2+1;
        s[n+i]=b*2;
    }
    sort(s,s+2*n);
    for(i=2*n-1;i>=0;i--)
    {
        if(s[i]%2==0)
        {
            if(s[i]/2+sum>=h)
            {
                ans++;
                break;
            }
            else {sum+=s[i]/2;ans++;}
        }
        else
            {ans+=(h-sum-1)/((s[i]-1)/2)+1;break;}
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main() {

	int h, w; cin >> h >> w;
	vector<vector<char>> c(h + 2, vector<char>(w + 2));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c[i][j];
		}
	}
	vector<int> dy = { 0,1,0,-1, 1,1,-1  ,-1 };
	vector<int> dx = { 1,0,-1,0, 1,-1,1, -1 };
	const int p = 8;
	vector<vector<int>> c_ans(h + 2, vector<int>(w + 2));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (c[i][j] == '#') {
				cout << c[i][j];
			}
			else {
				int tmpCnt = 0;
				for (int k = 0; k < p; k++) {
					if (c[i + dy[k]][j + dx[k]] == '#') tmpCnt++;
				}
				c_ans[i][j] = tmpCnt;
				cout << c_ans[i][j];
			}			
		}
		cout << endl;
	}
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    int N;
    cin >> N;

    map<string, int> S;
    string temp;
    REP(i,N){
        cin >> temp;
        S[temp]++;
    }

    multimap<int, string, greater<int>> ordered;
    int max = 0;
    for(auto i : S){
        ordered.insert(make_pair(i.second, i.first));
        if(max < i.second){
            max = i.second;
        }
    }

    for(auto i : ordered){
        if(i.first == max){
            cout << i.second << "\n";
        }
        else{
            break;
        }
    }

return 0;
}

Measured memory_bytes: 36352
#include <bits/stdc++.h>
#include <atcoder/all> // NOTE: AtCoderライブラリ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using namespace atcoder; // NOTE: AtCoderライブラリ
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int, int> pii;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int N, Q; cin >> N >> Q;
    dsu d(N);

    rep(i, Q) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }
}


Measured memory_bytes: 3944
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int n = sc.nextInt();
			if(n==0) break;
			int [] trains = new int[86400];
			for(int i=0;i<86400;i++) {
				trains[i] = 0;
			}
			String [] start = new String[3];
			String [] end = new String[3];
			int ss = 0;
			int ee = 0;
			for(int i=0;i<n;i++) {
				String st = sc.next();
				String en = sc.next();
				start = st.split(":");
				end = en.split(":");
				ss = Integer.parseInt(start[0])*3600 + Integer.parseInt(start[1])*60 + Integer.parseInt(start[2]);
				ee = Integer.parseInt(end[0])*3600 + Integer.parseInt(end[1])*60 + Integer.parseInt(end[2]);
				for(int j=ss;j<ee;j++) {
					trains[j]++;
				}
			}
			int ans = 0;
			for(int i=0;i<86400;i++) {
				ans = Math.max(ans, trains[i]);
			}
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 74920
#include <stdio.h>
int main(void)
{
  int a[31]={0};
  int i,n;
  for(i=0;i<28;i++){
    scanf("%d",&n);
    a[n]=1;
  }
  for(i=1;i<=30;i++){
    if(!a[i])
      printf("%d\n",i);
  }
  return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=int(input())
    ans=INF
    for i in range(N+1):
        tmp=0
        n=i
        while n>0:
            tmp+=n%6
            n//=6
        m=N-i
        while m>0:
            tmp+=m%9
            m//=9
        ans=min(ans,tmp)
    print(ans)

if __name__ == '__main__':
    main()


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

int main(){

  int a[50]={0},n;

  for(int i=0;i<28;i++){
    cin >> n;

    a[n] = 1;
  }

  for(int i=1;i<=30;i++){
    if(a[i] == 0) cout << i << endl;
  }

}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    long k;

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

    void run() {
        FastReader sc = new FastReader();
        k = sc.nextLong();
        solve();
    }

    void solve() {
        long n = 50;
        long[] as = new long[(int)n];
        long quotient = k / n;
        long remainder = k % n;
        for (int i = 0; i < n; i++) {
            as[i] = 49 + quotient;
        }
        for (int i = 0; i < remainder; i++) {
            as[i] += n;
            for (int j = 0; j < n; j++) {
                if (i == j) {
                    continue;
                }
                as[j] -= 1;
            }
        }
        System.out.println(n);
        for (int i = 0; i < n; i++) {
            System.out.print(as[i]);
            if (i < n - 1) {
                System.out.print(" ");
            } else {
                System.out.println();
            }
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
using namespace std;

class all {
public:
	all(vector<vector<int>>& a, vector<int>& c, int x);
	~all();
	int main_cal();
private:
	void recursive(vector<int> d, int cnt, int cval);
private:
	vector<int> ans;
	vector<int> val;
	vector<vector<int>>& A;
	vector<int>& C;
	int X;
	int N;
	int M;
};

all::all(vector<vector<int>>& a, vector<int>& c, int x) : A(a), C(c), X(x) {
	ans.clear();
	val.clear();
	N = A.size();
	M = A[0].size();
	for (int i = 0; i < M; i++) {
		val.push_back(0);
	}
}

all::~all() {
}

void all::recursive(vector<int> d, int cnt, int cval) {
	vector<int> dum = d;
	if (cnt == N) {
		for (int j = 0; j < M; j++) {
			if (d[j] < X) {
				return;
			}
		}
		ans.push_back(cval);
		return;
	}
	else {
		// 買わない
		recursive(d, cnt + 1, cval);

		// 買う
		for (int i = 0; i < M; i++) {
			dum[i] += A[cnt][i];
		}
		recursive(dum, cnt + 1, cval + C[cnt]);
	}
}

int all::main_cal() {
	recursive(val, 0, 0);

	int cmin = -1;
	if (ans.size() != 0) {
		cmin = *min_element(ans.begin(), ans.end());
	}
	return cmin;
}

int main() {

	int N, M, X;
	cin >> N >> M >> X;

	vector<int> C(N, 0);
	vector<vector<int>> A(N, vector<int>(M, 0));
	for (int i = 0; i < N; i++) {
		cin >> C[i];
		for (int j = 0; j < M; j++) {
			cin >> A[i][j];
		}
	}

	all av(A, C, X);

	cout << av.main_cal() << endl;

	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;


int main(){
  char b;
  cin>>b;
  if(b=='A'){
    cout<<'T'<<endl;
  }else if(b=='T'){
    cout<<'A'<<endl;
  }else if(b=='G'){
    cout<<'C'<<endl;
  }else if(b=='C'){
    cout<<'G'<<endl;
  }



}


Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll exp_mod(ll a, ll b, ll m) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

ll fact_mod(ll n, ll m) {
    ll res = 1;
    for (ll i = n; i>0; --i)
        res = (res * i) % m;
    return res;
}

ll comb_mod(ll n, ll r, ll p) {
    ll res = 1;
    for (int i = 0; i<r; ++i)
        res = (res * (n - i)) % p;
    return (res * exp_mod(fact_mod(r, p), p - 2, p)) % p;
}

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    ll ans1 = 0;
    ll p = 1000000007;
    REP(i, 1, M + 1) {
        ans1 += ll(i) * ll(M - i);
        ans1 %= p;
    }
    ans1 *= N;
    ans1 %= p;
    ans1 *= N;
    ans1 %= p;

    ll ans2 = 0;
    REP(i, 1, N + 1) {
        ans2 += ll(i) * ll(N - i);
        ans2 %= p;
    }
    ans2 *= M;
    ans2 %= p;
    ans2 *= M;
    ans2 %= p;
    ll ans = (ans1 + ans2) % p;
    cout << (comb_mod(N * M - 2, K - 2, p) * ans) % p << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>

int A[10000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while ( left < right ) {
    mid = ( left + right ) / 2;
    if ( key == A[mid] ) return 1;
    if ( key > A[mid] ) left = mid + 1;
    else if ( key < A[mid] ) right = mid;
  }
  return 0;
}

int main() {
  int i, q, k, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    scanf("%d", &A[i]);
  }

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &k);
    if ( binarySearch( k ) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}

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


def solve(S: str):
    s = S
    weather_list = ["Sunny", "Cloudy", "Rainy"]

    index = weather_list.index(s)
    if index != 2:
        print(weather_list[index + 1])
    elif index == 2:
        print(weather_list[0])


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n,i,j,k;
    cin>>n;
    int *a=new int[n];
    int *b=new int[n];
    int *c=new int[n];
    for(i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
    vector<int>tmp(n+1);
    vector<vector<int> >memo(3,tmp);
    memo[0][0]=memo[1][0]=memo[2][0]=0;
    for(i=1;i<=n;i++)
    {
        memo[0][i]=a[i-1]+max(memo[1][i-1],memo[2][i-1]);
        memo[1][i]=b[i-1]+max(memo[0][i-1],memo[2][i-1]);
        memo[2][i]=c[i-1]+max(memo[0][i-1],memo[1][i-1]);
    }
    cout<<max(max(memo[0][n],memo[1][n]),memo[2][n]);
}


Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      long A=sc.nextLong();
      long V=sc.nextLong();
      long B=sc.nextLong();
      long W=sc.nextLong();
      long T=sc.nextLong();
      if(A<B){
      long pursuer = A+V*T;
      long runner = B+W*T;
      	if(pursuer>=runner){
        	System.out.print("YES");
      	}else{
        	System.out.print("NO");
      	}
      }else{
      	long pursuer = A-V*T;
      	long runner = B-W*T;
      	if(pursuer<=runner){
        	System.out.print("YES");
      	}else{
        	System.out.print("NO");
      	}
      }     
    }
}

Measured memory_bytes: 35420
//JSD
#include<algorithm>
#include<iostream>
#include<set>
#define ll long long 
using namespace std;
int main(){
	ll n,t;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int nextNeed=1;
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]==nextNeed){
			nextNeed++;			
		}
		else{
			ans++;
		}		
	}	
	if(nextNeed==1){
		cout<<"-1\n";
	}
	else{
		cout<<ans<<"\n";
	}
	return 0;
}

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

using namespace std;

template <typename T> struct SegTree { /* {{{ */
  using F = function<T(T, T)>;

  int n;
  vector<T> node;
  const F f;
  const T init_val;

  SegTree(int size, const T init_val, const F f) : SegTree(size, vector<T>(), init_val, f) {}
  SegTree(const vector<T> &v, const T init_val, const F f) : SegTree(v.size(), v, init_val, f) {}
  SegTree(int size, const vector<T> &v, const T init_val, const F f) : init_val(init_val), f(f) {
    n = 1;
    while (n < size) n *= 2;
    node.assign(n * 2, init_val);
    if (!v.empty()) {
      for (int i = 0; i < v.size(); i++) {
        node[i + n] = v[i];
      }
      for (int i = n * 2 - 1; i >= 0; i--) {
        node[i] = f(node[i * 2], node[i * 2 + 1]);
      }
    }
  }
  void update(int idx, T v) {
    node[idx + n] = v;
    for (int i = (idx + n) / 2; i >= 1; i /= 2) {
      node[i] = f(node[i * 2], node[i * 2 + 1]);
    }
  }
  T search(int a, int b, int k = 1, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a or b <= l) return init_val;
    if (a <= l and r <= b) return node[k];
    auto vl = search(a, b, k * 2, l, (l + r) / 2);
    auto vr = search(a, b, k * 2 + 1, (l + r) / 2, r);
    return f(vl, vr);
  }
}; /* }}} */

int main() {
  int N, Q;
  string S;
  cin >> N >> S >> Q;
  vector<SegTree<int>> tree(26, SegTree<int>(N, 0, [](int a, int b) { return max(a, b); }));
  vector<int> str(N);
  for (int i = 0; i < N; i++) {
    str[i] = S[i] - 'a';
    tree[str[i]].update(i, 1);
  }
  vector<int> ans;
  for (int q = 0; q < Q; q++) {
    int t;
    cin >> t;
    if (t == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      c -= 'a';
      if (str[i] != c) {
        tree[str[i]].update(i, 0);
        tree[c].update(i, 1);
        str[i] = c;
      }
    } else {
      int l, r;
      cin >> l >> r;
      l--;
      int cnt = 0;
      for (int i = 0; i < 26; i++) {
        cnt += tree[i].search(l, r);
      }
      ans.push_back(cnt);
    }
  }
  for (auto a : ans) {
    cout << a << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 111620
X,Y,A,B,C = map(int, input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]

Ca = 0
Cb = 0
Cc = 0

ans = 0

while Ca + Cb + Cc != X + Y:
    if Cc == C:
        if q[Cb] > p[Ca]:
            ans = ans + q[Cb]
            Cb = Cb + 1
        else:
            ans = ans + p[Ca]
            Ca = Ca + 1
    else:
        if Ca == X:
            if q[Cb] > r[Cc]:
                ans = ans + q[Cb]
                Cb = Cb + 1
            else:
                ans = ans + r[Cc]
                Cc = Cc + 1
        else:
            if Cb == Y:
                if p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
            else:
                if p[Ca] >= q[Cb] and p[Ca] > r[Cc]:
                    ans = ans + p[Ca]
                    Ca = Ca + 1
                elif q[Cb] > p[Ca] and q[Cb] > r[Cc]:
                    ans = ans + q[Cb]
                    Cb = Cb + 1
                else:
                    ans = ans + r[Cc]
                    Cc = Cc + 1
print(ans)

Measured memory_bytes: 23328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	debug(a, b, c, k);
	debug(min(a, k));
	int su = 0;
	su += min(a, k);
	k -= min(a, k);
	debug(su, k);
	k -= min(b, k);
	debug(su, k);
	su += -1 * min(c, k);
	k -= min(c, k);
	cout << su << '\n';
	
	return 0;
}






Measured memory_bytes: 3652
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-03-04(Wed)
   note
**********************************************************************/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
//#define PI(acos(-1))
using namespace std;
typedef long long ll;

int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;

  s[k-1] = s[k-1] - 'A' + 'a';
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

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

  if(N%10 == 7){
    cout << "Yes"<<endl;
    return 0;
  }
  N = N/10;
  if(N%10 == 7){
    cout << "Yes"<<endl;
    return 0;
  }
  N = N/10;
  if(N == 7)
    cout << "Yes"<<endl;
  else
    cout <<"No"<<endl;
   
  return 0;
}


Measured memory_bytes: 3624
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>т мом
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 400031;

string st;

int eval(string st){
	int res=0;
	for (int i=0;i<st.size();i++){
		res+=st[i]-48;
	}
	return res;
}

string modif(string st,int ps,int val){
	for (int i=0;i<st.size();i++){
		if (i<ps)
			continue;
		if (i==ps)
			st[i]=val;
		if (i>ps)
			st[i]='9';
	}
	return st;
}

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>st;
	int res=eval(st);
	for (int i=0;i<st.size();i++){
		for (int j='0';j<st[i];j++){
			string temp=modif(st,i,j);
			res=max(res,eval(temp));
		}
	}
	cout<<res<<endl;

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 300
#define inf 0x3f3f3f3f3f3f3f3fll
#define B 233
const ll mod=1000000007;
ll n,p,mx,ans,a[N],c[N];
map<ll,vector< pair<ll,ll> > > mp;
struct node
{
    ll b,c;
    int i;
    bool operator<(const node&o)const
    {
        return b<o.b;
    }
}b[N];
ll popcount(ll x,ll y)
{
    if (x>=y)
        return inf;
    ll ret=0;
    for (ll i=60; i>=0; i--)
        if (((x>>i)&1)!=((y>>i)&1))
        {
            ret++;
            return ret;
        }
        else
            ret+=(x>>i)&1;
    return inf;
}

int main()
{
    scanf("%lld%lld",&n,&p);
    for (ll i=1; i<=n; i++)
        scanf("%lld",&a[i]);
    ll s=1;
    for(int i=0;i<=60;i++,s<<=1)
    {
        memset(b,0,sizeof b);
        for(int j=1;j<=n;j++)
            b[j].b=a[j]%s,b[j].c=a[j]/s,b[j].i=j;
        sort(b+1,b+n+1);
        b[n+1].b=s-1;
        for (ll j=0; j<=n; j++)
        {
            ll k=((j==0)?0:popcount(b[j].b,b[j+1].b)),hsh=0;
            ll mn=p-k-i;
            bool fl=0;
            b[j].c--;
            if(mn<0) continue;
            if(j!=0&&b[j].c<0)
                break;
            for (ll k=1; k<=n; k++)
                mn=min(mn,b[k].c);
            for (ll k=1; k<=n; k++)
                c[b[k].i]=b[k].c;
            for (ll k=2; k<=n; k++)
                hsh=((hsh*B+(c[k]-c[k-1]))%mod+mod)%mod;
            mp[hsh].push_back(make_pair(max(c[1]-mn,0ll),c[1]));
        }
    }
    for (map<ll,vector< pair<ll,ll> > >::iterator i=mp.begin(); i!=mp.end(); i++)
    {
        vector< pair<ll,ll> > &vec=i->second;// puts("-----");
        sort(vec.begin(),vec.end());
        mx=0;
        ll l=vec[0].first,r=vec[0].second;
        for(int j=1; j<vec.size(); j++)
            if(vec[j].first>r)
            {
                ans=(ans+(r-l+1)%mod)%mod;
                l=vec[j].first;
                r=vec[j].second;
            }
            else
                r=max(r,vec[j].second);
        ans=(ans+(r-l+1)%mod)%mod;
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

const int M_V=10000;
struct edge {int to,cap,rev;};

struct FordFulkerson{

    vector<edge> G[M_V];
    bool used[M_V];

    void add_edge(int from,int to,int cap){
        G[from].push_back({to,cap,G[to].size()});
        G[to].push_back({from,0,G[from].size()-1});
    }

    int dfs(int v,int t,int f){
        if(v==t) return f;
        used[v]=true;
        for(int i=0;i<G[v].size();i++){
            edge &e=G[v][i];
            if(!used[e.to]&&e.cap>0){
                int d=dfs(e.to,t,min(f,e.cap));
                if(d>0){
                    e.cap-=d;
                    G[e.to][e.rev].cap+=d;
                    return d;
                }
            }
        }
        return 0;
    }

    int max_flow(int s,int t){
        int flow=0;
        for(;;){
            memset(used,0,sizeof(used));
            int f=dfs(s,t,INF);
            if(f==0) return flow;
            flow+=f;
        }
    }
};

int main(){
    int H,W;
    cin >> H >> W;
    FordFulkerson FF;
    char a[H][W];
    P p,q;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> a[i][j];
            if(a[i][j]=='S') p=P(i,j);
            if(a[i][j]=='T') q=P(i,j);
        }
    }
    if(p.first==q.first||p.second==q.second){
        puts("-1");
        return 0;
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(a[i][j]=='.') continue;
            if(a[i][j]=='S'){
                FF.add_edge(0,j+1,INF);
                FF.add_edge(0,i+W+1,INF);
            }
            else if(a[i][j]=='T') {
                FF.add_edge(j+1,W+H+1,INF);
                FF.add_edge(W+i+1,W+H+1,INF);
            }
            else{
                FF.add_edge(i+W+1,j+1,1);
                FF.add_edge(j+1,i+W+1,1);
            }
        }
    }
    cout << FF.max_flow(0,W+H+1) << endl;
    return 0;
}

Measured memory_bytes: 1152
import collections
N=int(input())
X=list(input())
X=list(map(int,X))
#print(X)
ans1=0
ans2=0
c=collections.Counter(X)
div=c[1]
for i in range(N):
    ans1=(ans1+X[i]*pow(2,N-i-1,div+1))%(div+1)
    if div-1!=0:
        ans2=(ans2+X[i]*pow(2,N-i-1,div-1))%(div-1)
    else:
        ans2=None
    #print(ans1)
#print(ans1,div+1)
#print(ans2,div-1)
#ここまででXについてのXのbit数、X%(Xのbit数)がわかる
for i in range(N):
    cnt = 1
    if (X[i]==0):
        num=(ans1+pow(2,N-i-1,div+1))%(div+1)
        #print(num)
    else:
        if (div-1)!=0:
            num=(ans2+div-1-pow(2,N-i-1,div-1))%(div-1)
        else:
            cnt=0
            num=0
        #print(num)
    while num != 0:
        di = 0
        for j in range(18):
            if (num >> j)&1 == 1:
                di = di + 1
        num = num % di
        cnt = cnt + 1
    print(cnt)



Measured memory_bytes: 88192
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
  main(){
   int X,Y,Z,n;
   printf(" ");
   scanf("%d%d%d",&X,&Y,&Z);
   n=(X-Z)/(Z+Y);
   n=floor(n);
   printf("%d\n",n);

  }
         



Measured memory_bytes: 128
#include <bits/stdc++.h>
int k,n,a[300005],p;
int main(){
	scanf("%d%d",&k,&n);
	if (k%2==0){
		printf("%d ",k/2);
		for (int i=2;i<=n;i++) printf("%d ",k);
		return 0;
	} 
	for (int i=1;i<=n;i++) a[i]=(k+1)/2;
	p=n;
	for (int i=n/2;i;i--){
		if (a[p]==1) p--;
		else{
			a[p]--;
			for (int j=p+1;j<=n;j++) a[j]=k;
			p=n;
		}
	}
	for (int i=1;i<=p;i++) printf("%d ",a[i]);
} 

Measured memory_bytes: 3456