akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int getint()
{
    int i=0,f=1;char c;
    for(c=getchar();(c!='-')&&(c<'0'||c>'9');c=getchar());
    if(c=='-')c=getchar(),f=-1;
    for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0';
    return i*f;
}
const int N=200005,mod=1e9+7;
const ll INF=1e18;
int n,m,A,B,q[N];
ll f[N<<2],g[N<<2],h[N<<2],tag[N<<2];
void add(int k,ll v){//if(f[k]!=INF) f[k]+=v,
                         g[k]+=v,h[k]+=v,tag[k]+=v;}
void pushdown(int k){add(k<<1,tag[k]),add(k<<1|1,tag[k]);tag[k]=0;}
void update(int k)
{
   // f[k]=min(f[k<<1],f[k<<1|1]);
    g[k]=min(g[k<<1],g[k<<1|1]);
    h[k]=min(h[k<<1],h[k<<1|1]);
}
void build(int k,int l,int r)
{
    //f[k]=
	g[k]=h[k]=INF;
    if(l==r)return;
    int mid=l+r>>1;
    build(k<<1,l,mid),build(k<<1|1,mid+1,r);
}
void chkmin(int k,int l,int r,int p,ll v)
{
    if(l==r)
    {   
       // if(v<f[k])f[k]=v,
		g[k]=v-l,h[k]=v+l;
        return;
    }
    if(tag[k])pushdown(k);
    int mid=l+r>>1;
    p<=mid?chkmin(k<<1,l,mid,p,v):chkmin(k<<1|1,mid+1,r,p,v);
    update(k);
}
ll query(int k,int l,int r,int x,int y,int op)
{
    if(x>y)return INF;
    if(x<=l&&r<=y)return op?h[k]:g[k];
    if(tag[k])pushdown(k);
    int mid=l+r>>1;
    if(y<=mid)return query(k<<1,l,mid,x,y,op);
    else if(x>mid)return query(k<<1|1,mid+1,r,x,y,op);
    else return min(query(k<<1,l,mid,x,mid,op),query(k<<1|1,mid+1,r,mid+1,y,op));
}
int main()
{
    //freopen("lx.in","r",stdin);
    n=getint(),m=getint(),A=getint(),B=getint();
    build(1,1,n);
    for(int i=1;i<=m;i++)q[i]=getint();
    q[0]=B;chkmin(1,1,n,A,0);
    for(int i=1;i<=m;i++)
    {
        ll tmp=min(query(1,1,n,1,q[i],0)+q[i],query(1,1,n,q[i]+1,n,1)-q[i]);
        add(1,abs(q[i]-q[i-1]));chkmin(1,1,n,q[i-1],tmp);
    }
    long long ans=2e10;
    for ( int i=1;i<=n;i++)
  {  ans=min(ans,query(1,1,n,i,i,0)+i); }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 19456
def f(a):
    if a>1.0:return 0
    elif a>0.5:return 1
    elif a>0.1:return 2
    else:return 3
b=[0]*8
while 1:
    try:l,r=map(float,input().split())
    except:break
    b[f(l)]+=1
    b[4+f(r)]+=1
for i in range(4):print(b[i],b[4+i])

Measured memory_bytes: 7496
size = gets.to_i
d_array = Array.new(13.0)
h_array = Array.new(13.0)
s_array = Array.new(13.0)
c_array = Array.new(13.0)

size.times do
    c, n = gets.split
	if c == "D" then
		d_array[n.to_i-1] = 1
	elsif c == "H" then
		h_array[n.to_i-1] = 1
	elsif c == "S" then
		s_array[n.to_i-1] = 1
	elsif c == "C" then
		c_array[n.to_i-1] = 1
	end
end
0.upto(12) {|i| puts"S #{i+1}" if s_array[i] == nil}
0.upto(12) {|i| puts"H #{i+1}" if h_array[i] == nil}
0.upto(12) {|i| puts"C #{i+1}" if c_array[i] == nil}
0.upto(12) {|i| puts"D #{i+1}" if d_array[i] == nil}


Measured memory_bytes: 6880
import numpy as np
import copy


def visit(next_node, visited_nodes, adj_mat):
    assert next_node not in visited_nodes

    if len(visited_nodes) + 1 == len(adj_mat):
        # Visited all nodes
        return 1
    else:
        adj_nodes = np.argwhere(adj_mat[next_node].flatten() == 1)
        if len(adj_nodes) == 0:
            # Failed
            return 0
        else:
            n_paths = 0
            for adj_node in adj_nodes:
                if adj_node not in visited_nodes:
                    n_paths += visit(adj_node, visited_nodes +
                                     [next_node, ], adj_mat)
                else:
                    continue
            return n_paths


def main():
    N, M = map(int, input().split())
    adj_mat = np.zeros((N, N), dtype=np.int32)
    for _ in range(M):
        a, b = map(int, input().split())
        adj_mat[a-1][b-1] = 1
        adj_mat[b-1][a-1] = 1
    assert np.sum(adj_mat) == M * 2

    next_nodes = np.argwhere(adj_mat[0].flatten() == 1)
    n_paths = np.sum([visit(next_node, [0, ], adj_mat)
                      for next_node in next_nodes])

    print(n_paths)


if __name__ == '__main__':
    main()


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

typedef pair<int, int> int_p;

int main(){

  int N, M;
  int_p ab[100000];
  int prev_remove = 0, num_remove = 0;

  cin >> N >> M;
  for (int i = 0; i < M; ++i){
    cin >> ab[i].first >> ab[i].second;
  }

  sort(ab, ab + M, [](int_p l, int_p r){ return l.second < r.second; });

  for (int i = 0; i < M; ++i){
    if (ab[i].first <= prev_remove) continue;
    prev_remove = ab[i].second - 1;
    ++num_remove;
  }

  cout << num_remove << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define sz(v) (int)v.size()
#define pb push_back

using namespace std;
int N;
int V[55],C[55];

int main(){
    cin >> N;
    rep(i,N) cin >> V[i];
    rep(i,N) cin >> C[i];
    vector<int> ans;
    rep(i,N) ans.pb(V[i]-C[i]);
    int res = 0;
    rep(i,N) if(ans.at(i) >= 0) res += ans.at(i);
    cout << res << endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N;
  cin>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<pii>v(N);
  for(int i=0;i<N;i++)v[i]={A[i],i};
  sort(rng(v));
  reverse(rng(v));
  vector<vector<ll>>dp(N+1,vector<ll>(N+1,0));
  for(ll i=1;i<=N;i++){
    for(ll j=0;j<=i;j++){
      if(j-1>=0&&i-j-1>=0)dp[j][i-j]=max(dp[j-1][i-j]+v[i-1].first*(v[i-1].second-j+1),dp[j][i-j-1]+v[i-1].first*((N-(i-j))-v[i-1].second));
      else if(j-1>=0&&i-j-1<0)dp[j][i-j]=dp[j-1][i-j]+v[i-1].first*(v[i-1].second-j+1);
      else if(j-1<0&&i-j-1>=0)dp[j][i-j]=dp[j][i-j-1]+v[i-1].first*((N-(i-j))-v[i-1].second);
    }
  }
  ll ans=0;
  for(int i=0;i<=N;i++)ans=max(ans,dp[i][N-i]);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 34616
n,m,k=map(int,input().split())
mod=pow(10,9)+7
ans=0

#n*m-2個の中からk-2個選ぶときの組み合わせ数
cmb=1
for i in range(k-2):
  cmb*=n*m-i-2
  cmb%=mod
  cmb*=pow(i+1,mod-2,mod)
  cmb%=mod
for i in range(1,n):
  tmp=i*(n-i)
  tmp*=m**2
  tmp%=mod
  tmp*=cmb
  tmp%=mod
  ans+=tmp
  ans%=mod
for i in range(1,m):
  tmp=i*(m-i)
  tmp*=n**2
  tmp%=mod
  tmp*=cmb
  tmp%=mod
  ans+=tmp
  ans%=mod
print(ans)

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

string str;

int main()
{
    cin >> str ;

    for (string::iterator itr = str.begin() + 1; itr != str.end(); itr++)
    {
        if (*itr == *(itr - 1))
        {
            cout << (int)(itr - str.begin()) << " " << (int)(itr - str.begin()) + 1 << endl ;
            return 0;
        }
    }

    if (str.size() > 2)
        for (string::iterator itr = str.begin() + 2; itr != str.end(); itr++)
        {
            if (*itr == *(itr - 2))
            {
                cout << (int)(itr - str.begin()) - 1 << " " << (int)(itr - str.begin()) + 1 << endl ;
                return 0;
            }
        }
    cout << "-1 -1" << endl ;
    return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>

#include <cmath>

const long long MOD = (long long)(pow(10,9)+7);
const int MAX = 200005;

using namespace std;
int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

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

void binom_init(){
    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; ////  inv[i] = div(1,i) =  (1/i) mod M;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long binom(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;
}

long long no_cond(int i, int j, int H, int W){
    
    return binom(H-i + W-j, H-i) % MOD;
    
}


int main() {
    
    int H = in(); int W = in(); int A = in(); int B = in();
    
    long long ans = 0;
    binom_init();
    
    int i = 1;
    while(H-A+1 -i >=1 && B + i <= W){
        ans += no_cond(1,1, (H-A+1)-i, B+i)%MOD * no_cond((H-A+1)-i, B+i,H,W) %MOD;
        i++;
    }

    cout << ans%MOD << endl;

    return 0;
    
}




Measured memory_bytes: 4992
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

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


int main(){
    int ans = 0, N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N, 0);
    for(int i = 0; i < N; ++i) cin >> A[i];
    int i = 0;
    while(A[i] != 2){
        ans++;
        B[i] = 1;
        i = A[i] - 1;
        if(B[i] == 1){
            cout << -1 << endl;
            return 0;
        }
    }
    ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------
struct edge{
  int from;
  int to;
  int cost;
};

int main(){
  int N,M;
  cin >> N >> M;
  vector<edge> G(M);
  for(int i=0; i<M; i++){
    cin >> G[i].from >> G[i].to >> G[i].cost;
    G[i].from--;
    G[i].to--;
  }
  vector<vector<int>> dist(N, vector<int> (N));
  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      if(i==j){
        dist[i][j] = 0;
      }else{
        dist[i][j] = inf;
      }
    }
  }
  for(int i=0; i<M; i++){
    chmin(dist[G[i].from][G[i].to],G[i].cost);
    chmin(dist[G[i].to][G[i].from],G[i].cost);
  }
  for(int k=0; k<N; k++){
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        chmin(dist[i][j], dist[i][k]+dist[k][j]);
      }
    }
  }
  int ans = 0;
  for(int i=0; i<M; i++){
    bool sh = false;
    for(int j=0; j<N; j++){
      if(dist[j][G[i].from]+G[i].cost == dist[j][G[i].to]) sh = true;
    }
    if(sh){
      ans++;
    }
  }
  cout << M-ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    string S; cin>>S;
    vector<int> M(S.length(),0);

    int c;
    // count R
    c=0;
    for (int i=0;i<S.length();i++) {
        if (S[i]=='R') c++;
        else {
            M[i-1] += c;
            c=0;
        }
    }

    // count L
    c=0;
    for (int i=S.length()-1;i>=0;i--) {
        if (S[i]=='L') c++;
        else {
            M[i+1] += c;
            c=0;
        }
    }

    for (int i=0;i<M.size()-1;i++) {
        if (M[i] == 0) continue;
        if (S[i]=='R' && S[i+1]=='L') {
            int n1 = (int)ceil((M[i]-1)/2.0);
            int n2 = (int)ceil((M[i+1]-1)/2.0);
            M[i] = M[i] - n1 + n2;
            M[i+1] = M[i+1] - n2 + n1;
        }
    }

    for (int i=0;i<M.size();i++) {
        cout << M[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1024
my $n = <STDIN>;
my @w;
for ($i=0; $i<$n; $i++) {
  my $input = <STDIN>;
  chomp $input;
  push(@w, $input);
}
my %uniq = map {$_ => 1} @w;
my $num = keys %uniq;
if ($num != $n) {
  $ret = "No\n";
} else {
  $ret = "Yes\n";
  for ($i=0; $i<$n-1; $i++) {
    if(substr($w[$i],-1,1) ne substr($w[$i+1],0,1)) {
    	$ret = "No\n";
        last;
    }
  }
}
print $ret;

Measured memory_bytes: 512
n=int(input())
h=[]
for i in range(n):
    a,b=map(int,input().split())
    h.append((a,b))
h.sort(key=lambda x: x[1])
s=0
for i in range(n):
    s+=h[i][0]
    if h[i][1]<s:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 31872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            switch (s) {
                case "Sunny":
                    Console.WriteLine("Cloudy");
                    break;
                case "Cloudy":
                    Console.WriteLine("Rainy");
                    break;
                case "Rainy":
                    Console.WriteLine("Sunny");
                    break;
                default:
                    break;
            }
        }
    }
}


