akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int aa[1000010][50];
vector<long long> v;
vector<int> vv;

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

    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<long long> sum(n + 1);
    sum[0] = 0;
    for (int i = 0; i < n; i++)
    {
        sum[i + 1] = sum[i] + a[i];
    }
    for (int i = 0; i <= n; i++)
    {
        for (int j = i + 1; j <= n; j++)
        {
            v.push_back(sum[j] - sum[i]);
        }
    }
    for (int i = 0; i < v.size(); i++)
    {
        for (int j = 0; (long long)((long long)1 << (long long)j) <= v[i]; j++)
        {
            if (v[i] & ((long long)1 << (long long)j))
                aa[i][j] = 1;
        }
    }
    for (int i = 0; i <= (n * (n + 1)) / 2; i++)
        vv.push_back(i);
    for (int i = 42; i >= 0; i--)
    {
        int cnt = 0;
        vector<int> l;
        for (int j = 0; j < v.size(); j++)
        {
            if (aa[j][i] == 1)
            {
                cnt++;
                l.push_back(j);
            }
        }
        if (cnt >= k)
        {
            for (int j = 0; j < v.size(); j++)
            {
                if (aa[j][i] == 0)
                {
                    for (int jj = 0; jj < 50; jj++)
                        aa[j][jj] = 0;
                }
            }
            vv = l;
        }
    }
    long long ans = v[vv[0]];
    for (int i = 0; i < k; i++)
    {
        ans &= v[vv[i]];
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int n;

	cin >> n;
	if (n >= 65 && n <= 90) {
		cout << "1" << endl;
	} else if(n >= 97 && n <= 122) {
		cout << "2" << endl;
	} else {
		cout << "0" << endl;
	}

	return 0;
}


Measured memory_bytes: 3108
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	int n, k;
	int r, s, p, flags = 0, flagp =0, flagr = 0;
	ll cnt = 0;
	map <char,int> mp1;
	map <int,int> fl;
	string s1;
	re(n,k,r,s,p,s1);
	s1 = " "+s1;
	for(int i = 1; i<=k; i++)
	{
		mp1[s1[i]]++;
		if(s1[i]=='s')
		{
			flags = 1;
		}
		else if(s1[i]=='p')
		{
			flagp = 1;
		}
		else
		{
			flagr = 1;
		}
		fl[i] = 1;
	}
	for(int i = k+1; i<=n; i++)
	{
		if(s1[i]=='s')
		{
			if(s1[i-k]!='s') mp1[s1[i]]++, fl[i] = 1;
			else
			{
				if(fl[i-k] && s1[i-k]=='s')
				{
					fl[i] = 0;
				}
				else
				{
					mp1[s1[i]]++, fl[i] = 1;
				}
			} 
		}
		else if(s1[i]=='p')
		{
			if(s1[i-k]!='p') mp1[s1[i]]++, fl[i] = 1;
			else
			{
				if(fl[i-k] && s1[i-k] == 'p')
				{
					fl[i] = 0;
				}
				else
				{
					mp1[s1[i]]++, fl[i] = 1;
				}
			} 
		}
		else
		{
			if(s1[i-k]!='r') mp1[s1[i]]++, fl[i] = 1;
			else
			{
				if(fl[i-k] && s1[i-k] == 'r')
				{
					fl[i] = 0;
				}
				else
				{
					mp1[s1[i]]++, fl[i] = 1;
				}
			}
		}
	}
	for(auto i:mp1)
	{
		if(i.fst == 'r')
		{
			cnt += p*i.snd;
			//out<<"r "<<i.snd<<"\n";
		}
		else if(i.fst == 's')
		{
			cnt += r*i.snd;
			//cout<<"s "<<i.snd<<"\n";
		}
		else
		{
			cnt += s*i.snd;
			//cout<<"p "<<i.snd<<"\n";
		}
	}
	cout  << cnt << "\n";
}


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

int main(){
  int x,n;
  cin>>x>>n;
  vector<int> d(102);
  rep(i,n){
    int p;
    cin>>p;
    d[p]=1;
  }
  P ans(99999,-1);
  rep(i,102){
    if(d[i]==1)continue;
    int dif=abs(x-i);
    ans=min(ans,P(dif,i));
  }
  cout<<ans.second<<endl;

  return 0;
}

