akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 1
next = a[0]
while True:
  if next == 1:
    ans = -1
    break
  elif next == 2:
    break
  cur = next
  next = a[next - 1]
  a[cur - 1] = 1
  ans += 1
print(ans)

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

using namespace std;

int main()
{
    int n,d;
    cin>>n>>d;
    long long int  x[n],y[n];
     double  dist[n];
    int count =0;
    for (int i=0;i<n;i++)
    {
        cin>>x[i]>>y[i];
        dist[i]=sqrt((x[i]*x[i])+(y[i]*y[i]));
        
        if (dist[i]<=d)
            count++;
    }
    cout<<count<<"\n";
    return 0;
}



Measured memory_bytes: 8364
#include <iostream>

using namespace std;

const int Height = 1000;
const int Width = 1000;
bool b_map[Height][Width];
int i_map[Height+1][Width+1];

int main()
{
	int h, w, n;
	while(cin >> h >> w >> n, h | w | n)
	{
		for(int y=0; y < h; y++)
			for(int x=0; x < w; x++) {
				cin >> b_map[y][x];
				i_map[y][x] = 0;
			}
		for(int y=0; y < h; y++) i_map[y][w] = 0;
		for(int x=0; x < w; x++) i_map[h][x] = 0;
		i_map[0][0] = n - 1;
		for(int y=0; y < h; y++)
			for(int x=0; x < w; x++) {
				if(!i_map[y][x]) continue;
				int num = i_map[y][x] >> 1;
				if(i_map[y][x] & 1) {
					if(b_map[y][x]) {
						i_map[y][x+1] += num + 1;
						i_map[y+1][x] += num;
					}
					else {
						i_map[y][x+1] += num;
						i_map[y+1][x] += num + 1;
					}
					b_map[y][x] = !b_map[y][x];
				}
				else  {
					i_map[y+1][x] += num;
					i_map[y][x+1] += num;
				}
			}
		int x, y;
		x = y = 0;
		do {
			if(b_map[y][x])
				x++;
			else
				y++;
		}while(x < w && y < h);
		cout << y+1 << ' ' << x+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 5680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var wst = new Tuple<long,long,long,long>[N];
            for (var i = 0; i < N; ++i)
            {
                var t = Sarray();
                wst[i] = new Tuple<long,long,long, long>(t[0] + t[1], t[0], t[1], t[2]);//w+s,w,s,v
            }
            Array.Sort<Tuple<long, long, long, long>>(wst, (l, r) => (int)(l.Item1 - r.Item1));
            var len = wst[N - 1].Item2 + wst[N - 1].Item3;
            var dp = new long[len + 1].Select(_ => -1L).ToArray();
            dp[0] = 0;
            for (var i = 0; i < N; ++i)
            {
                for (var j = wst[i].Item3; 0 <= j; --j)
                    if (dp[j] != -1)
                        dp[j + wst[i].Item2] = Max(dp[j + wst[i].Item2], dp[j] + wst[i].Item4);
            }
            WriteLine(dp.Max());
        }
    }
}

Measured memory_bytes: 14048
#include<bits/stdc++.h>
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
using namespace std;

char s[maxn];
int x;

int main(){
	scanf("%d", &x);
	int a = x / 500,b = x % 500;
	int res = b / 5;
	printf("%d\n", a * 1000 + res * 5);
	return 0;
}

Measured memory_bytes: 256
S = str(input())
a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range(len(S)):
  if S[i] in a:
    a.remove(S[i])
print(None if a==[] else a[0])

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    string s; cin >> s;
    int q; cin >> q;
    vector<char> v1; //mae 後ろから出す
    vector<char> v2; //ato
    bool ok=0; //0は清純
    rep(i,q){
        int t; cin >> t;
        if(t==1){
            if(ok==0) ok=1;
            else ok=0;
            vector<char>tmp=v1;
            v1=v2;
            v2=tmp;
        }else{
            int f; char c;
            cin >> f >> c;
            if(f==1) v1.pb(c);
            else v2.pb(c);
        }
    }
    //cout << ok << endl;
    if(ok==1){
        for(int i=v1.size()-1;i>=0;i--) cout << v1[i];
        for(int i=s.size()-1;i>=0;i--) cout << s[i];
        rep(i,v2.size()) cout << v2[i];
    }else{
        for(int i=v1.size()-1;i>=0;i--) cout << v1[i];
        rep(i,s.size()) cout <<s[i];
        rep(i,v2.size()) cout << v2[i];
    }
}



Measured memory_bytes: 1152
#include <stdio.h>

#define N 100000

int Search(int S[], int n, int key)
{
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == S[mid])  return 1;
    if(key > S[mid]) left = mid +1;
    else if(key < S[mid]) right = mid;
  }
  return 0;
}

int main()
{

  int i, S[N], n, q, count = 0, T;

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d", &S[i]);

  scanf("%d",&q);
  
  for(i = 0; i < q; i++) {
    scanf("%d",&T);
    if( Search(S, n, T) == 1 ) count++;
	 }
  
    printf("%d\n", count);

    return 0;
}