Measured memory_bytes: 11092
n,m = map(int , input().split())

e = []

for i in range(m):
    a,b,c = map(int , input().split())
    e.append((a-1,b-1,c)) 

maxdis = [-float('inf') for i in range(n)]

maxdis[0] = 0
mugen = False

for i in range(2*n):
    for j in e:
        st,gl,cost = j
        if (maxdis[gl] < maxdis[st]+cost):
            maxdis[gl] = maxdis[st]+cost
            if (i >= n-1 and (gl == n-1)): 
                mugen = True 
                break
if mugen:
    print("inf")

else:
    print(maxdis[n-1])

Measured memory_bytes: 3316
from collections import Counter
def primeFactorize(n):
    fac = []
    if n < 2: return fac
    while n%2 == 0:
        n //= 2
        fac.append(2)
    for i in range(3,int(n**0.5)+1,2):
        while n%i == 0:
            n //= i
            fac.append(i)
    if n != 1: fac.append(n)
    return fac

n = int(input())
ans = 0
cnt = Counter(primeFactorize(n))
for v in cnt.values():
    c = 1
    while c <= v:
        ans += 1
        v -= c
        c += 1
print(ans)
# print(primeFactorize(n))
# print(cnt)

Measured memory_bytes: 9724
#include <iostream>
#include <algorithm>

