akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int numOdd = 0;
		int numEven = 0;
		int num = 0;
		for (int i = 0; i < n; i++) {
			num = sc.nextInt();
			if (num % 2 == 0) {
				numEven++;
			} else {
				numOdd++;
			}
		}
		numEven += numOdd/2;
		numOdd = numOdd%2;
		
		
//		System.out.println(numOdd + " " + numEven);
		if (numEven > 0) {
			numEven = 1;
		} else {
			numEven = 0;
		}
		
		if (numOdd + numEven == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 32504
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<vector>
#include<string>
#define int long long
using namespace std;

signed main() {
	int k, a, b; cin >> k >> a >> b;
	if (a >= k) { puts("1"); }
	else if (a <= b) {
		puts("-1");
	}
	else {
		int ans = (k - a) / (a - b);
		if ((k - a) % (a - b))ans++;
		cout << ans * 2 + 1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long int
using namespace std;
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,b) for(i=a;i<b;i++)
#define vll vector<ll>
#define vlll vector<vll>
#define all(x) x.begin(),x.end()

int main()
{
  string s;
  cin >> s;
  ll ans=0, sum=0;
  
  for (ll i=0; i<s.size(); i++) {
    sum = (s[i] == 'R') ? sum + 1 : 0;
    ans = max(sum,ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[11111],ans;
signed main(){
  int n,m;
  cin>>n>>m;
  int v[n],w[n];
  r(i,11111)dp[i]=1e15;
  dp[0]=0;
  r(i,n)cin>>v[i]>>w[i];
  r(i,n)for(int j=11110;j>=0;j--){
    if(j-v[i]>=0){
      dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
      if(dp[j]<=m)ans=max(ans,j);
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3196
using System;
using System.IO;
using System.Linq;
class E { static void Main() { new K(); } }
class K
{
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	public K()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		var N = F();
		var x = G();
		int L = F(), Q = F();
		var r = new int[N];
		for (var i = 0; i < N; i++) r[i] = FirstBinary(i, N, k => x[k] > x[i] + L) - 1;
		var rn = new int[20][];
		rn[0] = r;
		for (var c = 1; c < 20; c++)
		{
			rn[c] = new int[N];
			for (var i = 0; i < N; i++) rn[c][i] = rn[c - 1][rn[c - 1][i]];
		}
		for (var q = 0; q < Q; q++)
		{
			var I = G();
			Array.Sort(I);
			Console.WriteLine(FirstBinary(1, N, d =>
			{
				var p = I[0] - 1;
				for (var c = 0; c < 20; c++) if ((d & (1 << c)) != 0) p = rn[c][p];
				return p >= I[1] - 1;
			}));
		}
		Console.Out.Flush();
	}
	int FirstBinary(int s, int t, Predicate<int> p)
	{
		while (s < t)
		{
			var m = (s + t) / 2;
			if (p(m)) t = m;
			else s = m + 1;
		}
		return s;
	}
}

Measured memory_bytes: 21448
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int w,h,n;
int x,y,a;
bool c[110][110];
signed main(){
	cin>>w>>h>>n;
	rep(i,n){
		cin>>x>>y>>a;
		if(a==1){
			rep(j,x){
				rep(k,h+1)c[j][k]=true;
			}
		}
		else if(a==2){
			for(int j=x;j<w;j++){
				rep(k,h)c[j][k]=true;
			}
		}
		else if(a==3){
			rep(j,w+1){
				rep(k,y)c[j][k]=true;
			}
		}
		else{
			rep(j,w){
				for(int k=y;k<h;k++)c[j][k]=true;
			}
		}
	}
	int ans=0;
	rep(i,w){
		rep(j,h){
			if(!c[i][j])ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

void print_v (vector<int> A){
    for(auto iter_A = A.begin(); iter_A != (A.end()-1); iter_A++){
        cout << *iter_A << " ";
    }
    cout << *(A.end()-1) << "\n";
}

// code
vector<int> selectionSort(vector<int> A, int N){

    int count = 0;

    int min_idx = 0;
    for (int i = 0; i < N; i++){
        min_idx = i;
        for (int j = i; j < N; j++){
            if(A[min_idx] > A[j]){
                min_idx = j;
            }
        }
        if(i != min_idx){
            swap(A[min_idx], A[i]);
            count++;
        }
    }

    print_v(A);
    cout << count << "\n";

    return A;
}

// main
int main(){
    // input
    int n;
    cin >> n;
    vector<int> v;
    int x;
    for(int i = 0; i < n; ++i){
        cin >> x;
        v.push_back(x);
    }

    selectionSort(v, n);

    return 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

// const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int a, b; cin >> a >> b;
    if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0) cout << "Possible" << endl;
    else cout << "Impossible" << endl;

    return 0;
}


Measured memory_bytes: 256
let rec solution h i m =
    if i == Array.length h then "Yes"
    else if h.(i) < m then "No"
    else solution h (i+1) @@ max (h.(i)-1) m;;

Printf.printf "%s\n" @@
Scanf.scanf "%d\n" @@ fun n ->
    let h = Array.init n @@ fun _ -> Scanf.scanf "%d " ( + ) 0 in
    solution h 0 0;;



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

int main() {
    int n;
    cin >> n;
    map<char, int> m1;
    string s1;
    cin >> s1;
    for (int i = 0; i < s1.size(); ++i) {
        if(m1.count(s1[i])){
            m1[s1[i]]++;
        }else{
            m1[s1[i]] = 1;
        }
    }
    for (int i = 1; i < n; ++i) {
        string s;
        cin >> s;
        map<char, int> m2;
        for (int i = 0; i < s.size(); ++i) {
            if(m2.count(s[i])){
                m2[s[i]]++;
            }else{
                m2[s[i]] = 1;
            }
        }
        for(auto x: m1){
            if(m2.count(x.first)){
                if(x.second > m2[x.first]){
                    m1[x.first]--;
                }
            }else{
                m1.erase(x.first);
            }
        }
    }

    string ans = "";
    for(auto x: m1){
        for (int i = 0; i < x.second; ++i) {
            ans.push_back(x.first);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

lint N;

int canAlinement(vector<lint>* v) {
    map<int, int> hash;
    for (int j = N-1; j > 0; --j) {
        if ((*v).at(j) - (*v).at(j-1) <= (-2)) {
            return 0;
        } else if ((*v).at(j) - (*v).at(j-1) == (-1)) {
            --(*v).at(j-1);
        }
    }
    return 1;
}

int main(void){
    cin >> N;
    vector<lint> H(N);

    REP (i, N) cin >> H[i];
    canAlinement(&H) ? cout << "Yes" << endl : cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI acos(-1)

int main(){
    int h,m,h2,m2,k;
    int start,end;
    cin >> h >> m >> h2 >> m2 >> k;
    start = h * 60 + m;
    end = h2 * 60 + m2;
    cout << end -start - k << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {

	int a;
	int b[8];
	int c = 0;

	cin >> a;

	b[0] = a%100000000/10000000;
	b[1] = a%10000000/1000000;
	b[2] = a%1000000/100000;
	b[3] = a%100000/10000;
	b[4] = a%10000/1000;
	b[5] = a%1000/100;
	b[6] = a%100/10;
	b[7] = a % 10;

	for (int i = 0; i < 8; i++) {
		c += b[i];
	}

	if (a%c == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
// これはヒントですがにぶたんはオーバーキルっつーかキルできねぇTLEなったわ

package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	X, Y, A, B, C := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()
	P, Q, R := nextInts(A), nextInts(B), nextInts(C)
	sort.Sort(sort.Reverse(sort.IntSlice(P)))
	sort.Sort(sort.Reverse(sort.IntSlice(Q)))
	R = append(R, P[:X]...)
	R = append(R, Q[:Y]...)
	sort.Sort(sort.Reverse(sort.IntSlice(R)))
	ans := 0
	for i := 0; i < X+Y; i++ {
		ans += R[i]
	}
	fmt.Println(ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


Measured memory_bytes: 10752
alphabets = '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'.split()
s = sorted(list(set(input())))
N = len(s)
i = 0
while(alphabets[i] in s):
    i += 1
    if(i == 26):
        break
if(i == 26):
    print('None')
else:
    print(chr(i+97))

Measured memory_bytes: 3188
import java.util.Scanner;
 
public class Main {
 
    static Scanner in = new Scanner(System.in);
 
    void solve() {
		char[] s = in.nextLine().toCharArray(), t = in.nextLine().toCharArray();
		for(int i = s.length - t.length; i >= 0; i--){
			boolean f = true;
			for(int j = 0; j < t.length; j++){
				if(s[i + j] != '?' && t[j] != '?' && s[i + j] != t[j]){
					f = false;
				}
			}
			if(f){
				for(int j = 0; j < t.length; j++){
					s[i + j] = t[j];
				}
				for(int j = 0; j < s.length; j++){
					System.out.print(s[j] == '?' ? 'a' : s[j]);
				}
				System.out.println();
				return;
			}
		}
		System.out.println("UNRESTORABLE");
	}
	
    public static void main(String[] args) {
		new Main().solve();
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

struct edge {
  int t, c;
  edge() {}
  edge(int t, int c) : t(t), c(c) {}
};

int N, M;
vector<edge> G[500010];
map<pii, int> mp;
int n;
int dis[500010];

void add_edge(int s, int t, int c) {
  G[s].EB(t, c);
  G[t].EB(s, c);
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  n = N;
  REP(i, M) {
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;
    pii v = MP(p, c), w = MP(q, c);
    if (!mp.count(v)) {
      mp[v] = n++;
      add_edge(p, mp[v], 1);
    }
    if (!mp.count(w)) {
      mp[w] = n++;
      add_edge(q, mp[w], 1);
    }
    add_edge(mp[v], mp[w], 0);
  }

  fill(dis, dis+500010, INF);
  dis[0] = 0;
  deque<int> deq;
  deq.push_front(0);
  while (!deq.empty()) {
    int v = deq.front(); deq.pop_front();
    for (edge e : G[v]) {
      int nv = e.t;
      if (chmin(dis[e.t], dis[v]+e.c)) {
        if (e.c == 0) deq.push_front(nv);
        else deq.push_back(nv);
      }
    }
  }
  if (dis[N-1] == INF) cout << -1 << endl;
  else cout << dis[N-1]/2 << endl;

  return 0;
}

Measured memory_bytes: 70400
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = tuple(map(tuple, read().split()))


def bfs(grid, start):
    distance = [[-1] * W for _ in range(H)]
    queue = deque([start])
    distance[start[0]][start[1]] = 0
    while queue:
        x, y = queue.popleft()

        for i, j in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and distance[new_x][new_y] == -1:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
        if not queue:
            return distance[x][y]


answer = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue

        tmp = bfs(S, (i, j))
        if tmp > answer:
            answer = tmp

print(answer)


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m; cin >> n >> m;
    ll ans = 0;
    if(2*n>=m){
        ans = m/2;
    }else{
        ans = n;
        m -= 2*n;
        ans += m/4;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
import heapq
n,x,y = map(int,input().split())
G = [[]*n for i in range(n)]
for i in range(n-1):
  G[i].append((i+1))
  G[i+1].append(i)
x-=1;y-=1
G[x].append((y))
G[y].append((x))
# print(G)
def bfs(g,s):
    n=len(g)
    dist = [inf]*n
    dist[s] = 0
    q = collections.deque()
    q.append(s)
    while q:
        u = q.popleft()
        for v in g[u]:
            if dist[v] != inf:continue
            dist[v] = dist[u] + 1
            q.append(v)
    return dist
D = [0]*n
for i in range(n-1):
  dist = bfs(G,i)
  for j in range(i+1,n):
    D[dist[j]] += 1
for i in range(1,n):
  print(D[i])
    


Measured memory_bytes: 105948
d,n = map(int,input().split())
if n==100 and d==0:
    ans = 100**d*n+1
elif n==100 and d==1:
    ans = 100**d*n + 100
elif n==100 and d==2:
    ans = 100**d*n + 10000
else:
    ans = 100**d*n
print(ans)
    

Measured memory_bytes: 38384
from itertools import groupby

N = int(input())
S = input()

cnt_l = 0
cnt_r = 0
ans = ''
for key, elems in groupby(S):
    elems = list(elems)
    if key == '(':
        cnt_l += len(elems)
        ans += '(' * len(elems)
    else:
        cnt_r += len(elems)
        ans += ')' * len(elems)
        if cnt_l < cnt_r:
            ans = '(' * (cnt_r - cnt_l) + ans
            cnt_l += (cnt_r - cnt_l)

print(ans + ')' * (cnt_l - cnt_r))


Measured memory_bytes: 3188
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = map(int, readline().split())
    uf = UnionFind(N)

    for _ in range(M):
        a, b = map(int, readline().split())
        a, b = a - 1, b - 1
        uf.union(a, b)

    ans = 0

    for i in range(N):
        ans = max(ans,uf.size(i))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 73844
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    n = int(input())
    if n == 0:
        break
    status = 0
    flag = False
    point = 0
    fn = list(map(list,input().split()))
    for f in fn:
        status = status + 1 if f[1] == 'u' else status - 1
        if flag == False and status == 2:
            point += 1
            flag = True
        if flag == True and status == 0:
            point += 1
            flag = False

    print(point)

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

int main() {
    int N, M, ans=0;
    cin >> N >> M;
    vector<int> h(N), a(M), b(M), tmp(N, 1);
    for(int i=0; i<N; i++){
	cin >> h[i];
    }

    for(int i=0; i<M; i++){
	cin >> a[i] >> b[i];
	a[i]--;
	b[i]--;
    }


    for(int i=0; i<M; i++){
	if(h[a[i]] == h[b[i]]){
	    tmp[a[i]]=0;
	    tmp[b[i]]=0;
	}
	else if(h[a[i]] > h[b[i]])
	    tmp[b[i]]=0;
	else
	    tmp[a[i]]=0;
    }

    for(int i=0; i<N; i++){
	if(tmp[i]==1)
	    ans ++;
    }





    cout << ans << endl;
} 




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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define ASSERT(expr...) assert((expr))

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

// util {{{
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define ll long long int
#define VI vector <ll>
template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

//--------------------------------------------------------------------

void solve() {

  ll N,R;
  cin >> N ;
  cout << fixed << setprecision(0)<< ceil((double)N/2);
  

}

signed main() {
    

    solve();

    return 0;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;
typedef pair<char, int> Trump;


int main() {
    char c;
    while (cin >> c, c != '#') {
        Trump trump[4][13];
        REP (i, 0, 4) REP (j, 0, 13) {
            string s;
            cin >> s;
            char suit = s[1];
            int rank;
            if (s[0] == 'T') rank = 10;
            else if (s[0] == 'J') rank = 11;
            else if (s[0] == 'Q') rank = 12;
            else if (s[0] == 'K') rank = 13;
            else if (s[0] == 'A') rank = 14;
            else rank = s[0] - '0';
            trump[i][j] = Trump(suit, rank);
        }
        int ans[2] = {0};
        int lst = 0;
        REP (i, 0, 13) {
            int ind = ([&] (vector<Trump> t) -> int {
                char suit = t[lst].first;
                REP (i, 0, 4) if (t[i].first == c) suit = c;
                vector<int> indices(t.size());
                REP (i, 0, indices.size()) indices[i] = i;
                sort(begin(indices), end(indices), [&t, &suit](int a, int b) -> bool {
                    Trump &t1 = t[a];
                    Trump &t2 = t[b];
                    if (t1.first == t2.first && t1.first == suit) return t1.second > t2.second;
                    else if (t1.first == suit) return true;
                    else if (t2.first == suit) return false;
                    else return t1.second > t2.second;
                });
                return indices[0];
            })(vector<Trump>{trump[0][i], trump[1][i], trump[2][i], trump[3][i]});
            ans[ind % 2]++;
            lst = ind;
        }
        cout << (ans[0] < ans[1] ? "EW" : "NS") << ' ' << max(ans[0], ans[1]) - 6 << endl;
    } 
    return 0;
}


Measured memory_bytes: 3164
# 2Lと1Lを基準にして貪欲
q, h, s, d = map(int, input().split())
n = int(input())
arr = [8 * q, 4 * h, 2 * s, d]
x = min(arr)
if n % 2 == 0:
    print((n // 2) * x)
else:
    ans = (n // 2) * x
    ans += min([4 * q, 2 * h, s])
    print(ans)


Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=1e5;
LL as[L];
char op[L];
LL sum[L];
int main() {
	int N;
	scanf("%d",&N);
	op[0]='+';
	scanf("%lld",as);
	//cerr << as[0] << endl;
	for(int i=1;i<N;i++){
		char str[2];
		scanf("%s%lld",str,as+i);
		op[i]=str[0];
		//cerr << op[i] << " " << as[i] << endl;
	}
	sum[0]=as[0];
	for(int i=1;i<N;i++){
		if(op[i]=='-'){
			sum[i]=sum[i-1]-as[i];
		}
		else{
			sum[i]=sum[i-1]+as[i];
		}
		//cerr << i << ", " << sum[i] << endl;
	}
	LL s=0;
	LL m=0;
	LL ret=sum[N-1];
	for(int i=N-1;i>0;i--){
		s+=abs(as[i]);
		if(op[i]=='-'){
			ret=max(ret,sum[i-1]+m-(s-m));
			m=s;
		}
		//cerr << i << ": " << sum[i] << ", " << m << ", " << s << endl;
	}
	printf("%lld\n",ret);
	

	return 0;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r];
}
signed main(){
    ll N,K; cin>>N>>K;
    vi A(N);
    rep(i,0,N){
        cin>>A[i];
        A[i]--;
    }
    vi memo;
    vector<bool> F(N,1);
    memo.pb(0);
    F[0]=0;
    ll flag=-1;
    while(1){
        ll X=memo[memo.size()-1];
        ll Y=A[X];
        if(F[Y]){
            memo.pb(Y);
            F[Y]=0;
        }
        else{
            flag=Y;
            break;
        }
    }
    K++;
    ll cnt=0,sum=memo.size();
    rep(i,0,memo.size()){
        if(memo[i]==flag){
            cnt=i;
            break;
        }
    }
    sum-=cnt;
    if(cnt>=K) cout<<memo[K-1]+1<<endl;
    else{
        K-=cnt;
        K--;
        K%=sum;
        cout<<memo[cnt+K]+1<<endl;
    }
}


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

int main()
{
    int N;
    std::vector<double> v;
    double tmp_v;

    std::cin >> N;

    for (int i = 0; i < N; i++)
    {
        std::cin >> tmp_v;
        v.push_back(tmp_v);
    }

    double s = 0;
    double ans = 0;
    for (int i = 0; i < N; i++)
    {
        s += 1 / v[i];
    }
    ans = 1 / s;

    std::cout << ans << std::endl;

}

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

const int MOD = (int)1e9+7;
void solve()
{
    int row,col;
    cin >> row >> col;
    int dp[row][col];
    bool rowUp = 1,colUp = 1;
    for(int i=0;i<row;i++)
    {
        for(int j=0;j<col;j++)
        {
            char a;
            cin >> a;
            if(!i && !j)
                dp[i][j] = 0;
            else if(!i)
            {
                if(a == '#')
                    rowUp = 0;
                if(rowUp)
                    dp[i][j] = 1;
                else dp[i][j] = 0;
            }
            else if(!j)
            {
               if(a == '#')
                    colUp = 0;
                if(colUp)
                    dp[i][j] = 1;
                else dp[i][j] = 0;
            }
            else
            {
                if(a == '#')
                    dp[i][j] = 0;
                else
                    dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
    }
    cout << dp[row-1][col-1];
    
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 7480
//! Framework <https://github.com/vain0x/procon>

#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::*;

pub struct Scan(Box<dyn Iterator<Item = &'static str>>); // '

impl Scan {
    fn new() -> Self {
        let mut buf = String::new();
        let read_line = move || {
            std::io::stdin().read_line(&mut buf).unwrap();
            Box::leak(buf.split_off(0).into_boxed_str()).split_whitespace()
        };
        Scan(Box::new(std::iter::repeat_with(read_line).flatten()))
    }

    pub fn word<T: std::str::FromStr>(&mut self) -> T {
        self.0.next().unwrap().parse().ok().unwrap()
    }

    pub fn list<T: std::str::FromStr>(&mut self, len: usize) -> Vec<T> {
        std::iter::repeat_with(|| self.word()).take(len).collect()
    }
}

fn ch(c: char) -> i64 {
    (c as u8 - b'0') as i64
}

fn main() {
    let mut scan = Scan::new();

    let S = scan.word::<String>().chars().collect::<Vec<_>>();

    let N = S.len();
    const P: i64 = 2019;

    let mut T = vec![0; N + 1];
    let mut h = 1;
    for r in (0..N).rev() {
        let d = ch(S[r]);
        T[r] = (d * h + T[r + 1]) % P;
        h = (h * 10) % P;
    }

    let mut freq = vec![0_usize; P as usize];
    for i in 0..T.len() {
        freq[T[i] as usize] += 1;
    }

    let mut total = 0_usize;
    for i in 0..freq.len() {
        if freq[i] >= 1 {
            total += freq[i] * (freq[i] - 1) / 2;
        }
    }

    println!("{}", total);
}


Measured memory_bytes: 4656
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void maxHeapify(int i) {
    int l, r, largest;
    l = 2*i;
    r = 2*i+1;

    if (l<=H && A[l]>A[i]) largest=l;
    else largest=i;
    if (r<=H && A[r]>A[largest]) largest=r;

    if (largest!=i) {
        swap(A[i], A[largest]);
        maxHeapify(largest);
    }
}

int extract() {
    int maxv;
    if (H<1) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key) {
    if (key < A[i]) return ;
    A[i] = key;
    while (i>1 && A[i/2]<A[i]) {
        swap(A[i], A[i/2]);
        i = i/2;
    }
}

void insert(int key) {
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main() {
    int key;
    char com[10];
    while (1) {
        scanf("%s", com);
        if ( com[0]=='e' && com[1]=='n') break;
        if ( com[0]=='i' ) {
            scanf("%d", &key);
            insert(key);
        } else {
            printf("%d\n", extract());
        }
    }

    return 0;
}


Measured memory_bytes: 6624
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define LL long long 
using namespace std;

const int M = 250001;
int w,n,a[M],c[M],pre[M],f[60][M],s[M];
LL m,k,b[60][M];

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]), w=max(w,a[i]);
	for(int i=1;i<=n;i++)
	{
		if(!c[a[i]]) c[a[i]]=i;
		if(pre[a[i]]) f[0][pre[a[i]]]=i%n+1;
		if(i==n && pre[a[i]]) f[0][pre[a[n]]]=1, b[0][pre[a[n]]]=(n!=1 ? 1 : 2);
		pre[a[i]]=i;
	}
	
	for(int i=1;i<=n;i++) if(pre[a[i]]==i)
	{
		f[0][i]=c[a[i]]%n+1;
		b[0][i]=f[0][i]==1?2:1;
	}
	for(int i=1;i<=58;i++)
		for(int j=1;j<=n;j++) f[i][j]=f[i-1][f[i-1][j]], b[i][j]=b[i-1][f[i-1][j]]+b[i-1][j];
		
	w=1;
	for(int i=58;i>=0;i--) if(b[i][w]+k<m) 
		k+=b[i][w], w=f[i][w];
	
	memset(c,0,sizeof(c));
	int tp=0;
	if(n==1 && m!=k+1)  return 0;
	for(int i=w;i<=n;i++)
	{
		if(c[a[i]])
		{
			while(s[tp]!=a[i]) c[s[tp--]]=0;
			tp--; c[a[i]]=0;
		}
		else s[++tp]=a[i], c[a[i]]=1;
	}
	for(int i=1;i<=tp;i++) printf("%d\n",s[i]);
	//printf("\n");
}

Measured memory_bytes: 180608
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

long gcd(long a,long b){
  if(a<b) swap(a,b);
  if(a%b==0)return b;
  return gcd(b,a%b);
}

int main() {
  long a,b;
  cin>>a>>b;
  cout<<a*b/gcd(a,b);
}

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

int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  int correct[n] = {0};
  for(int i = 0; i < q; ++i)
  {
    int c;
    cin >> c;
    correct[c-1]++;
  }
  
  for(int i = 0; i < n; ++i)
  {
    bool ans = k - (q - correct[i]) > 0;
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 4016
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int cnt = 0;
int insertionsort(vector<int>& vi, int n, int g)
{
  for(int i=g; i<n; i++) // for each g times loop , each group adds one int;
  {
    int v = vi[i];
    int j = i-g; // must't plus 1
    while(j>=0 && vi[j] > v)// greater int goes to behind;
    {
      vi[j+g] = vi[j]; //g as interval
      j -= g;
      cnt++;
    }
    vi[j+g] = v;
  }
  return 0;
}

int shellsort(vector<int>& vi, int n)
{
  int m = 1;
  vector<int> G;
  G.push_back(1);
  while(1)
  {
    if(3*G[m-1]+1 < n)
    {
      G.push_back(3*G[m-1]+1);
      m++;
    }
    else break;
  }
  cout << m << endl;
  for(int i=m-1; i>=0; i--)
  {
    if(i!=m-1) cout << " ";
    cout << G[i] ;
  }
  cout << endl;
  for(int i=m-1; i>=0; i--)
  {
    insertionsort(vi, n, G[i]);
  }
  cout << cnt << endl;
  for(int i=0; i<n; i++)
  {
    cout << vi[i] << endl;
  }
  return 0;
}
int main()
{
  int n;
  cin >> n;
  vector<int> vi;
  for(int i=0; i<n; i++)
  {
    int temp;
    cin >> temp;
    vi.push_back(temp);
  }
  shellsort(vi, n);
  return 0;
}



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

int main(){
    int n,k,x,y,sum;
    cin>>n>>k>>x>>y;
    if(n>k){
    for(int i=0;i<k;i++){
        sum=sum+x;
    }
       for(int i=k;i<n;i++){
        sum=sum+y;
    }
    }
    else{
        for(int i=0;i<n;i++){
        sum=sum+x;
    }

    }
    cout<<sum<<endl;
    return 0;
}


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

int main() {
  cin >> s;
  if(s[0] == '1'){
    ans++;
  }
  if(s[1] == '1'){
    ans++;
  }
  if(s[2] == '1'){
    ans++;
  }
  
  cout << ans << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int num;
  int a[4];
  int sum;
  int i,j,posi;
  int breakFrag = 0;
  int numMai;
  char fugou[4];
  
  cin >> num ;
  
  a[0] = num / 1000;
  num = num % 1000;
  
  a[1] = num / 100;
  num = num % 100;
  
  a[2] = num / 10;
  num = num % 10;
  
  a[3] = num;
  
  sum = a[0];
  
  for(numMai = 0;numMai < 4;numMai++){
    if(numMai == 0){
      for(i=1;i<4;i++){
        sum += a[i];
      }
      if(sum == 7){
        break;
      } 
       sum = a[0];
    }
   
    else if(numMai == 1){
      for(j=1;j<4;j++){
        for(i=1;i<4;i++){
          if(i == j){
            sum -= a[i];
          }
          else{
            sum += a[i];
          }
        }
        if(sum == 7){
          breakFrag = 1; 
          break;
        }
        sum = a[0];
      }
  
      if(breakFrag==1){
          break;
      }
    }
    else if(numMai == 2){
      for(j=1;j<4;j++){
        for(i=1;i<4;i++){
          if(i == j){
            sum += a[i];
          }
          else{
            sum -= a[i];
          }
        }
        if(sum == 7){
           breakFrag = 1; 
          break;
        }
        sum = a[0];
      }
      if(breakFrag==1){
          break;
      }
    }
    else if(numMai == 3){
      for(i=1;i<4;i++){
        sum -= a[i];
      }
      if(sum == 7){
        break;
      }   
    }
  }
 
  if(numMai == 0){
    fugou[1] = '+';
    fugou[2] = '+';
    fugou[3] = '+';
  }
  else if(numMai == 3){
    fugou[1] = '-';
    fugou[2] = '-';
    fugou[3] = '-';
  }
  else if(numMai == 1){
    for(i=1;i<4;i++){
      if(i == j)
        fugou[i] = '-';
      else
        fugou[i] = '+';
    }
  }
  else if(numMai == 2){
    for(i=1;i<4;i++){
      if(i == j)
        fugou[i] = '+';
      else
        fugou[i] = '-';
    }
  }  
  
  
  cout<<a[0] <<fugou[1]<< a[1]<< fugou[2]<< a[2]<< fugou[3]<< a[3] <<"=7 "<<endl;;
 
  
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
W = (?a..?j).to_a

def solve(a, i, maxi, n) # 現在の文字列、外側の現在値、外側の最大値、何文字目か
  if n >= N
    puts a
    return
  end

  0.upto(maxi+1) do |j|
    solve(a+W[j], j, [maxi,j].max, n+1)
  end
end

solve(?a, 0, 0, 1)



Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <queue>
using namespace std;

int N, M, LL=0, RR=100100;
int L, R, ans;

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

    for (int i=0; i<M; i++) {
        cin >> L >> R;
        LL = max(LL, L);
        RR = min(RR, R);
    }

    if (LL > RR) ans = 0;
    else ans = RR - LL + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
class SegTree:
    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        # k+1ではなくkでは？
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res
from collections import defaultdict
import sys;input=sys.stdin.readline
N, = map(int, input().split())

A = [0] + list(map(int, input().split()))
G = [[] for _ in range(N+1)]
for v in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

iA = [(i, a) for i, a in enumerate(A)]
iA.sort(key=lambda x:x[1])
d = dict()
AA = [0]*(N+1)
a2f = [0]*(N+1)
rj = 0
for j, (i, a) in enumerate(iA):
    AA[i] = j
    if a not in d:
        rj = j
    a2f[i] = rj
    d[a] = 1
#print(AA, a2f)

R = [0]*(N+1)
R[1] = 1
ss = SegTree([0]*(N+1), N+1, -1, max)
ss.update(AA[1], 1)
stack = []
for u in G[1]:
    stack += [-1, u]
visited = set([1])
path = [1]
while stack:
    v = stack.pop()
    if v > 0:
        visited.add(v)
        path.append(v)
        qq = ss.query(0, a2f[v])
        ss.update(AA[v], qq+1)
        R[v] = ss.query(0, N+1)
        for u in G[v]:
            if u in visited:
                continue
            stack += [-v, u]
    else:
        c = path.pop()
        ss.update(AA[c], 0)
for i in range(1, N+1):
    print(R[i])


Measured memory_bytes: 198204
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 302;
int N, M, cnt[MAXN];
queue<int> p[MAXN];
bool on[MAXN];

int main(){
    scan(N, M);
    FOR(i,0,N) FOR(j,0,M){
        int x; scan(x); x--;
        p[i].push(x);
    }
    int ans = MAXN;
    FOR(i,0,M) on[i]=true;
    FOR(_,0,M){
        ms(cnt,0);
        FOR(i,0,N) cnt[p[i].front()]++;
        int mx = 0;
        FOR(i,0,M) if(cnt[i] > cnt[mx]) mx=i;
        mnze(ans, cnt[mx]);
        on[mx]=false;
        FOR(i,0,N) while(p[i].size() > 0 && !on[p[i].front()])
            p[i].pop();

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


Measured memory_bytes: 768
@ExperimentalStdlibApi
fun main(args: Array<String>) = abc162d()

@ExperimentalStdlibApi
fun abc162d() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val csRed = s.scan(0) { acc, c -> acc + if (c == 'R') 1 else 0 }.toIntArray()
    val csGreen = s.scan(0) { acc, c -> acc + if (c == 'G') 1 else 0 }.toIntArray()
    val csBlue = s.scan(0) { acc, c -> acc + if (c == 'B') 1 else 0 }.toIntArray()

    val list = listOf(csRed, csGreen, csBlue)

    var answer = 0L

    for (i in 0 until n) {
        val c = s[i]
        val other = when (c) {
            'R' -> list - csRed
            'G' -> list - csGreen
            else -> list - csBlue
        }
        for (j in i + 1 until n) {
            val c2 = s[j]
            if (c2 == c) continue
            val remain = when (c2) {
                'R' -> other - csRed
                'G' -> other - csGreen
                else -> other - csBlue
            }[0]

            val jump = j + (j - i) + 1

            answer += remain.last() - remain[j] -
                    if (jump in remain.indices) remain[jump] - remain[jump - 1] else 0
        }
    }

    println(answer)
}


Measured memory_bytes: 56172
import math
a,b,x = list(map(int,input().split()))
h = x/(a**2)
if b == h:
    ans = 0
elif h<=b/2:
    ans = math.degrees(math.atan(b**2/(2*a*h)))
else:
    ans = 90-math.degrees(math.atan(a/(2*(b-h))))
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X= sc.nextInt();
		int Y = sc.nextInt();
		if (X<Y*2) {
			System.out.println(0);
			return ;
		}

		System.out.println(X-Y*2);
	}
}

Measured memory_bytes: 23252
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int ans = C-(A-B);
    if (ans>0){
      System.out.println(ans);
    } else {
      System.out.println(0);
    }
  }
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			if(s.equals("G"))a[0]++;
			if(s.equals("W"))a[1]++;
			if(s.equals("Y"))a[2]++;
			if(s.equals("P"))a[3]++;
		}
		int count = 0;
		for(int i = 0; i < 4; i++) {
			if(a[i] != 0) count++;
		}
		System.out.println(count == 4 ? "Four" : "Three" );
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	long combination(int n, int r, int m) { //nCr mod m
		long[][] Combination = new long[n + 1][n + 1];
		for (int i = 0; i <= n; i++) {
			Combination[i][0] = 1;
			for (int j = 1; j <= i; j++) {
				Combination[i][j] = (Combination[i - 1][j - 1] + Combination[i - 1][j]) % m;
			}
		}
		return Combination[n][r];
	}

	int gcd(int a, int b) {
		if (a < b) {
			int c = a;
			a = b;
			b = c;
		}
		if (b == 0)
			return a;
		else
			return gcd(b, a % b);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23252
N = int(input())
s = [input() for i in range(N)]
ans ={}
num = 0

for i in range(N):
    s[i] = ''.join(sorted(s[i]))
    if s[i] in ans.keys():
        ans[s[i]] += 1
        num += ans[s[i]]
    else:
        ans[s[i]] = 0

print(num)

Measured memory_bytes: 19476
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	int dp[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	dp[1]=0;
	for(int i=2;i<=n;i++)
	{
		int op1=abs(a[i]-a[i-1])+dp[i-1];
		int op2=(i==2)? INT_MAX: abs(a[i]-a[i-2])+dp[i-2];

		dp[i]=min(op1,op2);
	}
	
	cout<<dp[n];
}

Measured memory_bytes: 1024
<?php

while (true) {
    fscanf(STDIN, '%s', $talon);
    if (isEnd($talon)) { break; }

    fscanf(STDIN, '%d', $shuffleCount);
    for ($i = 0; $i < $shuffleCount; $i++) {
        $talon = shuffleTalon($talon);
    }
    $result[] = $talon;
}

echo implode(PHP_EOL, $result), PHP_EOL;


function shuffleTalon($talon)
{
    fscanf(STDIN, '%d', $pos);
    $part      = substr($talon, 0, $pos);
    $remainder = substr($talon, $pos);

    return $remainder.$part;
}

function isEnd($talon)
{
    return ($talon == '-');
}

Measured memory_bytes: 6592
/*
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
int main()
{
	char str[21];
	int i;
	int length;
	scanf("%s",str);
	length=strlen(str);
	for(i=length-1; i>=0; i--){
		printf("%c",str[i]);
	}
	puts("");
    return 0;
}

Measured memory_bytes: 520
#include <iostream>
#include <string>

using namespace std;

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

    string s;
    cin >> s;

    for (int i = 0; i < s.length(); i++) {
        cout << "x";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>

using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int ct5=0,ct7=0;
	if(a==5)
	{
		ct5+=1;
	}
	else if(a==7)
	{
		ct7+=1;
	}
	if(b==5)
	{
		ct5+=1;
	}
	else if(b==7)
	{
		ct7+=1;
	}
	if(c==5)
	{
		ct5+=1;
	}
	else if(c==7)
	{
		ct7+=1;
	}
	if(ct5==2 && ct7==1)
	cout<<"YES";
	else
	cout<<"NO";
	cout<<endl;
	return 0;
	
}

Measured memory_bytes: 256