Measured memory_bytes: 3552
//##MohK
//16/2/2020 .....3,55
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll n,d,x,sum=1,res=0;
    cin>>n>>d>>x;
    ll h[n];
    vector<int>v;
    for(ll i=0;i<n;i++){
        cin>>h[i];
        sum=ceil((double)d/h[i]);
        v.push_back(sum);
        sum=1;
    }
    for(ll i=0;i<v.size();i++){
       res+=v[i];
    }
    cout<<res+x<<endl;


   return 0;
}





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

int main(){
	int n;
	cin >> n;
	int a[2][n];
	for(int j=0; j<n; ++j){
		cin >> a[0][j];
	}
	for(int j=0; j<n; ++j){
		cin >> a[1][j];
	}
	int candy=0;
	for(int j=0; j<n; ++j){
		int sum=0;
		for(int i=0; i<=j; ++i){
			sum += a[0][i];
		}
		for(int i=j; i<n; ++i){
			sum += a[1][i];
		}
		if(sum>=candy) candy=sum;
	}

	cout << candy << endl;
	
	return 0;
}

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

using namespace std;

int main() {
    int n, i, t;
    vector<int> a;
    unordered_map<int, int> mp;

    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> t;
        a.push_back(t);
        mp[t]++;
    }
    int ans = 0;
    sort(a.begin(), a.end());
    for (i = n - 1; i >= 0; i--) {
        if (mp[a[i]] == 0) continue;
        for (long pt = pow(2,31); pt >= 1; pt /= 2) {
            if (a[i] <= pt) {
                if (mp.find(pt - a[i]) == mp.end() || mp[pt - a[i]] == 0) {
                    continue;
                }
                mp[pt - a[i]]--;
                if (mp[a[i]] == 0) {
                    mp[pt - a[i]]++;
                    continue;
                }
                // cout << a[i] << " " << pt - a[i] << endl;
                mp[a[i]]--;
                ans++;
            }
        }
    }
    cout << ans;



    return 0;
}

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