Measured memory_bytes: 992
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"sort"
	"strconv"
)

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	M := nextInt()
	// P := make([]int, M)
	// Y := make([]int, M)
	city := make([][]Pair, N+1)
	cityIdx := make([]int, M+1)
	cityKen := make([]int, M+1)
	for i := 0; i < M; i++ {
		p := nextInt() // 県
		y := nextInt() // 年
		city[p] = append(city[p], Pair{a: i + 1, b: y})
	}
	log.Println(city)
	for i := 1; i < N+1; i++ {
		sort.Sort(Pairs(city[i]))
		for j := 0; j < len(city[i]); j++ {
			cityIdx[city[i][j].a] = j + 1
			cityKen[city[i][j].a] = i
		}
	}
	out := bufio.NewWriter(os.Stdout)
	for i := 1; i < M+1; i++ {
		fmt.Fprintf(out, "%06d%06d\n", cityKen[i], cityIdx[i])
	}
	out.Flush()
}
func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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


int main(void){
	ll n,t;
	cin>>n>>t;
	vector<ll> A(n);
	for(auto&i:A)cin>>i;
	ll cheapest = 2000000000;
	ll best_margin = 0;
	for(auto i:A){
		best_margin = max(best_margin, i - cheapest);
		cheapest = min(cheapest, i);
	}
	cheapest = 2000000000;
	int times = 0;
	for(auto i:A){
		ll margin = i - cheapest;
		if(margin == best_margin) times++;
		cheapest = min(cheapest, i);
	}
	cout<<times<<'\n';

	return 0;
}


Measured memory_bytes: 4028
#include <cstdio>
#include <cstring>
int dp[1002][1002],field[1002][1002];
int main() {
	int H,W,N;
	while(scanf("%d %d %d",&H,&W,&N),H|W|N) {
		for(int y=1;y<=H;y++) {
			for(int x=1;x<=W;x++) {
				scanf("%d",&field[x][y]);
			}
		}
		memset(dp,0,sizeof(dp));
		dp[1][1]=N-1;
		for(int y=1;y<=(H+1);y++) {
			for(int x=1;x<=(W+1);x++) {
				if(dp[x][y-1]&1) {
					if(!field[x][y-1]) dp[x][y]+=(dp[x][y-1]+1)/2; else dp[x][y]+=(dp[x][y-1]-1)/2;
				}else {
					dp[x][y]+=dp[x][y-1]/2;
				}
				if(dp[x-1][y]&1) {
					if(field[x-1][y]) dp[x][y]+=(dp[x-1][y]+1)/2; else dp[x][y]+=(dp[x-1][y]-1)/2;
				}else {
					dp[x][y]+=dp[x-1][y]/2;
				}
			}
		}
		int x=1,y=1;
		while(x<=W&&y<=H) {
			if((field[x][y]+dp[x][y])&1) x++; else y++;
		}
		printf("%d %d\n",y,x);
	}
}

Measured memory_bytes: 8880
#include <stdio.h>
int main ()
{
    int kansya[4][3][10];
    int kazu,tou,kai,ban,hito;
    int a,b,c,d;
 
    for(a=0;a<4;a++)//?????????
    {
        for(b=0;b<3;b++)
        {
            for(c=0;c<10;c++)
            {
                kansya[a][b][c]=0;
            }
        }
    }
 
 
    scanf("%d",&kazu);
 
    for(a=0;a<kazu;a++)//??\???
    {
        scanf("%d %d %d %d",&tou,&kai,&ban,&hito);
        kansya[tou-1][kai-1][ban-1]=hito + kansya[tou-1][kai-1][ban-1];
         
    }
 
     
    for(a=0;a<4;a++)//??????
    {
        for(b=0;b<3;b++)
        {
     
            for(c=0;c<10;c++)
            {
                printf(" %d",kansya[a][b][c]);
            }
     
             
            printf("\n");
 
        }
        if(a<3)
        {
             
            printf("####################\n");
             
        }
    }
    return(0);
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
         
typedef long long ll;
using namespace std;
        
#define F first
#define S second
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define repit(i, n) for(auto it = n.begin(); it != n.end(); ++it)
       
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);}
          
