akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
const ll C = 1e9+7;

int main(){
    // N:島の数, M:入力の数
    int N, M;
    cin >> N >> M;
    map<pair<int, int>, bool> m;

    for(int i=0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        m[make_pair(a, b)] = true;
        m[make_pair(b, a)] = true;
    }

    bool flag = false;

    for(int i=2; i<N; i++) {
        if(m[make_pair(1, i)] && m[make_pair(i, N)]) flag = true;
    }
    cout << (flag ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 41060
#include<iostream>
    #include<cstring>
    #include<cstdlib>
    #include<cstdio>
    #include<algorithm>
    #define ll long long
    #define MOD(x) ((x)>=mod?(x)-mod:(x))
    using namespace std;
    const int maxn=5010, inf=1e9, mod=1e9+7;
    struct edge{int too, pre;}e[maxn<<1];
    int n, tot, x, y;
    int last[maxn], size[maxn], f[maxn][maxn], g[maxn], tmp[maxn];
    template<typename T>
    inline void read(T &k)
    {
    	int f=1; k=0; char c=getchar();
    	while(c<'0' || c>'9') c=='-'&&(f=-1), c=getchar();
    	while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
    	k*=f;
    }
    inline void add(int x, int y){e[++tot]=(edge){y, last[x]}; last[x]=tot;}
    void dfs(int x, int fa)
    {
    	size[x]=1; f[x][1]=1;
    	for(int i=last[x], too;i;i=e[i].pre)
    	if((too=e[i].too)!=fa)
    	{
    		dfs(too, x);
    		for(int j=1;j<=size[x]+size[too];j++) tmp[j]=0;
    		for(int j=1;j<=size[x];j++)
    		{
    			for(int k=0;k<=size[too];k++)
    			tmp[j+k]=(tmp[j+k]+1ll*f[x][j]*f[too][k])%mod;
    		}
    		for(int j=1;j<=size[x]+size[too];j++) f[x][j]=tmp[j];
    		size[x]+=size[too];
    	}
    	for(int j=2;j<=size[x];j+=2)
    	f[x][0]-=1ll*f[x][j]*g[j]%mod, f[x][0]=MOD(f[x][0]+mod);
    }
    int main()
    {
    	read(n);
    	for(int i=1;i<n;i++) read(x), read(y), add(x, y), add(y, x);
    	g[0]=1; for(int i=2;i<=n;i+=2) g[i]=1ll*g[i-2]*(i-1)%mod;
    	dfs(1, 0);
    	printf("%d\n", mod-f[1][0]);
    }

Measured memory_bytes: 97280
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
 
int main() {
  ioso
  #ifndef ONLINE_JUDGE
  ffe
  #endif
  ll n; cin >> n;
  ll a[100011];
 // ll cn=0;
  for(int i=1;i<=n;i++) {
    cin >> a[i];
  }
  ll cn =0;
  for(int i=1;i<=n;i++) {
    for(int j=i+1;j<=n;j++) {
      for(int k=j+1;k<=n;k++) {
        if(a[i]!=a[j] and a[j]!=a[k] and a[k]!=a[i]) {
          if(a[i]+a[j]>a[k] and a[j]+a[k]>a[i] and a[i]+a[k]>a[j])
          {
            cn++;
          }
        }
         
      }
    }
  }

  cout << cn << endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, i, j, k;
	vector<long long> f(87);
	f[0] = 2;
	f[1] = 1;
	for (i = 2; i < 87; i++) f[i] = f[i - 1] + f[i - 2];

	cin >> n;
	cout << f[n] << "\n";


	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h[100005];
	vector<vector<int>> graph(100005);
	//set<int> s;
	int n,m,a,b,c=0;
	cin >> n >> m;

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

	for (int i = 1; i <= m; i++) {
		cin >> a >> b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	for (int i = 1; i <= n; i++) {
		if (graph[i].empty()) c++;
		else {
			bool flag = 1;
			for (int e : graph[i]) {
				if (h[i] <= h[e]) {flag = 0; break;}
			}
			if (flag) c++;
		}
	}
	cout << c << "\n";

	return 0;
}

Measured memory_bytes: 8736
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int h,w;
    cin>>h>>w;
    string s;
    rep(i,h) {
        cin>>s;
        for(char c:s) cout<<c;
        cout<<endl;
        for(char c:s) cout<<c;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def count_one(bit):
    n = 0
    while bit:
        n += (1 & bit)
        bit = bit >> 1
    return n

def main():
    N = I()
    F_bit = []
    P = []
    ans = -inf
    for i in range(N):
        f = LS()
        f_bit = int(''.join(f), base=2)
        F_bit.append(f_bit)

    for _ in range(N):
        p = LI()
        P.append(p)

    for bit in range(1, 1<<10):
        cur_ans = 0
        for i in range(N):
            i_bit = F_bit[i]
            ci = count_one(bit & i_bit)
            cur_ans += P[i][ci]
        ans = max(ans, cur_ans)
    print(ans)

    '''
    for i in range(N):
        n_open = n_open_time[i]
        i_max_prof = -1
        ix_max_prof = 0
        for j in range(n_open+1):
            if i_max_prof <= P[i][j]:
                i_max_prof = P[i][j]
                ix_max_prof = j
        cur_ans += i_max_prof
        selected_ix.add(ix_max_prof)
        if n_open > 0:
            least_ans = max(least_ans, max(P[i][1:n_open+1]))
    if len(selected_ix) == 1 and 0 in selected_ix:
        print(least_ans)
    else:
    '''

main()



Measured memory_bytes: 68824
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll gcd(ll a, ll b){ 
        if (a == 0) 
            return b;  
        return gcd(b % a, a);  
    } 
    ll lcm(ll a, ll b)  
    {  
        return (a*b)/gcd(a, b);  
    }  

    int main()
    {
    ll n,k;cin>>n>>k;
    ll max=(n-2)*(n-1)/2;
    if(k>max){cout<<-1;return 0;}
    vector<pair<int,int> > a;
    for(ll i=2;i<=n;i++)
    {
        a.push_back(make_pair(1,i));
    }
    ll diff=max-k;
    for(ll i=2;i<n;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(diff)
            {a.push_back(make_pair(i,j));diff--;}
            else break;
        }
    }
    cout<<a.size()<<"\n";
    for(auto i:a)
    {
        cout<<i.first<<" "<<i.second<<"\n";
    }
    return 0;  
    }


Measured memory_bytes: 384
a = []
for i in range(5):
  a.append(int(input()))
b = [i%10 for i in a]
c = [9 if i == 0 else i for i in b]
last = c.index(min(c))
fin = a[last]
del a[last]
del b[last]
d = [a[i] - b[i] if b[i] == 0 else a[i]-b[i] + 10 for i in range(4)]
print(sum(d)+ fin)

Measured memory_bytes: 3064
from sys import stdin
input = stdin.readline
def nCr(n,r):
    return fact[n]*(inv[n-r]%M)*(inv[r]%M)
M = 1000000007
k = int(input())
s = len(input().strip())
t = k+s
fact = [1]
p25 = [1]
for i in range(1,t+1):
    fact += [(fact[-1] * i)%M]
    if i<=k:
        p25  += [(p25[-1] * 25) % M]

inv = [1]*(t+1)
inv[t] = pow(fact[t], M-2, M)
for i in range(t-1, -1, -1):
    inv[i] = inv[i+1] * (i+1) % M


res = 0
for i in range(k+1):
    res+=nCr(t,t-i)*p25[i]
    res%=M
print(res)

Measured memory_bytes: 205016
a,b = map(int,input().split())

if min(a,b) == 1:
    print(1)
    exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)
    if temp!=1:
        arr.append(temp)
    if arr==[]:
        arr.append(n)
    return arr

A = factorization(a)
B = factorization(b)
ans = len(set(A) & set(B))
print(ans+1)



Measured memory_bytes: 63252
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int a, b;
    cin >> a >> b;
    cout << max(a - 2*b, 0) <<"\n";
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N, M = map(int, input().split())
cntX = Counter(map(int, input().split()))

cntMod = Counter()
cntDup = Counter()
for x, c in cntX.items():
    cntMod[x % M] += c
    cntDup[x % M] += c // 2

ans = 0
for n in range(M // 2 + 1):
    m = (M - n) % M
    if m == n:
        ans += cntMod[n] // 2
        continue

    cnt = min(cntMod[n], cntMod[m])
    cntMod[n] -= cnt
    cntMod[m] -= cnt

    ans += cnt
    ans += min(cntMod[n] // 2, cntDup[n]) + min(cntMod[m] // 2, cntDup[m])
print(ans)


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

int main(){
    string s;
    cin>>s;
    ll cnt=0;
    rep(i,3){
        if(s[i]=='R') cnt++;
    }
    if(s=="RSR") cout<<1<<endl;
    else cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N, X, T;
  cin >> N >> X >> T;
  ll ans = 0;
  while (N > 0) {
    N -= X;
    ans += T;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<vector>
using namespace std;
#define ll long long
int main()
{
    int a,p;
    while(~scanf("%d%d",&a,&p))
    {
        int sum=a*3+p;
        printf("%d\n",sum/2);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n;
int f(int a[])
{
 int t = a[0];
 for(int i = 0; i < n; i++)
 {
  if(t < a[i]) t = a[i];
 }
 return t;
}

int s(int a[])
{
 int t = 0;
 for(int i = 0; i < n; i++)
 {
  t += a[i];
 }
 return t;
}

int main()
{
 scanf("%d", &n);
 int i;
 int a[n];
 for(i = 0; i < n; i++)
  scanf("%d", a + i);
 printf("%d\n", s(a) - f(a) / 2);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  ll a,b,c;
  cin >> a >> b >>c ;
  ll arr[3];
  arr[0]=a;
    arr[1]=b;
      arr[2]=c;
  sort(arr,arr+3);
  ll k;
  cin >> k;
  while(k){
    arr[2]*=2;
    k--;
  }
  ll ans = arr[0]+arr[1]+arr[2];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int i, n, m, k, l, x, y, a[1 << 15][2];

int main() {
  for(scanf("%d", &n); i < n; i++) {
    for(scanf("%d", &m); m--;) {
      scanf("%d%d", &x, &y);
      a[i][y] |= 1 << x - 1;
    }
  }
  l = (1 << n) - 1;
  for(x = 1; x <= l; x++) {
    for(i = 0; i < n && !((x >> i) & 1 && (a[i][0] & x || a[i][1] & l - x)); i++);
    if(i == n) {
      y = __builtin_popcount(x);
      if(y > k)
        k = y;
    }
  }
  printf("%d\n", k);
  return 0;
}


Measured memory_bytes: 128
import itertools
import math
n = int(input())
ans = 0
data = []
per = itertools.permutations(range(n))
for i in range(n):
    data.append(list(map(int, input().split())))
for i in per:
    for k in range(n):
        if  k == n - 1:
            break
        ans += math.sqrt(((data[i[k]][0] - data[i[k+1]][0]) ** 2) + ((data[i[k]][1] - data[i[k+1]][1]) ** 2))
print(ans / math.factorial(n))

Measured memory_bytes: 3064
from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]###(*)
  ###これまでのやつに与えたダメージは引き継がれるものとする
  d = ds[i]
  if d>=h:
    continue###すでに体力以上のダメージを与えた敵
  h -= d###ダメージを与える
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  ###(*)のせいで, 2Dよりも向こう側にも、今考えたダメージの影響が
  ###出てしまうので. それを打ち消すために与えるダメージを引いておく
  b += times
print(b)


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

int main() {
	char S[3];
	cin >> S[0] >> S[1] >> S[2];
	int cnt = 0;
	int tmp = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'R') {
			tmp += 1;
		}
		else {
			tmp = 0;
		}
		cnt = max(tmp, cnt);
	}
	cout << cnt << endl;
}

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

const long MOD = 1e9 + 7;

int main() {
    int N, M; cin >> N >> M;
    vector<bool> ok_step(N+1, true);
    int a;
    for (int i = 0; i < M; i++) {
        cin >> a;
        ok_step[a] = false;
    }
    vector<long> dp(N+1, 0);
    dp[0] = 1;
    for (int n = 1; n <= N; n++) {
        if (ok_step[n]) {
            if (n == 1) dp[n] = 1;
            else dp[n] = (dp[n-1] + dp[n-2]) % MOD;
            if (dp[n] == 0) {
                dp[N] = 0;
                break;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}


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

using namespace std;

const long long inf = 1e18;
const int mod = 1e9 + 7;

inline void add(long long& x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}

vector<pair<long long, long long>> dijkstra(int S, vector<vector<pair<int, long long>>>& g) {
  vector<pair<long long, long long>> dis(g.size(), {inf, 0});
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
  q.push({0, S});
  dis[S] = {0, 1};
  vector<bool> vis(g.size());
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = true;
    for (auto& e : g[u]) {
      int v = e.first, w = e.second;
      if (dis[v].first > dis[u].first + w) {
        dis[v] = dis[u];
        dis[v].first += w;
        q.push({dis[v].first, v});
      } else if(dis[v].first == dis[u].first + w) {
        add(dis[v].second, dis[u].second);
      }
    }
  }
  return dis;
}

long long square(long long n) {
  n %= mod;
  return n * n % mod;
}

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);
  int n, m, S, T;
  cin >> n >> m >> S >> T;
  vector<vector<pair<int, long long>>> g(n + 1);
  vector<tuple<int, int, int>> edges;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    edges.emplace_back(u, v, w);
    edges.emplace_back(v, u, w);
  }
  auto dis1 = dijkstra(S, g), dis2 = dijkstra(T, g);
  long long ans = dis1[T].second, L = dis1[T].first;
  ans = ans * ans % mod;
  for (int i = 1; i <= n; i++) {
    if (dis1[i].first + dis2[i].first == L && dis1[i].first * 2 == L) {
      ans = ((ans - square(dis1[i].second * dis2[i].second)) % mod + mod) % mod;
    }
  }
  for (auto e : edges) {
    int u, v, w;
    tie(u, v, w) = e;
    if (dis1[u].first + w + dis2[v].first == L) {
      if (dis1[u].first * 2 < L && dis2[v].first * 2 < L) {
        ans = ((ans - square(dis1[u].second * dis2[v].second)) % mod + mod) % mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 23980
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    if '9' in a:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
S = input()
cursor = len(S)

while cursor:
    if S[cursor - 5: cursor] in ['dream', 'erase']:
        cursor -= 5
        continue
    elif S[cursor - 6: cursor] in ['eraser']:
        cursor -= 6
        continue
    elif S[cursor - 7: cursor] in ['dreamer']:
        cursor -= 7
    else:
        break

if cursor == 0:
    print('YES')
else:
    print('NO')



Measured memory_bytes: 40304
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int minutes = 0;
        for (int i = 0; i < 4; i++) {
            minutes += sc.nextInt();
        }
        System.out.println(minutes / 60);
        System.out.println(minutes % 60);
    }
}



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

using namespace std;

int main(void) {
  int N, K;
  cin >> N >> K;

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int x; cin >> x;
    ans += min(2*x, 2*abs(x-K));
  }

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

Measured memory_bytes: 256
n,k=map(int,input().split())
S=[] #[ネタ種類、おいしさ]のリスト
for i in range(n):
    S.append(list(map(int,input().split())))
S.sort(reverse=1,key=lambda x:x[1])

netano_min=min(S[j][0] for j in range(n))
for i in range(n):
    S[i][0]-=netano_min-1

neta=max(S[j][0] for j in range(n)) #ネタの種類数

F=[0 for i in range(neta+1)] #ネタi種のときの美味しさの和の最大値のリスト

ma=sum(S[i][1] for i in range(k))

neta_s=len(set([S[i][0] for i in range(k)]))

netano_min=min(S[j][0] for j in range(n))

F[neta_s]=ma

#print(S)
#print(F)
#print(ma)

netalist=[0 for i in range(n+1)] #i種類目のネタを使った個数
keseru=[] #ネタに重複がある寿司のリスト(消してもいい寿司)
for i in range(k):
    if netalist[S[i][0]]>=1 :
        keseru.append(S[i])
        
    netalist[S[i][0]]+=1

#print(keseru)
#print(netalist)

right=len(keseru)-1
left=k
i=neta_s+1
while len(keseru)>0 and i<=k and right>=0 and left<=n-1 :
    while left<=n-1 and netalist[S[left][0]]!=0 :
        left+=1
    if left==n :
        break
    netalist[S[left][0]]+=1
    F[i]=F[i-1]+S[left][1]-keseru[right][1]
    right-=1
    left+=1
    i+=1

#print(F)
for j in range(neta_s,i+1-1) :
    F[j]+=j**2

print(max(F))


Measured memory_bytes: 31672
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int INF = 1e9 + 5;
int n = 0;
 
int main() {
	string s;
	cin >> s;
	if(s == "ABC"){
		cout << "ARC" << endl;

	}
	else{
		cout << "ABC" << endl;
	}

	
 
    return 0;
} 

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

int main() {
  
  int n;
  cin >> n;
  int odd = 0;
  
  if(n % 2 == 0) odd = n/2;
  else odd = n/2+1;
  
  double ans = (double)odd / n;
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	public static void main(String[]__){
		int x=getInt(),a=getInt(),b=getInt();
		System.out.println(b-a<=0?"delicious":b-a<=x?"safe":"dangerous");
	}
}


Measured memory_bytes: 20564
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int ans=0;
	int ok=1;
	while(ok){
		for(int i=0; i<N; i++){
			if(A[i]%2==0){A[i]/=2;}
			else{
				ok=0;
				break;
			}
		}
		ans+=ok;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static final int INF = 1000000007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[100001];
		for(int i = 0 ; i < n ; i++) a[i] = sc.nextInt();
		for(int i = 0 ; i < n ; i++) b[a[i]]++;
		boolean ok = true;
		if(n % 2 == 0) {
			for(int i = 0 ; i < n / 2 ; i++) {
				if(b[2 * i + 1] != 2) ok = false;
			}
		} else {
			for(int i = 0 ; i < n / 2 ; i++) {
				if(i == 0) {
					if(b[0] != 1) ok = false;
				} else if(b[2 * i] != 2) ok = false;
			}
		}
		long ans = 1;
		if(ok) {
			for(int i = 0 ; i < 100001 ; i++) {
				if(b[i] == 2) {
					ans = ans * 2 % INF;
				}
			}
			System.out.println(ans);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 58884
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int n, k;
	cin>>n;
	ll res = 0;
	rep(i, n){
		int l, r;
		cin>>l>>r;
		res += r-l+1;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 100010;

struct lol {
	int a, b, c;
};

ll sg[N], ss[N], sb[N], pref[N], suff[N];
lol v[N];

int main()
{
	ios_base::sync_with_stdio(false);
	
	int x, y, z, n;
	ll currg, currs, currb;

	cin >> x >> y >> z;
	n = x + y + z;

	for(int i = 1; i <= n; ++i) cin >> v[i].a >> v[i].b >> v[i].c;
	sort(v + 1, v + n + 1, [](const lol &a, const lol &b) { return a.a - a.b < b.a - b.b; });

	for(int i = 1; i <= n; ++i) {
		sg[i] = sg[i - 1] + v[i].a;
		ss[i] = ss[i - 1] + v[i].b;
		sb[i] = sb[i - 1] + v[i].c;
	}

	currs = currb = 0;
	priority_queue<pii> q;

	for(int i = 1; i <= n; ++i) {
		q.push({v[i].c - v[i].b, i});
		currs += v[i].b;
		currb += v[i].c;

		if(q.size() > y) {
			currs -= v[q.top().se].b;
			currb -= v[q.top().se].c;
			q.pop();
		}

		pref[i] = currs + sb[i] - currb;
	}

	currb = currg = 0;
	while(!q.empty()) q.pop();

	for(int i = n; i >= 1; --i) {
		q.push({v[i].c - v[i].a, i});
		currg += v[i].a;
		currb += v[i].c;

		if(q.size() > x) {
			currg -= v[q.top().se].a;
			currb -= v[q.top().se].c;
			q.pop();
		}

		suff[i] = currg + sb[n] - sb[i - 1] - currb;
	}

	ll ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(i >= y && n - i >= x) ans = max(ans, pref[i] + suff[i + 1]);
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 6264
h, w = [int(i) for i in input().split()]
s = [list(input()) for _ in range(h)]
flg = True

for i in range(1, h-1):
    for j in range(1, w-1):

        if s[i][j] == "#" and s[i-1][j]==s[i+1][j]==s[i][j-1]==s[i][j+1]==".":
                flg = False

print('Yes' if flg else 'No')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k;
    cin >> n >> k;
    vll vec(n);
    REP(i, n) cin >> vec.at(i);
    ll total = 0;
    for (auto elem : vec) {
        total += min(elem, k - elem);
    }
    cout << total * 2 << endl;
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int q; cin>>q;
	vector<bool>sv(MAX,true); sv.at(0)=sv.at(1)=false;
	for(int i=2;i*i<MAX;++i){
		if(sv.at(i)){
			int j=i*i;
			while(j<MAX){
				sv.at(j)=false;
				j+=i;
			}
		}
	}
	vector<int>v(MAX,0);
	for(int i=3;i<MAX;++i){
		v.at(i)=v.at(i-1);
		if(sv.at(i)&&sv.at((i+1)/2))++v.at(i);
	}
	for(int i=0;i<q;++i){
		int l,r; cin>>l>>r;
		cout<<(v.at(r+1)-v.at(l-1))<<"\n"s;
	}
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define print(x) cout<<x<<endl;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	print(n * 800 - 200 * (n / 15));
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N, T, c, t;
	
	int ans = 1001;
	
	cin >> N >> T;
	
	for(int i = 1;i<=N;i = i + 1){
		cin >> c >> t;
		if(T >= t){
			     if (ans > c){
			     	       ans = c;
			     	       
			     	
			     }
			
			
		}
		
	}
	    
	   if (ans == 1001){
	   	cout << "TLE" << endl;
	   	
	   }
	  
	   else {
	   	cout  << ans <<endl;
	   }
       
       return 0;
}

Measured memory_bytes: 256
n = int(input())
b = list(map(int, input().split()))
a = [0]*n
a[0] = b[0]

for i in range(1, n - 1):
    a[i] = min(b[i - 1], b[i])
    
a[n - 1] = b[n - 2]

print(sum(a))

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

int main() {
    int N, Y;
    cin >> N >> Y;
    vector<int> numMax(3, 0);

    numMax[0] = min(Y/10000, N);
    numMax[1] = min(Y/5000, N);
    numMax[2] = min(Y/1000, N);

    int x, y, z;
    bool find = false;
    for (int a=0; a<=numMax[0]; ++a) {
        for (int b=0; b<=numMax[1]; ++b) {
            int c = N - a - b;
            if (c < 0) continue;

            int v = a * 10000 + b * 5000 + c * 1000;
            if (v == Y) {
                find = true;
                x = a;
                y = b;
                z = c;
                break;
            }
        }
        if (find) break;
    }
    if (find)
        cout << x << ' ' << y << ' ' << z << endl;
    else
        cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 3620
#include <iostream>

int main()
{
    int d, t, s;

    std::cin >> d >> t >> s;
      int dist = s * t;

  if( dist >= d ){
    
    

    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }
}

Measured memory_bytes: 3632
unittest
{
	assert( [ "aab", "xyz" ].solve == "No" );		// 追加ケース
	assert( [ "xyz", "aab" ].solve == "No" );		// 追加ケース
	
	assert( [ "azzel", "apple" ].solve == "Yes" );
	assert( [ "chokudai", "redcoder" ].solve == "No" );
	assert( [ "abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu" ].solve == "Yes" );
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	
	// 同じ文字を違う文字に置換する必要がある場合はダメ
	zip( s, t ).sort();
	foreach( i; 1L .. s.length.signed )
	{
		if( s[ i - 1 ] == s[ i ] && t[ i - 1 ] != t[ i ] ) return "No";
	}
	zip( t, s ).sort();
	foreach( i; 1L .. s.length.signed )
	{
		if( t[ i - 1 ] == t[ i ] && s[ i - 1 ] != s[ i ] ) return "No";
	}
	
	return "Yes";
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	int cost{-1};
	pair<int,int> from;
};

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

	int H=in(),W=in();
	vector<vector<int>> A(H,vector<int>(W,0)),F(H,vector<int>(W,0));
	vector<vector<Data>> C(H,vector<Data>(W));
	REP(i,H){
		REP(j,W){
			char c = in<char>();
			if(c=='#') A[i][j]=1;
		}
	}

	queue<pair<int,int>> Q;
	Q.emplace(0,0);
	C[0][0].cost=0;
	C[0][0].from=make_pair(-1,-1);
	F[0][0]=1;
	while(!Q.empty()){
		auto P = Q.front();
		Q.pop();
		auto func = [&](int h,int w,int oh,int ow){
			F[h][w]=1;
			C[h][w].cost=C[oh][ow].cost+1;
			C[h][w].from=make_pair(oh,ow);
			Q.emplace(h,w);
		};
		if(P.first>0 && !A[P.first-1][P.second] && !F[P.first-1][P.second]){
			func(P.first-1,P.second,P.first,P.second);
		}
		if(P.first<H-1 && !A[P.first+1][P.second] && !F[P.first+1][P.second]){
			func(P.first+1,P.second,P.first,P.second);
		}
		if(P.second>0 && !A[P.first][P.second-1] && !F[P.first][P.second-1]){
			func(P.first,P.second-1,P.first,P.second);
		}
		if(P.second<W-1 && !A[P.first][P.second+1] && !F[P.first][P.second+1]){
			func(P.first,P.second+1,P.first,P.second);
		}
	}

	if(C[H-1][W-1].cost==-1){
		out(-1);
		return 0;
	}
	
	pair<int,int> pos(H-1,W-1);
	while(true){
		A[pos.first][pos.second]=1;
		pos = C[pos.first][pos.second].from;
		if(pos.first==-1 && pos.second==-1){
			break;
		}
	}
	int sum = 0;
	REP(i,H){
		REP(j,W){
			if(!A[i][j]) sum++;
		}
	}
	
	out(sum);
	return 0;
}


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

const double pi = acos(-1) ;

int32_t main(){
	double a , b , x ;
	cin >> a >> b >> x ;
	x /= a;
	double ans ;
	if(a*b/2 < x){
		ans = atan(2*(a*b-x)/(a*a)) ;
	}else{
		ans = atan((b*b)/(2*x)) ;
	}
	cout << fixed << setprecision(10) << (ans*180)/pi ;
	return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"

using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}


typedef pair <int, int> pii;

int n;
string s;

void cleanup() {
    return;
}

void solve() {
    cin >> s;
    n = s.size();
    int ans = n, i = 0;
    while (i < n - 1) {
        if (s[i] == s[i + 1]) {
            ans--;
            i += 3;
        }   else {
            i++;
        }
    }
    cout << ans;
    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
    int tc = 1;
//    cin >> tc;
    while (tc--) {
        solve();
        cleanup();
    }
}


Measured memory_bytes: 720
#include<stdio.h>

int main(void){
  long N;
  scanf("%ld",&N);
  long sum=0;
  long i;
  for(i=1; i<=N; i++){
  	if(i%3!=0 && i%5!=0)
      sum+=i;
  }
  printf("%ld",sum);
  
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  bool dame=false;

  vector<int> p(n);
  vector<int> q(n);

  rep(i,n){
    cin>>p[i];
    if(i+1<p[i]) dame=true;
  }

  if(dame) cout << -1 << endl;

  else{
    int k=n-1;
    while(!p.empty()){
      for(int i=k;i>=0;i--){
        if(p[i]==i+1) {
          q[k]=p[i];
          k--;
          p.erase(p.begin()+i);
          break;
        }
      }
    }
    rep(i,n){
      cout << q[i] << endl;
    }
  }

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define R cin>>
#define C cout<<
const int INF = 1000000007;
typedef long long ll;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  R n;
  ll tmp = 0;
  rep(i,10000000)tmp += i;
  vector<int>v(n),c(n);
  rep(i,n)cin >> v[i];
  rep(i,n)cin >> c[i];
  int ans = -1 * INF;
  rep(i,(1 << n)){
    int a = 0,b = 0;
    rep(j,n){
      if(i & (1 << j)){
        a += v[j];
        b += c[j];
      }
    }
    ans = max(ans,a - b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
using System;

public class Hello
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] R = new int[n];
        for(int a = 0; a < n; a++)
        {
            R[a] = int.Parse(Console.ReadLine());
        }
        int minV = R[0];
        int maxV = -1000000000;
        for(int j = 1; j < n; j++)
        {
           minV = Math.Min(minV, R[j - 1]);
           maxV = Math.Max(R[j] - minV, maxV);
           
        }
        Console.WriteLine(maxV);
    }
}




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

class Solver{
    final long N;
    final long[] W;

    Solver(Scanner in){
        N = in.nextLong();
        W = new long[5];
        for(int i = 0; i < W.length; i++){
            W[i] = in.nextLong();
        }
    }

    void solve(){
        Arrays.sort(W);
        System.out.println((long) Math.ceil(N * 1. / W[0]) + 4);
    }
}

class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 23892
n,m=map(int,input().split())
g=[0]*(n+1)
for _ in range(m):
  a,b=map(int,input().split())
  g[a]+=1
  g[b]+=1
  g[a]%=2
  g[b]%=2
  
print("YES" if 1-max(g) else "NO")


Measured memory_bytes: 45640
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    long long a, b;
    cin >> a >> b;
    
    string res;
    if (a * b < 0) res = "Zero";
    else if (b < 0) {
        if ((b-a) % 2 == 1) res = "Positive";
        else res = "Negative";
    }
    else res = "Positive";
    
    cout << res << endl;
}

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

int main()
{
	int n;
	cin >> n;
	int ma = 0;
	for (int i = 0; i < n; ++i)
	{
		int in;
		cin >> in;
		ma += in % 2;
	}
	cout << (ma?"first":"second") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

pll operator + (pll a, pll b) {
	if (a > b) swap(a, b);
	pll rv = pll(b.first, max(a.first, b.second));
	return rv;
}

pll in[1000000];

ll val[1000000];
int main() {
	int N, i, j, k;
	scanf("%d", &N);
	for (i = 0; i < (1 << N); i++) {
		scanf("%d", &j);
		in[i] = pll(j, -INF);
	}
	for (i = 0; i < N; i++) {
		for (j = 0; j < (1 << N); j++) {
			if (j & (1 << i)) in[j] = in[j] + in[j ^ (1 << i)];
		}
	}

	for (i = 1; i < (1 << N); i++) val[i] = in[i].first + in[i].second;
	for (i = 1; i < (1 << N); i++) val[i] = max(val[i], val[i - 1]);
	for (i = 1; i < (1 << N); i++) printf("%lld\n", val[i]);
	return 0;
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define int long long
    signed main() {
		    	int n,k;
		    	cin>>n>>k;
		    	vector<int>v;
		    	v.push_back(0);
		    	for(int i=1;i<=n;i++){
		    		int x;
		    		cin>>x;
		    		v.push_back(x);
		    	}
		    	for(int i=k+1;i<=n;i++){
		    		if(v[i]>v[i-k])cout<<"Yes"<<endl;
		    		else cout<<"No"<<endl;
		    	}

    	return 0;
    }


Measured memory_bytes: 5360
N = input()
a = list(map(int, input().split()))

a.sort(reverse=True)

i = 0
k = [0, 0]
while i < len(a) - 1:
    if a[i] == a[i + 1]:
        i += 1
        k.append(a[i])
    if len(k) > 3:
        break
    i += 1

print(k[-1] * k[-2])


Measured memory_bytes: 14252
#include<iostream>
#define INF (1<<26)
using namespace std;
int n;



int compute(int a,int b,string str){

  int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
  while(1){ //cout<<a<<' '<<b<<endl;
    
    sum=0;
    if(str[i]=='('){
      sum=compute(i+1,0,str);
      //cout<<sum<<endl;
      cnt=0;
      for(i=i;i<(int)str.size();i++){
	if(str[i]==')')cnt--;
	if(str[i]=='(')cnt++;
	if(cnt==0)break;
      }
      i++;
      
    }else{
      while(1){
	if('0'<=str[i]&&str[i]<='9'){
	  sum*=10;
	  sum+=(str[i]-'0');
	  i++;
	}else{
	  break;
	}
      }
    }

    if(b==1){
      sum*=-1;
      b=0;
    }
    if(tmp!=INF){
      sum*=tmp;
      tmp=INF;
    }
    if(tmp2!=INF){
      sum=tmp2/sum;
      tmp2=INF;
    }
    //if(a==8)cout<<sum<<endl;    
    if(str[i]=='\0'||str[i]==')'||str[i]=='='||i==(int)str.size())return sum;
    if(str[i]=='+')return sum + compute(i+1,0,str);
    if(str[i]=='-')return sum + compute(i+1,1,str);
    if(str[i]=='*'){
      i++;
      tmp=sum;
    }else if(str[i]=='/'){
      i++;
      tmp2=sum;
    }
  }
      
}


int main(){
  string str;
  cin>>n;
  while(n--){
    cin>>str;

    //cout<<str<<endl;
    cout<<compute(0,0,str)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[101][10][1001];

int n,s;

int dfs(int now,int k,int t){
    if(t<0||k<0)return 0;
    if(now<0){
        if(!k&&!t)return 1;
        else return 0;
    }
    if(~dp[now][k][t])return dp[now][k][t];

    int ret=dfs(now-1,k,t)+dfs(now-1,k-1,t-now);
    return dp[now][k][t]=ret;
}
signed main(){
    fill_n(**dp,101*10*1001,-1);
    while(cin>>n>>s,n||s)cout<<dfs(100,n,s)<<endl;
    return 0;
}

Measured memory_bytes: 9056
n = int(input())
s = input()

ans = ''
for c in s:
    tmp_i = ord(c) - ord('A')
    if tmp_i + n < 26:
        ans+=chr(ord(c)+n)
    else:
        ans+=chr(ord('A')+(n-(ord('Z')-ord(c)))-1)
    
print(ans)

Measured memory_bytes: 3060
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Y = map(int,input().split())

ans = [-1,-1,-1]

for i in range(N+1):
    for j in range(N+1-i):
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            ans = [i,j,N-i-j]

print(" ".join(map(str,ans)))

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int memo[300][10][2048];

int dfs(int st, int depth, int N, int S, int used) {
    if(depth == N) {
        if(st == S) return 1;
        else return 0;
    }

    int &ans = memo[st][depth][used];
    if(ans >= 0) return ans;

    ans = 0;
    for(int i = 0; i < 10; ++i) {
        if(used & (1<<i)) continue;
        ans += dfs(st+i*(depth+1), depth+1, N, S, used | (1<<i));
    }
    return ans;
}

int main() {
    int N, S;
    while(cin >> N >> S) {
        memset(memo, -1, sizeof(memo));
        cout << dfs(0, 0, N, S, 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 24000
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;

    int ans = 0;
    int m = N+1;
    for(int i=0; i<N; i++) {
        int P;
        cin >> P;
        if(P < m) {
            ++ans;
            m = P;
        }
    }

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


Measured memory_bytes: 256
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int answer = 0;
  for (int i = 1; i * i <= N; ++i) {
    answer = i * i;
  }
  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){
    int N;
    vector<int> A(3);
    cin>>N;
    vector<int> L(N);
    for(auto &x:A){
        cin>>x;
    }
    for(auto &x:L){
        cin>>x;
    }
    int res =1<<29;


    vector<int> bit(3);
    for(bit[0]=1;bit[0]<(1<<N);++bit[0]){
            for(bit[1]=1;bit[1]<(1<<N);++bit[1]){
                //共通要素の排除
                if(bit[0]&bit[1])continue;
                for(bit[2]=1;bit[2]<(1<<N);++bit[2]){
                    if((bit[2]&bit[0])||(bit[2]&bit[1]))continue;

                    //それぞれの長さと使った竹の本数
                    vector<int> sums(3,0),nums(3,0);

                    for(int i=0;i<N;++i){
                        for(int j = 0; j < 3; j++)
                        {
                            if(bit[j]&(1<<i)){
                                sums[j]+=L[i];
                                nums[j]++;
                            }
                        }
                        
                    }

                    int score=0;
                    for(int i=0;i<3;++i){
                        score+=abs(sums[i]-A[i]);
                        score+=(nums[i]-1)*10;
                    }

                    res=min(res,score);
                    
                }

            }
            
    }

    cout<<res<<endl;

}

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

using namespace std;

int main(){


  int n;
  cin>>n;
  int a[10000];
  for(int i=0;i<n;i++) cin>>a[i];

  int mn = a[0], mx = a[0];
  
  long long sum = 0;
  
  for(int i=0;i<n;i++){
    
    mn = min(mn, a[i]);

    mx = max(mx, a[i]);
    sum += a[i];
  }

  cout<<mn<<" "<<mx<<" "<<sum<<endl;

}


Measured memory_bytes: 3108
#include <iostream>
#include <string>
using namespace std;
#define MAX 25
#define NIL -1

struct node{
    int parent;
    int sibling;
    int left;
    int right;
};

node T[MAX];
int depth(int dep, int id){
    if (T[id].parent == -1) return dep;
    ++dep;
    id = T[id].parent;
    depth(dep, id);
}
int height(int h, int id){
    if (T[id].left == -1 && T[id].right== -1) return h;
    else{
        h++;
        if (T[id].left != -1 && T[id].right != -1){
            return height(h, T[id].left) > height(h, T[id].right)? height(h, T[id].left): height(h, T[id].right);
        }
        else if (T[id].left != -1) return height(h, T[id].left);
        else if (T[id].right != -1) return height(h, T[id].right);
    }
}
int main(int argc, char* argv[]) {
    int n, id, left, right;
    cin >> n;
    for (int i = 0; i < n; i++) T[i].parent = T[i].sibling = T[i].left = T[i].right = NIL;

    for (int i = 0; i < n; i++){
        cin >> id >> left >> right;
        T[id].left = left;
        T[id].right = right;

        if (left != -1 || right != -1){
            T[left].parent = id;
            T[left].sibling = right;

            T[right].parent = id;
            T[right].sibling = left;
        }
    }
       for (int i = 0; i < n; i++){
       cout << "node " << i << ": parent = " << T[i].parent << ", sibling = " << T[i].sibling;

       int deg = 0;
       deg += T[i].left == -1? 0: 1;
       deg += T[i].right == -1? 0: 1;
       cout << ", degree = " << deg;

       cout << ", depth = " << depth(0, i);
       cout << ", height = " << height(0, i);

       if (T[i].parent == -1) cout << ", root\n";
       else if (T[i].left == -1 && T[i].right == -1) cout << ", leaf\n";
       else cout << ", internal node\n";
       }
    return 0;
}



Measured memory_bytes: 3100
a, b, k = map(int, input().split())
ans = []
for i in range(a, min(a + k, b + 1)):
    ans.append(i)
for i in range(max(b - k + 1, a), b + 1):
    ans.append(i)
print(*sorted(list(set(ans))), sep="\n")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int N = 1e6+5;
char s[N];
ll fact[2*N];

ll binpow(ll a, ll b) {
	ll ret = 1; a %= mod;
	while (b) {
		if (b & 1) ret = ret * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return ret % mod;
}

ll c(int n, int k) {
	return (fact[n] * (binpow(fact[k], mod-2) * binpow(fact[n-k], mod-2) % mod)) % mod;
}

int main()
{
	int k; scanf("%d%s", &k, s);
	ll ans = 0;
	int n = strlen(s);
	fact[0] = 1;
	for (int i = 1; i <= n+k-1; i++) {
		fact[i] = (fact[i-1] * i) % mod;
	}
	for (int i = 0; i <= k; i++) {
		ans = (ans + (c(n+k-i-1, n-1) * (binpow(25, k-i) * binpow(26, i) % mod) % mod)) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 20260