akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define endl "\n"
#define lln long long int
#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
    IOS;
    int n;
    cin >> n;
    for(int i=1;i<10;i++){
        if(n/i < 10 && !(n - (n/i)*i)){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fr(i, a, b) for(int i=a; i>=b; i--)
#define l long int
#define endl '\n'
#define pb push_back
#define pf pop.front()
using namespace std;


void solve()
{
int n;
cin>>n;

int d[n][2];

for(int i=0;i<n;i++)
cin>>d[i][0]>>d[i][1];


for(int i=0;i<n;i++)
{
	int j=2,y=0;
	if(d[i][0] == d[i][1])
	{
		while(j)
		{
		if(i+j>=n)
		{
		y=0;
		break;
		}
			
		if(d[i+j][0] == d[i+j][1])
		{
			y=1;
		}
		else
		{
		y=0;
		break;
		}
		j--;
		}
			
	}
	if(y){
		cout<<"Yes"<<endl;
		return;
	}

}
cout<<"No"<<endl;
}


int32_t main()
{
FAST
l T=1;
//cin>>T;
while(T--)
{
solve();
}
}










Measured memory_bytes: 3644
from collections import defaultdict

N = int(input())
S = [input() for _ in range(N)]
M = int(input())
T = [input() for _ in range(M)]

d = defaultdict(int)
d2 = defaultdict(int)
for k in S:
    d[k] += 1
    d2[k] = 0

for k in d2:
    d2[k] = S.count(k) - T.count(k)

d2 = sorted(d2.items(), key=lambda x: x[1], reverse=True)

print(d2[0][1] if d2[0][1] >= 0 else 0)

Measured memory_bytes: 3316
require 'set'

class Digraph
	def add_node(property = {})
		Node.new(property)
	end

	def add_edge(u, v, property = {})
		e = Edge.new(u, v, property)
		u.add_out_edge(e)
		v.add_in_edge(e)
		e
	end
	
	def del_edge(e)
		u, v = e.from, e.to
		u.out_edges.delete(e)
		v.in_edges.delete(e)
		e
	end

	class Node
		def initialize(property)
			@property = property
			@out_edges = Set.new
			@in_edges = Set.new
		end

		def to_s
			@property[:index]
		end

		def add_out_edge(e)
			@out_edges << e
		end

		def del_out_edge(e)
			@out_edges.delete(e)
		end

		def add_in_edge(e)
			@in_edges << e
		end

		def del_in_edge(e)
			@in_edges.delete(e)
		end

		attr_reader :property, :in_edges, :out_edges
	end

	class Edge
		def initialize(u, v, property)
			@from = u	
			@to = v
			@property = property
		end

		def length
			@property[:length] || 1
		end

		attr_reader :from, :to
	end
end

def min_assign(cost_mat)
	n = cost_mat.size
	g = Digraph.new
	s = g.add_node({:index => "s"})
	t = g.add_node({:index => "t"})
	l_nodes = (0..n-1).map{|i| g.add_node({:index => i}) }
	l_nodes.each {|v| g.add_edge(s, v, {:length => 0}) }
	r_nodes = (0..n-1).map{|i| g.add_node({:index => i})}
	r_nodes.each {|v| g.add_edge(v, t, {:length => 0}) }
	(0..n-1).each{|i|
		(0..n-1).each{|j|
			g.add_edge(l_nodes[i], r_nodes[j], {:length => cost_mat[i][j]})
		}
	}

	potential = Hash.new(0)
	n.times {
		queue = l_nodes + r_nodes + [s, t]
		dist = Hash.new(Float::INFINITY)
		dist[s] = 0
		path_edge = {}

		until queue.empty?
			u = queue.min_by{|v| dist[v]}
			queue.delete(u)	 
			u.out_edges.each{|e|
				d = dist[u] + e.length - (potential[e.to] - potential[e.from])
				v = e.to
				if d < dist[v] 
					dist[v] = d
					path_edge[v] = e
				end
			}	
		end

		u = t
		while e = path_edge[u]
			g.del_edge(e)
			g.add_edge(e.to, e.from, {:length => -e.length})
			u = e.from
		end

		dist.each_key{|v| potential[v] += dist[v]}
	}

	l_nodes.map{|u|
		u.in_edges.to_a[0].from.property[:index]
	}
end

n = gets.to_i
write_cost = (1..n).map{gets.split.map &:to_i}
erase_cost = (1..n).map{gets.split.map &:to_i}
written = (1..n).map{gets.chomp.each_char.map{|c| c == ?o ? 1 : 0}}

cleanup_cost = (0..n-1).map{|i|
	(0..n-1).map{|j| erase_cost[i][j] * written[i][j]}.inject(:+)
}

select_cost = (1..n).map{[]}
(0..n-1).each{|i|
	(0..n-1).each{|j|
		select_cost[i][j] = cleanup_cost[i]
		if written[i][j] == 1
			select_cost[i][j] -= erase_cost[i][j]
		else
			select_cost[i][j] += write_cost[i][j]
		end
	}
}

assign = min_assign(select_cost)

min_cost = 0
operation = []
(0..n-1).each{|i|
	(0..n-1).each{|j|
		if written[i][j] == 1
			if assign[i] == j
				min_cost += select_cost[i][j]	
			else
				operation << "#{i+1} #{j+1} erase"
			end
		else
			if assign[i] == j
				min_cost += select_cost[i][j]	
				operation << "#{i+1} #{j+1} write"
			else
			end
		end
	}
}

p min_cost
p operation.size
puts operation

Measured memory_bytes: 15416
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;
const int maxn=2e5+10;

ll n,k;
ll a[maxn];

ll check(int x){
	ll sum=0;
	for(int i=0;i<n;i++){
		sum+=(a[i]-1)/x;
	}
	return sum;
}

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	int low=1,high=inf;
	while(low<high){
		int mid=(low+high)>>1;
		if(check(mid)>k)
			low=mid+1;
		else
			high=mid; 
	}
	printf("%d\n",high);
	return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[] memo = new int[n];
                memo[0] = int.Parse(Console.ReadLine());

                int sum = memo[0];
                int max = memo[0];

                for (int i = 1; i < n; i++)
                {
                    memo[i] = int.Parse(Console.ReadLine());

                    sum = Math.Max(sum + memo[i], memo[i]);
                    max = Math.Max(max, sum);
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9344
#include <iostream>
using namespace std;
int main(){
	int N,count=0;
	cin>>N;
	int a[N];
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(i==0 || i==1)continue;
		else if(i==2){
			if(a[2]==a[1] && a[1]==a[0]){
				a[1]=0;
				count++;
			}else if(a[1]==a[0]){
				a[0]=0;
				count++;
			}
		}else{
			if(a[i]==a[i-1] && a[i-1]==a[i-2]){
				a[i-1]=0;
				count++;
			}else if(a[i-1]==a[i-2]){
				a[i-2]=0;
				count++;
			}
		}
	}
	if(N==2){
		if(a[0]==a[1])count=1;
	}else{
		if(a[N-1]==a[N-2]){
			count++;
		}
	}
	cout<<count<<endl;
	return 0;
} 

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    ll n,k;
    std::cin >> n>>k;
    if(k%2==0){
        std::cout << ll(pow(n/(k/2)-n/(k/1),3)+pow(n/(k/1),3)) << std::endl;
    }
    else{
        std::cout << ll(pow(n/(k/1),3)) << std::endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

// UVa 11504

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		String a = in.next();
		String b = in.next();
		String c = in.next();
		
		System.out.printf("%c%c%c\n", a.charAt(0), b.charAt(0), c.charAt(0));
	}
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)
#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;
    cin >>N;

    vector<int> B(N-1);
    rep(i,N-1) cin >> B[i];
    
    //-----------------------------------
    ll ans=B[0]+B[N-2];
    rep(i,N-2){
        ans+=min(B[i],B[i+1]);
    }


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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int Len = 55;
int head[Len];
struct node
{
	int to,next;
}edge[Len << 1];
int dfn[Len],low[Len],n,m,x,y,cnt = 1,num,ans;
bool bridge[Len << 1];
void add(int x,int y)
{
	edge[++ cnt].to = y;
	edge[cnt].next = head[x];
	head[x] = cnt;
}
void Tarjan(int root,int fa)
{
	dfn[root] = low[root] = ++ num;
	for(int i = head[root] ; i ; i = edge[i].next)
	{
		int to = edge[i].to;
		if(!dfn[to])
		{
			Tarjan(to,i);
			low[root] = min(low[root],low[to]);
			if(low[to] > dfn[root]) bridge[i] = bridge[i ^ 1] = true;
		}
		else if(i != (fa ^ 1))
			low[root] = min(low[root],dfn[to]);
	}
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i = 1; i <= m ; i ++)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i = 1; i <= n; i ++) if(!dfn[i]) Tarjan(i,0);
	for(int i = 2; i < cnt; i += 2) if(bridge[i]) ans ++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n,m;
    cin>>n>>m;
    int a[n];
    double total=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        total+=a[i];
    }
    total=total/4/m;
    int ans=0;
    for(int i=0;i<n;i++){
        if(a[i]>=total)
        ans++;
    }
    if(ans>=m)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