bool comp(pair<string, int> a, pair<string, int> b){
    return a.S < b.S;
}

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    int n , k;
    cin >> n >> k;
    int ans = 1;
    for(int i = 1; i <= n; ++i){
        if(ans * 2 < ans + k){
            ans *= 2;
        }else{
            ans += k;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.array,
       std.math,
       std.algorithm;

void main() {
    auto n = readln.chomp.to!int;
    while(n--) {
        auto p = readln.split.map!(x => x.to!double).array;
        auto x = ((p[1] - p[5]) * (p[1] * p[1] - p[3] * p[3] + p[0] * p[0] - p[2] * p[2]) - (p[1] - p[3]) * (p[1] * p[1] - p[5] * p[5] + p[0] * p[0] - p[4] * p[4])) / (2 * (p[1] - p[5]) * (p[0] - p[2]) - 2 * (p[1] - p[3]) * (p[0] - p[4]));
        auto y = ((p[0] - p[4]) * (p[0] * p[0] - p[2] * p[2] + p[1] * p[1] - p[3] * p[3]) - (p[0] - p[2]) * (p[0] * p[0] - p[4] * p[4] + p[1] * p[1] - p[5] * p[5])) / (2 * (p[0] - p[4]) * (p[1] - p[3]) - 2 * (p[0] - p[2]) * (p[1] - p[5]));
        auto r = sqrt((p[0] - x).pow(2) + (p[1] - y).pow(2));
        writefln("%.3f %.3f %.3f", x, y, r);
    }
}

Measured memory_bytes: 1140
n = int(input())
s = list(map(int, input()))

ans = []

for i in range(10):
    if i in s:
        a = s.index(i)
        for j in range(10):
            if j in s[a + 1 :]:
                b = a + s[a + 1 :].index(j) + 1
                for k in range(10):
                    if k in s[b + 1 :]:
                        ans.append(f"{i}{j}{k}")
print(len(ans))

Measured memory_bytes: 9544
// AtCoder Grand Contest 016 D

#include <cstdio>
#include <vector>
#include <map>

#define fir first
#define sec second
#define pb push_back

const int MAXN = 1e5 + 10;

typedef std::map<int, int> MyMp;
typedef int IntAr[MAXN];

int N, S, T, tote;
IntAr dgr, A, B, vis;
MyMp Mp;
std::vector<int> G[MAXN];

namespace FastIO {
	template <typename T>
		void read(T & x) {
			x = 0; register char ch = getchar();
			for (; ch < '0' || ch > '9'; ch = getchar());
			for (; ch >= '0' && ch <= '9'; x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar());
		}
}
inline void add_edge(int u, int v) {
	++tote, ++dgr[u], --dgr[v];
	G[u].pb(v);
}
void dfs(int u) {
	vis[u] = 1;
	for (auto v : G[u])
		if (!vis[v]) dfs(v);
}

int main() {
	using FastIO::read;
	read(N);
	int _xor = 0;
	for (int i = 0; i < N; i++) {
		read(A[i]);
		_xor ^= A[i], Mp[A[i]] = 0;
	}
	for (int i = 0; i < N; i++) {
		read(B[i]);
		Mp[B[i]] = 0;
	}
	Mp[_xor] = 0;
	int rk = 0;
	for (MyMp::iterator it = Mp.begin(); it != Mp.end(); ++it) it->sec = ++rk;
	for (int i = 0; i < N; i++) A[i] = Mp[A[i]], B[i] = Mp[B[i]];
	S = _xor = Mp[_xor];
	for (int i = 0; i < N; i++)
		if (A[i] ^ B[i]) add_edge(B[i], A[i]);
	int ans = 0;
	if (dgr[S] == 1) {
		T = -1;
		for (int i = 1; i <= rk; i++)
			if (i ^ _xor && dgr[i] == -1) {
				if (~T) return puts("-1"), 0;
				T = i;
			}
		add_edge(T, S), --ans;
	}
	else {
		T = S;
		for (int i = 1; i <= rk; i++)
			if (dgr[i]) return puts("-1"), 0;
	}
	for (int i = 1; i <= rk; i++) {
		if (G[i].size() && !vis[i]) {
			++ans;
			dfs(i);
		}
	}
	ans += tote;
	if (vis[S]) --ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 15104
n=int(input())
x=[int(input())]
for i in range(n-1):
  a=int(input())
  if x[-1]>=a:
    x+=[a]
  else:
    low=0
    high=len(x)-1
    mid=(high+low)//2
    while high-low>1:
      if x[mid]<a:
        high=mid
      else:
        low=mid
      mid=(high+low)//2
    if x[mid]<a:
      x[mid]=a
    else:
      x[high]=a
print(len(x))

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

#define MAX_N 100000

long N;
long A[MAX_N], B[MAX_N], C[MAX_N];

void solve(){
    long BS[MAX_N];
    for(long i = 0; i < N; i++){
        if (B[i] >= C[N - 1]) {
            BS[i] = 0;
            continue;
        }
        long n = distance(C, upper_bound(C, C + N, B[i]));
        BS[i] = N - n;
    }
    long BSS[MAX_N];
    for(long i = N - 1; i >= 0; i--){
        if (i == N - 1) {
            BSS[i] = BS[i];
            continue;
        }
        BSS[i] = BS[i] + BSS[i + 1];
    }
    long ans = 0;
    for(long i = 0; i < N; i++){
        if (A[i] >= B[N - 1]) break;
        long n = distance(B, upper_bound(B, B + N, A[i]));
        ans += BSS[n];
    }
    cout << ans << endl;
    return;
}

int main(){
    cin >> N;
    for(long i = 0; i < N; i++) cin >> A[i];
    for(long i = 0; i < N; i++) cin >> B[i];
    for(long i = 0; i < N; i++) cin >> C[i];
    sort(A, A + N);
    sort(B, B + N);
    sort(C, C + N);
    solve();
    return 0;
}

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]); // 経路縮約
  }
  bool unite(int x, int y) {
    x=find(x); y=find(y);
    if (x==y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  int size(int x) {
    return -d[find(x)];
  }
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) { // friend
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) { // block
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}
      
  
    


Measured memory_bytes: 6784
#include <iostream>
#include <vector>

using namespace std;

int r, c;
vector<vector<int> > field;
 
int search()
{
    int counter;
    int max_num = 0;

    counter = 1 << r;
    for (int i = 0; i < counter; i++) {
        int num = 0;

        for (int j = 0; j < r; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < c; k++) {
                    field[j][k] ^= 1;
                }
            }
        }

        for (int j = 0; j < c; j++) {
            int co_num = 0;
            for (int k = 0; k < r; k++) {
                co_num += field[k][j];
            }

            if (co_num <= r / 2) {
                num += r - co_num;
            } else {
                num += co_num; /*reverse*/
            }
        }

        if (max_num < num) {
            max_num = num;
        }

        for (int j = 0; j < r; j++) {
            if ((i >> j) & 1) {
                for (int k = 0; k < c; k++) {
                    field[j][k] ^= 1;
                }
            }
        }
    }

    return max_num;
}

