akhauriyash/Code-Regression huggingface dataset:
using AtCoderBeginnerContest138.Questions;
using AtCoderBeginnerContest138.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest138.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var a = inputStream.ReadDoubleArray();

            yield return 1.0 / a.Sum(d => 1.0 / d);
        }
    }
}


namespace AtCoderBeginnerContest138
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest138.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest138.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13396
#include <stdio.h>
#include <string.h>

int main(void)
{
    char S[10];

    scanf("%s", S);

    if(strcmp(S, "Sunny") == 0){
	printf("Cloudy\n");
    }

    else if(strcmp(S, "Cloudy") == 0){
	printf("Rainy\n");
    }

    else{
	printf("Sunny\n");
    }

    return 0;
}

Measured memory_bytes: 128
n, q = map(int, input().split())
s = input()
li = [0]
for i in range(1, n):
  incr = 1 if s[i-1] + s[i] == 'AC' else 0
  li.append(li[i-1] + incr)

for i in range(q):
  l, r = map(int, input().split())
  print(li[r-1] - li[l-1])

Measured memory_bytes: 7688
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>


#include <math.h>


using namespace std;


class Solution {
public:
    void solve(int num, std::istream& in, std::ostream& out) {
		string a, b; in >> a >> b;
		for (int i = 0; i < a.size(); i++) {
			if (a[i] != b[i]) {
				out << "No" << endl;
				return;
			}
		}
		out << "Yes";
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
	//int T; in >> T;
	//for(int i = 0;i < T;i++)
		//solution.solve(i+1, in, out);
	solution.solve(0, in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 3048
def input(f):
    global v, e, s, t, d
     
    v, e = map(int, f.readline().split())
    s = []
    t = []
    d = []
    for _ in range(e):
        s_, t_, d_ = map(int, f.readline().split())
        s.append(s_)
        t.append(t_)
        d.append(d_)
 
import os
 
if os.environ.get('ZEPPELIN_HOME'):
    import networkx as nx
    import matplotlib.pyplot as plt
     
    def visualize():
        G = nx.MultiDiGraph()
        for i in range(v):
            G.add_node(i, node_color='b')
        for i in range(e):
            G.add_edge(s[i], t[i], t=d[i])
 
        plt.figure()
        plt.style.use('seaborn')
        plt.axis("off")
        pos = nx.spring_layout(G)
        nodes = nx.draw_networkx_nodes(G, pos, node_color='w', linewidths=2)
        nodes.set_edgecolor('black')
        nx.draw_networkx_labels(G, pos)
        nx.draw_networkx_edges(G, pos)
 
        edge_labels = dict([((a, b), c['t']) for a, b, c in G.edges(data=True)])
        nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, label_pos=0.25, font_size=16)
 
        plt.show()
 
if os.environ.get('ZEPPELIN_HOME'):
    with open('/tmp/input1') as f:
        print('Example #1')
        input(f)
        visualize()
 
if os.environ.get('ZEPPELIN_HOME'):
    with open('/tmp/input2') as f:
        print('Example #2')
        input(f)
        visualize()
 
if os.environ.get('ZEPPELIN_HOME'):
    with open('/tmp/input3') as f:
        print('Example #3')
        input(f)
        visualize()
 
import sys
 
 
def init():
    global inf, g
    inf = sys.maxsize
     
    g = [[inf for _ in range(v)] for _ in range(v)]
    for i in range(v):
        g[i][i] = 0
    for i in range(e):
        g[s[i]][t[i]] = d[i]
         
 
def solve():
    init()
     
    for k in range(v):
        for i in range(v):
            for j in range(v):
                if g[i][k] == inf or g[k][j] == inf:
                    continue
                g[i][j] = min([g[i][j], g[i][k] + g[k][j]])
 
    for i in range(v):
        if g[i][i] != 0:
            print('NEGATIVE CYCLE')
            return
         
    for i in range(v):
        for j in range(v):
            if j > 0:
                print(' ', end='')
            if g[i][j] == inf:
                print('INF', end='')
            else:
                print(g[i][j], end='')
        print('')
 
if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input1'
 
with open(os.environ.get('INPUT') or '/dev/stdin') as f:
    input(f)
    solve()
 
if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input2'
 
    with open(os.environ.get('INPUT') or '/dev/stdin') as f:
        input(f)
        solve()
 
if os.environ.get('ZEPPELIN_HOME'):
    os.environ['INPUT'] = '/tmp/input3'
 
    with open(os.environ.get('INPUT') or '/dev/stdin') as f:
        input(f)
        solve()


Measured memory_bytes: 7284
from collections import deque, defaultdict

N,M=map(int,input().split())
G=defaultdict(lambda:[])
indeg = [0]*(N+1)
for _ in range(M):
    x,y=map(int,input().split())
    G[x].append(y)
    indeg[y]+=1

def topological_sort(adj, indeg):
    """
    幅優先探索によるトポロジカルソート
    O(|V|+|E|)

    adj: 隣接リスト
    indeg: 各ノード入次数を管理するリスト

    ret: トポロジカルソートされたリスト
    """
    is_visited = [0]*(N+1)
    ret = []

    def bfs(s):
        """
        sからBFSする
        """
        queue = deque([s])
        is_visited[s] = 1
        while queue:
            u = queue.popleft()
            # queueには入次数0のノードが入っているのでretに追加
            ret.append(u)

            for v in adj[u]: # uの子ノードを探索
                indeg[v] -= 1 #探索したら子の次数を減らす
                if (indeg[v] == 0) and (not is_visited[v]):
                    # 入次数0かつ未訪問なら
                    queue.append(v)
                    is_visited[v] = 1
    
    for u in range(1, N+1):
        if (indeg[u]==0) and (not is_visited[u]):
            # 流入0かつ未訪問なら
            bfs(u) # uからBFS
    
    return ret

L = topological_sort(G,indeg.copy())
dp = [0]*(N+1)
for i in range(N):
    node = L[i]
    for nx in G[node]:
        dp[nx] = max(dp[nx], dp[node]+1)
print(max(dp))

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

const int inf = 1000000009;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	vector < int > a(n);
	for (int i = 0; i < n; ++i) 
		cin >> a[i];
	sort(a.rbegin(), a.rend());
	int cnt = 1;
	long long ans = a[0];
	for (int i = 1; 2 * i + 1 <= n && cnt < n - 1; ++i) {
		if (cnt == n - 2)
			ans += a[i], ++cnt;
		else
			ans += 2 * a[i], cnt += 2;
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3984
# include <iostream>
using namespace std;
string a;
int n;
void work (void)
{
	int i,o,f;
	o=0;
	f=1;
	i=2;
	if (a[0]=='A')
	{
		while (i<=n-2)
		{
			if (a[i]=='C')
			if (o==0)
			{
				o=1;
				a[i]='c';
			}
	   else
	        {
	        	o=0;
	        	break;
			}
			i++;
		}
		if (o==1)
		{
			i=1;
			while (i<n)
			{
				if (a[i]>='A'&&a[i]<='Z')
				{
					f=0;
					break;
				}
				i++;
			}
		}
   else f=0;
	}
else f=0;
    if (f==1)
    cout<<"AC";
else cout<<"WA";
}
int main (void)
{
	cin>>a;
	n=a.size ();
	work ();
	return 0;
}


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

#define ALL(c) begin(c), end(c)

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> players[2];
    for (int i = 0; i < n; ++i) {
      int c; cin >> c; --c;
      players[0].push_back(c);
    }
    sort(ALL(players[0]));
    vector<int> all(2*n);
    for (int i = 0; i < 2*n; ++i)
      all[i] = i;
    set_difference(ALL(all), ALL(players[0]), back_inserter(players[1]));

    int play = -1;
    for (int turn = 0; ; turn = !turn) {
      vector<int>& player = players[turn];
      auto it = lower_bound(ALL(player), play);
      if (it == player.end()) {
        play = -1;
      } else {
        play = *it;
        player.erase(it);
        if (player.empty())
          break;
      }
    }

    cout << players[1].size() << endl << players[0].size() << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin >> n;
    vector <int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    vector <int> dp(n, 0);
    dp[1] = abs(h[0] - h[1]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]),dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1];
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc100_c() {
	ll N;
	ll ans = 0;
	cin >> N;

	ll a;
	rep(i, N) {
		cin >> a;
		while (a % 2 == 0) {
			ans++;
			a /= 2;
		}
	}

	cout << ans << "\n";
}

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

