akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d, g;
  cin >> d >> g;
  g /= 100;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
    c[i] /= 100;
  }
  int ans = 1e9;
  for (int i = 0; i < 1 << d; i++) {
    int cnt = 0;
    int score = 0;
    for (int j = 0; j < d; j++) {
      if (i >> j & 1) {
        cnt += p[j];
        score += p[j] * (j + 1);
        score += c[j];
      }
    }
    for (int j = d - 1; j >= 0; j--) {
      if (~i >> j & 1) {
        for (int k = 0; k < p[j] && score < g; k++) {
          score += j + 1;
          cnt++;
        }
      }
    }
    if (score >= g) {
      ans = min(ans, cnt);
    }
  }
  cout << ans << '\n';
}

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

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

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const int MAX = 510000;
const ll MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<int> G[200100];

pair<int, ll> info_low[200200];
int N;
ll ans[200200];


pair<int, ll> dfs1(int v, int par){

  int cnt = 1;

  ll inv_fac = 1;
  ll tmp_ans = 1;
  for(auto nv : G[v]){
    if(nv == par) continue;

    pair<int, ll> tmp_ret = dfs1(nv, v);

    cnt += tmp_ret.first;
    inv_fac = (inv_fac * finv[tmp_ret.first]) % MOD;
    tmp_ans = (tmp_ans * tmp_ret.second) % MOD;

  }

  ll ret;
  ret = ((fac[cnt-1] * tmp_ans) % MOD * inv_fac) % MOD;

  return info_low[v] = make_pair(cnt, ret);

}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

void dfs2(int v, int par){

  if(par == -1){
    ans[v] = info_low[v].second;
  }else{
    ll ans_par = ans[par];

    ans_par = (ans_par * fac[info_low[v].first]) % MOD;
    ans_par = (ans_par * finv[info_low[v].first-1]) % MOD;
    ans_par = (ans_par * fac[N-info_low[v].first-1]) % MOD;
    ans_par = (ans_par * finv[N-info_low[v].first]) % MOD;
    ans[v] = ans_par;

  }

  for(auto nv : G[v]){
    if(nv == par) continue;
    dfs2(nv, v);
  }
}

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

  COMinit();

  cin >> N;

  int a, b;
  rep(i, N-1){
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  dfs1(0, -1);
  dfs2(0, -1);

  rep(i, N){
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 30580
from heapq import heappush, heappop
def dijkstra(graph:list, node:int, start:int) -> list:
    # graph[node] = [(cost, to)]
    inf = float('inf')
    dist = [inf]*node

    dist[start] = 0
    heap = [(0,start)]
    while heap:
        cost,thisNode = heappop(heap)
        for NextCost,NextNode in graph[thisNode]:
            dist_cand = dist[thisNode]+NextCost
            if dist_cand < dist[NextNode]:
                dist[NextNode] = dist_cand
                heappush(heap,(dist[NextNode],NextNode))
    return dist

N = int(input())
g = [[] for _ in range(N)]

for _ in range(N-1):
    a,b = map(int,input().split())
    g[a-1].append((1,b-1))
    g[b-1].append((1,a-1))

df = dijkstra(g,N,0)
ds = dijkstra(g,N,N-1)

f = 0
for i in range(N):
    if df[i] <= ds[i]:
        f += 1
if f > N-f:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 105324
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int a=0;
  int N=S.size();
  for(int i=0;i<N;i++){
    long long count=0;
    for(int j=0;j<N;j++){
      if(S.at(i)==S.at(j)){
        count++;
      }
    }
    if(count%2==1)
      a=1;
  }
  if(a==1)
    cout<<"No"<<endl;
  else
   cout<<"Yes"<<endl;
}


Measured memory_bytes: 3592
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int ans = 0;
        for(int i = 0; i < N; i++)
        {
            for(int j = 0; j < N; j++)
            {
                if (i * 4 + j * 7 == N) ans++;
            }
        }
        if (ans > 0) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

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

int main(){
	int n, m;
  cin >> n >> m;
  
  if(n > m){
    cout <<"No" << endl;
  }
  
  else {
    cout << "Yes" << endl;
  }
}

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

int main(){
  int K;
  cin >> K;
  vector<int> a(32);
  a = { 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 };
  cout << a.at(K - 1) << endl;
}
  

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

int main(void){
    int i,j,k;
    int N,T,S1,S2,min = 9999999;
    int array[100];
   
    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&array[i]);
    }
    
    for(T = 0;T < N - 1;T++){
        S1 = 0;
        S2 = 0;
        for(i = 0;i <= T;i++){
            S1 += array[i];
        }
        for(i = T+1;i < N;i++){
            S2 += array[i];
        }
        if(abs(S1 - S2) < min) min = abs(S1 - S2);
    }
    
    
    printf("%d\n",min);
    
    return 0;
}


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