int main(int argc, char **argv)
{
    cin >> r >> c;

    while (r != 0 && c != 0) {
        field.clear();
        for (int i = 0; i < r; i++) {
            field.push_back(vector<int>(c));
            for (int j = 0; j < c; j++) {
                cin >> field[i][j];
            }
        }
        cout << search() << endl;
        cin >> r >> c;
    }
    return 0;
}

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

int main()
{
 int m = 100000;
 int w;

 cin >> w;

 for(int i=0; i<w; i++){
  m *= 1.05;
  m += 999;
  m /= 1000;
  m *= 1000;
 }

 cout << m << '\n';

 return 0;
}

Measured memory_bytes: 1160
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] A = new int[N];
		Arrays.setAll(A, $ -> Integer.parseInt(sc.get()));
		Arrays.sort(A);

		PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());
		queue.add(A[A.length - 1]);
		long sum = 0;
		for (int i = A.length - 2; i >= 0; i--) {
			int rem = queue.remove();
			sum += rem;

			queue.add(A[i]);
			queue.add(A[i]);
		}
		System.out.println(sum);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

Measured memory_bytes: 62840
n = int(raw_input())
r = []
for i in range(n):
    r.append(int(raw_input()))

min_v = r[0]
max_profit = -1000000000000
for i in range(1,n):
    if max_profit < r[i] - min_v:
        max_profit = r[i]-min_v
    if r[i] < min_v:
        min_v = r[i]

print max_profit

Measured memory_bytes: 18868
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    set<char> odd;
    set<char> even;

    string s;
    cin >> s;

    for(int i = 0; i < s.length(); i++) {
        if(i % 2 == 0) {
            odd.insert(s[i]);
        } else {
            even.insert(s[i]);
        }
    }

    int is_odd = odd.count('L');   // Lがあれば1
    int is_even = even.count('R'); // Rがあれば1

    if(is_odd || is_even) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, b, c;
	int max, min, total = 0;
	scanf("%d %d %d", &a, &b, &c);
	total = a + b + c;
	if(a > b && a > c)
	{
		max = a;
	}
	else if(b > a && b > c)
	{
		max = b;
	}
	else
	{
		max = c;
	}
	
	if(a < b && a < c)
	{
		min = a;
	}
	else if(b < a && b < c)
	{
		min = b;
	}
	else
	{
		min = c;
	}
	printf("%d %d %d\n", min, total-max-min, max);
	
	return 0; 
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
 // c_p_c();
  int v[3];
  for(int i=0;i<3;i++)
  {
    cin >> v[i];
  }
  sort(v,v+3);
  cout<<abs(v[0] - v[1]) + abs(v[1] - v[2])<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstdio>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007


double vector_2nd(double a,double b){

    return b-a;
}



int main(){

    //A(x1,y1) B(x2,y2) C(x3,y3) P(xp,yp)
    double x1,x2,x3,xp,y1,y2,y3,yp;
    while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
        double CA_X,CA_Y;
        double AP_X,AP_Y;
        double BC_X,BC_Y;
        double CP_X,CP_Y;
        double AB_X,AB_Y;
        double BP_X,BP_Y;
        CA_X = vector_2nd(x1,x3);
        CA_Y = vector_2nd(y1,y3);
        AP_X = vector_2nd(xp,x1);
        AP_Y = vector_2nd(yp,y1);
        BC_X = vector_2nd(x3,x2);
        BC_Y = vector_2nd(y3,y2);
        CP_X = vector_2nd(xp,x3);
        CP_Y = vector_2nd(yp,y3);
        AB_X = vector_2nd(x2,x1);
        AB_Y = vector_2nd(y2,y1);
        BP_X = vector_2nd(xp,x2);
        BP_Y = vector_2nd(yp,y2);

        double outer_product_1 = CA_X*AP_Y-CA_Y*AP_X;
        double outer_product_2 = BC_X*CP_Y-BC_Y*CP_X;
        double outer_product_3 = AB_X*BP_Y-AB_Y*BP_X;

        if((outer_product_1 > 0 && outer_product_2 > 0 && outer_product_3 > 0) || (outer_product_1 < 0 && outer_product_2 < 0 && outer_product_3 < 0)){

            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }




        




    }
    return 0;
}


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

int solve(int id, const vector< vector<int> > &edges, vector<int> &memo) {
  if (memo[id] == -1) {
    return -1;
  }
  if (memo[id] != 0) {
    return memo[id];
  }
  memo[id] = -1;
  int max_val = 0;
  for (int i = 0; i < edges[id].size(); i++) {
    auto nextId = edges[id][i];
    auto tmp = solve(nextId, edges, memo);
    if (tmp == -1) {
      return -1;
    }
    max_val = max(tmp, max_val);
  }
  memo[id] = max_val + 1;
  return memo[id];
}

