akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <utility>
#include <cctype>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#define LL long long
#define LB long double
#define x first
#define y second
#define Pair pair<int,int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL LINF=2e16;
const int INF=2e9;
const int magic=348;
const double eps=1e-10;
const double pi=3.14159265;

inline int getint()
{
    char ch;int res;bool f;
    while (!isdigit(ch=getchar()) && ch!='-') {}
    if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
    while (isdigit(ch=getchar())) res=res*10+ch-'0';
    return f?res:-res;
}

int n,k;
string s[2048];
int cntCh[27];
string ans;
bitset<1000048> can[2048];
Pair dp[2][1000048];

int main ()
{
	int i,j,cnt,ncnt,cur,minCh,minSt;
	n=getint();k=getint();
	for (i=1;i<=n;i++)
	{
		cin>>s[i];
		//for (j=0;j<int(s[i].size());j++)
		//	cntCh[s[i][j]-'a'+1]++;
	}
	/*int fcnt=0;
	for (i=1;i<=26;i++)
		if (cntCh[i]) fcnt++;
	if (fcnt==1)
	{
		for (i=1;i<=26;i++)
			if (cntCh[i])
			{
				ans=string(k,'a'+i-1);
				cout<<ans<<endl;
				return 0;
			}
	}*/
	can[n+1][0]=1;
	for (i=n;i>=1;i--)
		can[i]=can[i+1]|(can[i+1]<<(int(s[i].size())));
	for (i=1;i<=n;i++)
		if (can[i+1][k-int(s[i].size())]) dp[0][++cnt]=mp(i,0);
	cur=0;
	for (i=1;i<=k;i++)
	{
		cnt=min(cnt,10000);ncnt=0;
		minCh=26;
		for (j=1;j<=cnt;j++)
			minCh=min(minCh,s[dp[cur][j].x][dp[cur][j].y]-'a'+1);
		ans+=string(1,'a'+minCh-1);
		minSt=INF;
		for (j=1;j<=cnt;j++)
			if (s[dp[cur][j].x][dp[cur][j].y]-'a'+1==minCh)
			{
				if (dp[cur][j].y==int(s[dp[cur][j].x].size())-1)
					minSt=min(minSt,dp[cur][j].x+1);
				else
					dp[cur^1][++ncnt]=mp(dp[cur][j].x,dp[cur][j].y+1);
			}
		for (j=minSt;j<=n;j++)
			if (k-i-int(s[j].size())>=0 && can[j+1][k-i-int(s[j].size())])
				dp[cur^1][++ncnt]=mp(j,0);
		cnt=ncnt;cur^=1;
	}
	cout<<ans<<endl;
	return 0;
}	

Measured memory_bytes: 249728
#include <bits/stdc++.h>
#define endl "\n"
#include <set>


using namespace std;
int main(){
    
ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
int n;
cin>>n;
vector <int> a;
for (int i=0; i<n; i++)
{
	int temp; cin>>temp;
	a.push_back(temp);
}

long long int dp[n][n];
for (int i=0; i<n; i++)
{
	dp[i][i]=a[i];
}

for (int diff=1; diff<n; diff++)
{
	for (int i=0; i<n && i+diff<n; i++)
	{
		int j=i+diff;
		dp[i][j]= max(-dp[i+1][j] + a[i], -dp[i][j-1]+ a[j]);
	}
}

cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 70528
def q4():
    from itertools import accumulate

    N, K = (int(i) for i in input().split())
    P = [int(i) for i in input().split()]

    P_kitai = [0]
    # 整数1からNまでの合計は、sum = N(N+1)/2
    # 期待値は sum / N より、(N+1)/2 で表される。
    for p in P:
        P_kitai.append((p+1)/2)
    accu = list(accumulate(P_kitai))
    #print(accu)
    max_sum = 0
    for i in range(0, N-K+2):
        max_sum = max(max_sum, accu[i+K-1] - accu[i-1])
    print(max_sum)

if __name__ == '__main__':
    q4()


Measured memory_bytes: 81928
#include <unistd.h>
#include <stdio.h>
#include <algorithm>

typedef long long ll;

int mat[3000][3000];

ll dp[3000][3000][4];
ll dpl[3000];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    dp[0][0][1] = mat[0][0];
    for (int y = 0; y < rr; y++) {
        dp[y][0][0] = dpl[0];
        for (int c = 1; c < 4; c++) {
            dp[y][0][c] = dpl[0] + mat[y][0];
        }
        for (int x = 1; x < cc; x++) {
            dp[y][x][0] = std::max(dpl[x], dp[y][x - 1][0]);
            for (int c = 1; c < 4; c++) {
                int v = mat[y][x];
                dp[y][x][c] = std::max(dpl[x] + v, std::max(dp[y][x - 1][c], dp[y][x - 1][c - 1] + v));
            }
        }
        for (int x = 0; x < cc; x++) {
            dpl[x] = std::max(std::max(dp[y][x][0], dp[y][x][1]), std::max(dp[y][x][2], dp[y][x][3]));
        }
    }
    printf("%lld\n", dpl[cc - 1]);
    return 0;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

// https://onlinejudge.u-aizu.ac.jp/solutions/problem/DSL_2_B/review/4066643/haji149/C++14
class BIT{
public:
    int n;
    vector<ll> bit;
    BIT():n(-1){};
    BIT(int n_){
        n=1;
        while(n < n_+2) n *= 2;
        bit.resize(n+1, 0);
    }

    //[0, i]までの総和を得る
    ll sum(int i){
        i++;
        ll s=0;
        while(i>0){
            s = (s + bit[i]);
            i -= i & -i;
        }
        return s;
    }

    //i番目の要素にx加算(0 オリジン)
    void add(int i, ll x){
        i+=2;

        while(i <= n){
            bit[i] = (bit[i] + x);
            i += i & -i;
        }
    }

    ll sum(int l, int r){ //[l, r) 0オリジン
        return sum(r) - sum(l);
    }
};


int main() {
    int n, q;
    cin >> n >> q;


    BIT bit(n);
    rep(i, n) bit.add(i, 0);

    rep(i, q) {
        int command;
        cin >> command;
        if (command == 0) {
            ll x, y;
            cin >> x >> y;
            bit.add(x, y);
        } else {
            ll x, y;
            cin >> x >> y;
            cout << bit.sum(x, y + 1) << endl;
        }
    }

}



Measured memory_bytes: 3828
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    private void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        Map<Integer, Integer> map = new HashMap<>(n);
        for (int i = 0; i < n; i++) {
            int d = in.nextInt();
            map.compute(d, (key, old) -> (old == null) ? 1 : old + 1);
        }

        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            int t = in.nextInt();
            int tmp = map.compute(t, (key, old) -> (old == null) ? -1 : old - 1);
            if (tmp < 0) {
                out.println("NO");
                return;
            }
        }

        out.println("YES");
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

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

    double nextDouble() {
        return Double.parseDouble(this.sc.next());

    }

    @Override
    public void close() {
        this.sc.close();
    }
}