//#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e6 + 7;
const int M = 22;
const int mod = 1e9 + 7;

void solve1()
{
	ll n;
	cin >> n;
	ll k = n / 500;
	n %= 500;
	cout << k * 1000 + n / 5 * 5;
}

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

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}


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



int main() {
  ll n, k;cin>>n>>k;
  ll ans = n%k ;
  ll value = min(ans, abs(ans-k));
  cout<< value <<endl;
	return 0;
}



Measured memory_bytes: 3640
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 998244353

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,K; cin>>N>>K;
    vector<pair<ll,ll>> seg;
    for(ll i=0;i<K;++i)
    {
        ll L,R; cin>>L>>R;
        seg.push_back({L,R});
    }
    
    sort(seg.begin(),seg.end());
    
    vector<pair<ll,ll>> S;
    ll cur_L = seg[0].first;
    ll cur_R = seg[0].second;
    
    for(ll i=1;i<K;++i)
    {
        ll L = seg[i].first;
        ll R = seg[i].second;
        
        if(L > cur_R)
        {
            S.push_back({cur_L,cur_R});
            cur_L = L;
            cur_R = R;
        }
        else
            cur_R = max(R,cur_R);
    }
    
    S.push_back({cur_L,cur_R});
    
    /*for(auto it: S)
    {
        cout<<it.first<<" "<<it.second<<endl;
    }*/
    
    ll pre[N];
    ll dp[N];
    
    dp[0] = 1;
    pre[0] = 1;
    
    for(ll i=1;i<N;++i)
    {
        dp[i] = 0;
        for(auto it: S)
        {
            ll L = it.first;
            ll R = it.second;
            
            ll ans = 0;
            if(i >= L)
            {
                ans += pre[i - L];
                ans %= MOD;
            }
            
            if(i > R)
            {
                ans -= pre[i - R - 1];
                ans = (ans + MOD) % MOD;
            }
            
            //cout<<i<<" "<<L<<" "<<R<<" "<<ans<<endl;
            dp[i] += ans;
            dp[i] %= MOD;
        }
        
        pre[i] = ((i > 0) ? pre[i - 1] : 0) + dp[i];
        pre[i] %= MOD;
    }
    
    cout<<dp[N - 1]<<endl;
}

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int h, m, a, b, k;
	cin >> h >> m >> a >> b >> k;
	int q = a*60+b;
	int e = h*60+m;
	cout << q- k - e;




	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3648
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextLong();
            if (A[i] == 0) {
                System.out.println(0);
                return;
            }
        }
        long ans = 1L;
        for (int i=0;i<N;i++) {
            ans *= A[i];
            if ((ans > 1000000000000000000L) || (ans <= 0)) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(ans);
    }
}

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

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

    if(s == "Sunny"){
        cout<<"Cloudy"<<endl;
        return 0;
    }

    if(s == "Cloudy"){
        cout<<"Rainy"<<endl;
        return 0;
    }

    if(s == "Rainy"){
        cout<<"Sunny"<<endl;
        return 0;
    }

}


Measured memory_bytes: 256
"""
import random
import functools
import copy
import bisect
import array
import re
import collections
import heapq
import fractions
import itertools
import string
import math
from operator import itemgetter as ig
from bisect import bisect_left, bisect_right, insort_left, insort_right
from itertools import permutations, combinations, product, accumulate, groupby
from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
# import numpy as np

inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)]
ddn9 = ddn + [(0, 0)]
'''for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:'''
"""