int main() {
  int n; cin >> n;
  vector< vector<int> > as(n, vector<int>(n - 1, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) { cin >> as[i][j]; as[i][j]--; }
  }

  map< pair<int,int>, int > pair2id;
  map< int, pair<int,int> > id2pair;
  int idCnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      auto p = make_pair(i,j);
      pair2id[p] = idCnt;
      id2pair[idCnt] = p;
      idCnt++;
    }
  }
  vector< vector<int > > edges(idCnt, vector<int>(0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 2; j++) {
      int src = as[i][j];
      int dest = as[i][j+1];
      auto startId = pair2id[make_pair(min(i, src), max(i, src))];
      auto endId = pair2id[make_pair(min(i, dest), max(i, dest))];
      edges[startId].push_back(endId);
    }
  }
  vector<int> memo(idCnt, 0);
  auto ans = 0;
  for (int i = 0; i < idCnt; i++) {
    // cout << id2pair[i].first << "," << id2pair[i].second << endl;
    auto tmp = solve(i, edges, memo);
    if (tmp == -1) {
      ans = -1;
      break;
    } 
    ans = max(tmp, ans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80384
mod = pow(10,9)+7
n,m = map(int,input().split())
ans = 0
inv = [0,1]
fact = [1,1]
ifact = [1,1]
for i in range(2,m+1):
    inv.append(inv[mod%i]*(mod-int(mod/i))%mod)
    fact.append(i*fact[-1]%mod)
    ifact.append(ifact[-1]*inv[i]%mod)

def combi(a,b):
    return fact[a]*ifact[b]*ifact[a-b]%mod
def permi(a,b):
    return fact[a]*ifact[a-b]%mod

for i in range(n+1):
    now = combi(n,i)
    now *= permi(m-i,n-i)
    now %= mod
    ans += now*(-1)**(i&1)
    ans %= mod
ans *= permi(m,n)
ans %= mod
print(ans)

Measured memory_bytes: 192968
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct node
{
	int cost, x, y, o, hori;
	node(int cost, int x, int y, int o, int hori)
		: cost(cost), x(x), y(y), o(o), hori(hori) {}
};
bool operator<(const node& a, const node& b)
{
	return a.cost > b.cost;
}
int main()
{
	int W, H, f, m, o, c[10][10];
	while (scanf("%d%d", &W, &H), W|H)
	{
		scanf("%d%d%d", &f, &m, &o);
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				scanf("%d", &c[i][j]);

		static int visit[10][10][1<<10][51];
		for (int i = 0; i < H; ++i)
			for (int j = 0; j < W; ++j)
				for (int k = 0; k < 1 << W; ++k)
					for (int l = 0; l <= m; ++l)
					visit[i][j][k][l] = false;

		int res = -1;
		priority_queue<node> q;
		for (int i = 0; i < W; ++i)
			q.push(node(0, i, 0, o, 0));
		while (!q.empty())
		{
			node e = q.top(); q.pop();
			if (e.cost > f)
				break;
			else if (e.x < 0 || e.x >= W
				|| (e.y != H &&
					(e.o <= 1 || visit[e.y][e.x][e.hori][e.o])))
				continue;
			else if (e.y == H)
			{
				res = e.cost;
				break;
			}

			visit[e.y][e.x][e.hori][e.o] = true;
			--e.o;
			if (!(e.hori & (1 << e.x)))
			{
				e.hori |= 1 << e.x;
				if (c[e.y][e.x] < 0)
					e.cost -= c[e.y][e.x];
				else
					e.o = min(m, e.o + c[e.y][e.x]);
			}

			q.push(node(e.cost, e.x, e.y+1, e.o, 0));
			if (e.o > 1)
			{
				if (e.x > 0)
					q.push(node(e.cost, e.x-1, e.y, e.o, e.hori));
				if (e.x < W-1)
					q.push(node(e.cost, e.x+1, e.y, e.o, e.hori));
			}
			//q.push(node(e.cost, e.x, e.y+1, e.o, 0));
			//q.push(node(e.cost, e.x-1, e.y, e.o, e.hori));
			//q.push(node(e.cost, e.x+1, e.y, e.o, e.hori));
		}

		if (res != -1)
			printf("%d\n", res);
		else
			puts("NA");
	}

	return 0;
}

Measured memory_bytes: 20000
# -*- coding: utf-8 -*-

N, M = map(int, input().split())

road_count_list = [0] * N

for i in range(M):
    a, b = map(int, input().split())
    road_count_list[a - 1] = road_count_list[a - 1] + 1
    road_count_list[b - 1] = road_count_list[b - 1] + 1

print(*road_count_list, sep='\n')

Measured memory_bytes: 9148
import java.util.Scanner;
public class Main {

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

//		５０人以下のとき
		int a = 0;
	while(a<49){
//
//	m読み込み
		int m = sc.nextInt();
//
//	f読み込み
		int f = sc.nextInt();
//
//	r読み込み
		int r = sc.nextInt();
//
//	合計mf計算
		int mf = 0;
		
		if(m == -1){
			mf = f;
		}
		else if(f == -1){
			mf = m;
		}
		else{
			mf = m + f;
		}
		
		
//		m、f、r がすべて -1
			if(m==-1&&f==-1&&r==-1)break;//終了

//		mかfが-1ならF
			if((m!=-1&&f!=-1)&&80<=mf){
				System.out.println("A");
			}
			else if((m!=-1&&f!=-1)&&65<=mf){
				System.out.println("B");
			}
			else if((m!=-1&&f!=-1)&&50<=mf){
				System.out.println("C");
			}
			else if((m!=-1&&f!=-1)&&30<=mf){
				if(r<50){
					System.out.println("D");
				}
				else {
					System.out.println("C");
				}
			}
			else{
				System.out.println("F");
			}
			a++;
		}

	}

}



Measured memory_bytes: 26264
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int n, y, m, d, count;

	scanf("%d\n",&n);

	for(int i=0; i<n; i++){
		scanf("%d %d %d\n",&y, &m, &d);
		count=0;
		/* 翌年から記念日までの日数 */
		for(int j=y+1; j<1000; j++){
			if(j%3==0){ count += 200;}
			else{ count += 195;}
		}
		/* 翌月から年末までの日数 */
		for(int j=m+1; j<=10; j++){
			if((y%3!=0)&&(j%2==0)){ count += 19;}
			else{count += 20;}
		}
		/* 翌日から月末までの日数 */
		if((y%3!=0)&&(m%2==0)){ count += 19-d;}
		else{count += 20-d;}

		printf("%d\n",count+1); /* 当日分+1 */
	}
	return 0;
}