int main(void){
    string ans,s;
    cin >> s;
	if (s == "Sunny"){
		ans = "Cloudy";
	}
	if (s == "Cloudy"){
		ans = "Rainy";
	}
	if (s == "Rainy"){
		ans = "Sunny";
	}
	cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    rep(i, 3) if (n[i] == '1') ans++;

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


Measured memory_bytes: 3592
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

# array and variables are all 0 indexed
class UnionFind
	def initialize(n)
		@parent = Array.new(n){|i| i}
		@rank = Array.new(n){1}
	end
	def find(x)
		par = @parent[x]
		if(par == x)
			return x
		else
			return @parent[x] = find(par)
		end
	end
	def union(x,y)
		root_x = find(x)
		root_y = find(y)
		if(root_x == root_y)
			#ok
			return
		end
		if(@rank[root_x] < @rank[root_y])
			@parent[root_x] = root_y
		elsif(@rank[root_x] == @rank[root_y])
			@parent[root_y] = root_x
			@rank[root_x] += 1
		else
			@parent[root_y] = root_x
		end
	end
	def same_root?(x,y)
		return find(x)==find(y)
	end
end

# e : no directed edges
# n : the number of edges
def kruskal(es,n)
	u = UnionFind.new(n)
	sum = 0
	es.sort{|e1,e2| e1[2] <=> e2[2]}.each{|e|
		if(u.find(e[0]) != u.find(e[1]))
			sum += e[2]
			u.union(e[0],e[1])
		end
	}
	sum
end

N,_=gets.chomp.split(' ').map{|n| n.to_i}
X = Array.new(N){}
Y = Array.new(N){}
0.upto(N-1){|d|
	X[d],Y[d]=gets.chomp.split(' ').map{|n| n.to_i}
}
E = []
xsort = X.each_with_index.sort
for i in 0..(N-2) do
	dist = (xsort[i][0]-xsort[i+1][0]).abs
	E << [xsort[i][1], xsort[i+1][1],dist]
end
ysort = Y.each_with_index.sort
for i in 0..(N-2) do
	dist = (ysort[i][0]-ysort[i+1][0]).abs
	E << [ysort[i][1], ysort[i+1][1],dist]
end
puts kruskal(E,N)

Measured memory_bytes: 30440
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <typename T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

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

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

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+" << endl;

    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    string w; cin>>w;
    int n=w.size();
    map<char,int> mp;

    rep(i,0,n){
        mp[w[i]]++;
    }

    for(auto mi:mp){
        int cnt=mi.second;
        if(cnt%2){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}   

Measured memory_bytes: 256
A = input()
A = A[::-1]
divide = [i[::-1] for i  in ["dream", "dreamer", "erase", "eraser"]]

flag = 1
while flag and A:
  flag = 0
  for word in divide:
    if A.startswith(word):
      A = A[len(word):]
      flag = 1

if len(A) == 0:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 9244
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

fn main() {
   input! {
      n: usize,
      a: i64,
      mut x: [i64; n]
   }
   for i in 0..n {
      x[i] -= a;
   }
   let mut dp = BTreeMap::new();
   dp.insert(0i64, 1usize);
   for i in 0..n {
      let mut dp2 = dp.clone();
      for (&k, &v) in dp.iter() {
         dp2.entry(k + x[i]).and_modify(|x| *x += v).or_insert(v);
      }
      dp = dp2;
   }
   let ans = dp.get(&0).unwrap() - 1;
   println!("{}", ans);
}


Measured memory_bytes: 2232
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
    int m,f,r;
    while(1){
        cin>>m>>f>>r;
        if(m==-1 && f==-1 && r==-1)break;

        if(m==-1 ||f==-1){cout<<'F'<<endl;}
        else {
            if (m + f >= 80) { cout << 'A' << endl;
            }else if (m + f < 80 && m + f >= 65) { cout << 'B' << endl; 
            }else if (m + f < 65 && m + f >= 50) { cout << 'C' << endl; 
            }else if (m + f < 50 && m + f >= 30) {
                if (r < 50) { cout << 'D' << endl; }
                else if (r >= 50) { cout << 'C' << endl; }
            }else if (m + f < 30) { cout << 'F' << endl; }
        }
    }
    return 0;
}


Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = 0 ;count = 0 ;pro = 1


n,m=map(int,input().split())
AB=[tuple(map(int,input().split())) for i in range(n)]
AB.sort(key=lambda tup:tup[0])
i=0
while count<m:
    ans+=min(m-count,AB[i][1])*AB[i][0]
    count += min(m-count, AB[i][1])
    i+=1
print(ans)
    



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

int main() {
  ll n, T;
  cin >> n >> T;
  vector<ll> t(n), dt(n-1);
  rep(i, n) cin >> t[i];
  rep(i, n-1) dt[i] = t[i+1] - t[i];
  ll ans = 0, start = t[0];
  for (int i = 0; i < n-1; i++) {
    ans += min(T, dt[i]);
  }
  ans += T;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	var sum float64
	for i := 0; i < N; i++ {
		var a float64
		fmt.Scan(&a)
		sum += 1 / a
	}
	fmt.Println(1 / sum)
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    int n, m, k;
    cin >> n >> m >> k;
    reps(i, n) reps(j, m) {
        if (k == i * (m - j) + j * (n - i)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int gcd(int x, int y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}

int main() {
 int n,x; cin>>n>>x;
  int p[n]={0};
  rep(i, n)cin>>p[i];
  
  int gcdb=1000000001;
  rep(i, n){if(i==0)gcdb=abs(x-p[i]);
            gcdb=gcd(gcdb,abs(x-p[i]));
                     }
  cout<<gcdb<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int bitSwap(int num, int p) {
    int t = (num >> p) & 1;
    num -= (t << p);
    int e = (num >> (p + 1)) & 1;
    num -= (e << (p + 1));
    return num + (t << (p + 1)) + (e << p);
}

int main () {
    int n, m;
    cin >> n >> m;
    int num = 0;
    REP (i, 0, n) {
        int bit;
        cin >> bit;
        num = (num << 1) + bit;
    }
    int s0 = 0, s1 = 0;
    REP (i, 0, m) {
        int p;
        cin >> p;
        REP (j, 0, p) {
            s0 = (s0 << 1) + (i % 2);
            s1 = (s1 << 1) + !(i % 2);
        }
    }
    int size = 1 << n;
    const int inf = 1 << 30;
    vector<int> dp(size, inf);
    dp[s0] = dp[s1] = 0;
    bool run = true;
    while (run) {
        run = false;
        REP (i, 0, size) {
            if (dp[i] == inf) continue;
            REP (j, 0, n - 1) {
                int t = bitSwap(i, j);
                if (dp[t] > dp[i] + 1) {
                    dp[t] = dp[i] + 1;
                    run = true;
                }
            }
        }
    }
    cout << dp[num] << endl;
    return 0;
}

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

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    long s = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (a[i] > i) {
            cout << -1;
            return 0;
        }
        if (i < n - 1 && a[i] == a[i + 1] - 1) {
            continue;
        } else if (i < n - 1 && a[i] < a[i + 1] - 1) {
            cout << -1;
            return 0;
        } else {
            s += a[i];
        }
    }
    cout << s;
 
    return 0;
}

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

int main() {
  int H,W;
  while(1){
    cin >> H >> W;
    if(H==0 && W==0)
      break;
    for(int i=1; i<=H; i++){
      for(int j=1; j<=W; j++){
        if(i%2==0 && j%2==0 || i%2==1 && j%2==1){
          cout << '#';
        }
        else{
          cout << '.';
        }
      }
      cout << endl;
    }
    cout << endl;
  }
}



Measured memory_bytes: 3116
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
using namespace std;
 
typedef long long ll;

int main(){
	ll n;
    ll max,dif;
    cin >> n;
    max = ceil( (-1+ sqrtl(1+8*n))/2);
    dif = max*(max+1)/2 -n;
    for(int i=1;i<=max;i++){
    	if(i!=dif) cout << i << endl;
    }
	
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	string s = in<string>();
	int y = stoi(s.substr(0, 4)), m = stoi(s.substr(5, 2)), d = stoi(s.substr(8, 2));
	if (y < 2019 || y == 2019 && m < 4 || y == 2019 && m == 4 && d <= 30)cout << "Heisei";
	else cout << "TBD" << endl;
}

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

using namespace std;

int main() {
   int n;
   string s;
   cin >> n >> s;
   
   if (n % 2 != 0) {
      cout << "No" << '\n';
   }
   else {
      bool flag = true;
      int mid = n / 2;
      string s1(s.begin(), s.begin() + mid);
      string s2(s.begin() + mid, s.end());
      
      for (int i = 0; i < (int) s1.length(); i++) {
         if (s1[i] != s2[i]) {
            flag = false;
            break;
         }
      }
      if (flag) {
         cout << "Yes";
      }
      else {
         cout << "No";
      }
      cout << '\n';
   }
   
   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    
    public static void main (String... args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        
        int count = 0;
        for (int i=0; i<n; i++) {
            int a = Integer.parseInt(scanner.nextLine());
            
            if (isPrime(a)) {
                count++;
            }
        }
        System.out.println(count + "");
    }
    
    private static boolean isPrime(int a) {
        if (a == 2) {
            return true;
        } else if (a < 2 || a%2 == 0) {
            return false;
        } else {
            for (int i = 3; i <= Math.sqrt(a); i = i + 2) {
                if (a % i == 0) {
                    return false;
                }
            }
            return true;
        }
    }
}



Measured memory_bytes: 58436
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());

        if( n == 1 ){
            System.out.println(1);
            return;
        }

        if( n % 2 == 0 ){
            System.out.println( 0.5 );
        }
        else {
            int oddCount = n/2+1;
            System.out.println( (double)oddCount/n );
        }

    }
}


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

