akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    int N;
    ll T;

    cin >> N >> T;
    ll now = 0;
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll t;
        cin >> t;
        ans += min(t - now, T);
        now = t;
    }
    ans += T;

    cout << ans << endl;

    return 0;
}


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

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

  string s;
  int k;
  cin >> s >> k;
  set<string> cand;
  for (int j = 1; j <= k; j++) {
    for (int i = 0; i < s.size() - j + 1; i++) {
      cand.insert(s.substr(i, j));
    }
  }
  vector<string> res(cand.begin(), cand.end());
  cout << res[k-1] << '\n';
  return 0;
}

Measured memory_bytes: 1792
N, K=map(int, input().split())
P=list(map(int, input().split()))

#n面サイコロの出る目の期待値
def n_mean(n):
  return 0.5*(n+1)

Pmean=list(map(lambda x: n_mean(x), P))
Psum=[0]*N
Psum[0]=Pmean[0]
for i in range(1,N):
  Psum[i]=Psum[i-1]+Pmean[i]
#print(Psum)
ans=0
for i in range(N-K+1):
  if i==0:
    ans=Psum[K-1]
  else:
    #1~6 
    ans=max(ans, (Psum[i+K-1]-Psum[i-1]))
  
print(ans)

Measured memory_bytes: 24804
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0 ; i < n ; i++)

using namespace std;

typedef pair<int,string> P;

int main(){
  int n,m,a;

  while(cin >> n ,n){
    vector<P> v;
    vector<int> d[n],p[n];
    string s[n];

    rep(i,n){
      cin >> s[i] >> m;

      rep(j,m){
	cin >> a;
	d[i].push_back(a);
	p[i].push_back(n);
      }

      sort(d[i].begin(),d[i].end());
    }

    rep(i,n){
      rep(j,n){
	if(i == j) continue;

	int len1 = d[i].size();
	int len2 = d[j].size();	

        rep(k,len1){
	  rep(l,len2){
	    if(d[i][k] == d[j][l]){
	      p[i][k]--;
	      break;
	    }
	  }
	}

      }
    }

    rep(i,n){
      int len = p[i].size();
      int sum = 0;
      rep(j,len){
	sum += p[i][j];
      }
      v.push_back(P(sum,s[i]));
    }

    sort(v.begin(),v.end());
    cout << v[0].first << " " << v[0].second << endl;
  }

  return 0;
}

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



int main(){
    int A,B,C,X;
    cin>>A>>B>>C>>X;
    X=X/50;
    
    int num=0;
    //10,2,1を合計Xにする方法
    for (int i=0; i<=A; i++) {
        for (int k=0; k<=B; k++) {
            for (int l=0; l<=C; l++) {
                if (i*10+k*2+l==X) {
                    num++;
                }
            }
        }
    }
    
    cout<<num;
    return 0;
    
}

Measured memory_bytes: 256
using Yorukatsu027.Questions;
using Yorukatsu027.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu027.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        /// <summary>
        /// ABC093 A
        /// </summary>
        /// <param name="inputStream"></param>
        /// <returns></returns>
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var s = inputStream.ReadLine();
            yield return s.Contains('a') && s.Contains('b') && s.Contains('c') ? "Yes" : "No";
        }
    }
}


namespace Yorukatsu027
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu027.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu027.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
#UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
n,m = map(int,input().split())
uf = UnionFind(n+1)
for _ in range(m):
    a,b = map(int,input().split())
    uf.union(a,b)

print(uf.group_count()-2)

Measured memory_bytes: 12836
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int main(){
   string s;
   cin>>s;
   vector<char> ans;
   for(auto e:s){
      if(e=='1') ans.push_back('1');
      else if(e=='0') ans.push_back('0');
      else if(e=='B'&&!ans.empty()) ans.erase(ans.end()-1);
   }
   for(auto e:ans){
   cout<<e;
   }
   cout<<endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<queue>
using namespace std;
int dp[16434825], x[8][8]; queue<int>Q;
int main() {
	int n; cin >> n; int minp = 0, maxp = 0; for (int i = 0; i < n; i++) { minp += (n - 1 - i)*(1 << (3 * i)); maxp += i*(1 << (3 * i)); }
	for (int i = minp; i <= maxp; i++)dp[i] = 1000000007;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)cin >> x[i][j];
	}
	int G = 0, maxn = 0; for (int i = 0; i < n; i++) { G += (1 << (3 * i))*i; }Q.push(G); dp[G] = 0;
	while (!Q.empty()) {
		int H = Q.front(); Q.pop(); int I[8], J[8]; for (int i = 0; i < 8; i++)I[i] = (H / (1 << (3 * i))) % 8;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < 8; k++)J[k] = I[k];
				swap(J[i], J[j]); int K = 0;
				for (int k = 0; k < 8; k++)K += (1 << (3 * k))*J[k];
				if (dp[K] > dp[H] + x[i][j]) { dp[K] = dp[H] + x[i][j]; Q.push(K); }
			}
		}
	}
	for (int i = minp; i <= maxp; i++) { if (dp[i] != 1000000007 && maxn < dp[i])maxn = dp[i]; }
	cout << maxn << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