Measured memory_bytes: 1192
# from math import factorial
# from collections import defaultdict, deque
#  from heapq import heappush, heappop

# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]

S = (input())
T = (input())
ans = 0
for i in range(len(S)):
  if S[i] == T[i]:
     ans += 1
print(ans)


Measured memory_bytes: 2940
n,k = map(int,input().split())
j=0
m=0
ans = 0
if k % 2 == 1:
    j= n//k
    #print('j',j)
    ans=j*j*j

else:
    j=n//k
    m=(n-k//2)//k+1
    #print('j',j,'m',m)
    ans=m*m*m+j*j*j
 
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
int main() {
    int i,n,x,min,max;
    min=1000000;
    max=-1000000;
    long long int sum=0; 
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&x);
        if(x<min){
            min=x;
        }
        if(x>max){
            max=x;
        }
        sum=sum+x;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
using namespace std;

int main()
{
    int n, k;
    int ans = 1000000000;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h), greater<int>());
    rep(i, n - k + 1)
    {
        ans = min(ans, h[i] - h[i + k - 1]);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int N, K;
ll R, S, P;
string T;

ll dp[100000 + 100][3];//j -> 0->r 1->s 2->p

int main() {
	cin >> N >> K >> R >> S >> P >> T;
	ll ans = 0;
	for (int i = 0; i < K; i++) {
		if (T[i] == 'r') {
			dp[i][2] = P;
		}
		else if (T[i] == 'p') {
			dp[i][1] = S;
		}
		else {
			dp[i][0] = R;
		}
		ll tmp = 0;
		for (int j = i + K; j < N; j += K) {
			dp[j][0] = max(dp[j - K][1], dp[j - K][2]);
			dp[j][1] = max(dp[j - K][0], dp[j - K][2]);
			dp[j][2] = max(dp[j - K][0], dp[j - K][1]);
			if (T[j] == 'r') {
				dp[j][2] = P + max(dp[j - K][0], dp[j - K][1]);
			}
			else if (T[j] == 'p') {
				dp[j][1] = S + max(dp[j - K][0], dp[j - K][2]);
			}
			else {
				dp[j][0] = R + max(dp[j - K][1], dp[j - K][2]);
			}
			tmp = max(tmp, max(dp[j][0], max(dp[j][1], dp[j][2])));
		}
		//ans += tmp;
	}
	for (int i = N - 1; i > N - 1 - K; i--) {
		ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; }
const ll MAXN=1e5+4;
ll c[MAXN];
bool r[MAXN];
int main() {
	ios_base::sync_with_stdio(false);
	ll n,m; scanf("%lld %lld",&n,&m);
	for (ll i=1;i<=n;i++) {c[i]=1;r[i]=false;}
	r[1]=true;
	for (ll i=0;i<m;i++) {
		ll x,y; scanf("%lld %lld",&x,&y);
		c[y]++;
		if (r[x]) r[y]=true;
		c[x]--;
		if (c[x]==0) r[x]=false;
		//printf("x:%d c:%d r:%d -> y:%d c:%d r:%d\n",x,c[x],r[x],y,c[y],r[y]);
	}
	ll ans=0;
	for (ll x=1;x<=n;x++) {
		if (r[x]) ans++;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys



def main(h, w, a):
    ret = []
    ret.append(''.join(['#'] * (w + 2)))
    for v in a:
        r = '#' + v + '#'
        ret.append(r)
    ret.append(''.join(['#'] * (w + 2)))
    for r in ret:
        print(r)

if __name__ == '__main__':
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    main(h, w, a)


Measured memory_bytes: 3060
S = int(input())
cache = {}
cache[S] = 1
for i in range(1000000):
  if S % 2 == 0:
    S = S // 2
  else:
    S = 3 * S + 1
  if cache.get(S):
    print(i + 2)
    exit()
  cache[S] = 1

Measured memory_bytes: 38256
h = Hash.new(0)
gets
a = gets.chomp.split(" ").map(&:to_i)
a.each {|v| h[v] += 1}

ans = 0
h.each do |key, val|
    if val < key
        ans += val
    elsif val > key
        ans += val - key
    end
end
puts ans

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

int main() {
    ll aa=0,bb=0,cc=0;
    string a,b,c;
    cin>>a>>b>>c;
    char now;
    char ans;
    now='a';
    while(1){
        if(now=='a'){
           
            if(aa==a.size()){
                cout<<"A"<<endl;
                return 0;
            }
            now=a[aa];
            aa++;
        }else if(now=='b'){
            
            if(bb==b.size()){
                cout<<"B"<<endl;
                return 0;
            }
            now=b[bb];
            bb++;
        }else if(now=='c'){
            
            if(cc==c.size()){
                cout<<"C"<<endl;
                return 0;
            }now=c[cc];
            cc++;
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] s = new int[n];
		for (int i = 0; i < n; i++) {
			s[i] = sc.nextInt();
		}

		int q = sc.nextInt();
		int[] t = new int[q];
		for (int i = 0; i < q; i++) {
			t[i] = sc.nextInt();
		}
		sc.close();

		int count = 0;
		for(int sagasu : t) {
			for(int sagasareru : s) {
				if(sagasu == sagasareru) {
					count++;
					break;
				}
			}
		}

		System.out.println(count);

	}
}

Measured memory_bytes: 40156
n = int(input())
b = list(map(int, input().split()))

s = 0
for i in range(n):
    if 0 < i < n-1:
        if b[i-1] < b[i]:
            s += b[i-1]
        else:
            s += b[i]
    elif i == 0:
        s += b[i]
    else:
        s += b[i-1]
print(s)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n, y;

  cin >> n >> y;

  y /= 1000;

  for(int i=0;i<=n;i++){
    for(int j=0;i+j<=n;j++){
      int z = y - i*10 - j*5;
      if(0 <= z && z + i + j == n){
        printf("%d %d %d\n", i, j, z);
        return 0;
      }
    }
  }

  printf("-1 -1 -1\n");
  
  return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    ll h;
    cin>>h;
    ll chc=1;
    while(h>chc){
        chc=chc*2+1;
    }
    cout<<chc<<endl;
    return 0;
}

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

int main(){
    int n,x,i;
    cin >> n>> x;
    int a[n];
    for(i=0;i<n;i++){
        cin >> a[i];
    }

    sort(a,a+n);
    for(i=0;i<n;i++){
        x-=a[i];
        if(x<0){
            break;
        }
    }
    if(x>0) i--;
    cout << i << endl;
}

Measured memory_bytes: 256
K=int(input())
ls = [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]
print(ls[K-1])

Measured memory_bytes: 2940
def f(x,y):
    if x==1:
        return(y)
    if x%2==0:
        return(f(x/2,y+1))
    else:
        return(f(3*x+1,y+1))

while True:
    x=int(input().strip())
    if x==0:
        break
    print(f(x,0))



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

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}
	printf("%d\n", pop());
	return 0;
}


Measured memory_bytes: 2128
#include <stdio.h>

int main(void){
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a < b){
		if(b < c)
			d = a*b;
		else
			d = a*c;
	}
	else{
		if(a < c)
			d = a*b;
		else
			d = b*c;
	}
	
	d = d/2;
	printf("%d",d);
	
	return 0;
	}