	solve_abc100_c();

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

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

    int N,K,L,R; cin>>N>>K>>L>>R;
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];

    const int X=N/2,Y=(N+1)/2;
    vector<vector<int>> sumL(X+1),sumR(Y+1);
    for(int S=0;S<(1<<X);S++){
        int sum=0;
        for(int i=0;i<X;i++) if(S>>i&1){
            sum+=a[i];
        }
        sumL[__builtin_popcount(S)].push_back(sum);
    }
    for(int S=0;S<(1<<Y);S++){
        int sum=0;
        for(int i=0;i<Y;i++) if(S>>i&1){
            sum+=a[N/2+i];
        }
        sumR[__builtin_popcount(S)].push_back(sum);
    }
    for(int i=0;i<=Y;i++) sort(sumR[i].begin(),sumR[i].end());

    int ans=0;
    for(int i=0;i<=min(X,K);i++){
        if(K-i>Y) continue;
        for(int l:sumL[i]){
            ans+=upper_bound(sumR[K-i].begin(),sumR[K-i].end(),R-l)-lower_bound(sumR[K-i].begin(),sumR[K-i].end(),L-l);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 23424
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
  int a;
  cin>>a;
  cout<<"Christmas";
  switch(a){
    case 22:
      cout<<" Eve";
    case 23:
      cout<<" Eve";
    case 24:
      cout<<" Eve";
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a[10000];
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    int f=0;
    for(int i=0; i<n; i++)
    {
        if(a[i]%2==0)
        {
           // cout<<a[i]<<endl;
            if(a[i]%5==0 || a[i]%3==0)
            {
                continue;
            }
            else
            {
                f=1;
                break;

            }
        }
    }
    if(f)
        cout<<"DENIED"<<endl;
    else
        cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n%sumDigits(n)!=0){
        System.out.println("No");
      }else{
        System.out.println("Yes");
      }
  }
    public static int sumDigits(int n) {
      int sum = 0;
  //自然数の各桁の和を計算
      while (n != 0) {
  //sumDigitsは単独ではloopしないので、while loopを使う。
          sum += n % 10;
  //再右端の桁を得るために%10を利用する。
          n /= 10;
  //再右端の桁を取り除くためにn/=10を利用する。
      }
      return sum;//合計を返す
  }
}