#define VMAX 500000
#define MAX 200000
#define NIL -1

using namespace std;

struct Node {int p, l, r;};
struct Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";
  
  if( T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";
  
  cout << "[";
  
  for(i=0, c=T[u].l; c != NIL; i++, c=T[c].r){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL) rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p+1);
}

int main(int argc, const char * argv[]) {
  int i, j, d, v, c, l, r;
  cin >> n;
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    cin >> v >> d;
    for(j=0; j<d; j++){
      cin >> c;
      if(j==0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  
  for(i=0; i<n; i++){
    if(T[i].p == NIL) r = i;
  }
  
  rec(r, 0);
  
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



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

int cnt=0,K;
string s;

void dfs(string subs){
  if(cnt==K){
    cout << subs << endl;
  }
  else if(cnt<K){
    for(char c='a';c<='z';++c){
      if(s.find(subs+c)!=string::npos){
        cnt++;
        dfs(subs+c);
      }
    }
  }
}

int main(){
  cin>>s>>K;
  dfs("");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, M, K;

int main()
{
	in >> N >> M >> K;

	/*if ((K / M + 1) <= N && (K / M + 1)*M - K <= N) { out << "Yes" << std::endl; }
	else if ((K / N + 1) <= M && (K / N + 1)*N - K <= M) { out << "Yes" << std::endl; }
	else { out << "No" << std::endl; }*/
	rep(i, N + 1)
	{
		rep(j, M + 1)
		{
			auto sum = i*M + j*N - i*j*2;
			if (sum == K)
			{
				out << "Yes" << std::endl;
				return 0;
			}
		}
	}
	out << "No" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a;
	char s[100000];
	scanf("%d", &a);
	scanf("%s", &s);

	int x = a;

	for (int i = 1; i < x; i++) {
		if (s[i - 1] == s[i]) {
			a--;
		}
	}

	printf("%d", a);

	return 0;
}

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

using namespace std;

typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;
typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
int main()
{
  int x,a,b; si(x);si(a);si(b);
  if(abs(x-a)<abs(x-b)) puts("A");
  else puts("B");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <numeric>
#define ll long long
using namespace std;
int main() {
  ll X;
  bool f=false;
  cin>>X;
  if(X%100==0) cout<<"1"<<endl;
  else{
    int a=X/100,b=X%100;
    for(int i=0;i<=X%100;i++){
      for(int j=0;i+2*j<=X%100;j++){
        for(int k=0;i+j*2+k*3<=X%100;k++){
          for(int l=0;i+j*2+3*k+l*4<=X%100;l++){
            for(int m=0;i+j*2+3*k+l*4+m*5<=X%100;m++){
              if(i+j*2+3*k+l*4+m*5==X%100&&i+j+k+l+m<=X/100){
                cout<<"1"<<endl;
                f=true;
                break;
              }
            }
            if(f) break;
          }
            if(f) break;
        }
          if(f) break;
      }
        if(f) break;
    }
    if(f==false) cout<<"0"<<endl;
  }
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int>A(N,0);
  vector<int>B(N,0);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  if(K>50){
    for(int i=0;i<N-1;i++){
      cout<<N<<" ";
    }
    cout<<N<<endl;
    return 0;
  }
  
  while(K){
      for(int i=0;i<N;i++){
          B[i]=0;
      }
      for(int i=0;i<N;i++){
          int left=max(0,i-A[i]);
          int right=min(N,i+A[i]);
          B[left]++;
          if(right+1<N){
              B[right+1]--;
          }
      }
      for(int i=1;i<N;i++){
          B[i]+=B[i-1];
      }
      for(int i=0;i<N;i++){
          A[i]=B[i];
      }
      K--;
  }
  
  for(int i=0;i<N-1;i++){
      cout<<A[i]<<" ";
  }
  cout<<A[N-1]<<endl;
  return 0;
}


Measured memory_bytes: 4816
#include<iostream>
using namespace std;
int main()
{
  int n,w;
  cin>>n>>w;
  int * wt= new int[n];
  int * val=new int[n];
  for(int i=0;i<n;i++)
  {  cin>>wt[i]>>val[i];
  }
  long long  dp[n+1][w+1];
  
  for(int item=0;item<=n;item++)
  {
    for(int weight=0;weight<=w;weight++)
    {
      if(weight==0||item==0)
      {
        dp[item][weight]=0;
      }
      else if(wt[item-1]<=weight)
      {   
        dp[item][weight]=std::max(dp[item-1][weight],val[item-1]+dp[item-1][weight-wt[item-1]]);
      }
      else
      { dp[item][weight]=dp[item-1][weight];
      }
      
  
    }
  }
  cout<<dp[n][w]<<endl;
  
  
  
  
 return 0;
  
}

Measured memory_bytes: 82420
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1e5+10;
int T;
int main()
{
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    int res=0;
    if(K<=A)
        res=K;
    else if(K<=A+B)
        res=A;
    else
        res=A-(K-A-B);
    cout<<res<<endl;
}

Measured memory_bytes: 3592
def main():
    S = input()
    if (S.count("N") >= 1 and S.count("S") >= 1 and S.count("E") == 0 and S.count("W") == 0)\
       or (S.count("N") == 0 and S.count("S") == 0 and S.count("E") >= 1 and S.count("W") >= 1)\
       or (S.count("N") >= 1 and S.count("S") >= 1 and S.count("E") >= 1 and S.count("W") >= 1):
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9044
#include <stdio.h>
int main (void){
    int data[3];
    int flag=0;
    int loop1;
    scanf("%d %d %d",&data[0],&data[1],&data[2]);
    if((data[0]+data[1]+data[2])%2!=0)flag=1;
    int half=(data[0]+data[1]+data[2])/2;
    //1つでもhalfを超えたらあうと
    for(loop1=0;loop1<3;loop1++){
        if(half<data[loop1])flag=1;
    }
    for(loop1=0;loop1<2;loop1++){
        int temp;
        if(data[loop1]<data[loop1+1]){
            temp=data[loop1];
            data[loop1]=data[loop1+1];
            data[loop1+1]=temp;
            loop1=-1;
        }
    }
    if(data[0]!=(data[1]+data[2])){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
//
// Created by pureZer on 2019-07-20.
//
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 99999999;
const double eps = 1e-6;
const int maxn = 2e5+5;

int N;
struct Node {
    int id, num;
    bool operator < (const Node &n1) const {
        if(num != n1.num) return num > n1.num;
        return id < n1.id;
    }
} n[maxn];

int main(){
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 1; i <= N; ++i) {
        cin >> n[i].num;
        n[i].id = i;
    }
    sort(n+1, n+1+N);
    for(int i = 1; i <= N; ++i) {
        int j = 1;
        while(n[j].id == i) ++j;
        cout << n[j].num << endl;
    }
    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
const string ok = "Yes";
const string ng = "No";

int main(){
    string s;
    cin>>s;
    int bg=0;
    int ed=s.size()-1;
    int ret=0;
    while(bg<ed){
        int l=0;
        int r=0;
        while(bg<ed&&s[bg]=='x'){
            bg++;l++;
        }
        while(bg<ed&&s[ed]=='x'){
            ed--;r++;
        }
        if(bg<ed){
            if(s[bg]!=s[ed]){
                cout<<-1<<endl;
                return 0;
            }
            else{
                ret+=abs(r-l);
            }
        }
        if(bg==ed){
            if(s[bg]!='x')ret+=abs(r-l);
        }
        bg++;
        ed--;
    }
    cout<<ret<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
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(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int S;
  cin >> S;
  int h, m;
  m = S / 60;
  S = S % 60;
  h = m / 60;
  m = m % 60;
  cout << h << ":" << m << ":" << S << endl;
}



Measured memory_bytes: 3112
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ma = sc.nextInt();
        int mb = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        int c[] = new int[n];
        int suma = 0;
        int sumb = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();
            suma += a[i];
            sumb += b[i];
        }

        suma += 150;
        sumb += 150;
        // dp[i][j][k] := i個数目まで商品を使って(j,k)の品物を作るのに必要な最小値
        int dp[][][] = new int[n][suma][sumb];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < suma; j++) {
                for (int j2 = 0; j2 < sumb; j2++) {
                    // 大きい値で初期化しておく
                    dp[i][j][j2] = Integer.MAX_VALUE / 2;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            // 一つの商品だけを使う場合
            dp[i][a[i]][b[i]] = c[i];
        }
        for (int i = 0; i < n; i++) {
            dp[i][0][0] = 0;
        }

        for (int i = 1; i < n; i++) {
            // i番目までの商品をを使う
            dp[i][a[i]][b[i]] = c[i];
            int aa = a[i];
            int bb = b[i];
            for (int j = 0; j < suma; j++) {

                for (int k = 0; k < sumb; k++) {
                    dp[i][j][k] = Math.min(dp[i][j][k], dp[i - 1][j][k]);
                    if (j - aa < 0) {
                        continue;
                    }
                    if (k - bb < 0) {
                        continue;
                    }
                    dp[i][j][k] = Math.min(dp[i][j][k], dp[i - 1][j - aa][k - bb] + c[i]);
                }
            }
        }
        int ans = Integer.MAX_VALUE / 2;
        int cnt = 1;
        while (true) {
            if (cnt * ma >= suma || cnt * mb >= sumb) {
                break;
            }
            ans = Math.min(ans, dp[n - 1][cnt * ma][cnt * mb]);
            cnt++;
        }
        if (ans == Integer.MAX_VALUE / 2) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
        sc.close();
    }
}


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

// right -> turn 90 deg. right;
// left  -> turn 90 deg. left;

int map[101][101];


int main(){
    int m, n;
    while (1){
	int x = 1, y = 1, dir = 0;
	cin >> m >> n;
	if (m == 0 && n == 0) break;
	string command;
	while (1){
	    cin >> command;
	    if (command == "STOP") break;

	    if (command == "RIGHT"){
		dir++;
		if (dir == 4) dir = 0;
	    }
	    else if (command == "LEFT"){
		dir--;
		if (dir == -1) dir = 3;
	    }

	    else {
		int w;
		cin >> w;
		if (command == "FORWARD"){
		    switch (dir){
		    case 0: y += w; break;
		    case 1: x += w; break;
		    case 2: y -= w; break;
		    case 3: x -= w; break;
		    }
		    if (x > m) x = m;
		    if (y > n) y = n;
		    if (x < 1) x = 1;
		    if (y < 1) y = 1;
		}
		else if (command == "BACKWARD"){
		    switch (dir){
		    case 0: y -= w; break;
		    case 1: x -= w; break;
		    case 2: y += w; break;
		    case 3: x += w; break;
		    }
		    if (x > m) x = m;
		    if (y > n) y = n;
		    if (x < 1) x = 1;
		    if (y < 1) y = 1;
		}
//		cout << x << " " << y << " " << dir << " " << w << endl;;
	    }

	}
	
	cout << x << " " << y << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>

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

typedef long long ll;

using namespace std;

int main() {
    
    int x;
    cin >> x;
    int ans=1;
    FOR(b, 2, 32){
        FOR(p, 2, 10){
            if((pow(b, p)>ans)&&(pow(b, p)<=x)){
                ans = pow(b, p);
            }
        }
    }
    
    cout << ans << endl;
    
    
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n; string s;
int vv[111111];
int ch[111111];

void finish(void)
{
	int i;
	for(i=0 ; i<n ; i++)
	{
		if(vv[i]==0) cout<<"S";
		else cout<<"W";
	}
	exit(0);
}

void tryout(int s, int e)
{
	vv[0]=s; vv[1]=e; int i;
	for(i=2 ; i<n ; i++) vv[i]=(4-vv[i-2]-vv[i-1]-ch[i-1])%2;
	if((vv[n-2]+vv[n-1]+vv[0]+ch[n-1])%2==0 && (vv[n-1]+vv[0]+vv[1]+ch[0])%2==0) finish();
}

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n>>s; int i;
	for(i=0 ; i<n ; i++) if(s[i]=='x') ch[i]=1;
	tryout(0,0); tryout(0,1); tryout(1,0); tryout(1,1);
	cout<<"-1"; return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 1360
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

const int MOD = 1e9 + 7;

int mult(int a, int b) {
  return (a * 1ll * b) % MOD;
}

int b_pow(int a, int b) {
  if (!b) {
    return 1;
  }
  if (b & 1) {
    return mult(b_pow(a, b - 1), a);
  }
  return b_pow(mult(a, a), b >> 1);
}

const int N = 2e5 + 10;
int f[N], rf[N];

int C(int n, int k) {
  return mult(f[n], mult(rf[k], rf[n - k]));
}

vector<int> g[N];
int dp[N], sz[N], up[N], flex[N];

void dfs(int v, int p = 0) {
  dp[v] = 1;
  up[v] = 1;
  int was = 0;
  for (auto u : g[v]) {
    if (u != p) {
      dfs(u, v);
      dp[v] = mult(dp[v], mult(C(was + sz[u], sz[u]), dp[u]));
      was += sz[u];
    }
  }
  sz[v] = was + 1;
}

void dfs2(int v, int p = 0) {
  up[v] = 1;
  if (p != 0) {
    up[v] = mult(up[p], dp[p]);
    up[v] = mult(up[v], b_pow(C(sz[p] - 1, sz[v]), MOD - 2));
    up[v] = mult(up[v], b_pow(dp[v], MOD - 2));
    up[v] = mult(up[v], C(sz[1] - sz[v] - 1, sz[1] - sz[p]));
  }
  for (auto u : g[v]) {
    if (u != p) {
      dfs2(u, v);
    }
  }
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = mult(f[i - 1], i);
  }
  for (int i = 0; i <= n; i++) {
    rf[i] = b_pow(f[i], MOD - 2);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1);
  dfs2(1);
  cout << dp[1] << '\n';
  for (int i = 2; i <= n; i++) {
    int cur = dp[i], was = sz[i] - 1, new_sz = n - sz[i];
    cur = mult(cur, mult(C(was + new_sz, new_sz), up[i]));
    cout << cur << '\n';
  }
} 

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli pp[200];

void func(long long X, long long N, std::vector<long long> p){

    SORT(p);

    REP(i,0,N){
        pp[p[i]]=1;
    }

    vector<lli> y;
    REP(i,-100,300){
        y.push_back(i);
    }

    lli ans = INF;
    lli ansNum = -INF;

    REP(i,0,y.size()){
        if(y[i]>=0 && pp[y[i]]==1)continue;
        if(ans > abs(X-y[i])){
            ans = abs(X-y[i]);
            ansNum = y[i];
        }
    }

    cout<<ansNum<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    func(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3700
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    map<string, int> M;
    for(int i = 0; i < n; i++){
        string S;
        cin >> S;
        if (M.find(S) == M.end()){
            M.insert(make_pair(S, 1));
        }
        else M[S]++;
    }
    int num = 0;
    vector<string> ANS;
    map<string, int>::iterator it;
    for(it = M.begin(); it != M.end(); ++it){
        if (it->second < num)continue;
        else if (it->second == num){
            ANS.push_back(it->first);
        }
        else{
            num = it->second;
            ANS.clear();
            ANS.emplace_back(it->first);
        }
    }
    sort(ANS.begin(), ANS.end());
    for(int i = 0; i < ANS.size(); i++)cout << ANS[i] << endl;
    return 0;
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int Sweets_cnt;
  string Color; 
  int flg = 0;
 
  cin >> N;
  // ここにプログラムを追記
  while(Sweets_cnt < N){
    cin >> Color;
    if(Color == "Y"){
      flg = 1;
    }
    Sweets_cnt++;
  }
  if(flg){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;
int M=10;
map<ll,vector<ll> > memo;

int main(void){
  ll N;cin >> N;
  ll sum = 0;
  for(int i=1; i<=sqrt(N);i++){
    if(N%i!=0)continue;
    ll n = N/i - 1;
    ll m = i-1;
    if(n!=0 && N/n == N%n) sum += n;
    if(m!=0 && n!=m &&  N/m == N%m) sum+= m;
  }
  cout << sum <<  endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a, b, result;
  char op;

  for (; scanf("%d %c %d", &a, &op, &b), op != '?'; ) {
    switch (op) {
      case '+': result = a + b; break;
      case '-': result = a - b; break;
      case '*': result = a * b; break;
      case '/': result = a / b; break;
    }

    printf("%d\n", result);
  }

  return 0;
}

Measured memory_bytes: 600
import Data.List
f k x = if k == fromEnum 'z' +1 then "None" else if null x then [toEnum k] else if head x == toEnum k then f (k+1) (tail x) else [toEnum k]
main=getLine>>=putStrLn.(\x-> if null x then "a" else f (fromEnum 'a') x).sort.nub

Measured memory_bytes: 4988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    if(s < t)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


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

int main() {
	int N;
	double goukei=0, x, x2, x3, x4, x5, x6, x7, x8, x9, x10;
	string u;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x >> u;
		if (u == "JPY") {
			goukei += x;
		}
		else {
			goukei += x * 380000.0;
		}
	}
	cout << goukei << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>

using namespace std;

const int SZ = 365;
const int K = 26;
int c[K];
int s[SZ][K];
int d;

vector<int> ans;

int get_result() {
    int res = 0;
    vector<int> last(K, -1);
    for (int i = 0; i < d; ++i) {
        res += s[i][ans[i]];
        last[ans[i]] = i;
        for (int j = 0; j < 26; ++j) {
            res -= c[j] * (i - last[j]);
        }
    }
    return res;
}

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

    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    cin >> d;
    for (int i = 0; i < K; ++i) {
        cin >> c[i];
    }
    for (int i = 0; i < d; ++i) {
        for (int j = 0; j < K; ++j) {
            cin >> s[i][j];
        }
    }
    vector<int> last(K, -1);
    for (int i = 0; i < d; ++i) {
        vector<double> x;
        for (int j = 0; j < K; ++j) {
            x.push_back((double) s[i][j] * s[i][j] * s[i][j] * c[j] * (i - last[j]) * c[j] * (i - last[j]));
        }

        double sum = 0;
        for (int j = 0; j < K; ++j) {
            sum += x[j];
        }
        for (int j = 0; j < K; ++j) {
            x[j] /= sum;
        }

        double prob = (double) (rand() % RAND_MAX) / (double) RAND_MAX;
        double cur = 0;
        for (int j = 0; j < K; ++j) {
            if (cur + x[j] <= prob) {
                cur += x[j];
                continue;
            }
            ans.push_back(j);
            last[j] = i;
            break;
        }
    }
//    cout << get_result() << "\n";

    for (auto u : ans) {
        cout << u + 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const modulo = 998244353;
std::map<std::string,int> dp, dp2;
int solve(std::string s);

int solve2(std::string s) {
  if(s.size() == 1)
    return 0;
  if(dp2.find(s) == dp2.end()) {
    int result = 0;
    for(int i = 1; i < s.size(); i++) {
      if(s.size() % i == 0) {
        std::string part;
        part.resize(i);
        for(int j = 0; j < i; j++)
          part[j] = '1';
        for(int j = 0; j < s.size(); j++)
          part[j % i] = std::min(part[j % i], s[j]);
        result += solve(part);
        if(modulo <= result)
          result -= modulo;
      }
    }
    dp2[s] = result;
    return result;
  } else
    return dp2[s];
}

int solve(std::string s){

  if(s.size() == 1)
    return s[0] - '0' + 1;
  else if(dp.find(s) == dp.end()){
    std::vector<int> pref(s.size() + 1);
    pref[0] = 1;
    for(int i = 1;i <= s.size(); i++) {
      pref[i] = 1LL * pref[i - 1] * (s[i - 1] - '0' + 1) % modulo;
      for(int j = 1; j <= i; j++){
        pref[i] += 1LL * pref[j - 1] * solve2(s.substr(j - 1, i - j + 1)) % modulo;
        if(modulo <= pref[i])
          pref[i] -= modulo;
      }
    }
    dp[s] = pref.back();
    return pref.back();
  } else
    return dp[s];
}

int main() {
  std::string s;
  std::cin >> s;
  std::cout << solve(s);
  return 0;
}


Measured memory_bytes: 10644
s = list(input())
n = len(s)
data = [0 for i in range(n)]

rcounter = 0
lcounter = 0
for i in range(n):
    if s[i] == "R" and s[i+1] == "L":
        rcounter += 1
        data[i] = rcounter
        rcounter = 0
    elif s[i] == "R":
        rcounter += 1
for i in range(n):
    if s[-i] == "L" and s[-i-1] == "R":
        lcounter += 1
        data[-i] = lcounter
        lcounter = 0
    elif s[-i] == "L":
        lcounter += 1

i = 0
while i < n-1:
    if data[i] != 0:
        if (data[i] + data[i+1]) % 2 == 0:
            data[i] = (data[i]+data[i+1])//2
            data[i+1] = data[i]
        else:
            if data[i] > data[i+1]:
                if (data[i]-1)%2 == 0:
                    data[i] = (data[i]+data[i+1]+1)//2
                    data[i+1] = data[i]-1
                else:
                    data[i+1] = (data[i]+data[i+1]+1)//2
                    data[i] = data[i+1]-1
            else:
                if (data[i+1]-1)%2 == 0:
                    data[i+1] = (data[i]+data[i+1]+1)//2
                    data[i] = data[i+1] - 1
                else:
                    data[i] = (data[i]+data[i+1]+1)//2
                    data[i+1] = data[i]-1
        i += 2
    else:
        i += 1

for i in range(n):
    if i != n-1:
        print(data[i],end=" ")
    else:
        print(data[i])

Measured memory_bytes: 5680
//22
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

struct S{
  int t,v,r;
  bool operator<(S a)const{
    return v<a.v;
  }
};

int main(){
  for(int n;cin>>n,n;){
    vector<S> v;
    queue<S> que[2];
    for(int i=0;i<n;i++){
      S p;
      cin>>p.v>>p.r;
      p.r*=2;
      p.t=p.v;
      v.push_back(p);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++){
      que[0].push(v[i]);
    }
    int t;
    while(!que[0].empty()||!que[1].empty()){
      int x=que[0].empty()||(!que[1].empty()&&que[0].front().t>que[1].front().t);
      t=que[x].front().t;
      vector<S> b;
      while(!que[x].empty()&&que[x].front().t<=t){
	S c=que[x].front();
	if(--c.r){
	  c.t=t+c.v;
	  b.push_back(c);
	}
	que[x].pop();
      }
      sort(b.begin(),b.end());
      for(int i=0;i<b.size();i++){
	que[!x].push(b[i]);
      }
    }
    cout<<t<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

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

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

//const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

// Function to return 
// maximum XOR subset 
// in set[] 
ll maxSubarrayXOR(ll set[], ll n) 
{ 
    // Initialize index of 
    // chosen elements 
    ll index = 0; 
  
    // Traverse through all 
    // bits of lleger  
    // starting from the most 
    // significant bit (MSB) 
    for (ll i = 60; i >= 0; i--) 
    { 
        // Initialize index of 
        // maximum element and 
        // the maximum element 
        ll maxInd = index; 
        ll maxEle = INT_MIN; 
        for (ll j = index; j < n; j++) 
        { 
            // If i'th bit of set[j] 
            // is set and set[j] is  
            // greater than max so far. 
            if ( (set[j] & ((ll)1 << i)) != 0  
                     && set[j] > maxEle ) 
                maxEle = set[j], maxInd = j; 
        } 
  
        // If there was no  
        // element with i'th 
        // bit set, move to 
        // smaller i 
        if (maxEle == INT_MIN) 
        continue; 
  
        // Put maximum element 
        // with i'th bit set  
        // at index 'index' 
        std::swap(set[index], set[maxInd]); 
  
        // Update maxInd and  
        // increment index 
        maxInd = index; 
  
        // Do XOR of set[maxIndex] 
        // with all numbers having 
        // i'th bit as set. 
        for (ll j=0; j<n; j++) 
        { 
            // XOR set[maxInd] those 
            // numbers which have the 
            // i'th bit set 
            if (j != maxInd && 
               (set[j] & ((ll)1 << i)) != 0) 
                set[j] = set[j] ^ set[maxInd]; 
        } 
  
        // Increment index of 
        // chosen elements 
        index++; 
    } 
  
    // Final result is  
    // XOR of all elements 
    ll res = 0; 
    for (ll i = 0; i < n; i++) 
        res ^= set[i]; 
    return res; 
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,ans=0;
  std::cin>>n;

  std::vector<ll> a(n),check;

  rep(i,0,n){
    std::cin>>a[i];
    ans=(ans^a[i]);
  }

  ll set[100000]={0};

  rep(i,0,60)if(!((ans>>i)&1))check.push_back(i);

  rep(i,0,n){
    ll temp=0;
    rep(j,0,check.size()){
      if((a[i]>>check[j])&1)temp+=((ll)1<<check[j]);
    }
    set[i]=temp;
  }

  ans+=(maxSubarrayXOR(set,100000))<<1;

  std::cout<<ans;

  return 0;
}


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

int main() {
    int n,m;
    while(cin >> n >> m, n) {
        vector<vector<bool>> relation(n, vector<bool>(n));
        for(int i=0; i<m; ++i) {
            int a, b;
            cin >> a >> b;
            a--; b--;
            relation[a][b] = relation[b][a] = true;
        }
        vector<bool> friends(n);
        for(int i=0; i<n; ++i) {
            if(relation[0][i]) {
                friends[i] = true;
                for(int j=0; j<n; ++j) {
                    if(relation[i][j]) {
                        friends[j] = true;
                    }
                }
            }
        }
        friends[0] = false;
        cout << count(friends.begin(), friends.end(), true) << endl;
    }
}

Measured memory_bytes: 3120