def factorize(n):
    fact = dict()
    k = n
    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if k % i == 0:
            c = 0
            while k % i == 0:
                c += 1
                k //= i
            fact[i] = c
    if k != 1:
        fact[k] = 1
    if not fact:
        fact[n] = 1
    return fact


def main():
    n = int(input())
    if n == 1:
        print(0)
        return
    c = sum([[i for _ in range(i + 1)] for i in range(9)], [])
    print(sum(c[f] for f in factorize(n).values()))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  string S; cin>>S;
  rep(i,S.length()){
    if(i%2==0){
      if(S[i]!='h'){
        cout<<"No\n";
        return 0;
      }
    }else{
      if(S[i]!='i'){
        cout<<"No\n";
        return 0;
      }
    }
  }
  if(S.length()%2) cout<<"No\n";
  else cout<<"Yes\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main()
{
  int i;	
  string a,b;	
  cin>>a; 
  for(i=0;i<a.size();i++)
    if(a[i]=='0'||a[i]=='1') 
	  b+=a[i]; 
    else
      if(b.size()>0) 
        b.erase(b.size()-1,1);
  cout<<b<<endl; 
  return 0; 
}

Measured memory_bytes: 256
#4x3x10の配列を作りすべての要素を０にする
count = [[[0 for i in range(10)]for j in range(3)]for k in range(4)]