Measured memory_bytes: 23124
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

if As[0]>=Bs[0]:
    cnt = Bs[0]
    yo = 0
else:
    cnt = As[0]
    yo = min(Bs[0],Bs[0]-As[0])
    
for i in range(1,N):
    if As[i]-yo>=Bs[i]:
        cnt += Bs[i]+yo
        yo = 0
    else:
        cnt += As[i]
        yo = min(Bs[i],Bs[i]-(As[i]-yo))
    
        
cnt += min(As[N], yo)
print(cnt) 

Measured memory_bytes: 19004
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> a(n+1);
  rep(i,n+1) cin >> a[i];
  if (n == 0) {
    if (a[0] == 1) {
      cout << 1 << endl;
      return 0;
    }
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[n] == 0 || a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> maxv(n+1);
  ll sum = 0;
  for (int i = n; i >= 0; --i) {
    sum += a[i];
    maxv[i] = sum;
  }
  ll ans = 1, now = 1;
  for (int i = 1; i <= n; ++i) {
    now *= 2;
    chmin(now, maxv[i]);
    ans += now;
    now -= a[i];
    if (now < 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;
int main(){

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

    int bar,x;
    while(m--){
        cin>>bar>>x;
        cout<< sum - cot[bar] +x<<endl;
    }

    return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  int n, m;
  cin >> n >> m;
  char a[n][n];  rep(i, 0, n) {rep(j, 0, n) cin >> a[i][j];}
  char b[m][m];  rep(i, 0, m) {rep(j, 0, m) cin >> b[i][j];}
  
  for(int i = 0; i+m-1 < n; i++) {
    for(int j = 0; j+m-1 < n; j++) {
      bool flag = true;
      rep(k, 0, m) {
        rep(l, 0, m) {
          if(a[i+k][j+l] != b[k][l]) flag = false;
        }
      }
      if(flag) {
        cout << "Yes" << "\n";
        return 0;
      }
    }
  }
  cout << "No" << "\n";
}

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

#define FOR(type, i, a, b) for (type i = (a); i < (b); ++i)
#define RFOR(type, i, a, b) for (type i = (b)-1;i >= (a); --i)
#define REP(type, i, n) for (type i = 0; i < (n); ++i)
#define RREP(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

constexpr auto PI = 2 * acos(0.0);
constexpr auto INF = 0x33433433;

using ll = long long;
using llu = unsigned long long;

int main(void) {
  int N; scanf("%d", &N);
  std::vector<int> L; REP(int, i, N*2) {
    int L_i; scanf("%d", &L_i);
    L.push_back(L_i);
  }

  int answer = 0;
  std::sort(ALL(L), std::greater<int>());
  for (int i = 1; i < N*2; i += 2) {
    answer += L[i];
  }
  printf("%d\n", answer);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
  
  int n,k; cin>>n>>k;
  vector<int>p,m;
  for(int i=0; i<n; i++){
    int a; cin>>a;
    if(a==0) k--;
    else if(a>0){
      p.push_back(a);
    }
    else{
      m.push_back(-a);
    }
  }
  int ans=1e9;
  if(k==0){
    cout << 0 << endl;
    return 0;
  }
  sort(m.begin(),m.end());
  if(p.size()>=k){
    ans = min(ans,p.at(k-1));
  }
  if(m.size()>=k){
    ans = min(ans,m.at(k-1));
  }
  for(int i=1; i<k; i++){
    if(k-i-1>=p.size()||i-1>=m.size())continue;
    int x = p.at(k-i-1);
    int y = m.at(i-1);
    ans = min(ans,x+y+min(x,y));
  }
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 4020
#include <iostream>
using namespace std;
int main()
{
	int n, sum = 0;
	cin >> n;
	if (n % 10 == 2)
	{
		sum++;
	}
	if (n / 10 % 10 == 2)
	{
		sum ++;
	}
	if (n / 100 % 10 == 2)
	{
		sum++;
	}
	if (n / 1000 == 2)
	{
		sum++;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


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

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

    ll n, k;
    cin >> n >> k;
    vector<ll> p(n), c(n);
    rep(i, n){
        cin >> p[i];
        --p[i];
    }
    rep(i, n) cin >> c[i];

    ll res = -(1ll << 60);
    rep(start, n){
        ll score = 0;
        int now = start;
        int nxt;
        int endidx = -1;
        ll rangesm;
        rep(i, k){
            nxt = p[now];
            if(nxt == start){
                score += c[nxt];
                // scores.insert(score);
                res = max(res, score);
                rangesm = score;
                endidx = i;
                break;
            }

            score += c[nxt];
            // scores.insert(score);
            res = max(res, score);
            now = nxt;
        }

        if(endidx != -1){
            ll sm = rangesm;
            ll rest = k - endidx - 1;
            ll mx = sm + sm * max(0ll, (rest / (endidx+1)) - 1);
            ll mod = rest % (endidx+1);
            // scores.insert(mx);
            res = max(res, mx);
            int nows = start;
            int nxts;
            int t = endidx+1;
            if(rest < t) t = 0;
            rep(j, t+mod){
                nxts = p[nows];
                mx += c[nxts];
                // scores.insert(mx);
                res = max(res, mx);
                nows = nxts;
            }
        }

    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N,x;
  cin >> N >> x;
  vector<int64_t> v(N);
  for (int64_t i=0;i<N;i++){
    cin >> v[i];
  }
  int64_t ans=0;
  for (int64_t i=0;i<N-1;i++){
    int64_t y=v[i]+v[i+1]-x;
    if (y>0){
      if (v[i+1]<y){
        v[i]-=y-v[i+1];
        v[i+1]=0;
      }
      else {
        v[i+1]-=y;
      }
      ans+=y;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

bool solve() {
	int n;
	if(scanf("%d", &n) == EOF) {
		return false;
	}
	multiset<int> D;
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		D.insert(x);
	}
	int m;
	scanf("%d", &m);
	bool valid = true;
	for (int i = 0; i < m; i++) {
		int x;
		scanf("%d", &x);
		auto it = D.find(x);
		if (it == D.end()) {
			valid = false;
		} else {
			D.erase(it);
		}
	}
	printf("%s\n", valid ? "YES" : "NO");
	return true;
}

int main() {
	while (solve());
	return 0;
}

Measured memory_bytes: 9600
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
using namespace std;

typedef long long ll;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  double ans;
  ll n,m,p[20];

  while(scanf("%lld %lld",&n,&m) && (n||m)){
    for(int i=0;i<m;i++)scanf("%lld",&p[i]);

    sort(p,p+m);
    ans = ( (n+1)*n ) / 2;

    ll num = 0;
    for(int i=1;i<(1<<m);i++){
      int bit = 0;
      for(int j=i;j!=0;j>>=1)bit += j&1;
      ll tmp = 1;
      for(int j=0;j<m;j++)
	if(i>>j & 1)tmp = lcm(tmp,p[j]);

      if(bit&1){
	num += n/tmp;
	ans -= (n/tmp+1)*n/2;
      }else{
	num -= n/tmp;
	ans += (n/tmp+1)*n/2;
      }
    }

    if(num==n)printf("0.00000000\n");
    else printf("%.8lf\n",ans/(n-num));
  }
}

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

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1;
	for(int j=p;j<r;j++){
		if(A[j]<=x){
			i++;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	int tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i+1;
}

int main(){
	int size;
	cin >> size;
	int S[size];
	for(int i=0;i<size;i++){
		cin >> S[i];
	}

	int q = partition(S,0,size-1);

	for(int i=0;i<size;i++){
		if(i==q){
			cout<<"["<<S[i]<<"]";
		}else{
			cout<<S[i]<<"";
		}
		if(i!=size-1){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	return 0; 
}


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

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

	int x,y,z;

	cin >> x >> y >> z;

	x-=z;

	cout << x/(y+z) << '\n';

	return 0;
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int A = sc.nextInt();
        if(H % A == 0){
          System.out.println(H/A);
        }else{
            System.out.println(H/A+1);
        }
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
int main(){

    int a=0,b=0,c=0,i;
    char st[5];

    char st1,st2;

    scanf("%s", &st);
    st1 = st[0];

    for(i=0;i<4;i++){
            if(st[i] == st1){
                a++;
            }else{
                if(b==0){
                    st2=st[i];
                }
                if(st2==st[i]){
                    b++;
                }else{
                    c++;
                }
            }
    }
    if(a==2 && b==2 && c==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

int main(){
    ll n; cin >> n;
    vector<ll> l(n);
    rep(i, n) cin >> l[i];
    sort(l.rbegin(), l.rend());
    ll cnt = 0;
    rep(i, n){
        for(ll j = i+1; j < n; ++j){
            ll a1 = l[i] - l[j], a2 = l[j] - l[i], a3 = l[i] + l[j];
            for(ll k = j+1; k < n; ++k){
                if(a1 < l[k] && a2 < l[k] && l[k] < a3) cnt++;
                //else break;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
#define MAX_N 200
using namespace std;

int d[MAX_N + 1][MAX_N + 1];

void warshall_floyd(int n) {
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    int r[R];
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            d[i][j] = (i == j) ? 0 : INF;
        }
    }
    for (int i = 0; i < R; i++) {
        cin >> r[i];
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd(N);
    int ans = INF;
    int seq[R];
    for (int i = 0; i < R; i++) {
        seq[i] = i;
    }
    do {
        int tmp = 0;
        for (int i = 1; i < R; i++) {
            tmp += d[r[seq[i]]][r[seq[i - 1]]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(seq, seq + R));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
q = 10**9 + 7

dp = [[None] * m for _ in range(n)] #[i][j]: s[i], t[j]を使ってできる部分列の数
sumdp = [[None] * m for _ in range(n)]

if s[0] == t[0]:
    dp[0][0] = 1
    sumdp[0][0] = 2
else:
    dp[0][0] = 0
    sumdp[0][0] = 1
    
# j=0
for i in range(1, n):
    if s[i] == t[0]:
        dp[i][0] = 1
        #dp[i][j] = sumdp[i-1][j-1] or 0
        sumdp[i][0] = sumdp[i-1][0] + 1
        sumdp[i][0] %= q
        #sumdp[i][j] = dp[i][j] + (sumdp[i-1][j] - sumdp[i-1][j-1])
        #              + (sum[i][j-1] - sumdp[i-1][j-1]) + sumdp[i-1][j-1]
        
    else:
        dp[i][0] = 0
        sumdp[i][0] = sumdp[i-1][0]
        
for j in range(1, m):
    if s[0] == t[j]:
        dp[0][j] = 1
        sumdp[0][j] = sumdp[0][j-1] + 1
        sumdp[0][j] %= q
    else:
        dp[0][j] = 0
        sumdp[0][j] = sumdp[0][j-1]
        
for i in range(1, n):
    for j in range(1, m):
        if s[i] == t[j]:
            dp[i][j] = sumdp[i-1][j-1]
        else:
            dp[i][j] = 0
        sumdp[i][j] = dp[i][j] + sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %= q

print(sumdp[n-1][m-1])

Measured memory_bytes: 149128
n, a, b, m, M = map(int, input().split())
n -= 1
l, r = -1, n + 1
while r - l > 1:
	mid = (l + r) // 2
	t = (n - 2 * mid) * (m + M)
	if abs(t - 2 * (b - a)) <= n * (M - m):
		print("YES")
		exit()
	if t > 2 * (b - a):
		l = mid
	else:
		r = mid
print("NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N,M;
int A[20001];
int B[20001];
vector<int>G[20001];
int p[20001];
int h[20001];
bool used[20001];
bool st[20001];
typedef pair<int,int>P;

vector<int>make(int x,int y){
	int now=y;
	vector<int>v;
	v.push_back(now);
	while(now!=x){
		now=p[now];
		v.push_back(now);
	}
	return v;
}

vector<int> bfs(int x){
	REP(i,N){
		p[i]=-1;
		used[i]=false;
	}
	vector<int>v;
	REP(i,N+1){
		v.push_back(i);
	}
	queue<int>que;
	que.push(x);
	while(que.empty()==false){
		int q=que.front();
		que.pop();
		REP(i,G[q].size()){
			if(G[q][i]==x){
				return make(x,q);
			}
			if(used[G[q][i]]==false){
				used[G[q][i]]=true;
				p[G[q][i]]=q;
				que.push(G[q][i]);
			}
		}
	}
	return v;
}

int main(){
	cin>>N>>M;
	REP(i,M){
		cin>>A[i]>>B[i];
		A[i]--;
		B[i]--;
		G[A[i]].push_back(B[i]);
		//G[B[i]].push_back(A[i]);
	}
	vector<int>ans;
	REP(i,N+1){
		ans.push_back(i);
	}
	REP(i,N){
		vector<int>v=bfs(i);
		//cout<<v.size()<<endl;
		if(v.size()<ans.size()){
			ans=v;
		}
	}
	if(ans.size()==N+1){
		cout<<-1<<endl;
	}else{
		cout<<ans.size()<<endl;
		REP(i,ans.size()){
			cout<<ans[i]+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 768
n = int(input())

s_dic = dict()
a_dic = dict()

for i in range(n):
  s = input()
  if s not in s_dic:
    s_dic[s] = 1
  else:
    s_dic[s] += 1

# s_dic_sk = sorted(s_dic.items())
s_dic_s = sorted(s_dic.items(), key= lambda x:x[1], reverse=True)

# print(len(s_dic_s))
#print(s_dic_s)

m_count = s_dic_s[0][1]
# print(m_count)

max_n = True
j = 0

while max_n:
  if s_dic_s[j][1] == m_count:
    a_dic[s_dic_s[j][0]] = s_dic_s[j][1]
    j += 1
    if j == len(s_dic_s):
      max_n = False
  else:
    max_n = False

# print(a_dic)
a_dic_s = sorted(a_dic.items())
    
# print(a_dic_s)

for i in range(len(a_dic_s)):
  print(a_dic_s[i][0])

Measured memory_bytes: 70756
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;
#define INF 1e+18
#define int long long

signed main() {
	int n, m;
	while (cin >> n >> m, n) {
		int ma[110], ans = 0;
		for (int i = 0; i < m; i++) ma[i] = 0;
		for (int i = 0; i < n; i++) {
			int a, b;
			cin >> a >> b;
			ma[a - 1] = max(ma[a - 1],b);
		}
		for (int i = 0; i < m; i++) ans += ma[i];
		cout << ans << endl;
	}
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	string s;
	cin>>s;
	cout<<s.substr(0,3)<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    vector<int> res(2);
    cin >> res[0] >> res[1] >> res[2];

    for(int i = res.size(); i>0; i--) {
        for(int j = 1; j<=i; j++) {
            if(res[j-1] > res[j]) {
                int tmp = res[j-1];
                res[j-1] = res[j];
                res[j] = tmp;
            }
        }
    }

    cout << res[0] << " " << res[1] << " " << res[2] << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pi pair<ll, ll>
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define pd pair<double, double>
#define vp vector<pi>
#define f(i, n) for(int i = 0; i < n; i++)
#define fo(i, a, n) for(int i = a; i < n; i++)
#define mod (1000*1000*1000+7)
#define sz(x) int((x).size())
#define all(x) x.begin(),x.end()
#define DBG(v) cerr << #v << " = " << (v) << endl;
ll INF = (1ll<<61);

using namespace std;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5]){
      cout << "Yes" << endl;
    }else{
      cout <<"No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> a = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int b; cin >> b;
	cout << a[b - 1] << endl;
	return 0;
}

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

const double EPS = 1e-9;

struct Point {
	double x, y;

	Point () {}
	Point (double _x, double _y) {
		x = _x; y = _y;
	}

	Point operator+ (const Point & other) const {
		return Point (x + other.x, y + other.y);
	}

	Point operator- (const Point & other) const {
		return Point (x - other.x, y - other.y);
	}

	double operator^ (const Point & other) const {
		return x * other.y - y * other.x;
	}

	double operator* (const Point & other) const {
		return x * other.x + y * other.y;
	}

	double operator~ () const {
		return sqrt (x * x + y * y);
	}
};

struct Circle {
	Point o;
	double r;

	Circle () {}
	Circle (Point _o, double _r) {
		o = _o; r = _r;
	}

	double getDist (Circle c) {
		double d = ~(o - c.o);
		double ans = d - r - c.r;
		if (ans < 0) return 0;
		return ans;
	}
};

const int MAXN = 1123;

Circle v[MAXN];
vector <pair <int, double> > g[MAXN];
double dist[MAXN];

int main () {

	Point s, t;
	scanf ("%lf %lf %lf %lf", &s.x, &s.y, &t.x, &t.y);

	int n;
	cin >> n;

	for (int i = 0; i < n; ++i)
		scanf ("%lf %lf %lf", &v[i].o.x, &v[i].o.y, &v[i].r);

	v[n++] = Circle (s, 0);
	v[n++] = Circle (t, 0);

	for (int i = 0; i < n; ++i) {
		dist[i] = HUGE_VAL;
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			g[i].push_back (make_pair (j, v[i].getDist (v[j])));
		}
	}

	dist[n - 2] = 0;
	priority_queue <pair <double, int> > pq;

	pq.push (make_pair (0, n - 2));

	while (!pq.empty()) {
		int x = pq.top().second;
		double d = -pq.top().first;

		pq.pop();

		if (dist[x] < d) continue;

		for (int i = 0; i < g[x].size(); ++i) {
			int y = g[x][i].first;
			double nd = d + g[x][i].second;
			if (dist[y] - EPS > nd) {
				dist[y] = nd;
				pq.push (make_pair (-nd, y));
			}
		}
	}

	cout << fixed << setprecision (12) << dist[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 22512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;


#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

    int ans = 0;
    for(int i = 0; i < n - 2; ++i){
        string substr;
        rep(j, 3){
            substr.push_back(s[i + j]);
        }

        if(substr == "ABC") ans++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    cout << (n+999) / 1000 * 1000 - n << endl;
    return 0;
}

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

#define rep(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a);i>(b);i--)
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  int n,k; cin >> n >> k;
  vi l(n); rep(i,n) cin >> l[i];
  sort(l.rbegin(),l.rend());
  int ans=0;
  rep(i,k) ans+=l[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
        x: i32,
        y: i32
    }
    let mut min_price = 1_000_000_000;
    for i in 0..=100_000 {
        // a と b が i 枚ずつ
        let c_num = i * 2;
        let a_num = (x - i).max(0);
        let b_num = (y - i).max(0);
        let price = a_num * a + b_num * b + c_num * c;
        min_price = min_price.min(price);
    }
    println!("{}", min_price);
}


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

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

    long long x;
    cin>>x;

    long long m=100;
    int ans=0;
    while(m<x){
        m+=(m/100);
        ans++;
    }

    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout << "Yes";
  }else{
    cout << "No";
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
vector<vector<int>> G;
vector<int> grundy;

int dfs(int cur = 0, int par = -1){
    int ret = 0;
    for(int v: G[cur]){
        if(v != par){
            ret ^= dfs(v, cur) + 1;
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    G.resize(N);
    grundy.resize(N);
    rep(i, N - 1){
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].pb(y);
        G[y].pb(x);
    }
    
    output(dfs() ? "Alice" : "Bob");
    
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<< "\n"


int main(){
    int n;
    cin >> n;
    pair<pair<string,int>,int> rest[n];
    REP(i,n){
        string s;
        int t;
        cin >> s >> t;
        rest[i] = make_pair(make_pair(s,-t),i);//-tとしたのはソートした際にsecondが昇順に並ぶから
    }
    sort(rest,rest+n);
    REP(i,n){
        cout << rest[i].second+1 << endl;
    }
    return 0;
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n;
    cin >> n;

    string ant, w;

    cin >> ant;
    bool shiritoridesu = true;
    set<string> jafoi;
    jafoi.insert(ant);
    fo(i, n - 1) {
        cin >> w;

        if ( w[0] != ant.back() or jafoi.find(w) != jafoi.end() ) shiritoridesu = false;
        jafoi.insert(w);

        ant = w;
    }

    cout << (shiritoridesu ? "Yes\n" : "No\n");

    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn enum_all_pats(cur: &mut Vec<(usize, usize)>, a: &Vec<Vec<char>>, h: usize, w: usize) -> Vec<Vec<(usize, usize)>>{
    if *cur.last().unwrap() == (h-1, w-1){
        return vec![cur.clone()];
    }
    if cur.len() == h+w-1{
        return vec![];
    }
    let mut res = vec![];
    let cur_pos = *cur.last().unwrap();
    if cur_pos.0 < h-1 && a[cur_pos.0+1][cur_pos.1] == '#'{
        cur.push((cur_pos.0+1, cur_pos.1));
        let mut tmp = enum_all_pats(cur, a, h, w);
        cur.pop();
        res.append(&mut tmp);
    }

    if cur_pos.1 < w-1 && a[cur_pos.0][cur_pos.1+1] == '#'{
        cur.push((cur_pos.0, cur_pos.1+1));
        let mut tmp = enum_all_pats(cur, a, h, w);
        cur.pop();
        res.append(&mut tmp);
    }

    return res;
}

fn main(){
    let line = read_as_vec::<usize>();
    let (h, w) = (line[0], line[1]);

    let mut a: Vec<Vec<char>> = vec![];

    for _ in 0..h{
        a.push(read_as_string().chars().collect::<Vec<char>>());
    }
    let mut sc = 0;
    for i in 0..h{
        for j in 0..w{
            if a[i][j] == '#'{
                sc += 1;
            }
        }
    }

    let mut tmp = vec![(0, 0)];
    let pats = enum_all_pats(&mut tmp, &a, h, w);
    for route in pats{
        if sc == route.len(){
            println!("Possible");
            return;
        }
    }
    println!("Impossible");
}


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


void solve(long long N){
    long long ans =0;
    for(int i=1;i<=N;i++){
        if(i%3 != 0 && i% 5 != 0){
            ans +=i;
        }
    }
    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


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

    vector<vector<int>> color(N+1,vector<int>(3,0));
    REP(i,N){
        if(s[i]=='R'){
            S.push_back('0');
            color[i][0]++;
        }else if(s[i]=='G'){
            S.push_back('1');
            color[i][1]++;
        }else if(s[i]=='B'){
            color[i][2]++;
            S.push_back('2');
        }
    }

    REP(i,N-1){
        REP(j,3){
            color[i+1][j] += color[i][j];
        }
    }
    ll ans = 0;
    FOR(i,1,N-1){
        int c = S[i]-'0';
        ans += color[i-1][(c+1)%3]*(color[N-1][(c+2)%3]-color[i][(c+2)%3]);
        ans += color[i-1][(c+2)%3]*(color[N-1][(c+1)%3]-color[i][(c+1)%3]);
        FOR(j,1,min(i,N-1-i)+1){
            if(S[i]!=S[i-j] && S[i]!=S[i+j] && S[i-j]!=S[i+j]){
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3764
s = input()
n = len(s)

r = 0
l = 0


def gathering_children(r, l, output):
    output.extend(["0" for _ in range(r - 1)])
    if (r + l) % 2 == 0:
        output.append(str((r + l) // 2))
        output.append(str((r + l) // 2))
    else:
        # Rが偶数のときは左が大きい
        x = (r + l) // 2
        output.append(str(x + 1 if r % 2 == 1 else x))
        output.append(str(x + 1 if l % 2 == 1 else x))
    output.extend(["0" for _ in range(l - 1)])
    return output

pre_char = ''
output = []
for c in s:
    if pre_char == 'L' and c == 'R':
        output = gathering_children(r, l, output)
        r = 0
        l = 0

    if c == 'R':
        r += 1
    else:
        l += 1

    pre_char = c

output = gathering_children(r, l, output)
print(" ".join(output))

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

#define MAX 100005
#define NIL -1

struct Node {
    int p, l ,r;
};

void print(vector<Node>& tree, vector<int>& depth ,int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << tree[u].p << ", ";
    cout << "depth = " << depth[u] << ", ";

    if(tree[u].p == NIL) cout << "root, ";
    else if(tree[u].l == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for(i = 0, c=tree[u].l; c != NIL; i++, c = tree[c].r) {
        if(i) cout <<", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(vector<Node>& tree, vector<int>& depth, int u, int p) {
    depth[u] = p;
    if(tree[u].r != NIL) rec(tree, depth, tree[u].r, p);
    if(tree[u].l != NIL) rec(tree, depth, tree[u].l, p+1);
}

int main() {
    int num;
    cin >> num;
    vector<Node> tree(num);
    vector<int> depth(num, 0);
    for(int i=0; i<num; i++) {
        tree[i].p = tree[i].l = tree[i].r = NIL;
    }

    for(int i=0; i<num; i++) {
        // IDと次数を入力する
        int id, degree;
        cin >> id >> degree;
        // 次数を処理する
        int leftId = NIL;
        for(int j=0; j<degree; j++) {
            int childId;
            cin >> childId;
            // 一番左の子はNodeのLeftにセットする
            if(j==0) {
                tree[id].l = childId;
            } else {
                tree[leftId].r = childId;
            }
            leftId = childId;
            tree[childId].p = id;
        }
    }
    // 親のIDを取得する
    int rootId = NIL;
    for(int i=0; i<num; i++) {
        if(tree[i].p == NIL) {
            rootId = i;
            break;
        }
    }

    // 深さをセットする
    rec(tree, depth, rootId, 0);
    for(int i=0; i<num; i++) {
        print(tree, depth, i);
    }
}


Measured memory_bytes: 9096