def main():
    N, A, B = map(int, input().split())
    a = A*(N-1)+B
    b = B*(N-1)+A
    if b-a+1 >= 0:
        print(b-a+1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n, k, q;
int f[N];

int32_t main()
{
	IOS;
	cin >> n >> k >> q;
	for(int i = 1; i <= q; i++)
	{
		int x;
		cin >> x;
		f[x]++;
	}
	for(int i = 1; i <= n; i++)
	{
		int pnt = k - (q - f[i]);
		if(pnt <= 0)
			cout << "No" << endl;
		else
			cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 1408
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(A%2!=0 && B%2!=0)System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void){
	int a, b, c;

	cin >> a >> b >> c;



	if (a == b)
		cout << c;
	else if (b == c)
		cout << a;
	else
		cout << b;
}

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

#define inf 1000000007

using namespace std;

typedef long long ll;

int a[100005], ma[100005];

int main()
{
    int n, q;
    ll z=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        ma[a[i]]++;
        z=z+a[i];
    }
    scanf("%d",&q);
    while(q--)
    {
        int u, v;
        scanf("%d%d",&u,&v);
        z=z+((ll)ma[u])*((ll)(v-u));
        ma[v]+=ma[u];
        ma[u]=0;
        printf("%lld\n",z);
    }
    return 0;
}


Measured memory_bytes: 4536
#include<cstdio>
#include<cmath>
#include<iostream>
typedef long long ll;

using namespace std;

int main()
{
	ll max,A,B,C,D,S1,S2;
	scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
	
		S1 = A * B;
		S2 = C * D;
		max = S1 > S2 ? S1 : S2;
		printf("%lld\n",max);
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//降順
int desc(const void* a, const void* b){
    long p=*(long*)a;
    long q=*(long*)b;
    if((q-p)>0) return 1;
    else if((q-p)<0) return -1;
    else return 0;
}

int main(void){
    int N;
    long W;
    scanf("%d%ld",&N,&W);

    long A[4][N];
    int M[4]={0,0,0,0};
    long w1;
    scanf("%ld%ld",&w1,&A[0][0]);
    M[0]++;
    for(int i=1;i<N;i++){
        long w2;
        long a;
        scanf("%ld%ld",&w2,&a);
        A[w2-w1][M[w2-w1]]=a;
        M[w2-w1]++;
    }
    for(int i=0;i<4;i++) qsort(A[i],M[i],sizeof(long),desc);

    //累積和にする
    for(int i=0;i<4;i++){
        for(int j=1;j<=M[i];j++) A[i][j]+=A[i][j-1];
    }

    long ans=0;
    for(int a=0;a<=M[0];a++){
        for(int b=0;b<=M[1];b++){
            for(int c=0;c<=M[2];c++){
                for(int d=0;d<=M[3];d++){
                    long w_sum=a*w1+b*(w1+1)+c*(w1+2)+d*(w1+3);
                    if(w_sum<=W){
                        long price=0;
                        if(a!=0) price+=A[0][a-1];
                        if(b!=0) price+=A[1][b-1];
                        if(c!=0) price+=A[2][c-1];
                        if(d!=0) price+=A[3][d-1];
                        ans=MAX(ans,price);
                    }
                }
            }
        }
    }
    printf("%ld\n",ans);

    return 0;
}

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

using namespace std;

int a[101];

int main(void) {

	int n;
	cin>>n;
	for(int i = 0; i < 2*n; ++i)
		cin>>a[i];
	sort(a, a+2*n);
	int ans = 0;
	for(int i = 0; i < 2*n; i += 2) {
		ans += min(a[i], a[i+1]);
	}
	cout<<ans;

	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;

int n,m,k;

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			if(k==(i*j)+(n-i)*(m-j)) 
			{
				puts("Yes"); 
				return 0;
			}
	puts("No");		
	return 0;
}

Measured memory_bytes: 256
/** @Date    : 2017-09-02 20:20:43
  * @FileName: B.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

int vis[N];
int a[N];
int main()
{
	int n;
	while(cin >> n)
	{
		MMF(vis);
		for(int i = 1; i <= n; i++)
		{
			scanf("%d", a + i);
			if(a[i] == i)
				vis[i] = 1;
		}
		vis[n + 1] = 1;
		int ans = 0;
		for(int i = 1; i <= n; i++)
		{
			if(vis[i] == 1)
			{
				ans++;
				if(vis[i + 1] == 1)
					vis[i] = vis[i + 1] = 0;
				else vis[i] = 0;
			}
		}
		cout << ans << endl;
	}
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int i,num;
}A[110000];
bool comp(node a,node b)
{
	return a.num<b.num;
}
int main()
{
	int N;
	cin>>N;
	for(int i=1;i<=N;i++)
	{
		int t;
		cin>>t;
		A[i].i=i;
		A[i].num=t;
	}
	sort(A+1,A+N+1,comp);
	for(int i=1;i<=N;i++)
	{
		cout<<A[i].i<<" ";
	}
} 

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

const int N = 2e5 + 5;
int n, k, l, x, y, no[2][N], nom[2];
vector<int> v[2][N];
map<pair<int, int>, int> ma;

void sgd(int dg, bool kl) {
	no[kl][dg] = nom[kl];
	for(int i = 0; i < v[kl][dg].size(); ++i) {
		if(!no[kl][v[kl][dg][i]]) {
			sgd(v[kl][dg][i], kl);
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k >> l;
	for(int i = 1; i <= k; ++i) {
		cin >> x >> y;
		v[0][x].push_back(y);
		v[0][y].push_back(x);
	}
	for(int i = 1; i <= l; ++i) {
		cin >> x >> y;
		v[1][x].push_back(y);
		v[1][y].push_back(x);
	}
	for(int i = 1; i <= n; ++i) {
		if(!no[0][i]) ++nom[0], sgd(i, 0);
		if(!no[1][i]) ++nom[1], sgd(i, 1);
		++ma[{no[0][i], no[1][i]}];
	}
	for(int i = 1; i <= n; ++i) {
		cout << ma[{no[0][i], no[1][i]}] << " ";
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 27904
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef long double Double;
const Double INF = 1e20;
const double PI = acos(-1);
const double EPS = 1e-8;

char ba[500][500];
Double disg[500][500];
Double disb[500][500];
bool visited[500][500];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int h,w;
void bfs(Double hoge[500][500], queue<pii> &Q, bool vis[500][500]) {
  
  while(!Q.empty()) {
    pii p = Q.front(); Q.pop();
    int y = p.first;
    int x = p.second;
    REP(k, 4) {
      int yy = y+dy[k];
      int xx = x+dx[k];
      if (yy<0||yy>=h||xx<0||xx>=w) continue;
      if (ba[yy][xx] != '.') continue;
      if (vis[yy][xx]) continue;
      vis[yy][xx] = 1;
      hoge[yy][xx] = hoge[y][x] + 1;
      Q.push(pii(yy,xx));
    }
  }  
}

// Cð½·àÌªub¤É èACð½·Å¬lðßéÆ«B
template<class T> T lower_search(T lb, T ub, bool (*C)(T)) {
  REP(i, 200) {
    T mid = (lb+ub)/2;
    if (C(mid)) ub = mid;
    else lb = mid;
  }
  return ub;
}

int num = 0;

bool C(Double E) {
  Double hoge = 0;
  REP(i, h) {
    REP(j, w) {
      if (ba[i][j] == '.') {
        if (disg[i][j] < disb[i][j] + E) {
          hoge += disg[i][j];
        } else {
          hoge += disb[i][j] + E;
        }
      }
    }
  }
  hoge /= num;
  //cout << hoge << " "<< E << endl;
  return  E >= hoge;
}

int main() {
  cin >> w >> h;
  int sx,sy,gx,gy;
  queue<pii> Q;
  memset(visited, 0, sizeof(visited));
  REP(i,h)REP(j,w) disb[i][j] = disg[i][j] = INF;
  num = 0;
  REP(i, h) {
    REP(j, w) {
      cin >> ba[i][j];
      if (ba[i][j] == 's') {
        sx = j; sy = i;
        ba[i][j] = '.';
        num++;
      } else if (ba[i][j] == 'g') {
        gx = j; gy = i;
      } else if (ba[i][j] == '*') {
        Q.push(pii(i,j));
        visited[i][j] = 1;
        disb[i][j] = 0;
      } else if (ba[i][j] == '.') {
        num++;
      }
    }
  }
  bfs(disb, Q, visited);
  
  memset(visited,0,sizeof(visited));
  disg[gy][gx] = 0;
  visited[gy][gx] = 1;
  Q.push(pii(gy,gx));
  bfs(disg, Q, visited);

  // REP(i, h) {
  //   REP(j, w) {
  //     if (disb[i][j] == INF) cout << "* ";
  //     else cout << disb[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  
  // REP(i, h) {
  //   REP(j, w) {
  //     if (disg[i][j] >= INF)cout << "* ";
  //     else cout << disg[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  Double E = lower_search<Double>(0, 1e20, C);
  //cout << E << endl;
  Double ans = min((Double)disg[sy][sx],disb[sy][sx]+E);
  printf("%.12Lf\n", ans);
}

Measured memory_bytes: 7564
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int gcd(int x, int y) {
  if (x < y) swap(x, y);
  while (y > 0) {
    int r = x % y;
    x = y;
    y = r;
  }
  return x;
}

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
    int h,w;
    cin>>h>>w;
    char a[h][w];
    bool ho[h];
    bool wi[w];

    for(int i = 0; i<h; i++){
        ho[i]=true;
    }

    for(int i = 0; i<w; i++){
        wi[i]=true;
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin>>a[i][j];
            if(a[i][j]=='#') ho[i]=false;
        }
    }

     for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            if(a[j][i]=='#') wi[i]=false;
        }
     }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(ho[i]!=0||wi[j]!=0) ;
                else{
                    cout<<a[i][j];
                }
        }
        if(ho[i]==0)
        cout<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
/*
 * ALDS1_6_D.cpp
 *
 *  Created on: May 2, 2018
 *      Author: 13743
 */

#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int n;
	int A[1000];
	int B[1000];
	int aW[10001] = {-1};
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> A[i];
		B[i] = A[i];
		aW[A[i]] = i;
	}

	sort(B, B+n);
	int glMin = B[0];
	int rm = 0;

	for(int i=0; i<n; i++) {
		if(aW[B[i]] == -1) continue;
		int c = 0;
		int lcMin = B[i];
		int j = aW[lcMin];
		aW[lcMin] = -1;
		rm -= lcMin;
		while(j != -1) {
			rm += A[j];
			c++;
			int a = B[j];
			j = aW[B[j]];
			aW[a] = -1;
		}
		rm += min(lcMin*(c-1), 2*(lcMin+glMin)+glMin*(c-1));
	}

	cout << rm << endl;
}