const ll md = 998244353;

ll solve(vector<ll> &va, ll s, ll offset, vector<vector<ll>> &memo) {
  if (offset == va.size()) {
    return s == 0;
  }

  if (memo[s][offset] == -1) {
    ll ans = solve(va, s, offset + 1, memo) * 2;
    if (s - va[offset] >= 0) {
      ans += solve(va, s - va[offset], offset + 1, memo);
    }

    ans %= md;
    memo[s][offset] = ans;
  }

  return memo[s][offset];
}

int main(int argc, const char *argv[]) {
  ll n, s;
  cin >> n >> s;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  ll ans = 0;
  vector<vector<ll>> memo(s + 1, vector<ll>(n + 1, -1));
  cout << solve(va, s, 0, memo) << '\n';
}

Measured memory_bytes: 73932
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto S = sread();
    auto T = sread();
    long g = gcd(N, M);
    foreach (i; 0 .. g)
    {
        if (S[i * (N / g)] != T[i * (M / g)])
        {
            writeln(-1);
            return;
        }
    }
    writeln((N * M) / g);
}


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
const int N=200100,mod=1000000007;
typedef long long ll;
int f[N],sum[N],n,m;
char s[N];

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m>>(s+1);
	int mn=max(n,m)+1,sz=0,flag=0;
	for(int i=1;i<=m;++i)	
		if(s[i]==s[1])++sz;
		else{
			if(sz&1)mn=min(mn,sz);
			else if(sz&&!flag)mn=min(mn,sz+1);
			sz=0;flag=1;
		}
	int L=0,R=0;
	if(flag){
		if(n&1){
			cout<<0<<'\n';
			return 0;
		}
		n/=2;L=1;R=min(n,(mn+1)/2);
	}else L=2,R=n;
	f[0]=sum[0]=1;
	for(int i=1;i<=n;++i){
		f[i]=sum[i-L];if(i>R)f[i]=(f[i]-sum[i-R-1]+mod)%mod;
		sum[i]=(sum[i-1]+f[i])%mod;
	}
	int ans=0;
	for(int i=L;i<=R;++i)ans=(ans+(ll)i*f[n-i])%mod;
	if(flag)ans=ans*2%mod;else ans=(ans+1)%mod;
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cstdlib>
#define N 105
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main()
{
	int n,k,x;
	int i,tot = 0;
	scanf("%d%d",&n,&k);
	for(i = 0; i < n; i ++)
	{
		scanf("%d",&x);
		tot += min(2*x,2*(k-x));
	}
	printf("%d",tot);
	return 0;
}

Measured memory_bytes: 256
List = list(map(int, input().split()))

if List[0] >= 2 and List[1] >= 2:
    c = List[0]*(List[0]-1)/2  + List[1]*(List[1]-1)/2
elif List[0] < 2 and List[1] >= 2:
    c = List[1]*(List[1]-1)/2
elif List[0] >= 2 and List[1] < 2:
    c = List[0]*(List[0]-1)/2
else:
    c = 0

print(int(c))

Measured memory_bytes: 3064
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad
import Data.Ord

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine



main :: IO ()
main = do
    let l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    k <- readLn
    print $ l!!(k-1)



Measured memory_bytes: 508
def main():
    A = [a for a in input()]
    B = [b for b in input()]
    C = [c for c in input()]

    state = "a"
    flag = False
    answer = ""
    while not flag:
        if state == "a":
            if A:
                state = A[0]
                del A[0]
            else:
                flag = True
                answer = "A"
        elif state == "b":
            if B:
                state = B[0]
                del B[0]
            else:
                flag = True
                answer = "B"
        else:
            if C:
                state = C[0]
                del C[0]
            else:
                flag = True
                answer = "C"
    print(answer)