Measured memory_bytes: 89612
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    a = getN()
    if a >= 30:
        print("Yes")
    else:
        print("No")

def main():
    n = getN()
    for _ in range(n):
        solve()


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

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

int main(){
    vector <int> a(5);
    for(int i = 0; i < 5; i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << i + 1 << endl;
        }
    }
}
        

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
long T;
vector<pair<int,int> >A;
vector<int>zero;
long t[40];
main()
{
	cin>>N>>T;
	for(int i=0;i<N;i++)
	{
		int a,b;cin>>a>>b;
		if(a==0)zero.push_back(b);
		else A.push_back(make_pair(a,b));
	}
	sort(A.begin(),A.end(),[](pair<int,int>a,pair<int,int>b){
		return (long)b.first*(a.second+1)<(long)a.first*(b.second+1);
	});
	for(int i=0;i<40;i++)t[i]=T+1;
	t[0]=0;
	for(int i=0;i<A.size();i++)
	{
		long a=A[i].first,b=A[i].second;
		for(int j=40;j--;)
		{
			if((t[j]+1)*(a+1)+b<=T)
			{
				t[j+1]=min(t[j+1],(t[j]+1)*(a+1)+b);
			}
		}
	}
	sort(zero.begin(),zero.end());
	int ans=0;
	for(int i=0;i<40;i++)
	{
		if(t[i]>T)continue;
		long now=t[i];
		int cnt=i;
		for(int b:zero)
		{
			if(now+b+1<=T)
			{
				now+=b+1;
				cnt++;
			}
			else break;
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
}


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

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    int use[n]={0};
    int price[n],rikai[n][m];
    int ans=100000000;
    for (int i = 0; i < n; ++i) {
        cin>>price[i];
        for (int j = 0; j < m; ++j) {
            cin>>rikai[i][j];
        }
    }
    while(use[0]!=2){
        int nowr[m]={0},nowp=0;
        for (int i = 0; i < n; ++i) {
            if(use[i]==1){
                nowp+=price[i];
                for (int j = 0; j < m; ++j) {
                    nowr[j]+=rikai[i][j];
                }
            }
        }
        for (int k = 0; k < m; ++k) {
            if(nowr[k]<x)goto out;
        }
        ans=min(ans,nowp);
        out:;
        use[n-1]++;
        for (int l = n-1; l > 0; --l) {
            if(use[l]==2){
                use[l-1]++;
                use[l]=0;
            }
        }
    }
    if(ans!=100000000)cout<<ans<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3628
#探索範囲増やすとどのくらい時間が伸びるのか

x=int(input())

def is_prime(p):
  cnt=0
  for i in range(2,p):
    if p%i==0:
      cnt+=1
  if cnt==0:
    return True
  #2からp-1までみて、cntが0ならpは素数
  else:
    return False
      
#print(*[(x,is_prime(x)) for x in range(1,10+1)])
num=x
while True:
  if is_prime(num):
    ans=num
    break
  num+=1
print(ans)


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

int main()
{
  int i, j, k, v, n;
  int *A;

  scanf("%d",&n);

  A = (int *)malloc(n * sizeof(int));
  
  for( i=0 ; i<n ; i++ )
    scanf("%d",&A[i]);
  
  for( i=0 ; i<n-1 ; i++ )
    printf("%d ",A[i]);
  printf("%d\n",A[i]);

    for( i=1 ; i<=n-1 ; i++ ){
      v = A[i];
      j = i-1;
      while(j>=0 && A[j]>v){
	A[j+1] = A[j];
	j--;
      }
      A[j+1] = v;
      for( k=0 ; k<n-1 ; k++ )
	printf("%d ",A[k]);
      printf("%d\n",A[k]);
    }

  free(A);
  return 0;
}

Measured memory_bytes: 600
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def Find(x):	#xの根を返す
	global table

	if table[x] == x:
		return x
	else:
		table[x] = Find(table[x])	#親の更新(根を直接親にして参照距離を短く)
		return table[x]

def Union(x,y):	#xとyを繋げる
	x = Find(x)
	y = Find(y)

	if x == y:
		return

	if rank[x] > rank[y]:
		table[y] = x
	else:
		table[x] = y
		if rank[x] == rank[y]:
			rank[y] += 1

def Check(x,y):
	if Find(x) == Find(y):
		return True
	else:
		return False



N = int(input())


#Union-Find
table = [i for i in range(N)]	#木の親 table[x] == x なら根
rank  = [1 for i in range(N)]	#木の長さ

# 優先度付きキューの作成
q = []
heapq.heapify(q)


xys = [list(map(int,input().split()))+[i] for i in range(N)]
xys.sort()
for i in range(N-1):
	xa,ya,a = xys[i]
	xb,yb,b = xys[i+1]
	heapq.heappush(q,[xb-xa,a,b])

xys.sort(key=lambda x:x[1])
for i in range(N-1):
	xa,ya,a = xys[i]
	xb,yb,b = xys[i+1]
	heapq.heappush(q,[yb-ya,a,b])

#総コスト
weight = 0


while q:
	w,a,b = heapq.heappop(q)

	if not Check(a,b):
		weight += w
		Union(a,b)

print(weight)


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if((A + B) % 2 == 0) {
    cout << (A + B) / 2 << endl;
  }
  else if((A + B) % 2 != 0) {
  cout << "IMPOSSIBLE" << endl;
  }
}
    

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

#define SZ(v) ((int)(v).size())
using ll = long long;

const int MAXN = 2e5+1;

int ans[MAXN];
vector<int> G[MAXN];
vector<int> best;
bool change[MAXN];
int val[MAXN];
int sol(0);


void dfs(int u, int p)
{
	if (SZ(best) == 0 or best.back() < val[u])
	{
		best.push_back(val[u]);
		ans[u] = SZ(best);
		for (auto v : G[u])
			if (v != p)
				dfs(v,u);
		best.pop_back();
	}
	else
	{
		int pos = lower_bound(best.begin(), best.end(), val[u]) - best.begin();
		int old = best[pos];
		ans[u] = SZ(best);
		best[pos] = val[u];
		for (auto v : G[u])
			if (v != p)
				dfs(v,u);
		best[pos] = old;
	}
}

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

	int N;
	cin >> N;
	for (int i(0); i < N; ++i)
		cin >> val[i];
	for (int i(1); i < N; ++i)
	{
		int _u, _v;
		cin >> _u >> _v;
		--_u, --_v;
		G[_u].push_back(_v);
		G[_v].push_back(_u);
	}

	dfs(0,0);
	for (int i(0); i < N; ++i)
		cout << ans[i] << '\n';
}