Measured memory_bytes: 3192
h, w = map(int, input().split())
while not (h == 0 and w == 0):
    for i in range(h):
        if i == 0 or i == h-1:
            print("#"*w)
        else:
            print("#" + "."*(w-2) + "#")
    print("")
    h, w = map(int, input().split())


Measured memory_bytes: 5608
import heapq
import math

def make_Graph(N, edges):#頂点の名前はi - 1で受け付ける
    graph = {}
    for i in range(N):
        graph[i] = {}
        for j in range(N):
            graph[i][j] = 0
    for edge in edges:
        a, b, c = edge
        graph[a][b] = c
        graph[b][a] = c
    return graph

def Dijkstra(graph, start):
    N = len(graph)
    d = {}
    prev = {}
    for i in range(N):
        prev[i] = None
        if i == start:
            d[i] = 0
        else:
            d[i] = float('inf')
    Q = []
    heapq.heappush(Q, (0, start))
    while Q:
        d_u, u = heapq.heappop(Q)
        if d[u] < d_u:#ダブりを回避
            continue
        for i in range(N):
            if graph[u][i]:
                temp = d_u + graph[u][i]
                if d[i] > temp:
                    d[i] = temp
                    prev[i] = u
                    heapq.heappush(Q, (d[i], i))
    return (d, prev)