if __name__ == "__main__":
    main()


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

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define FI first
#define SE second
using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vector<P> vec;
  int at = 0;
  for(int i = 0; i < sz(s); i++){
    if(s[i] == '1'){
      if(i == 0 || s[i-1] == '0')at = i;
    }else{
      if(i > 0 && s[i-1] == '1'){
        vec.pb(mk(at, i-1));
      }
    }
  }
  if(sz(vec) <= k - 1){
    cout << n << endl;
    return 0;
  }
  int res = vec[k-1].SE + 1;
  for(int i = 0; i < sz(vec); i++){
    int fi = vec[i].first;
    int en;
    if(i + k >= sz(vec))en = n-1;
    else en = vec[i+k].SE;
    res = max(res, en - fi + 1);
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1020
import heapq
#解説の方法
N,M = map(int,input().split())
AB = [[] for _ in range(10**5+1)]#報酬振り込み日数ごとに報酬を格納
for _ in range(N):
    a,b = map(int,input().split())
    AB[a].append(-b)
q = []
heapq.heapify(q)
ans =0
for i in range(1,M+1):
    for b in AB[i]:
        heapq.heappush(q,b)
    if len(q)>0:
        ans += -heapq.heappop(q)
print(ans)



Measured memory_bytes: 22148
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
result_list = [1] * n

for _ in range(m):
    a, b = map(int, input().split())
    if h_list[a-1] > h_list[b-1]:
        result_list[b-1] = 0
    elif h_list[a-1] == h_list[b-1]:
        result_list[a-1] = 0
        result_list[b-1] = 0
    else:
        result_list[a-1] = 0

print(result_list.count(1))

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

int main() {
	int n,temp_highest=0,ans=0;
	cin >> n;
	vector<int> h(n);
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
		if (temp_highest <= h[i]) {
			ans++;
			temp_highest = h[i];
		}
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
#define int long long
using namespace std;
//template

//main
signed main(){
  int N,K;cin>>N>>K;
  std::vector<int> v(K,1);
  for(int i=0;i<K-1;i++)N--;
  v[K-1]=N;
  cout<<v[K-1]-v[0]<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new  Scanner(System.in);
		while(in.hasNext())
		{
			double a=in.nextDouble(),b=in.nextDouble(),c=in.nextDouble();
			double d=in.nextDouble(),e=in.nextDouble(),f=in.nextDouble();
			double x,y;
			y=(c*d-a*f)/(b*d-a*e);
			x=(c-b*y)/a;
			System.out.printf("%.3f ",x);
			System.out.printf("%.3f",y);
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,m;
    cin >> n >> m;
    ll ans=1;
    rep(i,n){
        if(i==0){
            ans *= m;
        }
        else{
            ans *= m-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split.to!(long[]);
	auto X = data[0], Y = data[1], Z = data[2], K = data[3];
	auto A = readln.split.to!(long[]), B = readln.split.to!(long[]), C = readln.split.to!(long[]);
	
    long[] _AB;
    foreach (b; B) {
        _AB ~= A.map!(x => x+b).array;
    }
    //writeln(_AB);
    auto AB = _AB.sort!"a>b"().array[0 .. min(K, $)];
    //writeln(AB);
    
    long[] ans;
    foreach (c; C) {
        ans ~= AB.map!(x => x+c).array;
    }
    ans.sort!"a>b"().array[0 .. min(K, $)].each!writeln;
}



Measured memory_bytes: 123604
import java.util.*;

 
class Main {
 
    private static Scanner sc = new Scanner(System.in);
    static int n = sc.nextInt();
    static int k = sc.nextInt();


    public static void main(String[] args) {
        int ans = 0;
        ans=n-k+1;
        System.out.println(ans);
    }


}


Measured memory_bytes: 21844
# Date [ 2020-08-29 21:59:01 ]
# Problem [ e.py ]
# Author Koki_tkg
# After Contest

import sys
import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

# osa_k 法 O(NloglogN + logA)
class PrimeFactorization():
    def __init__(self, num):
        self.num = num
        self.factor_table = [0] * (num + 1)
        self.eratosthenes()

    def eratosthenes(self):
        for i in range(2, self.num + 1):
            if self.factor_table[i] == 0:
                self.factor_table[i] = i
                for j in range(i * i, self.num + 1, i):
                    if self.factor_table[j] == 0:
                        self.factor_table[j] = i
    
    def factorization(self, a):
        now = a
        ret = []
        while now > 1:
            cnt = 0
            prime = self.factor_table[now]
            while now % prime == 0:
                cnt += 1
                now //= prime
            ret.append((prime, cnt))
        return ret

def Main():
    n = read_int()
    a = read_int_list()
    max_num = max(a)

    pf = PrimeFactorization(max_num + 1)
    used_prime = [False] * (max_num + 1)
    for x in a:
        factor = pf.factorization(x)
        for prime, cnt in factor:
            if used_prime[prime]:
                break
            used_prime[prime] = True
        else:
            continue
        break
    else:
        print('pairwise coprime')
        exit()

    gcd_num = a[0]
    for x in a[1:]:
        gcd_num = math.gcd(gcd_num, x)
    print('setwise coprime' if gcd_num == 1 else 'not coprime')

if __name__ == '__main__':
    Main()

Measured memory_bytes: 133476
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

const ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

void solve() {
	int N, K; cin >> N >> K;
	if (K == 0) {
		cout << N*N << endl;
		return;
	}
	int res = 0;
	for (int b = K+1; b <= N; ++b) {
		int cnt = N / b;
		res += cnt*(b - K);
		res += max(0LL, N%b - K + 1);
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define REP(i,n) for(i=0;i<n;i++)
const int K=1024,N=331;
int B[]={1,2,4,8,16,32,64,128,256,512},C[K]={0},D[K][N]={0};
int init(){
    int i,tmp,tmp2,n,dp,i2,j,k;
    REP(i,K){
        REP(j,N)D[i][j]=0;
        tmp=i,tmp2=0,n=0;
        while(tmp){
            n+=tmp&1;
            tmp2++;
            tmp/=2;
        }
        C[i]=n;
        if(n==1)D[i][std::find(B,B+10,i)-B]=1;
        else{
            tmp=i;
            REP(j,tmp2){
                if(tmp&1){
                    dp=n*j,i2=i-B[j];
                    REP(k,N-dp)D[i][k+dp]+=D[i2][k];
                }
                tmp/=2;
            }
        }
    }
    return 0;
}
int main(){
    init();
    int n,s,i,x;
    while(1){
        std::cin>>n>>s;
        if(std::cin.eof())break;
        x=0;
        if(s<N)
            REP(i,K)if(C[i]==n)x+=D[i][s];
        std::cout<<x<<'\n';
    }
}

Measured memory_bytes: 2488
#include<stdio.h>

int main(void){
  int num, i, count=0, count_M=0;
  char Word[11];
  scanf("%s", &Word);
  for(num=0; Word[num]!=NULL; num++) {
      if(Word[num] == 'A' ||Word[num] == 'C' || 
         Word[num] == 'G' ||Word[num] == 'T') count++;
      else {
        if(count_M < count) { 
	    	count_M = count;
        }        
      	count = 0;
      }
  }
  if(count_M < count){
    count_M = count;
  }
  printf("%d",count_M);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
    long int sx, sy, tx,ty,i,j,sumx,sumy;
    scanf("%ld %ld %ld %ld",&sx,&sy,&tx,&ty);
    sumx = tx - sx;
    sumy = ty - sy;
    for(i = 0 ;i<sumy;i++)
    {
        printf("U");
    }
      for(i = 0 ;i<sumx;i++)
    {
        printf("R");
    }
    for(i = 0 ;i<sumy;i++)
    {
        printf("D");
    }
    for(i = 0 ;i<sumx;i++)
    {
        printf("L");
    }
    printf("L");
    for(i = 0 ;i<=sumy;i++)
    {
        printf("U");
    }
      for(i = 0 ;i<=sumx;i++)
    {
        printf("R");
    }
    printf("DR");
     for(i = 0 ;i<=sumy;i++)
    {
        printf("D");
    }
    for(i = 0 ;i<=sumx;i++)
    {
        printf("L");
    }
    printf("U");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

long long inputValuelong(){
    long long a;
    cin >> a;
    return a;
}

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    long long N;
    N = inputValuelong();
    long long i;
    long long seki = N;
    
    for(i=int(sqrt(N));i>0;i--){
        if(seki%i==0){
            seki = seki/i;
            break;
        }
    }
    long long sum = (seki-1) + (i-1);
    cout << sum << endl;
    return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    int c[50][26] = {};

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

        for (int j = 0; j < s.size(); ++j) {
            ++c[i][s[j] - 'a'];
        }
    }

    int count[26];
    for (int i = 0; i < 26; ++i) {
        count[i] = INF;
    }

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 26; ++j) {
            count[j] = min(count[j], c[i][j]);
        }
    }

    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < count[i]; ++j) {
            cout << (char)('a' + i);
        }
    }

    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (register int i = a; i <= b; i++)

using namespace std;

const int N = 1010;

void savecode() {

}

struct node {
    int i, j, d;
    node (int i, int j, int d) : i(i), j(j), d(d) {}
};

int m, n;
char mp[N][N];
queue<node> q;
int ans;

void bfs() {
    while(!q.empty()) {
        node now = q.front(); q.pop();
        ans = max(ans, now.d);
        int dd = now.d + 1;
        int i = now.i, j = now.j;
        if (i > 1 && mp[i - 1][j] == '.') mp[i - 1][j] = '#', q.push({i - 1, j, dd});
        if (i < m && mp[i + 1][j] == '.') mp[i + 1][j] = '#', q.push({i + 1, j, dd});
        if (j > 1 && mp[i][j - 1] == '.') mp[i][j - 1] = '#', q.push({i, j - 1, dd});
        if (j < n && mp[i][j + 1] == '.') mp[i][j + 1] = '#', q.push({i, j + 1, dd});
    }
}

int main() {
    scanf("%d%d", &m, &n);
    getchar();
    rep(i, 1, m) {
        rep(j, 1, n) {
            scanf("%c", &mp[i][j]);
            if (mp[i][j] == '#') q.push({i, j, 0});
        }
        getchar();
    }
    bfs();
    cout << ans;
}


Measured memory_bytes: 13328
def main():
    N = input()
    
    a_s =list(map(int, input().split()))

    ai_to_a_num = {}
    for ai in a_s:
        if ai in ai_to_a_num.keys():
            ai_to_a_num[ai] += 1
        else:
            ai_to_a_num[ai] = 1
    
    max_num = 0
    for ai in ai_to_a_num.keys():
        num = 0
        num += ai_to_a_num[ai]
        if ai-1 in ai_to_a_num.keys():
            num += ai_to_a_num[ai-1]
        if ai+1 in ai_to_a_num.keys():
            num += ai_to_a_num[ai+1]
        max_num = max(max_num, num)
    
    print(max_num)

main()


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

using namespace std;

int main(void){
  int N;
  cin >> N;
  string ans;
  if(N == 0) ans.push_back('0');
  while(N != 0){
    if(abs(N) % 2 == 1){
      ans.push_back('1');
      N--;
    }else{
      ans.push_back('0');
    }
    N /= 2;
    N *= -1;
  }
  for(int i = ans.length() - 1; i >= 0; i--) cout << ans[i];
  cout << endl;
  return 0;
}


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

int main(int argc, char const* argv[])
{
    std::string str_in;
    std::cin >> str_in;

    int count = 0;

    for(auto c: str_in)
    {
        if(c == '1')
        {
            count ++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

int W, H, N;

char field[50][50];
bool seen[50][50];
int cost[50][50];

//s ... start, g ... goal
int bfs(pair<int,int> s, pair<int,int> g){
  //探索済リストを初期化
  memset(seen, false, sizeof(seen));
  seen[s.fi][s.se] = true;
  cost[s.fi][s.se] = 0;

  //幅優先探索用のque (時間と座標のペア)
  queue<pair<int,int>> q;
  q.push(s);

  while(!q.empty()) {
    auto now = q.front(); q.pop();
    if (now == g) {
      return cost[now.fi][now.se];
    }
    REP(k,4) {
      auto next = now;
      next.fi += dy[k];
      next.se += dx[k];
      if (next.fi<0 || next.fi>=H || next.se<0 || next.se>=W) continue;
      if (field[next.fi][next.se] == '#' || seen[next.fi][next.se]) continue;
      cost[next.fi][next.se] = cost[now.fi][now.se] + 1;
      seen[next.fi][next.se] = true;
      q.push(next);
    }
  }
  return NIL;
}

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

  cin >> H >> W;

  int num_black = 0;
  REP(i,H) {
    REP(j,W) {
      char c;
      cin >> c;
      field[i][j] = c;
      if (c=='#') num_black++;
    }
  }

  int cost = bfs(make_pair(0,0), make_pair(H-1,W-1));

  if (cost != NIL) {
    cout << H*W-num_black-cost-1 << endl;
  }
  else {
    cout << "-1" << endl;
  }

  return 0;
}


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

// 計算量 : O(n)
int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int ans = 0;
  // max(x, y) 個だけ「ABピザ2枚セット」を購入すると、
  // x,y ともにノルマが満たされる
  for (int i = 0; i <= max(x, y); i++) {
    int amount = (c*2 * i) + (a * max(0, x-i)) + (b * max(0, y-i));
    if (ans == 0) {
      ans = amount;
    } else {
      ans = min(ans, amount);
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
import java.util.ArrayDeque;
import java.util.Scanner;

class Pos{
	int h, w;
	public Pos(int _h, int _w) {
		h = _h; w = _w;
	}
}
class Main{
	static int[] dx = {0, 0, -1, 1};
	static int[] dy = {-1, 1, 0, 0};
	public static void main(String args[]){
		Scanner sc=new Scanner(System.in);
		int H = sc.nextInt(), W = sc.nextInt();
		char[][] map = new char[H][W];
		for(int i = 0; i < H; i++) {
			String S = sc.next();
			for(int j = 0; j < W; j++) map[i][j] = S.charAt(j);
		}
		boolean check = true;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				if(map[i][j] == '.') continue;
				ArrayDeque<Pos> que = new ArrayDeque<Pos>();
				int cnt = 0;
				que.add(new Pos(i, j));
				map[i][j] = '.';
				while(!que.isEmpty()) {
					Pos now = que.poll();
					cnt++;
					for(int k = 0; k < 4; k++) {
						if(now.h + dx[k] < 0 || now.w + dy[k] < 0 || now.h + dx[k] >= H || now.w + dy[k] >= W) continue;
						if(map[now.h + dx[k]][now.w + dy[k]] == '#') {
							map[now.h + dx[k]][now.w + dy[k]] = '.';
							que.add(new Pos(now.h + dx[k], now.w + dy[k]));
						}
					}
				}
				if(cnt == 1) check = false;
			}
		}
		System.out.println(check ? "Yes" : "No");
	}
}

Measured memory_bytes: 23380
#include<stdio.h>
int main(void)
{
	int x,y;
	
	while(1)   {
		scanf("%d",&x);
		scanf("%d",&y);
		if(x==0&&y==0) {
				break;
		}
		if(x<y) {
			printf("%d %d\n",x,y);
		}
		else if(x>y) {
			printf("%d %d\n",y,x);
		}
		else if(x==y) {
			printf("%d %d\n",x,y);
		}
	}
	return 0;
}


Measured memory_bytes: 2100
N, K = [int(n) for n in input().split()]
M = N*(N - 1)//2

if K > M - N + 1:
    print(-1)
else:
    print(M - K)
    for i in range(1, N):
        print(str(N) + " " + str(i))
    C = M - K - N + 1
    C_ = 0
    for i in range(1, N - 1):
        for j in range(i + 1, N):
            C_ += 1
            if C_ <= C:
                print(str(i) + " " + str(j))


Measured memory_bytes: 3336
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))

B = [[A[i], i] for i in range(n)]
B.sort(reverse=True)

DP = [[0] * (n+1) for i in range(n)]

DP[0][0] = B[0][0] * B[0][1]
DP[0][1] = B[0][0] * (n-1-B[0][1])


for i in range(1, n):
    ind = B[i][1]
    for j in range(i+2):
        if j-1 >= 0:
            DP[i][j] = DP[i-1][j-1] + B[i][0] * abs(n-1-(j-1)-ind)
        # print(i,j,ind, i+1-j, ind-(i+1-j))
        DP[i][j] = max(DP[i][j], DP[i-1][j] + B[i][0] * abs(ind-(i-1+1-j)))
# print(DP)
print(max(DP[-1]))

Measured memory_bytes: 106224
n = int(input())
t, a = list(map(int, input().split()))
h = list(map(int, input().split()))

min_diff_temp = 999
out_i = 0
for i, x in enumerate(h):
    diff_temp = abs(a - (t - x * 0.006))
    if diff_temp < min_diff_temp:
        min_diff_temp = diff_temp
        out_i = i + 1

print(out_i)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int dp[100050];
int main(){
  memset(dp,0,sizeof(dp));
  int N;
  cin >> N;
  vector<int> h(N+1);
  for(int i=1; i<=N; i++){
    cin >> h[i];
  }
  dp[1] = 0;
  dp[2] = abs(h[2]-h[1]);
  for(int i=3; i<=N; i++){
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[N] << endl;
  return 0;
}


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

typedef long long ll;

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

    int N;
    double T, A;
    cin >> N >> T >> A;

    double min = 10000;
    int ans = 0;

    for(int i = 0; i < N; i++) {
        double H;
        cin >> H;

        double x = T - H * 0.006;

        if(abs(x - A) < min) {
            min = abs(x - A);
            ans = i + 1;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

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

using namespace std;

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

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


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

	int cnt = 0;
	int len = Z;

	while ( 1 )
	{
		if ( len + Y > X - Z )
		{
			break;
		}
		len += Y + Z;
		cnt++;
	}

	cout << cnt << endl;

	return ( 0 );
}


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

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

    ll N;
    cin>>N;
    vector<ll> ans(N);
    ll a;
    rep(i,N-1){
        cin>>a;
        ++ans[a-1];
    }

    rep(i,N){
        cout<<ans[i]<<"\n";
    }

	return 0;
}

Measured memory_bytes: 4784
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a=0, b=0, c=0, ans = 0, n, ret = 0, m, d;
	string s,t;
	char tmp;
	cin >> s >> t;
	rep(i, s.size()) {
		//cout << s << endl;
		if (s == t) {
			cout << "Yes\n";
			return 0;
		}
		else {
			tmp = s[s.size() - 1];
			repr(i, s.size() - 1) s[i + 1] = s[i];
			s[0] = tmp;
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <numeric>
#include <algorithm>
#include <math.h>

using namespace std;

int H, W;
char S[50][50];

bool draw(int y, int x){
    if( 0 < x && S[y][x-1] == '#' )     return true;
    if( 0 < y && S[y-1][x] == '#' )     return true;
    if( x < W-1 && S[y][x+1] == '#' )   return true;
    if( y < H-1 && S[y+1][x] == '#' )   return true;
    
    return false;
}

int main(){
    cin >> H >> W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)    cin >> S[i][j];
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if( S[i][j] == '#' && !draw(i, j) ){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 100010
#define ll long long
using namespace std;
int n,m;
ll delta[N],f[N];
ll ton[N];
int top;
void work(ll x,ll y)
{
    if(!x) return;
    int pos=upper_bound(ton+1,ton+1+top,x)-ton-1;
    if(!pos)
	{
		delta[1]+=y;
		delta[x+1]-=y;
	}
    else
	{
		f[pos]+=x/ton[pos]*y;
		work(x%ton[pos],y);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	ton[++top]=n;
	for(int i=1;i<=m;i++)
	{
		ll a;
		scanf("%lld",&a);
		while(a<=ton[top]) top--;
		ton[++top]=a;
	}
	f[top]=1;
	for(int i=top;i>=2;i--)
	{
		f[i-1]+=ton[i]/ton[i-1]*f[i];
		work(ton[i]%ton[i-1],f[i]);
	}
	delta[1]+=f[1];
	delta[ton[1]+1]-=f[1];
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		ans+=delta[i];
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int N;
  int A[100];
  int i;
  int flag=0;

  
  cin >> N;
  for(i=0;i<N;i++){
    cin >> A[i];
  }
  for(i=0;i<N;i++){
    if(A[i]%2==0){
      if(A[i]%3==0){
      }else if(A[i]%5==0){
      }else{
        flag=1;
      }
    }
  }
  if(flag==0){
    cout << "APPROVED";
  }else{
    cout << "DENIED";
  }
}



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

int main(){
  ll N,sum=0;
  cin >> N;
  if(N<15){
    for(int i=1;i<=N;++i){
      if(i%3&&i%5&&i%15){
        sum += i;
      }
    }
  }else{
    ll x = N/15;
    ll y = N%15;
    rep(i,x){
      sum += 60 + 120 * i;
    }
    for(int i=N-y;i<=N;++i){
      if(i%3&&i%5&&i%15){
        sum += i;
      }
    }
  }
  cout << sum << endl;
}


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

template<class T> inline int sgn(T x){return (x>0)-(x<0);}

int main() {
  int x, y, ans; cin >> x >> y;

  if (sgn(x) == sgn(y)) {
    if (x <= y) ans = y - x;
    else ans = 2 + x - y;
  }
  else ans = 1 + abs(abs(y) - abs(x));
  
  if (x == 0) ans = ((sgn(y) == 1) ? y : abs(y) + 1);
  if (y == 0) ans = ((sgn(x) == 1) ? x + 1 : abs(x));
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N, x = map(int, input().split())
    if 2 <= x < 2*N-1:
        print("Yes")
        ans = [0] * (N*2-1)
        for i in range(1, N):
            if i == x:
                ans[i*(-1)**i+N-1] = N
            else:
                ans[i*(-1)**i+N-1] = i
        for i in range(1, N):
            if N*2-i == x:
                ans[i*(-1)**(i+1)+N-1] = N
            else:
                ans[i*(-1)**(i+1)+N-1] = N*2-i
        ans[N-1] = x
        for i in range(0, N*2-1):
            print(ans[i])
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 49244
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	static int MAX = 1000;
	static int VMAX = 10000;
	
	static int s;
	static int[] A = new int[MAX];
	static int[] B = new int[MAX];
	static int[] T = new int[VMAX + 1];
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		s = VMAX;
		for (int i=0; i<n; i++){
			A[i] = sc.nextInt();
			s = Math.min(s, A[i]);
		}
		int ans = solve(n);
		System.out.println(ans);
	}
	
	static int solve(int n){
		int ans = 0;
		
		int[] V = new int[MAX];
		for(int i=0; i<n; i++){
			B[i] = A[i];
			V[i] = 1;
		}
		Arrays.sort(B, 0, n);
		for(int i=0; i<n; i++) T[B[i]] = i;
		for(int i=0; i<n; i++){
			if (V[i] == 0) continue;
			int cur = i;
			int S = 0;
			int  m = VMAX;
			int an = 0;
			for (;;) {
				V[cur] = 0;
				an++;
				int v = A[cur];
				m = Math.min(m,v);
				S += v;
				cur = T[v];
				if (V[cur] == 0) break;
			}
			ans += Math.min(S + (an - 2) * m, m + S + (an + 1) * s);
		}
		return ans;
	}
}


Measured memory_bytes: 30060
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>
#define N 100020
using namespace std;

int f[N];
vector<pair<int, int> > k;
bool u[N];

int GetUFS(int x)
{
    int i, t;

    for(i = x; f[i] > -1; i = f[i])
        ;
    while(x != i)
    {
        t = f[x];
        f[x] = i;
        x = t;
    }

    return i;
}

void MergeUFS(int u, int v)
{
    u = GetUFS(u);
    v = GetUFS(v);
    if(u != v)
    {
        if(f[u] > f[v])
            swap(u, v);
        f[u] += f[v];
        f[v] = u;
    }

    return;
}

int main(void)
{
    int n, q, u, v, w;
    long long m;
    int i, c, d;

    scanf("%d %lld %d", &n, &m, &q);
    for(i = 0; i < n; i ++)
        f[i] = -1;
    while(q --)
    {
        scanf("%d %d %d", &u, &v, &w);
        if(!w)
            MergeUFS(u, v);
        else
            k.push_back(make_pair(u, v));
    }

    for(i = c = 0; i < n; i ++)
        if(f[i] < 0)
        {
            c ++;
            m -= -f[i] - 1;
        }
    if(m < 0)
    {
        printf("No\n");

        return 0;
    }

    for(i = d = 0; i < (signed)k.size(); i ++)
        if(GetUFS(k.at(i).first) == GetUFS(k.at(i).second))
        {
            printf("No\n");

            return 0;
        }
        else
        {
            d += !::u[GetUFS(k.at(i).first)];
            d += !::u[GetUFS(k.at(i).second)];
            ::u[k.at(i).first] = ::u[k.at(i).second] = true;
        }

    m -= d;
    if(m < 0)
    {
        printf("No\n");

        return 0;
    }

    m -= (long long)c * (c - 1) / 2 - d;
    printf("%s\n", m <= 0 ? "Yes" : "No");

    return 0;
}


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

int main(){
  int q;cin>>q;
  vector<int> p(2e5,1);
  p[0]=0,p[1]=0;
  for(int i=2;i<2e5;i++){
    if(p[i]){
      for(int j=i*2;j<2e5;j+=i)p[j]=0;
    }
  }
  vector<int> vec(2e5);
  rep(i,2e5){
    if(p[i]&&p[(i+1)/2])vec[i]=1;
  }
  vector<int> sum(2e5+1);
  rep(i,2e5)sum[i+1]=sum[i]+vec[i];
  rep(i,q){
    int l,r;cin>>l>>r;
    cout<<sum[r+1]-sum[l]<<endl;
  }
}

Measured memory_bytes: 5620