Measured memory_bytes: 27536
#include <iostream>

using namespace std;
 
int main(){
    int Q,A,qq[4],aa[4],Hit,Blow,num;
 
    while(1){ 
	num = 1000;
	Hit = Blow = 0;
 
	cin >> Q >> A;
	if( Q == 0 && A == 0 ) break;
 
	for( int i = 0 ; i < 4 ; i++ ){
 
	    qq[i] = Q / num % 10;
	    aa[i] = A / num % 10;
	    num/=10;
 
	}
 
	for( int i = 0 ; i < 4 ; i++ ){
	    for( int j = 0 ; j < 4 ; j++ ){
 
		if( qq[i] == aa[j] && i == j ) Hit++;
		else if( qq[i] == aa[j] && i != j ) Blow++;
 
	    }
	}
	cout << Hit << " " << Blow << endl;
    }
    return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}


int main(){
    string s;
    cin >> s;
    vector<ll> c(3,0);
    rep0(i, s.size())++c[s[i] - 'a'];
    if(abs(c[0] - c[1]) <= 1 && abs(c[1] - c[2]) <= 1 && abs(c[0] - c[2]) <= 1)pf("YES");
    else pf("NO");
    return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
const ll Mod=1000000007;
const ll INF=999999999999999999;
const ll NN=(ll)(1e6+5);
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
ll n,m;
vector <set<ll>> g;
vector <ll> vis; 
ll dfs(ll node)
{
    vis[node]++;
    ll c=0;
    for(auto u:g[node])
     if(!vis[u])
      c+=dfs(u);
    return 1+c;  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {
       cin>>n>>m;
       g.resize(n+1);
       vis.resize(n+1);
       ll i,x,y;
       for(i=0;i<m;i++)
       {
           cin>>x>>y;
           g[x].insert(y);
           g[y].insert(x);
       }
       ll ans=-INF;
       for(i=1;i<=n;i++)
        if(!vis[i])
         ans=max(ans,dfs(i));
       cout<<ans;  
   }
}

Measured memory_bytes: 38984
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> H(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> H.at(i);
    }

    // 逆向きに見ていく
    bool isOK = true;
    for (ll i = N - 2; i >= 0; i--)
    {
        if (H.at(i + 1) < H.at(i))
        {
            if (H.at(i + 1) == H.at(i) - 1)
            {
                H.at(i)--;
            }
            else
            {
                isOK = false;
                break;
            }
        }
    }

    cout << (isOK ? "Yes" : "No") << endl;

    return;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  int x=0;
  for(int i=A;i<=B;i++){
    int s=i%10;
    int t=i/10%10;
    int u=i/1000%10;
    int v=i/10000;
    if(s==v&&t==u){
      x++;
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	mp := map[string]bool{}
	var bak string
	fmt.Scan(&bak)
	mp[bak] = true
	for i := 1; i < n; i++ {
		var s string
		fmt.Scan(&s)
		if s[0] != bak[len(bak)-1] || mp[s] {
			fmt.Println("No")
			return
		}
		mp[s] = true
		bak = s
	}
	fmt.Println("Yes")
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
using lint = long long int;

int main() {
    int N, P;
    string S;
    cin >> N >> P;
    cin >> S;

    reverse(S.begin(), S.end());

    if (P == 2 or P == 5) {
        lint ans = 0;
        for_(i,0,N) {
            int c = int(S[i] - '0');
            if (c % P == 0) ans += N - i;
        }
        cout << ans << endl;
        return 0;
    }

    vector<int> pow10(N, 1);
    for_(i,1,N) pow10[i] = (pow10[i-1] * 10) % P;

    vector<int> mod(N);
    int cur = 0;
    for_(i,0,N) {
        cur = (cur + int(S[i] - '0') * pow10[i]) % P;
        mod[i] = cur;
    }

    lint ans = 0;
    vector<int> cnt(P, 0);
    cnt[0] = 1;
    for_(i,0,N) {
        ans += cnt[mod[i]];
        ++cnt[mod[i]];
    }
    cout << ans << endl;
}


Measured memory_bytes: 2180
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k;
    cin >> n >> k;

    vector <int> A(n);

    int ans = n;
    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++) {
            int a;
            cin >> a;
            A[--a]++;
            if (A[a] == 1) ans--;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<math.h>
int main(){
int N,i,a=0;
double ans,D,ans1;
double X[200001],Y[200001];
scanf("%d %lf",&N,&D);
for(i = 1; i <= N; i++){
scanf("%lf %lf",&X[i],&Y[i]);
}
for(i = 1; i<= N; i++){
ans1 = pow(X[i],2.0) + pow(Y[i],2.0);
ans = sqrt(ans1);
if(D >= ans){
  a++;
}
}
  printf("%d",a);
}

Measured memory_bytes: 5316
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    string S, s;
    cin >> S;
    for(int i = 4; i < 10; i++)
        s += S[i];
    cout << "2018" << s << endl;
    return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<lli, lli> pll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int digit(lli n) {
    int res = 0;
    do {
        res += n % 10;
        n /= 10;
    } while (n != 0);
    return res;
}

int main() {
    lli K;
    cin >> K;
    //*
    vector<pll> candidates;

    lli bs = 0;
    REP(d, 0, 13) {
        REP(i, 1, 1000) {
            lli n = 9 * bs + (9 * bs + 1) * i;
            candidates.push_back({n, digit(n)});
        }
        bs = bs * 10 + 1;
    }

    sort(begin(candidates), end(candidates));
    candidates.erase(unique(begin(candidates), end(candidates)), end(candidates));

    //dump((*rbegin(candidates)).first);

    int cnt = 0;
    REP(i, 0, candidates.size()) {
        if (cnt >= K) {
            break;
        }
        pll ans = candidates[i];
        bool ok = true;
        REP(j, i + 1, candidates.size()) {
            pll c = candidates[j];
            if (ans.first * c.second > ans.second * c.first) {
                ok = false;
            }
        }
        if (ok) {
            cnt++;
            cout << ans.first << endl;
        }
    }
    //*/
    /*
    int cnt = 0;
    REP(i, 1, 10000000) {
        bool ok = true;
        REP(j, i + 1, 1000000) {
            if (i * digit(j) > j * digit(i)) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cnt++;
            cout << "#" << cnt << " " << i << endl;
        }
    }
    //*/
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

int N;
vector<int> cls[10];
int cnt[10];

bool judge(const vector<int>& a,const vector<int>& b){
  vector<int> c=a;
  sort(all(c));
  do{
    set<int> st;
    rep(i,3){
      st.insert((c[i]+60-b[i])%60);
    }
    if(st.size()==1)return true;
  }while(next_permutation(all(c)));
  return false;
}

int main(){
  while(1){
    cin>>N;
    if(N==0)break;
    rep(i,N){
      cls[i].clear();
      rep(j,3){
        int a;
        cin>>a;
        cls[i].push_back(a);
      }
      sort(all(cls[i]));
    }
    int st=-1,ed=-1;
    vector<P> ps;
    rep(i,43200){
      int h=i/3600;
      int m=i%3600/60;
      int s=i%60;
      vector<int> tmp(3);
      tmp[0]=h*5+(m/12);
      tmp[1]=m;
      tmp[2]=s;

      int mask=0;
      rep(j,N){
        if(judge(cls[j],tmp)){
          mask|=1<<j;
        }
      }

      if(mask){
        ps.push_back(P(i,mask));
      }
    }
    sort(all(ps));

    memset(cnt,0,sizeof(cnt));
    int mnlen=INF,mnst=-1,mned=-1;
    for(int l=0,r=0,crt=0;l<ps.size();){
      for(;r<ps.size();r++){
        rep(i,N){
          if((ps[r].se>>i)&1){
            if(cnt[i]==0)crt|=1<<i;
            cnt[i]++;
          }
        }
        if(crt==(1<<N)-1)break;
      }

      if(r==ps.size())break;
      if(crt==(1<<N)-1){
        if(mnlen>ps[r].fi-ps[l].fi){
          mnlen=ps[r].fi-ps[l].fi;
          mnst=ps[l].fi; mned=ps[r].fi;
        }
      }

      for(;l<r;l++){
        if(crt==(1<<N)-1){
          if(mnlen>ps[r].fi-ps[l].fi){
            mnlen=ps[r].fi-ps[l].fi;
            mnst=ps[l].fi; mned=ps[r].fi;
          }
        }
        rep(i,N){
          if((ps[l].se>>i)&1){
            cnt[i]--;
            if(cnt[i]==0)crt^=(1<<i);
          }
        }
        if(crt!=(1<<N)-1){
          break;
        }
      }
      if(l<r)l++;
      r++;
    }

    {
      int sth=mnst/3600;
      int stm=mnst%3600/60;
      int sts=mnst%60;
      int eth=mned/3600;
      int etm=mned%3600/60;
      int ets=mned%60;
      printf("%02d:%02d:%02d %02d:%02d:%02d\n", sth,stm,sts,eth,etm,ets);
    }
  }
  return 0;
}



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

int main() {
    int h, n;
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        h -= a;
        if (h <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cassert>
using namespace std;

int main(){
    string S,T;
    cin >> S >> T;
    int M = T.size();
    string SS = S + S;
    while(SS.size()<2*M) SS += S;
    int N = S.size();
    vector<int> kmpnext(M+1,-1);
    vector<vector<int>> v(N+1);
    auto prekmp = [&](string x,int m){
        int i = 0,j = kmpnext[0] = -1;
        while(i<m){
            while(j>-1 && x[i]!=x[j]) j = kmpnext[j];
            i++; j++;
            if(x[i]==x[j]) kmpnext[i] = kmpnext[j];
            else kmpnext[i] = j;
        }
    };
    auto KMP = [&](string x,int m,string y,int n){
        int i = 0,j = 0;
        prekmp(x,m);
        while(j<n){
            while(i>-1 && x[i]!=y[j]) i = kmpnext[i];
            i++; j++;
            if(i>=m){
                v[(j-i)%N].push_back((j-i+x.size())%N);
                i = kmpnext[i];
            }
        }
    };
    KMP(T,M,SS,SS.size());
    vector<int> vis(N+1,0);
    vector<int> u;
    function<bool(int)> dfs = [&](int n){
        vis[n] = -1;
        bool ok = true;
        for(auto x:v[n]){
            if(vis[x]==0) ok &= dfs(x);
            else if(vis[x]==-1) return false;
        }
        u.push_back(n);
        vis[n] = 1;
        return ok;
    };
    for(int i=0;i<N;i++){
        if(vis[i]==0){
            if(!dfs(i)){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    for(int i=0;i<N;i++) vis[i] = 0;
    reverse(u.begin(),u.end());
    vector<int> d(N+1,0);
    function<int(int)> dfs2 = [&](int n){
        vis[n] = 1;
        d[n] = 1;
        for(auto x:v[n]){
            if(!vis[x] && !v[x].empty()) d[n] = max(d[n],dfs2(x)+1);
            else if(vis[x]==1) d[n] = max(d[n],d[x]+1);
        }
        return d[n];
    };
    for(int i=0;i<N;i++) vis[i] = 0;
    for(auto x:u){
        if(!vis[x] && !v[x].empty()) dfs2(x);
    }
    int ans = 0;
    for(int i=0;i<N;i++) ans = max(ans,d[i]);
    cout << ans << endl;
}

Measured memory_bytes: 68040
#include<stdio.h>
#include<string.h>

int main(){

	int N,M;
	int Flag=0;
	int start=50;
	char A[50][50];
	char B[50][50];

	scanf("%d %d",&N,&M);

	for(int i=0; i<N; i++){
		scanf("%s",A[i]);
	}

	for(int j=0; j<M; j++){
		scanf("%s",B[j]);
	}

	for(int i=0; i<N; i++){
			if( strstr(A[0],B[i]) != NULL){
				if(start > i){
					start = i;
				}
			}
	}

	for(int i=0; i<M; i++){
		if( strstr(A[i+start],B[i]) == NULL){
			Flag = 1;
		}else{
			
		}
	}

	if(Flag==0){
		printf("Yes");
	}else{
		printf("No");
	}

	return 0;


}

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


typedef long long ll;
#define DEBUG


ll getDivisorNum(long long N){
    ll cnt = 0;
    for(ll i=1; i <= N; i++){
        if(N % i == 0){
            cnt++;
        }
    }
    return cnt;
}

void solve(long long N){
    ll cnt = 0;
    for(int i=1; i <= N; i++){
        if(i % 2 == 1 && getDivisorNum(i) == 8){
            cnt++;
        }
    }
    cout << cnt << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = 0;
		// 文字列の入力
		int[] d = new int[a];
		int[] e = new int[a];
		for(int i = 0; i < a; i++){
			d[i] = sc.nextInt();
          d[i] --;
			e[d[i]] = i + 1;
		} 
		for(int i = 0; i < a; i++){
			System.out.print(e[i] + " ");
          
		}
		
		
	}
}

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

int main() {
    string S;
    cin >> S;
    int OddBlack = 0;
    int OddWhite = 0;
    int EvenBlack = 0;
    int EvenWhite = 0;
    for(int i=0; i<S.size(); i=i+2) {
        if(S[i] == '0') {
            EvenBlack++;
        }else{
            EvenWhite++;
        }
    }
    for(int i=1; i<S.size(); i=i+2) {
        if(S[i] == '0') {
            OddBlack++;
        }else{
            OddWhite++;
        }
    }

    int ans = min(EvenBlack+OddWhite, EvenWhite+OddBlack);
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
/*######################################################
#########~~~~~####~~~~###~~##~~##~~##~~##~~##~~#########
#########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~#########
#~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~#
#########~~######~~##~~##~~##~~##~~##~~##~~##~~#########
#########~~######~~##~~##~~##~~##~~##~~###~~~~##########
######################################################*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

#pragma GCC optimize("O3")
#define rtn return
#define endl '\n'
#define F first
#define S second
#define mt make_tuple
#define pb push_back
#define int long long
#define value_at find_by_order
#define index_of order_of_key
#define fill(a, v) memset(a,v,sizeof(a))
#define copy(a, b) memcpy(b,a,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i, n) for(int i=0;i<(int)n;++i)
#define per(i, n) for(int i=(int)n-1;i>=0;--i)
#define rep1(i, n) for(int i=1;i<=(int)n;++i)
#define per1(i, n) for(int i=(int)n;i>=1;--i)
#define loop(i, begin, end) for(int i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef string str;
typedef long double db;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<db> vdb;

template<class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; }
template<class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; }
template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e18;
const db EPS = 1e-15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

//

int32_t main() {
  FAST_IO;
  int x;
  cin >> x;
  int f = x / 500;
  x -= f * 500;
  int y = x / 5;
  cout << f * 1000 + y * 5;
  rtn 0;
}


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

int N;
bool ada = false;

int main (){
    cin >> N;
    for(int i=1; i<=9; i++) {
        for(int j=1; j<=9; j++) {
            if(i*j ==N) {
                ada = true;
            }
        }
    }
    if(ada) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3560
/**
 *    Author:  AKASH-ALAM       
**/
#include <bits/stdc++.h>
#define endl        '\n'
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define pf(x) 		push_front(x)
#define pb(x)       push_back(x)
#define eb(x)		emplace_back(x)
#define all(x)      (x).begin(), (x).end()
#define rall(x) 	(x).rbegin(), (x).rend()
#define sz(x) 		(int)x.size()
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define Fast_io    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18; 
using namespace std;

int main(){
    Fast_io;
    int w, a, b;    cin >> w >> a >> b;
    if((a + w) < b) cout << b - (a+w) << endl;
    else if ((b+w) < a) cout << a  - (b + w)<< endl;
    else if(a+w >= b && (b+w) >= a) cout << 0 <<  endl;
    return 0;
}


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

using namespace std;
 
int main()
{
    int num, count = 0;
    string ans;
    cin >> num >> ans;
    while(--num >= 0){
        string S;
        cin >> S;
        int flag = 0;
        //全探索
        for(int i = 0; i < S.size()-ans.size()+1; i++){
        	//j文字飛ばしで見る
            for(int j = 1; j < S.size(); j++){
                string L;
                //おんなじ文字列できたらflag立てる
                for(int k = i; k < S.size(); k += j){
                    L += S[k];
                    if(L == ans){
                        flag = 1;
                        break;
                    }
                }
            }
        }
        if(flag == 1){count++;}
    }
 
    cout << count << endl;
 
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n;
  cin >> n;
  cout << (n - 1) * n / 2 << endl;
}

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

#define ll long long
#define ld double
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define setpr(pp) fixed<<setprecision(pp)
#define FOR(I,N) for(I=0;I<N;++I)
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod	%1000000007
#define pi 3.141592653
#define NL -5000000

int main()
{	IOS;
	ll i,j,a[101][101];
	FOR(i,101)
	{
		FOR(j,101)
		a[i][j]= 2*i + 4*j;
	}
	ll x,y;
	cin>>x>>y;
	FOR(i,101)
	{
		FOR(j,101)
		{
			if(a[i][j]==y && x==(i+j))
			{
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<string> g(h);
    for(int i = 0; i < h; i++) {
        cin >> g[i];
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(g[i][j] == '.') {
                int cnt = 0;
                for(int r = 0; r < 8; r++) {
                    int ni = i + dy[r];
                    int nj = j + dx[r];
                    if(0 <= ni && ni < h && 0 <= nj && nj < w &&
                       g[ni][nj] == '#') {
                        cnt++;
                    }
                }
                g[i][j] = (char)('0' + cnt);
            }
        }
    }
    for(int i = 0; i < h; i++) {
        cout << g[i] << "\n";
    }
}

Measured memory_bytes: 3660
N = int(input())
A = list(map(int, input().split()))
L = [[] for i in range(N)]
for i in range(N):
    L[i] = [A[i], i+1]
L.sort()
ans = [0 for i in range(N)]
for i in range(N):
    ans[i] = L[i][1]
print(*ans)

Measured memory_bytes: 23632
#include <bits/stdc++.h>
using namespace std;
#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MP make_pair
#define PB push_back
#define fi first
#define se second

typedef long long LL;
typedef pair<int, int> PII;
const int N= 2e5 +10;

int a[N], n;
int main(){
	#ifdef che
	#endif
	LL ans=0;
	scanf("%d", &n);for (int i=0; i<n; i++) scanf("%d", &a[i]);
	int pre=a[0],r=1;
	for (r=1; r<n; r++)
		if( pre&a[r]) break;	else pre|=a[r];
	for (int i=0; i<n; i++){
		ans += 1LL*(r-i);
		pre^= a[i];
		for (; r<n; r++)	if ( pre&a[r]) break; else pre|=a[r];
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  long long N, C; cin >> N >> C;
  vector<long long> X(N), V(N);
  for (int i = 0; i < N; i++) cin >> X.at(i) >> V.at(i);

  vector<long long> sumV(N+1, 0);
  for (int i = 0; i < N; i++) sumV.at(i+1) = sumV.at(i) + V.at(i);

  vector<long long> maxA(N+1, 0);
  long long tmpA = 0;
  for (int i = 1; i <= N; i++) {
    tmpA = max(tmpA, sumV.at(i) - X.at(i-1));
    maxA.at(i) = tmpA;
  }

  vector<long long> maxB(N+1, 0);
  long long tmpB = 0;
  for (int i = 1; i <= N; i++) {
    tmpB = max(tmpB, sumV.at(N) - sumV.at(N-i) - (C - X.at(N-i)));
    maxB.at(i) = tmpB;
  }

  long long ans = 0;
  for (int i = 0; i <= N; i++) {
    long long cost = i ? (2 * (C - X.at(N-i))) : 0;
    ans = max(ans, sumV.at(N) - sumV.at(N-i) - cost + maxA.at(N-i));
  }
  for (int i = 0; i <= N; i++) {
    long long cost = i ? (2 * X.at(i-1)) : 0;
    ans = max(ans, sumV.at(i) - cost + maxB.at(N-i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        BigInteger[] a = new BigInteger[N];
        BigInteger all = BigInteger.ONE;
        for (int i = 0; i < N; i++) {
            long x = scan.nextLong() * 1000000;
            a[i] = new BigInteger(Long.toString(x));
            all = all.multiply(a[i]);
        }
        BigInteger sum = BigInteger.ZERO;
        for (int i = 0; i < N; i++) {
            sum = sum.add(all.divide(a[i]));
        }
        double answer = all.divide(sum).doubleValue() / 1000000;
        System.out.println(String.format("%.6f", answer));
    }
}


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

signed main(){
    typedef pair<long long,long long> P;
    constexpr long long INF=LLONG_MAX;
    int N,A,B;cin>>N>>A>>B;
    vector<long long> v(N);
    REP(i, N) cin >> v[i];
    vector<vector<P>> dp(N+1,vector<P>(N+1,P(-INF,0LL)));
    REP(i,N+1) dp[i][0]=P(0,1);
    P ans=P(0LL,1LL);
    REP(i,N) REP(j,N){
        long long u=dp[i][j+1].first,d=dp[i][j].first+v[i];
        if(u>d) dp[i+1][j+1]=P(u,dp[i][j+1].second);
        if(u==d) dp[i+1][j+1]=P(u,dp[i][j+1].second+dp[i][j].second);
        if(u<d) dp[i+1][j+1]=P(d,dp[i][j].second);
        long long tmp=max(u,d);
        if(A<=j+1&&j+1<<B&&ans.first*(j+1)<tmp*ans.second){
            ans=P(tmp,j+1);
        }
    }
    long long choice=0;
    rep(i,A,B+1){ 
        long long sum=dp[N][i].first;
        if(sum*ans.second==ans.first*i){
            choice+=dp[N][i].second;
        }
    }
    printf("%.16f\n",(double)ans.first/(double)ans.second);
    cout<<choice<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
string a;
int len;
int main()
{
	cin>>a;
	len=a.size();
	for(int i=0;i<len;i++){
		if(a[i]=='C'){
			for(int j=i+1;j<len;j++){
				if(a[j]=='F'){
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t=0,n,m,k,i,a,b,j;
	cin >> n;
	for(i=1;i<=n;i++)
	{
		cin >> m;
		if(m%2 && i%2)
			t++;
	}
	cout << t << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)
int solve(int n){
	return n * (n - 1) / 2;
}
int main(){
	int n, m; cin>>n>>m;
	cout<<solve(n) + solve(m)<<endl;
}


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

int main(){
    long long int sum;
    int n, i, a, b,  min, max;
    sum = 0;
    cin >> n;
    cin >> a;
    if ( n == 1 ){cout << a << " " << a << " " << a << endl;return 0;}
    cin >> b;
    sum = a + b;
    if ( n == 2 ){
        if ( a < b ){
            cout << a << " " << b << " " << sum << endl;
        } else {
            cout << b << " " << a << " " << sum << endl;
        }
        return 0;
    }
    if (a < b){
        min = a; max = b;
    } else{
        min = b; max = a;
    }
    for (i = 1; i < n-1; i++){
        cin >> a;
        sum += a;
        if (a < min){
            min = a;
        } else if (max < a){
            max = a;
        }
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int aoki = a % d == 0 ? a/d : a/d + 1;
    int takahashi = c % b == 0 ? c/b : c/b + 1;
    if(takahashi <= aoki) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		Dice dice = new Dice();

		dice.setDice(input.readLine().split(" "));

		String solution = dice.Move(input.readLine().toCharArray());

		System.out.println(solution);
	}
}


class Dice{

	private String[] dice;

	private char[] move;

	private String[] over;

	public void setDice (String[] diceStr)
	{
		dice = new String[6];

		for(int num = 0; num < diceStr.length; num++)
			dice[num] = diceStr[num];
	}

	public String Move (char[] compass)
	{
		move = compass;

		//move.length回、転がす
		for(int kai = 0; kai < move.length; kai++)
		{
			over = new String[6];

			//東に転がす場合
			if(move[kai] == 'E')
			{
				over[0] = dice[3];
				over[1] = dice[1];
				over[2] = dice[0];
				over[3] = dice[5];
				over[4] = dice[4];
				over[5] = dice[2];

				for(int num = 0; num < over.length; num++)
					dice[num] = over[num];
			}

			//西に転がす場合
			else if(move[kai] == 'W')
			{
				over[0] = dice[2];
				over[1] = dice[1];
				over[2] = dice[5];
				over[3] = dice[0];
				over[4] = dice[4];
				over[5] = dice[3];

				for(int num = 0; num < over.length; num++)
					dice[num] = over[num];
			}

			//南に転がす場合
			else if(move[kai] == 'S')
			{
				over[0] = dice[4];
				over[1] = dice[0];
				over[2] = dice[2];
				over[3] = dice[3];
				over[4] = dice[5];
				over[5] = dice[1];

				for(int num = 0; num < over.length; num++)
					dice[num] = over[num];
			}

			//北に転がす場合
			else if(move[kai] == 'N')
			{
				over[0] = dice[1];
				over[1] = dice[5];
				over[2] = dice[2];
				over[3] = dice[3];
				over[4] = dice[0];
				over[5] = dice[4];

				for(int num = 0; num < over.length; num++)
					dice[num] = over[num];
			}
		}
		return dice[0];
	}
}


Measured memory_bytes: 24352