Measured memory_bytes: 128
n = gets.to_i
s = gets.chomp
cnt = ans = 0
(0..s.size-1).each do|i|
  x = s.slice(0..i).chars.uniq
  y = s.slice(i+1..s.size-1).chars.uniq
  cnt = 0
  x.each do |k|
    if y.include?(k)
      cnt += 1
    end
  end
  ans = cnt if ans < cnt
end
puts ans


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

int main(){
  int n;
  cin >> n;
  vector<string> a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  sort(a.begin(),a.end());
  
  vector<int> b(n);
  
  for(int i=n-1;i>0;i--){
    if(a.at(i)==a.at(i-1)){
      b.at(i-1)++;
      b.at(i-1)+=b.at(i);
      a.at(i)=' ';
    }
  }
  
  int k=0;
  
  for(int i=0;i<n;i++)
    k=max(k,b.at(i));
  
  for(int i=0;i<n;i++){
    if(b.at(i)==k)
      cout << a.at(i) << endl;
  }
  
}

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

/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int main()
{
    int w, h, n;

    cin >> w >> h >> n;

    int a[10000], b[10000];
    REP(i, n){
        int c, d;
        cin >> c >> d;
        a[i] = c;
        b[i] = d;
    }

    int sum = 0;
    REP(i, n - 1){
        if (a[i] < a[i + 1] && b[i] < b[i + 1]){
            sum += max(a[i + 1] - a[i], b[i + 1] - b[i]);
        }
        else if (a[i] > a[i + 1] && b[i] > b[i + 1]){
            sum += max(a[i] - a[i + 1], b[i] - b[i + 1]);
        }
        else {
            sum += abs(a[i + 1] - a[i]) + abs(b[i + 1] - b[i]);
        }
    }

    CL(sum);
    
	return (0);
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		//1周の距離
		int K = sc.nextInt();
		//家の数
		int N = sc.nextInt();

		//家の距離
		int A[] = new int[N];
		int B[] = new int[N];

		int sum = 0;
		//家の数分繰り返す
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();

		}

		//
		for (int i = 0; i < N; i++) {
			if (i == 0) {
				B[i] = K - A[N - 1] + A[i];
			} else {
				B[i] = A[i] - A[i - 1];
			}
		}
		Arrays.sort(B);

		for (int i = 0; i < N - 1; i++) {
			sum += B[i];

		}
		System.out.println(sum);
		sc.close();
	}

}