int n, A[50];

//入力値の M から選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i+1, m) || solve(i+1, m-A[i]);
    return res;
}

int main() {
    int q, M, i;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }

    return 0;
}


Measured memory_bytes: 3164
#include <cstdio>
double x1,x2,x3,x4,y1,y2,y3,y4;
int main()
{
	while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) == 8) {
		if (x1 > x4 || x2 < x3 || y1 > y4 || y2 < y3) puts("NO");
		else puts("YES");
	}
	return 0;
}

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

using namespace std;

bool check(string &str)
{
    for(int i=0;i<str.size();i++)
    {
       if(i%2==0)
       {
           if(str[i]=='L')
                return false;
       }
       else
       {
           if(str[i]=='R')
                return false;
       }
    }
    return true;
}
int main(int argc,char *argv[])
{
    string s;
    while(cin>>s)
    {
        if(check(s))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}


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

int dp[11][331][1025];

int solve(int n,int s,int used){
	if(n == 0 && s == 0) return 1;
	if(n <= 0 || s < 0) return 0;
	if(dp[n][s][used] != -1) return dp[n][s][used];

	int sum = 0;
	for(int i=0;i<10;i++){
		if((used>>i) % 2 == 0){
			used += 1<<i;
			sum += solve(n-1, s-i*n, used);
			used -= 1<<i;
		}
	}

	return dp[n][s][used] = sum;
}

int main(void){
	int n,s;

	memset(dp,-1,sizeof(dp));

	while(cin>>n>>s){
		if(0 <= s && s <= 330){
			int used = 0;
			cout<<solve(n,s,used)<<endl;
		}
		else{
			cout<<0<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    S = input()
    res = 0
    num = 0
    for i in range(len(S)):
        if S[i] == 'W':
            res += num
        else:
            num += 1
    print(res)
if __name__ == '__main__':
  main()


Measured memory_bytes: 5916
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m, k;
	int ans;

	fgets(str, 100, stdin);
	sscanf(str, "%d %d", &n, &m);

	printf("%d\n", n + m/2);

	return 0;
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;

public class Main {
  private static long M = 1_000_000_007;
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    Map<Key, Long> memo = new HashMap<>();
    System.out.println(dfs(new Key(N, new char[]{'T', 'T', 'T'}), memo));
  }

  private static long dfs(Key key, Map<Key, Long> memo) {
    if (memo.containsKey(key)) return memo.get(key);
    if (key.d == 0) return 1;
    long res = 0;
    for (char c : new char[]{'A', 'G', 'C', 'T'}) {
      if (c == 'C') {
        if (key.last[1] == 'A' && key.last[2] == 'G') continue;
        if (key.last[1] == 'G' && key.last[2] == 'A') continue;
        if (key.last[0] == 'A' && key.last[1] == 'G') continue;
        if (key.last[0] == 'A' && key.last[2] == 'G') continue;
      }
      if (key.last[1] == 'A' && key.last[2] == 'C' && c == 'G') continue;
      res += dfs(new Key(key.d - 1, new char[]{key.last[1], key.last[2], c}), memo);
      res %= M;
    }
    memo.put(key, res);
    return res;
  }

  private static class Key {
    private final int d;
    private final char[] last;

    private Key(int d, char[] last) {
      this.d = d;
      this.last = last;
    }

    @Override public boolean equals(Object o) {
      if (this == o) return true;
      if (o == null || getClass() != o.getClass()) return false;
      Key key = (Key) o;
      return d == key.d &&
          Arrays.equals(last, key.last);
    }

    @Override public int hashCode() {
      int result = Objects.hash(d);
      result = 31 * result + Arrays.hashCode(last);
      return result;
    }
  }
}

Measured memory_bytes: 25556
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define lo long long
using namespace std;
int n,m,x,vis[li],vis2[li];
string s;
int main(){
	scanf("%d %d",&n,&m);
	int hata=0,gg=0;
	for(int i=1;i<=m;i++){
		cin>>x>>s;
		if(vis[x]==1) continue;
		if(s[0]=='W') {hata++;vis2[x]++;}
		if(s[0]=='A') {vis[x]=1;gg++;}
	}
	for(int i=1;i<=n;i++){
		if(vis[i]==0) hata-=vis2[i];
	}
	printf("%d %d\n",gg,hata);
	return 0;
}




Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<deque>

#define INF 1e8

using namespace std;

long long int K;

int main(void) {
    cin>>K;
    vector<int> d(K,INF);
    vector<bool> used(K,0);
    d[1] = 1;
    deque<int> q;
    q.push_front(1);

    while(!q.empty()) {
        int current = q.front();
        q.pop_front();
        if(used[current]) continue;
        used[current] = 1;
        int next = (current+1) % K;
        if(d[next] > d[current] + 1) {
            d[next] = d[current] + 1;
            q.push_back(next);
        }

        next = (current*10) % K;
        if(d[next] > d[current]) {
            d[next] = d[current];
            q.push_front(next);
        }
    }

    cout<<d[0]<<endl;

    return 0;
}


Measured memory_bytes: 896
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

string S, T;
vector<vector<int>> dp(3010, vector<int>(3010, 0));

int main(void){
	cin >> S >> T;
	int sl = S.size(), tl = T.size();
	for(int i = 1; i <= sl; i++){
		for(int j = 1; j <= tl; j++){
			if(S[i-1] == T[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}

	string ans = "";
	while(sl > 0 && tl > 0){
		if(dp[sl][tl] == dp[sl-1][tl]){
			sl--;
			continue;
		}
		if(dp[sl][tl] == dp[sl][tl-1]){
			tl--;
			continue;
		}
		ans += S[sl-1];
		sl--, tl--;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


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

namespace TYC
{
	const int N = 5005 * 3;

	int n, A[N], B[N];
	char S[N], T[N];	

	inline int calc(const char c)
	{
		int ac = 0, bc = 0, ans = 0x3f3f3f3f;
		for (int i = 1; i < n; i++)
			if (S[i] == c && S[i + 1] != c)
				A[++ac] = i;
		for (int i = 1; i <= n; i++)
			B[++bc] = 0;
		for (int i = 1; i < n; i++)
			if (T[i] == c && T[i + 1] != c)
				B[++bc] = i;
		for (int i = 1; i <= n; i++)
			B[++bc] = n;
		for (int i = 1; i + ac - 1 <= bc; i++)
		{
			int v = 0;
			for (int j = 1; j <= ac; j++)
				v += abs(A[j] - B[i + j - 1]);
			for (int j = 1; j < i; j++)
				v += B[j];
			for (int j = i + ac; j <= bc; j++)
				v += n - B[j];
			ans = min(ans, v);
		}
		return ans;
	}

	void work()
	{
		scanf("%d%s%s", &n, S + 1, T + 1);
		if (n <= 2)
		{
			int ans = 0;
			for (int i = 1; i <= n; i++)
				ans += S[i] != T[i];
			printf("%d\n", ans);
		}
		else
			printf("%d\n", calc('0') + calc('1'));
	}
}

int main()
{
	TYC::work();
	return 0;
}

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

using namespace std;

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

  int n; 
  cin >> n;
  vector<int> A(n);
  for (auto &a : A) cin >> a;
  int res = 0, diff;
  for (int i = 0; i < n; ++i) 
    for (int j = i+1; j < n; ++j) {
      diff = abs(A[i]-A[j]);
      if (diff > res) res = diff;
    }
  cout << res << endl;


  return 0;
}



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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;
struct Corr {
    int y;
    int x;
    int depth;
};

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:
int h, w;
int y, x, depth;
int s_y, s_x, g_y, g_x;
int ans = 0;
vector<string> vec;
queue<Corr> q;

vector<int> y_vec = {0, 0, -1, +1};
vector<int> x_vec = {-1, +1, 0, 0};

//Prototype Declarations:
int gcd(int, int);
int bfs();

//================ Main Loop ================
int main() {
    cin >> h >> w;
    vec.resize(h);
    rep(i, h) cin >> vec[i];
    for(s_y = 0; s_y < h; s_y++) {
        for(s_x = 0; s_x < w; s_x++) {
            if(vec[s_y][s_x] == '#') continue;
            for(g_y = 0; g_y < h; g_y++) {
                for(g_x = 0; g_x < w; g_x++) {
                    if(vec[g_y][g_x] == '#') continue;
                    Corr start = {s_y, s_x, 0};
                    queue<Corr> empty;

                    //dbg
                    //cout << q.empty() << " ";

                    swap(q, empty);
                    q.emplace(start);

                    //reset (x -> .)
                    rep(i, h) {
                        rep(j, w) {
                            if(vec[i][j] == 'x') vec[i][j] = '.';
                        }
                    }

                    int tmp = bfs();

                    //dbg
                    //cout << "(" << s_x << ", " << s_y << ") -> (" << g_x << ", " << g_y << ")   ";
                    //cout << tmp << endl;

                    if(tmp > ans) ans = tmp;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int bfs() {
    while(!q.empty()) {
        Corr now = q.front();
        q.pop();
        y = now.y, x = now.x, depth = now.depth;

        if(y == g_y && x == g_x) return depth;

        for(ll i = 0; i < 4; ++i) {
            Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
            if(0 <= next.y && next.y <= h - 1 && 0 <= next.x && next.x <= w - 1 && vec[next.y][next.x] == '.') {
                vec[next.y][next.x] = 'x';
                q.push(next);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
// uno {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
 
void RI() {}
 
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
 
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }
 
template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}
 
#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);
 
template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
 
template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
 
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}
 
string S;
LL K;
void input() {
    cin >> S >> K;
}
 
void solve() {
    LL ans1 = 0, ans2 = 0;
    int n = S.length();
    
    if(S == string(n, S[0])) {
        printf("%lld\n", K*n/2);
    } else {
        REP(i, n-1) {
            if(S[i%n] == S[(i+1) % n]) {
                ans1++;
                i++;
            }
        }
        REP(i, 2*n-1) {
            if(S[i%n] == S[(i+1) % n]) {
                ans2++;
                i++;
            }
        }
        printf("%lld\n", ans1*K + (ans2-2*ans1)*(K-1));
    }
}
 
int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iostream>
#include <utility>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
 
using namespace std;
using ll = long long;
using ld = long double;
using Vl = vector<ll>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
using vs = vector<string>;

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)

ll N,K;
string S;
int main(){
  cin>>N>>K>>S;
//   cout << K << endl;
//   cout << S << endl;
  ll changing = 0; 
  char lastLR = 'a'; 
  REP(i,N){ 
    changing += lastLR != S[i]; 
    lastLR = S[i]; 
  } 
  changing = max(ll(1),changing - K*2); 
  cout<<N-changing<<endl;
  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
int n,w;
long long wei[200005], v[200005], dp[200005];
long long best=0,sum;

inline long long maks(long long a, long long b){
	return a>b?a:b;
}
inline long long mini(long long a, long long b){
	return a<b?a:b;
}

int main(){

	scanf("%d %d", &n, &w);
	for(int i=0;i<n;i++){
		scanf("%lld %lld", &wei[i], &v[i]);
		sum += v[i];
	}
	for(int i=1;i<=sum*2;i++){
		dp[i]=w+10;
	}
	for(int j=0;j<n;j++){
		for(int i=sum;i>=0;i--){
				dp[i+v[j]]=mini(dp[i+v[j]], dp[i]+wei[j]);
				if(dp[i+v[j]]<=w)best=maks(best, i+v[j]);
		}
	}
	printf("%lld\n", best);
}


Measured memory_bytes: 3712
<?php
$str = "0".trim(fgets(STDIN));
$l = strlen($str);
$dp0 = array_fill(0, $l+1, 0);//超えてないやつ
$dp1 = array_fill(0, $l+1, 0);//超えたやつ
for($i = 0; $i < $l; $i++){
    $dp0[$i+1] = min($dp0[$i]+$str[$i], $dp1[$i]+10-$str[$i]);
    $dp1[$i+1] = min($dp0[$i]+$str[$i]+1, $dp1[$i] + 9 -  $str[$i]);
}
echo $dp0[$i],"\n";


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

int main() {
  int N;
  cin >> N;
  int sum = 0;
    
  for(int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    sum += r - l + 1;
  }
  cout << sum << endl;
}
    

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 1e5 + 55;

int n;
ll cnt[maxN];

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

	cin >> n;

	for(int i = 1; i <= n; i++){
		int ai;	cin >> ai;	ai++;
		cnt[ai]++;
	}
	
	ll fRes = 0;
	for(int i = 1; i + 1 < maxN; i++){
		fRes = max(fRes, cnt[i - 1] + cnt[i] + cnt[i + 1]);
	}

	cout << fRes << '\n';
	return 0;
}

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

using namespace std;

const int inf = 1000000000; // 10^9

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for(int i = 0; i < N; i++)
        cin >> X[i];
    int ans = inf;
    for(int i = 1; i <= 100; i++) {
        int cost = 0;
        for(int j = 0; j < N; j++)
            cost += (X[j] - i) * (X[j] - i);
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
 }

Measured memory_bytes: 3628
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd

N,P=map(int,input().split())
S=input()

if P in [2,5]:
    count=0
    for i in range(N):
        if int(S[i])%P==0:
            count+=i+1
    print(count)
    exit()
S=list(S)
S.reverse()
nlst=[0,int(S[0])%P]
for i in range(1,N):
    nlst.append((nlst[i]+int(S[i])*pow(10,i,P))%P)

count=0
for i,n in Counter(nlst).most_common():
    count+=n*(n-1)//2

print(count)


Measured memory_bytes: 86636
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String t = sc.next();
		
		// 計算
		long result = 0;
		int n = t.length();
		char pre = ' ';
		for(int i = 0; i < n; i++){
		    if(t.charAt(i) == 'D' || t.charAt(i) == '?'){
		        System.out.print('D');
		    }else{
		        System.out.print('P');
		    }
		}
		
		
		// 出力
		//System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    string s;
    cin >> s;
    if (s == "SUN")
        cout << 7 << "\n";
    else if (s == "MON")
        cout << 6 << "\n";
    else if (s == "TUE")
        cout << 5 << "\n";
    else if (s == "WED")
        cout << 4 << "\n";
    else if (s == "THU")
        cout << 3 << "\n";
    else if (s == "FRI")
        cout << 2 << "\n";
    else if (s == "SAT")
        cout << 1 << "\n";
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const double Pi=acos(-1.0);
const int mod=200003,G=2,N=4000010;
struct CP{
	CP (double xx=0,double yy=0){x=xx,y=yy;}
	double x,y;
	CP operator + (CP const &B) const
	{return CP(x+B.x,y+B.y);}
	CP operator - (CP const &B) const
	{return CP(x-B.x,y-B.y);}
	CP operator * (CP const &B) const
	{return CP(x*B.x-y*B.y,x*B.y+y*B.x);}
};
int tr[N];
void fft(CP *f,int n,int flag){
	for(int i=0;i<n;++i)
		if(i<tr[i]) swap(f[i],f[tr[i]]);
	for(int p=2;p<=n;p<<=1){
		int len=p>>1;
		CP tg(cos(2*Pi/p),sin(2*Pi/p));
		if(flag==-1) tg.y*=-1;
		for(int k=0;k<n;k+=p){
			CP buf(1,0),tt;
			for(int l=k;l<k+len;++l)
				tt=buf*f[l+len],
				f[l+len]=f[l]-tt,
				f[l]=f[l]+tt,
				buf=buf*tg;
		}
	}
	if(flag==-1){
		for(int i=0;i<n;++i)
			f[i].x/=n;
	}
} 
CP f[N];
int Lg[N],a[N],g[N];
int ksm(int b,int n){
	int res=1;
	while(n){
		if(n&1) res=res*b%mod;
		b=b*b%mod; n>>=1;
	}
	return res;
}
void init(){
	int x=1;
	for(int i=0;i<mod-1;++i)
		g[i]=x,Lg[x]=i,x=x*G%mod;
	//for(int i=0;i<mod-1;++i)
	//	cout<<g[i]<<" ";cout<<endl;
	//cout<<"egerdf\n";
}
signed main(){
//	freopen("2.out","w",stdout);
	init();
	int n,x;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i])f[Lg[a[i]]].x++;
	}
	int limit=1;
	while(limit<=((mod-1)<<1)) limit<<=1;
	//cout<<limit<<endl;
	for(int i=0;i<limit;++i)
		tr[i]=(tr[i>>1]>>1)|(i&1?limit>>1:0);
	//cout<<"segrtryhaw\n";
	fft(f,limit,1);
	for(int i=0;i<limit;++i)
		f[i]=f[i]*f[i];
	fft(f,limit,-1);
	//for(int i=0;i<limit;++i)cout<<f[i].x<<" ";cout<<endl;
	//cout<<"wegrtjrtsfh\n";
	for(int i=1;i<=n;++i)
		if(a[i])f[Lg[a[i]]+Lg[a[i]]].x--;
	int ans=0;
	//cout<<"fgrerttdfbdfgb\n";
	for(int i=0;i<limit;++i)
		ans+=(long long)(f[i].x/2+1e-1)*g[i%(mod-1)];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 75264
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _

        ll n; cin >> n;
        cout<<(n*(n-1))/2<<endl;




return 0;
}



Measured memory_bytes: 3584