n = int(input())

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

for i in range(4):
    for j in range(3):
        for k in range(10):
            print("",count[i][j][k],end="")
        print()
    if i < 3:
        print("####################")



Measured memory_bytes: 5636
n,m = map(int,input().split())
arr = [ [] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

flg = [-1 for i in range(n)]

ima = [0]
tugi = []

while len(ima) > 0:
    for i in ima:
        for j in arr[i]:
            if flg[j] == -1:
                tugi.append(j)
                flg[j] = i+1

    ima = tugi
    tugi = []
print("Yes")
for i in flg[1:]:
    print(i)

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> ans;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        for (int j = 0; j < x; ++j) {
            ans.emplace_back(i + 1);
        }
    }
    for (int i = 0; i < h; ++i) {
        vector<int> now;
        for (int j = 0; j < w; ++j) {
            now.emplace_back(ans[i * w + j]);
        }
        if (i % 2 == 1) reverse(now.begin(), now.end());
        for (int k : now) {
            cout << k << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<double> v(N);
    for (auto& i : v) cin >> i;
    for (int i = 0; i < N - 1; i++) {
        sort(v.begin(), v.end(), greater<double>());
        *(v.end() - 2) = (*(v.end() - 2) + *(v.end() - 1)) / 2.0;
        v.pop_back();
    }
    cout << v[0] << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <utility>

using std::pair;
typedef long long ll;
typedef pair<int,ll> pil;
const int N = 110;
int _w;

ll n;
pil a[N];
int m;

void solve() {
	int p = 0;
	ll s = 1;
	for( int i = 1; i <= m; ++i ) {
		s += a[i].second;
		if( s <= n ) p = i;
	}
	s = 0;
	for( int i = 0; i <= p; ++i ) s += a[i].second;
	++p;
	for( int i = m+1; i > p; --i ) a[i] = a[i-1];
	a[p] = pil(++m, s);
	n -= s;
}

int main() {
	_w = scanf( "%lld", &n );
	a[0] = pil(0, 1);
	while(n) solve();
	printf( "%d\n", m*2 );
	for( int i = 1; i <= m; ++i )
		printf( "%d ", a[i].first );
	for( int i = 1; i <= m; ++i )
		printf( "%d ", i );
	puts("");
	return 0;
}


Measured memory_bytes: 128
from collections import deque
n = int(input())
a = list(map(int,input().split()))

d = deque()
for i in range(n):
    if i % 2 == 0:
        d.append(a[i])
    else:
        d.appendleft(a[i])
d = list(d)
if n % 2 == 1:
    d.reverse()
print(*d)

Measured memory_bytes: 25536
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <functional>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);

    int cnt = 0;
    ll sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        if(a[i] < 0)cnt++;
        sum += abs(a[i]);
    }

    if(cnt % 2 == 0)cout << sum << endl;
    else{
        ll m = -1e10;
        ll p = 1e10;

        for(int i = 0;i < n;i++){
            if(a[i] < 0)m = max(m,a[i]);
            else p = min(p,a[i]);
        }

        cout << max(sum+2*m,sum-2*p) << endl;
    }
}