Measured memory_bytes: 61756
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int A,B,C; cin >> A >> B >> C;
    int ans;

    int maxnum = max(max(A,B),C);
    if(((maxnum-A)+(maxnum-B)+(maxnum-C)) % 2 == 0) ans = ((maxnum-A)+(maxnum-B)+(maxnum-C)) / 2;
    else ans = (maxnum - A + maxnum - B + maxnum - C + 3) / 2;

    cout << ans << endl;

}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define endl '\n'

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int a, b;
	cin >> a >> b;
	if(b > a) swap(a, b);
	int dif = a - b;
	if(dif % 2 == 0) cout << b + (dif / 2) << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
import heapq

N = int(input())
A = list(map(int, input().split()))

A_sorted = sorted(A,reverse = True)

circle = []
heapq.heappush(circle, -A_sorted[1])
heapq.heappush(circle, -A_sorted[1])
answer = A_sorted[0]

for i in range(2,N):
    target = A_sorted[i]
    popped = heapq.heappop(circle)
    answer -= popped
    heapq.heappush(circle, -target)
    heapq.heappush(circle, -target)

print(answer)

Measured memory_bytes: 100180
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#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 FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    CIN(H);CIN(W);
    REP(i,H){
        string s;cin >> s;
        COUT(s);COUT(s);
    }
    return 0;
}


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

struct p{
	long long x,y,idx;
	unsigned long long sqrdist(p b){
		return (x-b.x)*(x-b.x)+(y-b.y)*(y-b.y);
	}
	void read(){
		cin >> x >> y;
	}
	long long operator *(p b){
		return x*b.y - y*b.x;
	}
	bool operator ==(p b){
		return x == b.x && y == b.y;
	}
	void operator -=(p b){
		x -= b.x,y -= b.y;
	}
	bool operator >=(p b){
		return x >= b.x && y >= b.y;
	}
	bool operator <=(p b){
		return x <= b.x && y <= b.y;
	}
	p operator -(p b){
		return {x-b.x,y-b.y};
	}
	long long crossprod(p a , p b){
		a.x -= x , b.x -= x , a.y -= y , b.y -= y;
		return a*b;
	}
};

struct segment{
	p p1,p2;
	void equal(p a , p b){
		p1 = a , p2 = b;
	}
	void readseg(){
		p1.read(),p2.read();
	}
};

bool comp(p a , p b){
	return a.y < b.y;
	//
}

void convexhull(vector<p> v , vector<p> c){
	sort(v.begin(),v.end(),comp);
	for(long long q = 0 ; q < 2 ; q += 1){
		vector<p> g;
		g.push_back(v[0]);
		for(long long i = 1 ; i < v.size() ; i += 1){
			while(g.size() >= 2 && ((v[i] - g[g.size()-2])*(g.back() - g[g.size()-2]) <= 0)){
				g.pop_back();
			}
			g.push_back(v[i]);
		}
		if(q == 0){
			g.pop_back();
		}
		for(p i : g){
			c.push_back(i);
		}
		reverse(v.begin(),v.end());
	}
}

bool intersect(segment a , segment b){
	for(long long i = 0 ; i < 2 ; i += 1){
		p p1 = a.p1;
		long long v1 = (b.p1 - p1)*(a.p2 - p1) , v2 = (b.p2 - p1)*(a.p2 - p1);
		if(v1 * v2 > 0){
			return false;
		}else if(v1 == 0 && v2 == 0){
			if(max(a.p1.x,a.p2.x) < min(b.p1.x,b.p2.x) || max(a.p1.y,a.p2.y) < min(b.p1.y,b.p2.y)){
				return false;
			}
		}
		swap(a,b);
	}
	return true;
}

bool equal(vector<p> a , vector<p> b){
	if(a.size() != b.size()){
		return false;
	}
	for(long long i = 0 ; i < a.size() ; i += 1){
		if(a[i] == b[i]){
			continue;
		}
		return false;
	}
	return true;
}
vector<p> all = {{1,0},{0,1},{-1,0},{0,-1}};
bool ok[22][22];
int n,m;

int bfs(p s , p e){
	queue<p> q;
	q.push(s);
	vector<vector<bool>> seen(22,vector<bool>(22,false));
	int dist = 0;
	while(q.size()){
		int f = q.size();
		while(f--){
			p a = q.front();
			q.pop();
			if(seen[a.x][a.y] || a.x <= 0 || a.x > n || a.y <= 0 || a.y > m){
				continue;
			}
			seen[a.x][a.y] = true;
			if(a.x == e.x && a.y == e.y){
				return dist;
			}
			for(p i : all){
				p next = a;
				next -= i;
				if(!seen[next.x][next.y] && ok[next.x][next.y]){
					q.push(next);
				}
			}
		}
		dist += 1;
	}
}

int main(){
	cin >> n >> m;
	for(int i = 1 ; i <= n ; i += 1){
		for(int j = 1 ; j <= m ; j += 1){
			char a;
			cin >> a;
			if(a == '.'){
				ok[i][j] = true;
			}
		}
	}
	int maxi = 0;
	for(int i = 1 ; i <= n ; i += 1){
		for(int j = 1 ; j <= m ; j += 1){
			for(int ii = 1 ; ii <= n ; ii += 1){
				for(int jj = 1 ; jj <= m ; jj += 1){
					if(ok[i][j] && ok[ii][jj]){
						p a = {i,j} , b = {ii,jj};
						maxi = max(maxi,bfs(a,b));
					}
				}
			}
		}
	}
	cout << maxi << endl;
}

Measured memory_bytes: 256