def saitan(start, goal, d, prev):
    temp = goal
    res = [goal]
    while True:
        res.append(prev[temp])
        if prev[temp] == start:
            break
        else:
            temp = prev[temp]
    return res

N,M = (int(i) for i in input().split())
edges = []
for i in range(M):
    a,b,c = (int(i) for i in input().split())
    edges.append((a-1, b-1, c))

graph = make_Graph(N, edges)

res = []
for i in range(N):
    d, prev = Dijkstra(graph, i)
    for j in range(N):
        if i != j:
            sait = saitan(i, j, d, prev)
            for k in range(len(sait) - 1):
                res.append(  (min(sait[k], sait[k + 1]) , max(sait[k], sait[k + 1]) ) )

res = set(res)
print(M - len(res))

Measured memory_bytes: 27664
#include<stdio.h>

long long n,r[16384]={0};

void rep(long long x,long long y,long long z,long long tg){
  if(x*x+y*y+z*z+x*y+y*z+z*x>n){return;}
  r[x*x+y*y+z*z+x*y+y*z+z*x]++;
  if(tg<=0){rep(x+1,y,z,0);}
  if(tg<=1){rep(x,y+1,z,1);}
  if(tg<=2){rep(x,y,z+1,2);}
}

int main(){
  long long i;
  scanf("%lld",&n);
  rep(1,1,1,0);
  for(i=1;i<=n;i++){printf("%lld\n",r[i]);}
  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int n;
int edge[44][44];
Int dp[44][44][44];
Int ans = 0;

int main(){
    cin >> n;
    for(int i = 0;i < 2 * n;i++)
        for(int j = 0;j < 2*n;j++)
            scanf("%1d", &edge[i][j]);
    n *= 2;

    for(int i = 1;i < n;i++)dp[i][i+1][i] = 1;
    for(int l1 = n-1;l1 >= 0;l1--){
        for(int l4 = l1+1;l4 <= n;l4++){            
            for(int l2 = l1 + 1;l2 < n;l2++){
                for(int m1 = l1;m1 < l2;m1++){
                    for(int l3 = l2 + 1;l3 < n;l3++){
                        if(l4 <= l3)break;
                        for(int m2 = l2;m2 < l3;m2++){
                            for(int m3 = l3;m3 < l4;m3++){
                                if(edge[m1][m3]){
                                    dp[l1][l4][m2] += dp[l1][l2][m1] * dp[l2][l3][m2] * dp[l3][l4][m3];
                                }
                            }
                        }
                    }
                }
            }            
        }
    }
    for(int m = 0;m < n;m++)
        if(edge[0][m])
            ans += dp[1][n][m];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
using namespace std;

set<int> guest;
int n, m;
vector<int> people[501];
int main()
{
    while((cin >> n >> m) && n && m)
    {
        int a, b;
        int t;
        for(int i=0;i<m;i++)
        {
            cin >> a >> b;
            people[a].push_back(b);
            people[b].push_back(a);
        }
        for(int i=0;i<people[1].size();i++)
        {
            t = people[1][i];
            guest.insert(t);
            for(int j=0;j<people[t].size();j++) guest.insert(people[t][j]);
        }
        guest.insert(1);
        cout << guest.size()-1 << endl;
        guest.clear();
        for(int i=0;i<n;i++) people[i].clear();
    }
}

Measured memory_bytes: 1372
n,m = map(int,input().split())
h = list(map(int, input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
count = [0]*n
	
for j in range(m):

	#print(str(h[ab[j][0]-1])+","+str(h[ab[j][1]-1]))
	if(h[ab[j][0]-1] >= h[ab[j][1]-1]):
		count[ab[j][1]-1] += 1
	if(h[ab[j][0]-1] <= h[ab[j][1]-1]):
		count[ab[j][0]-1] += 1
print(count.count(0))


Measured memory_bytes: 31816
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

typedef long long ll;

const int ALPH=26;
string s;
int compteur[ALPH];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> s;
    int n=s.size();
    
    for(int i=0;i<n;i++){
		compteur[s[i]-'a']++;
	}
	
	for(int i=0;i<ALPH;i++){
		if(compteur[i]==0){
			s+=(char)('a'+i);
			cout << s << endl;
			return 0;
		}
	}
	string meilleur="";
	
	for(int i=n-1;i>=0;i--){
		int minimum=26;
		for(int j=i+1;j<n;j++){
			if(s[i]<s[j]){
				minimum=min(minimum,s[j]-'a');
			}
		}
		if(minimum!=26){
			for(int j=0;j<i;j++){
				meilleur+=s[j];
			}
			meilleur+=(char)('a'+minimum);
			cout << meilleur << endl;
			return 0;
		}
	}
				
	cout << -1 << endl;
			
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005
using namespace std;
const int maxn = 1e5 + 100;
vi G[maxn];
int dp[maxn];

int in[maxn];
queue<int>q;
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#ifdef LOCAL_DEFINE
	ifstream cin("input.txt");
#endif
	int N, M;
	cin >> N >> M;
	while (M--)
	{
		int u, v;
		cin >> u >> v;
		G[u].push_back(v);
		in[v]++;
	}

	for (int i = 1; i<= N; i++)  
		if (in[i] == 0) q.push(i);  
	vector<int>topo;   
	while (!q.empty())
	{
		int p = q.front(); q.pop();
		topo.push_back(p);
		for (int i = 0; i<G[p].size(); i++)
		{
			int v = G[p][i];
			in[v]--;
			if (in[v] == 0)
				q.push(v);
		}
	}
	int ans = 0;
	for (auto i: topo)
		for (auto j : G[i])
		{
			dp[j] = max(dp[j], dp[i] + 1);
			ans = max(ans, dp[j]);
		}
	cout << ans << '\n';
}

Measured memory_bytes: 7032
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;

int main() {

    ll x,y;
    cin >> x >> y;
    ll ans;
    if (x * y > 0) {
        if (y >= x) ans = y - x;
        else ans = x - y + 2;
    } else if (x * y < 0) {
        ans = abs(abs(x)-abs(y)) + 1;
    } else {
        if (y > x) ans = y - x;
        else ans = x - y + 1;
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3560
N = int(input())
s = input()
animals = ["S", "W"]
for s1 in animals:
    for s2 in animals:
        t = [s1, s2]
        for i in range(1, N-1):
            if s[i] == "o":
                if t[i] == "S":
                    if t[i-1] == "S":
                        t.append("S")
                    else:
                        t.append("W")
                else:
                    if t[i-1] == "S":
                        t.append("W")
                    else:
                        t.append("S")
            else:
                if t[i] == "S":
                    if t[i-1] == "S":
                        t.append("W")
                    else:
                        t.append("S")
                else:
                    if t[i-1] == "S":
                        t.append("S")
                    else:
                        t.append("W")
        ans = ""
        for i in range(N):
            prev = i - 1 if 0 <= i - 1 else N - 1
            next = i + 1 if i + 1 < N else 0
            if t[i] == "S":
                if t[prev] == t[next]:
                    ans += "o"
                else:
                    ans += "x"
            else:
                if t[prev] == t[next]:
                    ans += "x"
                else:
                    ans += "o"
        if ans == s:
            print("".join(t))
            exit()
print(-1)


Measured memory_bytes: 4348
import sys
import math
import bisect

def main():
    d = dict()
    for _ in range(int(input())):
        s = input()
        if s not in d:
            d[s] = 0
        d[s] += 1
    A = ['AC', 'WA', 'TLE', 'RE']
    for a in A:
        if a not in d:
            d[a] = 0
        print('%s x %d' % (a, d[a]))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define int long long
using namespace std;

map<char, int> mp;

signed main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		mp[s[i]]++;
	}
	for (auto e : mp) {
		if (e.second % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
ll i,j,k;
ll n,m;
ll a,b;
ll x[200005],y[200005];

int main(){
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x[i];
		y[i]=x[i];
	}
	sort(x,x+n);
	a=x[n/2-1];
	b=x[n/2];
	for(i=0;i<n;i++){
		if(y[i]<=a){
			cout<<b<<endl;
		}else{
			cout<<a<<endl;
		}
	}
	

	
	
	return 0;
}

Measured memory_bytes: 9984
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
 
const ll INF=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll cnt=0; //負の数を数える
    ll m=INF; //absが最も小さいものを記録
    bool exe=false; //0があるかどうか
    ll sum=0; //absの合計
    rep(i,n){
        cin >> a[i];
        if(a[i]<0) cnt++;
        if(a[i]==0) exe=true;
        m=min(m,abs(a[i]));
        sum+=abs(a[i]);
    }
    if(exe) cout << sum << endl;
    else{
        if(cnt%2==0){
            cout << sum << endl;
        }
        else{
            cout << sum-2*m << endl;
        }
    }
    
    return 0;
} 

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

int main(){

  int n, m, sum=0;
  cin >> n;
  int t[n];
  for(int i=0; i<n; i++){
    cin >> t[i];
    sum += t[i];
  }

  cin >> m;
  int p[m], x[m];
  for(int i=0; i<m; i++){
    cin >> p[i] >> x[i];
  }

  for(int i=0; i<m; i++){
    cout << sum-(t[p[i]-1]-x[i]) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
[n,k]=[int(_) for _ in input().split()]
d=[int(_) for _ in input().split()]
dt=list({_ for _ in range(10)}-set(d))
def c(n,l):
  for _c in str(n):
    if int(_c) not in l: return False
  return True
while True:
  if c(n,dt): break
  n+=1
print(n)

Measured memory_bytes: 3188
#include <iostream>
#include <list>
#include <map>
#include <string>

using namespace std;

string s;
int k, n;

string subs_rec(string prefix, list<int> &idx_l, int *count) {
  map<char, list<int>> next_ch;
  list<int>::iterator it_to_erase = idx_l.end();
  for (auto it = idx_l.begin();it != idx_l.end();it++) {
    //    cout << "index\t" << *it << endl;
    if (*it >= n) {
      it_to_erase = it;
      continue;
    }
    if (next_ch.find(s[*it]) == next_ch.end()) {
      list<int> next_idx;
      next_ch[s[*it]] = next_idx;
    }
    next_ch[s[*it]].push_back((*it) + 1);
  }
  if (it_to_erase != idx_l.end()) {
    idx_l.erase(it_to_erase);
  }
  string ans = "";
  //  cout << "prefix\t" << prefix << endl;
  for (auto it = next_ch.begin();it != next_ch.end();it++) {
    string prefix2(prefix);

    //    cout << it->first << endl;
prefix2.push_back(it->first);
    (*count)++;
    if ((*count) == k) {
      return(prefix2);
    } else {
      //      cout << prefix2 << endl;
      ans = subs_rec(prefix2, it->second, count);
      if (ans != "") {
	return(ans);
      }
    }
  }
  return(ans);
}


int main(){
  map<char, list<int>> m;
  cin >> s;
  cin >> k;
  n = s.length();
  string ans = "";
  list<int> idx_list;
  int count = 0;
  for (int i=0;i<n;i++) {
    idx_list.push_back(i);
  }
  cout << subs_rec(ans, idx_list, &count) << endl;
  return(0);
}


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

int main() {
  int N,K,x,sum=0;
  cin >> N>>K;
  int i=1;
  
  for(i;i<=N;i++){
    cin>>x;
      if(x<K-x){
        sum+=2*x;
      }else{
        sum+=2*(K-x);
      }
  }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 55;
const int mod = 1000000007;

int n,m;
ll mask[maxn];
vector<int>e[maxn],id[maxn];

ll ttmask;
bool dfs(int x,int fa, int y){
  if(x == y) return true;
  for(int i=0;i<e[x].size();i++){
    int v = e[x][i];
    if(v==fa)continue;
    if(dfs(v, x, y)){
      ttmask|=(1LL<<id[x][i]);
      return true;
    }
  }
  return false;
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=0;i<n-1;i++){
    int x,y;
    cin>>x>>y;
    e[x].push_back(y);
    id[x].push_back(i);
    e[y].push_back(x);
    id[y].push_back(i);
  }
  cin>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    ttmask = 0;
    dfs(x, 0, y);
    mask[i] = ttmask;
  }
  ll ret = 0;
  for(int i=0;i<(1<<m);i++){
    ll am = 0;
    int cnt2 = 0;
    for(int j=0;j<m;j++)if(i&(1LL<<j)){am|=mask[j];cnt2++;}
    int cnt =0;
    for(int j=0;j<n-1;j++)if(am&(1LL<<j))cnt++;
    ll tmp = 1LL<<(n-1-cnt);
    if(cnt2&1)ret-=tmp;
    else ret+=tmp;
  }
  cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

  string s;
  cin >> s;
  int ans = 0, popo = 0;
  for(int i = 0;i < s.size();i++){
    if(s[i] == 'R'){
      popo++;
    }else{
      popo = 0;
    }
    ans = max(ans, popo);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3588
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < q; i++) {
            int x = sc.nextInt()-1;
            a[x]++;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            if(0 < k - q + a[i]) sb.append("Yes");
            else sb.append("No");
            sb.append("\n");
        }
        System.out.println(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 49984
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

#include <set>

typedef tuple<int, int, int> tup;

int n, q;

multiset<int> stop;
vector<tup> events;
Vi ans;

void init()
{
	cin >> n >> q;
	events.reserve(2 * n + q);
	ans.resize(q);

	REP(_i, n)
	{
		int s, t, x;
		cin >> s >> t >> x;

		s -= x;
		t -= x;

		events.emplace_back(tup(s, 0, x));
		events.emplace_back(tup(t, 1, x));
	}

	REP(i, q)
	{
		int t;
		cin >> t;
		events.emplace_back(tup(t, 2, i));
	}

	sort(ALL(events));

}

int main()
{
	init();

	REP(i, n * 2 + q)
	{
		if (get<1>(events[i]) == 0)
			stop.insert(get<2>(events[i]));

		else if (get<1>(events[i]) == 1)
			stop.erase(stop.find(get<2>(events[i])));

		else // if (get<1>(events[i]) == 2)
		{
			if (!stop.empty())
				ans[get<2>(events[i])] = *(stop.begin());
			else
				ans[get<2>(events[i])] = -1;
		}
	}

	REP(i, q)
		cout << ans[i] << endl;
}


Measured memory_bytes: 18432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        String[] input_str_array = br.readLine().split(" ");
        int[] input_array = new int[N];

        for(int i = 0; i < N; i++) {
            input_array[i] = Integer.parseInt(input_str_array[i]);
        }

        int[] dp = new int[N];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        // dp[1] = Math.abs(input_array[0] - input_array[1]);

        for(int i = 0; i < N; i++) {
            for(int j = 1; j <= K; j++) {
                if(i+j > N-1) break;
                if(dp[i + j] == -1) {
                    dp[i + j] = Math.abs(input_array[i] - input_array[i + j]) + dp[i];
                } else {
                    dp[i + j] = Math.min(Math.abs(input_array[i] - input_array[i + j]) + dp[i], dp[i + j]);
                }
                
            }
        }
        
        pw.println(dp[N-1]);
        pw.close();
        br.close();
    }
}


Measured memory_bytes: 45768
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  REP(i,h){
    cin>>s[i];
  }
  
  int b=0;
  REP(i,h){
    REP(j,w){
      if(s[i][j]=='#'){
        b++;
      }
    }
  }
  
  vector<vector<int>> dist(h,vector<int>(w,-1));
  dist[0][0]=0;
  
  queue<pair<int,int>> q;
  q.push(make_pair(0,0));
  pair<int,int> p;
  int x,y;
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};
  int nx,ny;
  while(!q.empty()){
    p = q.front();
    x = p.first;
    y = p.second;
    q.pop();
    REP(i,4){
      nx = x + dx[i];
      ny = y + dy[i];
      if(0<=nx && nx<h && 0<=ny && ny<w){
        if(s[nx][ny]=='.' && dist[nx][ny]==-1){
          dist[nx][ny] = dist[x][y]+1;
          q.push(make_pair(nx,ny));
        }
      }
    }
  }
  
  if(dist[h-1][w-1]==-1){
    cout<<-1<<endl;
    return 0;
  }
  
  int ans;
  ans = h*w-b-(dist[h-1][w-1]+1);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256