Measured memory_bytes: 1024
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int d,n;  cin >> d >> n;
  if(n == 100){
    cout << (int)pow(100,d)*(n+1);
  }else{
    cout << (int)pow(100,d)*n;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

struct P{
  ll sum,l,r;
  bool operator < (const P &a) const {
    return sum > a.sum;
  }
};
vector<P> v;

int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) {
    ll a,b;
    cin >> a >> b;
    v.eb((P){a+b,a,b});
  }
  sort(ALL(v));

  ll suma = 0, sumb = 0;
  REP (i,n) {
    if (i&1) sumb += v[i].r;
    else suma += v[i].l;
  }
  cout << suma-sumb << endl;
}


Measured memory_bytes: 4980
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,i,j;
    cin>>a>>b;
    if((b&1)||((a*4)<b)) cout<<"No"<<endl;
    else
    {
        if(b%4==0)c=b/4;
        else c=c+1;
        i=b/2;
        if(a>=c&&a<=i)
        {
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
}


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

int main()
{
  string s; cin >> s;
  int q; cin >> q;
  deque<char> dq;
  for (auto c:s) dq.push_back(c);
  int st = 0;
  rep(i, q) {
    int t; cin >> t;
    if (t == 1) {
      st ^= 1;
    } else {
      int f; cin >> f;
      char c; cin >> c;
      if (f == 1) {
        if (st) dq.push_back(c);
        else dq.push_front(c);
      } else {
        if (st) dq.push_front(c);
        else dq.push_back(c);
      }
    }
  }
  if (st) {
    reverse(dq.begin(), dq.end());
  }
  for (auto c:dq) cout << c;
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
n = int(input())
*a, = sorted(map(int, input().split()))
a_max = a[n-1]
dp = [True] * a_max
ans = 0
recent = 0

if n == 1:
    print(1)
    exit()

for i in a:
    if recent == i:
        ans -= 1
        recent = 0
    if dp[i-1] == False:
        continue
    else:
        for j in range(i, a_max+1, i):
            dp[j-1] = False
        ans += 1
        recent = i

print(ans)

Measured memory_bytes: 32220
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,k,m[110];
int dp[110][5][2];
signed main(){
  string s;cin>>s;int k;cin>>k;
  rep(i,s.length()){
    m[i] = (int)(s[i] - '0');
  }
  n = s.length();
  rep(i,110)rep(j,5)rep(l,2)dp[i][j][l] = 0;
  dp[0][0][0] = 1;
  rep(i,n+1){
    rep(j,k+1){
      dp[i+1][j][0] += dp[i][j][0]*(int)(m[i] == 0);
      dp[i+1][j+1][0] += dp[i][j][0]*(m[i] != 0);
      
      dp[i+1][j][1] += dp[i][j][0]*(m[i] > 0);
      dp[i+1][j+1][1] += dp[i][j][0]*max(0LL,(m[i]-1));
      dp[i+1][j][1] += dp[i][j][1];
      dp[i+1][j+1][1] += dp[i][j][1] * 9;      
    }
  }

  cout << dp[n][k][0] + dp[n][k][1] << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  set<string> s;
  string temp;
  for(int i = 0; i < n; ++i){
    cin >> temp;
    s.insert(temp);
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 19228
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
from heapq import heapify,heappush,heappop
n,m=n1()
A=n1()
BC=t3(m)

heapify(A)
BC.sort(key=lambda x:-x[1])

D=[]
for b,c in BC:
    D.extend([c]*b)
    if len(D)>=n:
        break
D=D[:n]


for d in D:
    a=heappop(A)
    if a>=d:
        heappush(A,a)
        break;
    else:
        heappush(A,d)

print(sum(A))

Measured memory_bytes: 25372
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;

double dot(P x,P y){return real(conj(x)*y);}

double cross(P x,P y){return imag(conj(x)*y);}

bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

int main(){
  int n;
  double x1[110],y1[110],x2[110],y2[110];
  L l[110];
  vector<P> v;

  while(cin >> n,n){
    for(int i=0;i<n;i++){
      cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      l[i] = L(P(x1[i],y1[i]),P(x2[i],y2[i]));
    }

    int ans = 1;
    for(int i=0;i<n;i++){
      v.clear();
      for(int j=0;j<i;j++){
	if(!para(l[i],l[j])){
	  P tmp = line_cp(l[i],l[j]);
	  if(-100.0<tmp.real() && tmp.real()<100.0 &&
	     -100.0<tmp.imag() && tmp.imag()<100.0)v.push_back(tmp);
	}
      }

      for(int j=0;j<(int)v.size();j++){
	for(int k=j+1;k<(int)v.size();k++){
	  if(EQ(v[j],v[k])){
	    v.erase(v.begin()+k);
	    k--;
	  }
	}
      }
      ans += v.size() + 1;
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,s,ans=0;
	cin>>k>>s;
	for(int i=0;i<=k;++i)
		for(int j=0;j<=k;++j)
			if(s-i-j>=0 && s-i-j<=k)
				++ans;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n, k = gets.split.map{|v|
  v.to_i
}

if k == 0 then
  p n * n
  exit
end

ans = 0
for b in (k+1)..n
  ans += (n / b) * (b - k) + [0, (n % b) - k + 1].max
end
p ans


Measured memory_bytes: 1788
n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
    if a[i] in d:
        d[a[i]] += 1
    else:
        d[a[i]] = 1
total = 0
for i in d.values():
    total += i*(i-1)//2
for i in range(n):
    diff = d[a[i]]*(d[a[i]]-1)//2 - (d[a[i]]-1)*(d[a[i]]-2)//2
    print(total - diff)


Measured memory_bytes: 24748
N,K = map(int,input().split())
A = list(map(int,input().split()))

# 全要素を列挙する　O(N^2) = 10 ** 6 (1000 * 999 // 2)
beauty = []
for i in range(N):
  cur = 0
  for j in range(i, N):
    cur += A[j]
    beauty.append(cur)

keta = len(bin(max(beauty))[2:])

for i in range(len(beauty)):
  beauty[i] = bin(beauty[i])[2:].zfill(keta)
  
# 入力例1の全要素
# 0010
# 0111
# 1001
# 1110
# 0101
# 0111
# 1100
# 0010
# 0111
# 0101
# ある桁のビットに1がK個以上あれば、その桁は1にできる
# 最大値が大きいほど良いので、頭の桁から貪欲に候補を選んでいけばよい。

ans = 0
for k in range(keta):
  # 0桁目から順に見る
  # その桁でK個以上の"1"を得ることができるのであれば、全て候補となる。
  # その桁が0のデータは候補からすべて除外してよい。
  # 同時に、その桁の美しさを答えに加算する (2 ** (keta - k - 1))
  # その桁にK個以上の"1"が存在しない場合は候補を絞る必要がないので何もしない10
  # 計算量は、要素数が10**6、桁数がlog(10 ** 9 * 10 ** 3) = 40
  # なので10 ** 7未満
  temp = []
  cnt = 0
  for j in range(len(beauty)):
    if beauty[j][k] == "1":
      temp += [beauty[j]]
      cnt += 1
  if cnt >= K:
    beauty = temp
    ans += 2 ** (keta - k - 1)

print(ans)


Measured memory_bytes: 51460
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll =long long;
#define mINF -1000000000000000

int main()
{
    int N;cin>> N;
    vector<ll> A(N+1);
    for (int i=0;i<N;i++) cin >> A[i];
    ll dp[N+1][3][2];
    for (int i=0;i<N+1;i++)
        for (int j=0;j<3;j++) 
            for (int k=0;k<2;k++) dp[i][j][k]=mINF;
    dp[0][1][0]=0;
    dp[0][1][1]=0;
    for (int i=1;i<N+1;i++)
    {
        if ((i-1)%2==0)
        {
        dp[i][0][0]=max(dp[i-1][0][1],dp[i-1][0][0]);
        dp[i][1][0]=max(dp[i-1][1][0],dp[i-1][1][1]);
        dp[i][1][1]=dp[i-1][0][0]+A[i-1];
        dp[i][2][0]=dp[i-1][2][1];
        dp[i][2][1]=dp[i-1][1][0]+A[i-1];
        }
        else
        {
        dp[i][0][0]=max(dp[i-1][1][1],dp[i-1][1][0]);
        dp[i][0][1]=dp[i-1][0][0]+A[i-1];
        dp[i][1][0]=max(dp[i-1][2][0],dp[i-1][2][1]);
        dp[i][1][1]=dp[i-1][1][0]+A[i-1];
        dp[i][2][1]=dp[i-1][2][0]+A[i-1];
        }
    }
    cout << max(dp[N][1][0],dp[N][1][1]) << endl;
return 0;

}

Measured memory_bytes: 14024
/*************************************************************************
    > File Name: newC.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/7/1 20:49:53
 ************************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
const int maxn = 1e5+5;
int v[maxn];
int m;
int cost[maxn];
vector<int>pos[maxn];
int n;
int calc(int x, int y){
    if(y >= x)return y-x;
    return y-x+m;
}
ll solve(int x){
    ll ret = 0;
    rep(i,2,n){
        ret += min(1+calc(x,v[i]),calc(v[i-1],v[i]));
    }
    return ret;
}
int cnt[maxn];
bool in(int pr, int nw, int v){
    if(pr <= nw)return v>=pr && v<=nw;
    else return v >= pr || v <=nw;
}
int out[maxn];
int main(){
#ifdef HandsomeHow
    freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
#endif
    gn(n);gn(m);
    rep(i,1,n){ gn(v[i]); }
    if(m <= 5){
        ll ans = solve(1);
        rep(i,1,m){
            ll cc = solve(i);
            if(cc<ans)ans=cc;
        }
        cout<<ans<<endl;
        return 0;
    }
    rep(i,1,n-1){
        int cc = calc(v[i],v[i+1]);
        if(cc>1){
            cnt[v[i]]++;
            out[v[i+1]]++;
            cost[i+1]=cc;
            pos[v[i+1]].pb(i+1);
        }
    }
    out[0]=out[m];
    cnt[0]=cnt[m];
    ll ans = solve(1);
    rep(i,2,5){ ll cc = solve(i); if(cc < ans)ans = cc; }
    int tot = 0;
    rep(i,2,n)if(1+calc(1,v[i]) < calc(v[i-1],v[i])){ tot++; }
    dbg(tot);
    ll nowcalc = solve(1);
    dbg(nowcalc);
    rep(i,2,m){
        tot -= out[i-1];
        tot += cnt[i-2];
        for(auto it:pos[i-1]){
            nowcalc += cost[it];
            nowcalc--;
        }
        nowcalc -= tot;
        //printf("%d %d %d\n",i,tot,nowcalc);
        if(nowcalc<ans)ans=nowcalc;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 6528
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;
constexpr double EPS = 1e-10;
#pragma endregion

void solve() {
    int h, w;
    cin >> h >> w;
    vector<int> cnt(26);
    for (int i=0; i<h; i++) {
        string s;
        cin >> s;
        for (char c : s) {
            cnt.at(c-'a')++;
        }
    }
    bool odd = false;
    int cnt2 = 0, cnt4 = 0;
    for (int i=0; i<26; i++) {
        if (cnt.at(i)%2 != 0) {
            if (odd) {
                cout << "No" << "\n";
                return;
            } else {
                odd = true;
                cnt.at(i)--;
            }
        }
        if (cnt.at(i)%4 == 0) {
            cnt4++;
        } else if (cnt.at(i)%2 == 0) {
            cnt2++;
        }
    }
    if (h%2 != 0 && w%2 != 0) {
        if (odd && cnt2 <= h/2 + w/2) cout << "Yes" << "\n";
        else cout << "No" << "\n";
    } else if (h%2 == 0 && w%2 == 0) {
        if (odd || cnt2 > 0) cout << "No" << "\n";
        else cout << "Yes" << "\n";
    } else {
        int tmp = (h%2 == 0) ? h/2 : w/2;
        if (odd || cnt2 > tmp) cout << "No" << "\n";
        else cout << "Yes" << "\n";
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22)
	{
		cout<<"bust";
	} 
	else
	{
		cout<<"win";
	 } 
	return 0;	
}

Measured memory_bytes: 256
s = [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 = int(input())

ans = s[k - 1]
print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll n; cin >> n;
  ll sum = 0;
  rep(i, n) {
    ll a; cin >> a;
    sum += a - 1;
  }
  outl(sum);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
ll a, b, c;
cin >> a >> b>> c;
if (c <= a+b)cout << "Yes"; else cout << "No";
    return 0;
}

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

int main()
{
  string S;

  cin >> S;

  char a = S.at(S.length() - 1);

  if (a == '2' || a == '4' || a == '5' || a == '7' || a == '9')
  {
    cout << "hon" << endl;
  }
  else if (a == '0' || a == '1' || a == '6' || a == '8')
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "bon" << endl;
  }
}


Measured memory_bytes: 3596
#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:tt)*) => (if cfg!(debug_assertions) {print!("[DEBUG] "); println!($($arg)*)});
}

fn f(b: i64, n: i64) -> i64 {
    if n < b {
        n
    } else {
        f(b, n / b) + n % b
    }
}

const N: i64 = 1000000;

fn main() {
    let mut rd = reader::Reader::new();

    let n: i64 = rd.next();
    let s: i64 = rd.next();

    if n == s {
        println!("{}", n + 1);
        return;
    }

    for i in 2..N {
        if f(i, n) == s {
            println!("{}", i);
            return;
        }
    }

    let mut ans: i64 = -1;
    for i in 1..N {
        let b = n / i;
        if b < 2 || i * i > n {
            break;
        }
        let r = n % b;
        let nb = n / (i + 1) + 1;

        debug!("i = {}, b = {}, r = {}, nb = {}", i, b, r, nb);
        let lb = f(b, n);
        let ub = f(nb, n);

        debug!("lb = {}, ub = {}", lb, ub);
        if lb <= s && s <= ub && (s - n % b) % i == 0 {
            ans = b - (s - i) / i;
            debug!("cand = {}, f(n, b) = {}", ans, f(ans, n));
        }
    }
    println!("{}", ans);
}

mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        let _ = io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line()
            .split_whitespace()
            .map(|s| s.to_string())
            .collect()
    }

    #[allow(dead_code)]
    pub struct Reader {
        buf: VecDeque<String>,
    }

    #[allow(dead_code)]
    impl Reader {
        pub fn new() -> Reader {
            Reader { buf: VecDeque::new() }
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T
            where
                T: FromStr,
                T::Err: Debug,
        {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn next_n<T>(&mut self, n: usize) -> Vec<T>
            where
                T: FromStr,
                T::Err: Debug,
        {
            let mut vec: Vec<T> = Vec::with_capacity(n);

            for _ in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}


Measured memory_bytes: 4352
s = input()
words = ['dream', 'dreamer', 'erase', 'eraser']
words = sorted(words, reverse=True)
print()
for word in words:
    if word in s:
        s = s.replace(word, "")

if not s:
    ans = "YES"
else:
    ans = "NO"

print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int res;
int main() {

    int n,i,j;
    cin>>n;
    int b[n],a[n+1];
    for(i=1;i<n;i++) cin>>b[i];

    for(i=1;i<=n;i++) a[i] = 1e9;

    for(i=1;i<n;i++){
        a[i] = min(b[i],a[i]);
        a[i+1] = min(a[i+1],b[i]);
    }

    for(i=1;i<=n;i++) res += a[i];

    cout<<res;
    return 0;
}

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

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;

constexpr size_t    operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t  operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End

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

    size_t H, W;
    cin >> H >> W;

    auto mat = make_v(' ', H + 2, W + 2);
    for (size_t i = 1; i <= H; ++i) {
        for (size_t j = 1; j <= W; ++j) {
            cin >> mat[i][j];
        }
    }

    vector<string> symbol(2);
    cin >> symbol[0] >> symbol[1];

    auto f = [&](size_t y, size_t x) -> bool {
        for (size_t i = 0; i < 2; ++i) {
            for (size_t j = 0; j < 2; ++j) {
                if (mat[y + i][x + j] != symbol[i][j]) {
                    return false;
                }
            }
        }
        return true;
    };

    int64_t base = 0;
    for (size_t i = 1; i <= H; ++i) {
        for (size_t j = 1; j <= W; ++j) {
            if (f(i, j)) {
                base++;
            }
        }
    }

    string joi = "JOI";
    int64_t add = 0;
    for (size_t i = 1; i <= H; ++i) {
        for (size_t j = 1; j <= W; ++j) {

            char c = mat[i][j];

            int cnt = 0;
            const int dy[] = {0, -1, -1, 0};
            const int dx[] = {0, 0, -1, -1};
            for (size_t k = 0; k < 4; ++k) {
                if (f(i + dy[k], j + dx[k])) {
                    cnt++;
                }
            }

            for (size_t k = 0; k < 3; ++k) {
                mat[i][j] = joi[k];
                int changed_cnt = 0;
                for (size_t l = 0; l < 4; ++l) {
                    if (f(i + dy[l], j + dx[l])) {
                        changed_cnt++;
                    }
                }

                chmax(add, changed_cnt - cnt);
            }

            mat[i][j] = c;
        }
    }

    cout << base + add << "\n";

    return 0;
}



Measured memory_bytes: 3944
function main(input) {
    var args = input.trim().split(" ").map((v) => parseInt(v));
    var K = Number(args[0]);
    var X = Number(args[1]);

    var space = K - 1;

    var start = X - space;
    var end = X + space;

    var result = [];
    for(var i = start; end >= i; i++) {
        result.push(i);
    }

    console.log(result.join(" "));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define rep(ver,n) rep2(ver,0,n)
#define rep2(ver,m,n) for(int ver=m;i<(n);i++)
#define dup(x,y) (((x)+(y)-1)/(y))
#define vecadd emplace_back

typedef long long ll;

int main(){
  int n,k;
  string s;
  cin>>n>>k>>s;
  int div=1;
  rep2(i,1,n){
    if(s[i-1]==s[i]){}
    else{
      div++;
    }
  }
  
  int ans=(n-div+2*k<n-1)?(n-div+2*k):(n-1);
  cout<<ans;
  
  return 0;
}


Measured memory_bytes: 512
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    l = ''.join(['#' for _ in range(w)])
    m = ''.join(['#'] + ['.' for _ in range(w-2)] + ['#'])
    print(l)
    for i in range(h-2):
        print(m)
    print(l)
    print()


Measured memory_bytes: 5616
import collections

N=int(input())
A=list(map(int,input().split()))
S=[0 for i in range(N+1)]
S[0]=A[0]
for i in range(1,N):
    S[i]=S[i-1]+A[i]
S=collections.Counter(S)
#print(S)
print(sum([round(S[i]*(S[i]-1)/2) for i in S if S[i]>=2]))


Measured memory_bytes: 41672
// Created on: 22-Aug-2020 18:07:37 //

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, x, t;
    cin >> n >> x >> t;
    n = ceil((double)n / (double)x);
    cout << n * t << endl;

    return 0;
}

Measured memory_bytes: 3588
s = list(input())
k = int(input())

if list(s[0]*len(s))==s:
	#print('a')
	print(len(s)*k//2)
	exit()

res = [1]
for i in range(len(s)-1):
	if s[i]==s[i+1]:
		res[-1] += 1
	else:
		res.append(1)
ans = 0
for i in res:
	ans += (i//2)*k
if s[0]==s[-1]:
	diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2)
	ans += diff*(k-1)
print(ans)


Measured memory_bytes: 9096
//Created by Aminul on 8/15/2020.

import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = in.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                for (int k = j + 1; k < n; k++) {
                    if (isTriangle(arr[i], arr[j], arr[k])) {
                        cnt++;
                    }
                }
            }
        }

        pw.println(cnt);
        pw.close();
    }

    static boolean isTriangle(int a, int b, int c) {
        return a != b && a != c && b != c && (a + b > c) && (a + c > b) && (b + c > a);
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }
}

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

int main(){

	int N,M,Q;
	cin>>N>>M>>Q;

	list<int> L;

	for(int i=0;i<N;i++)
		L.push_back(i);

	list<int>::iterator btn =L.begin();


	for(int i=0;i<M;i++){
		int a;
		cin>>a;
		if(a%2==0){
			for(int j=0;j<a;j++){
				btn++;
				if(btn==L.end())		//最後尾にはダミーのendがあるから動かしてから
					btn=L.begin();
			}
		}
		else{
			for(int j=0;j<a;j++){
				if(btn==L.begin())		//先頭beginの前にはダミーがないのでチェックしてから
					btn=L.end();
				btn--;
			}
		}
		list<int>::iterator it=btn;
		btn++;
		if(btn==L.end())
			btn=L.begin();
		L.erase(it);
	}

	for(int i=0;i<Q;i++){
		int q;
		cin>>q;
	
		list<int>::iterator it;
	
		for(it=L.begin(); it!=L.end();it++){
			if(*it==q)
				break;
		}
		if(it!=L.end())
			cout<<1<<endl;
		else
			cout<<0<<endl;
	}
	
	return 0;
}

		

Measured memory_bytes: 7440
import Foundation

func main() {
    let s = Array(readLine()!)
    var i = 0
    var res = 0
    
    var j = 1
    for j in 1...3 {
        if s[j-1] == "R"{
            i += 1
        } else {
            if res < i {
                res = i
            }
            i = 0
        }
    }
    
    if res < i {
        res = i
    }
    
    print(res)
}

main()

Measured memory_bytes: 13200
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n,k; cin >> n >> k;
  ll ans = 0;
  REP(i,n){
    ll x; cin >> x;
    ans += 2*min(x,k-x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

long long f(ll l,ll r,ll s,ll t){
	if(l > s){
		swap(l,s);
		swap(r,t);
	}
	if(r >= s){
		ll m = (l+t)/2;
		ll m_ = l+t-m;
		return m*m_;
	}
	return r*s;
}

int main(){
	int Q;
	cin >> Q;
	for(int i = 0 ; i < Q ; i ++){
		ll A,B;
		cin >> A >> B;
		ll l = 0, r = A+B;
		while(l<r){
			ll m = (l+r+1)/2;
			ll ret = 0;
			if(A-1 <= m-B){
				ret = max( ret , f( 1,A-1,m+3-A,m+1 ) );
				ret = max( ret , f( A+1,m+2-B,B+1,m+2-A ) );
				ret = max( ret , f( m+3-B,m+1,1,B-1 ) );
			}
			else {
				ret = max( ret , f( 1,m+1-B,B+1,m+1 ) );
				ret = max( ret , f( m+2-B,A-1,m+2-A,B-1 ) );
				ret = max( ret , f( A+1,m+1,1,m+1-A ) );
			}
			if(ret >= A*B)r = m-1;
			else l = m;
		}
		cout << l << endl;
	}
}



Measured memory_bytes: 256