akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws IOException {
       Scanner in = new Scanner(System.in);
       int s = in.nextInt();
       int h = s / 3600;
       s -= 3600*h;
       int m = s / 60;
       s -= 60*m;
       System.out.printf("%d:%d:%d\n",h,m,s);
    }
}

Measured memory_bytes: 17168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

i64 n, a[300][300];
bool b[300][300];
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            if (i == k) continue;
            for (int j = 0; j < n; ++j) {
                if (j == k) continue;
                if (a[i][k] + a[k][j] < a[i][j]) {
                    cout << -1 << endl;
                    return 0;
                }
                if (a[i][k] + a[k][j] == a[i][j]) {
                    b[i][j] = true;
                }
            }
        }
    }

    i64 ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (!b[i][j]) ans += a[i][j];
        }
    }

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(5e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, pmax=0, sum=0;
    cin >> n;
    REP(i,n){
        int p;
        cin >> p;
        sum += p;
        pmax = max(pmax, p);
    }
    sum -= pmax/2;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
import re
bracket = re.compile(r'\[([\w?+-]+)\]')
incr = re.compile(r'([+-]*)([\w?])')

def f(s, c):
    if c == '?': return 'A'
    return chr(ord('A')+(ord(c)-ord('A')+s.count('+')-s.count('-'))%26)

while True:
    s = input().strip()
    if s == '.': break

    s = incr.sub(lambda m: f(*m.group(1, 2)), s)
    while '[' in s:
        s = bracket.sub(lambda m: m.group(1)[::-1], s)

    print(s)



Measured memory_bytes: 6520
k = 1
loop do
  n = gets.to_i
  break if n == 0
  p = []
  n.times{ p << gets.split.map(&:to_f) }
  n.times{ |i| p[i] += p[(i+1) % n] }
  s = p.map{ |x0, x1, y0, y1| x1*y0 - x0*y1 }.inject(:+) / 2
  puts "#{k} %.1f" % s
  k += 1
  gets
end

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

int tab[2][1024][1024];
int initial[1024][1024];

int main() {
	int H, W, N;
	while(cin >> H >> W >> N, H || W || N) {
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				cin >> initial[i][j];
			}
		}

		for(int i = 0; i < 1024; i++)
			for(int j = 0; j < 1024; j++)
				tab[0][i][j] = tab[1][i][j] = 0;

		N--;
		if(initial[0][0] == 0) {
			tab[0][1][1] = N / 2 + (N % 2);
			tab[1][1][1] = N / 2;
		}
		else {
			tab[0][1][1] = N / 2;
			tab[1][1][1] = N / 2 + (N % 2);
		}

		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				int tmp;
				tmp = tab[0][i-1+1][j+1] + tab[1][i+1][j-1+1];
				tab[0][i+1][j+1] += tmp / 2 + (initial[i][j] == 0 ? (tmp % 2) : 0);
				tab[1][i+1][j+1] += tmp / 2 + (initial[i][j] == 1 ? (tmp % 2) : 0);
			}
		}

		int x, y;
		x = y = 0;
		while(x < W && y < H) {
			if((initial[y][x] + tab[0][y+1][x+1] + tab[1][y+1][x+1]) % 2) {
				x++;
			}
			else {
				y++;
			}
		}
		cout << y+1 << " " << x+1 << endl;
	}
}

Measured memory_bytes: 13448
#include <stdio.h>
int prime(int a){
  int i;
  if(a < 2) return 0;
  if(a == 2) return 1;
  if(a % 2 == 0) return 0;
  for(i = 3;i * i <= a;i += 2)
    if(a % i == 0) return 0;

  return 1;
}

int main(){
  int   n, c = 0, m;
  scanf("%d", &n);
  while(n--){
    scanf("%d", &m);
    c += prime(m);
  }
  printf("%d\n", c);
  return 0;
}



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


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Scanner in = new Scanner(System.in);
	     int k = in.nextInt();
	     int t = in.nextInt();

	     int arr[] = new int[t];
	     for(int i=0;i<t;i++)
	    	 arr[i]=in.nextInt();
	     
	     
	     Arrays.sort(arr);
	     int step =0;
	     int ans=0;
	     while(step<k){
	    	 int get = 0;
	    	 for(int i=arr.length-1;i>=0;i--){
	    		 if(arr[i]>0){
	    			 get++;
	    			 arr[i]--;
	    		 }
	    		 if(get==2)
	    			 break;
	    	 }
	    	 step+=get;
	    	 if(get==1 && step!=k)
	    		 ans++;
	     }
    		 System.out.println(ans);
    	 
	}

}


Measured memory_bytes: 10068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  	ll n , x;
  	cin >> n >> x;
  	ll sum = 0;
  	for(int i = 1 ; i <= n ;i++){
	  int r;
      cin >> r;
      sum += r;
      if(sum > x){
		cout << i << endl;
        return 0;
      }
    }
    cout << n + 1 << endl;
  	return 0; 
}

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

#define MAX(p,q) ((p>q)?(p):(q))
#define MIN(p,q) ((p<q)?(p):(q))

#define REP(i,n) for(i=0;i<n;i++)

int gcd(int a,int b);

int main(void)
{
  int i,n;
  int l[10] = {0};
  scanf("%d",&n);
  int max=0,sum=0;
  REP(i,n)
  {
    scanf("%d",&l[i]);
    sum += l[i];
    if(max<l[i]) max = l[i];
  }
  //書き換え
  /*
  if((sum-max)>max) printf("Yes");
  else printf("No");*/
  printf(((sum-max)>max)?"Yes":"No");

  return 0;
}

int gcd(int a,int b)
{
  int max,min,tmp;
  max = MAX(a,b);
  min = MIN(a,b);
  if(max%min==0) return min;
  else
  {
    tmp = min;
    min = max%min;
    max = tmp;
    return gcd(max,min);
  }
}


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

const ll INF = 1LL << 60;

vector<ll> A(3);

int main() {
    rep(i, 3) cin >> A[i];

    vector<ll> v(3);
    rep(i, 3) v[i] = i;

    ll ans = INF;
    do {
        ll tmp = 0;
        tmp += abs(A[v[1]] - A[v[0]]);
        tmp += abs(A[v[2]] - A[v[1]]);

        ans = min(ans, tmp);

    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ri register int
using namespace std;

typedef long long LL;
const int N = 3e5 + 5;

int a[N], n, id[N];
LL L[N], R[N], A[N], B[N], g[N], sum[N], suf[N];

inline void DivideAndConquer(int l, int r, LL *L, LL *R, LL *dp) {
  if (l == r) {
    dp[l] = max(dp[l], L[l - 1] + R[l + 1] - a[l] + 1);
    return;
  }
  int mid = (l + r) >> 1;
  int top = 0;
  for (int i = l - 1; i < mid; i ++) {
    g[i] = L[i] + sum[i] + 1LL * i * (i - 1) / 2;
    while (top > 1 && (g[i] - g[id[top]]) * (id[top] - id[top - 1]) >= (g[id[top]] - g[id[top - 1]]) * (i - id[top])) top --;
    id[++ top] = i;
  }
  for (int i = mid; i <= r; i ++) {
    while (top > 1 && g[id[top]] - g[id[top - 1]] <= 1LL * i * (id[top] - id[top - 1])) top --;
    suf[i] = g[id[top]] - sum[i] + 1LL * i * (i + 1) / 2 - 1LL * id[top] * i + R[i + 1];
  }
  LL t = suf[r];
  dp[r] = max(dp[r], t);
  for (int i = r - 1; i >= mid; i --) {
    t = max(t, suf[i]);
    dp[i] = max(dp[i], t);
  }
  DivideAndConquer(l, mid, L, R, dp);
  DivideAndConquer(mid + 1, r, L, R, dp);
}

inline void DP(LL *dp) {
  int top = 1;
  LL S = 0;
  id[1] = 0;
  for (int i = 1; i <= n; i ++) {
    S += a[i];
    while (top > 1 && g[id[top]] - g[id[top - 1]] <= 1LL * i * (id[top] - id[top - 1])) top --;
    dp[i] = g[id[top]] - S + 1LL * i * (i + 1) / 2 - 1LL * id[top] * i;
    dp[i] = max(dp[i], dp[i - 1]);
    g[i] = dp[i] + S + 1LL * i * (i - 1) / 2;
    while (top > 1 && (g[i] - g[id[top]]) * (id[top] - id[top - 1]) >= (g[id[top]] - g[id[top - 1]]) * (i - id[top])) top --;
    id[++ top] = i;
  }
}

int main() {
  scanf("%d", &n);
  memset(A, - 0x3f, sizeof (LL) * (n + 2));
  memset(B, - 0x3f, sizeof (LL) * (n + 2));
  for (ri i = 1; i <= n; i ++) scanf("%d", &a[i]);
  DP(L); reverse(a + 1, a + n + 1);
  DP(R); reverse(R + 1, R + n + 1);
  reverse(a + 1, a + n + 1);
  for (ri i = 1; i <= n; i ++) sum[i] = sum[i - 1] + a[i];
  DivideAndConquer(1, n, L, R, A);
  for (ri i = (n >> 1); i; i --) {
    swap(L[i], L[n - i + 1]);
    swap(R[i], R[n - i + 1]);
    swap(a[i], a[n - i + 1]);
  }
  for (ri i = 1; i <= n; i ++) sum[i] = sum[i - 1] + a[i];
  DivideAndConquer(1, n, R, L, B);
  for (ri i = (n >> 1); i; i --) {
    swap(L[i], L[n - i + 1]);
    swap(R[i], R[n - i + 1]);
    swap(a[i], a[n - i + 1]);
    swap(B[i], B[n - i + 1]);
  }
  int m, p, v;
  scanf("%d", &m);
  for (; m; m --) {
    scanf("%d%d", &p, &v);
    printf("%lld\n", max(L[p - 1] + R[p + 1], max(A[p], B[p]) - v + a[p]));
  }
  return 0;
}


Measured memory_bytes: 21376
mod stdin_reader {
  use std::io::stdin;
  use std::io::Read;

  pub struct StdinReader {
    pub buf: Vec<String>,
    pub cursor: usize,
  }

  pub fn new() -> StdinReader {
    StdinReader::new()
  }

  impl StdinReader {
    pub fn new() -> Self {
      let mut s = String::new();
      let stdin = stdin();
      stdin.lock().read_to_string(&mut s).unwrap();
      let buf = s.split_whitespace().map(|s| s.to_string()).collect();
      return StdinReader { buf: buf, cursor: 0 }
    }

    pub fn read_all(&self) -> Vec<String> {
      return self.buf.clone()
    }

    pub fn next(&mut self) -> Option<String> {
      let val = self.buf.get(self.cursor).cloned();
      self.cursor += 1;
      return val
    }

    pub fn as_i64(&mut self) -> Option<i64> {
      self.next().and_then(|s| s.parse::<i64>().ok())
    }

    pub fn as_f64(&mut self) -> Option<f64> {
      self.next().and_then(|s| s.parse::<f64>().ok())
    }

    pub fn as_usize(&mut self) -> Option<usize> {
      self.next().and_then(|s| s.parse::<usize>().ok())
    }
  }
}

mod utils {
  pub fn is_int(n: f64) -> bool {
    let trunc = (n.trunc() as i64) as f64;
    return (n - trunc) < 0.0001
  }
}

fn main() {
  // stdout
  use std::io::{stdout, Write, BufWriter};
  let stdout = stdout();
  let mut writer = BufWriter::new(stdout.lock());

  // stdin
  let mut reader = stdin_reader::new();

  let n = reader.as_usize().unwrap();
  let a_list: Vec<i64> = (0..n).map(|_| reader.as_i64().unwrap()).collect();
  let sum: i64 = a_list.iter().sum();
  let even_a_sum: i64 = a_list.iter().enumerate().filter(|&(i, val)| (i+1) % 2 == 0).map(|(i, val)| val).sum();
  let mut x: i64 = sum - 2 * even_a_sum;
  let mut xs = vec![format!("{}", x)];

  for i in 0..(n-1) {
    x = 2 * a_list[i] - x;
    xs.push(format!("{}", x));
  }

  writeln!(writer, "{}", xs.join(" "));
}

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

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<vii> vvii;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int n, m, si, sj, ei, ej;
int memo[1010][1010], vis[1000010];
vector <string> b;

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
vvi g;

void dfs(int i, int j, int id){
    memo[i][j] = id;
    for (int k = 0; k < 4; ++k) {
        int x = i+dx[k];
        int y = j + dy[k];
        if (x >= 0 && y >= 0 && x < n && y < m && memo[x][y] == -1 && b[x][y] == '.') dfs(x,y,id);
    }
}

int main(){
    mem1(memo);
    mem0(vis);
    cin >> n >> m >> si >> sj >> ei >> ej;
    si--; sj--; ei--; ej--;
    for (int i = 0; i < n; ++i) {
        string s; cin >> s; b.pb(s);
    }
    int id = 0;
    for (int j = 0; j < n; ++j) {
        for (int i = 0; i < m; ++i) {
            if (memo[j][i] == -1 && b[j][i] == '.') dfs(j, i, id++);
        }
    }
    g.assign(id+1, vi());
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            for (int k = 0; k < 5; ++k) {
                for (int l = 0; l < 5; ++l) {
                    int x = k - 2 + i;
                    int y = l - 2 + j;
                    if (x >= 0 && y >= 0 && x < n && y < m && memo[x][y] != memo[i][j] && b[i][j] == '.' && b[x][y] == '.') {
                        g[memo[i][j]].pb(memo[x][y]);
                        g[memo[x][y]].pb(memo[i][j]);
                    }
                }
            }
        }
    }
    mem0(vis);
    queue <ii> q;
    q.push({memo[si][sj], 0});
    vis[memo[si][sj]] = 1;
    while (q.size()){
        int u = q.front().ff;
        int d = q.front().ss; q.pop();
        if (u == memo[ei][ej]){
            cout << d << "\n";
            return 0;
        }
        for (int v: g[u]){
            if (!vis[v]){
                vis[v] = 1;
                q.push({v, d+1});
            }
        }
    }
    cout << "-1\n";
}


Measured memory_bytes: 35472
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	int w;
	cin >> w;
	int len = s.size() / w;
	string ans;
	if (s.size() % w == 0) {
		for (int i = 0; i < w * len; i += w) {
			ans += s[i];
		}
	}
	else {
		for (int i = 0; i <= w * len; i += w) {
			ans += s[i];
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations
from functools import reduce

n = int(input())
x = [0 for _ in range(5)]
for _ in range(n):
    s = input()
    if s[0] == "M":
        x[0] += 1
    if s[0] == "A":
        x[1] += 1
    if s[0] == "R":
        x[2] += 1
    if s[0] == "C":
        x[3] += 1
    if s[0] == "H":
        x[4] += 1

def f(a, b): return a*b

x = [n for n in x if n != 0]
ans = 0
for c in combinations(x, 3):
    ans += reduce(f, c)

print(ans)

Measured memory_bytes: 9656
N, M = map(int, input().split())
acc = [0 for i in range(N + 1)]
for i in range(M):
    L, R = map(int, input().split())
    L -= 1
    acc[L] += 1
    acc[R] -= 1
for i in range(N):
    acc[i + 1] += acc[i]
result = 0
for i in range(N):
    if acc[i] == M:
        result += 1
print(result)


Measured memory_bytes: 7080
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    a,b,m=map(int,input().split())
    A=[int(_) for _ in input().split()]
    B=[int(_) for _ in input().split()]
    ans=min(A)+min(B)
    for i in range(m):
        x,y,c=map(int,input().split())
        ans=min(ans,A[x-1]+B[y-1]-c)
    print(ans)

if __name__=='__main__':
    main()

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



int main() {
  int ans = 0;
  int i = 0;
  string s;
  cin >> s;
  int n = s.length();
  while(ans == 0){
    int a = n - 2 * (i + 1);
    if (s.substr(0, a) == s.substr(0, a/2) + s.substr(0, a/2)){
      ans = s.substr(0, a).length(); 
    }
    i++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3496
//01 = r, 10 = g, 11 = b

#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<map>
#include<cmath>
using namespace std;

#define P pair<int, int>

int makeWormBit(string str);
void makeEnd(int size);
bool checkEnd(int n);
int changeColor(int n, int i, int size);
int searchChangeColor(int n, int i, int mask);
int makeResetMask(int size, int mask);

int endColor[3];

int main(){
    string str;
    while(cin >>str){
        if(str[0] == '0') break;
        int bw = makeWormBit(str), deep = 1;
        queue<P> q;
        set<int> s;
        q.push( make_pair(0, bw) );
        s.insert(bw);
        makeEnd(str.size());
        while(!q.empty()){
            P tmp = q.front();
            if(checkEnd(tmp.second)){
                cout <<tmp.first <<endl;
                break;
            } else{
                for(int i = 0; i < str.size() - 1; i++){
                    int t = changeColor(tmp.second, i, str.size());
                    if(s.find(t) == s.end()){
                        q.push( make_pair(tmp.first + 1, t) );
                        s.insert(t);
                    }
                }
            }
            q.pop();
        }
        if(q.empty()) cout <<"NA" <<endl;
    }
    return 0;
}

int makeWormBit(string str){
    int ret = 0;
    for(int i = 0; i < str.size(); i++){
        ret = ret << 2;
        if(str[i] == 'r') ret |= 1;
        else if(str[i] == 'g') ret |= 2;
        else if(str[i] == 'b') ret |= 3;
    }
    return ret;
}
bool checkEnd(int n){
    bool ret = false;
    for(int i = 0; i < 3; i++){
        if(endColor[i] == n){
            ret = true;
            break;
        }
    }
    return ret;
}
int changeColor(int n, int i, int size){
    int ret = n, mask = 15 << (i * 2), resetMask = makeResetMask(size, mask), color = searchChangeColor(n, i, mask);
    ret &= resetMask;
    ret |= (color << (i * 2));
    return ret;
}

void makeEnd(int size){
    int dx[] = {1, 2, 3}, ans;
    for(int i = 0; i < 3; i++){
        ans = 0;
        for(int j = 0; j < size; j++){
            ans = ans << 2;
            ans |= dx[i];
        }
        endColor[i] = ans;
    }
}

int searchChangeColor(int n, int i, int mask){
    int strc[] = {5, 10, 15, 6, 7, 9, 11, 13, 14}, strret[] = {5, 10, 15, 15, 10, 15, 5, 10, 5};
    int c = (n & mask), ret;
    c = c >> (i * 2);
    for(int i = 0; i < 9; i++){
        if(c == strc[i]) ret = strret[i];
    }
    return ret;
}

int makeResetMask(int size, int mask){
    int ret = 1 << (size * 2);
    ret--;
    ret ^= mask;
    return ret;
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define se second
#define fi first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 2, N = 5e5 + 7, mod = 1e9 + 7;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

char s[N];
int n, a[N], ans;

main () {
	scanf("%s", s);
	n = strlen(s);
	forn (i, 0, n - 1) {
		int cnt1 = 0, cnt2 = 0;
		while (i < n && s[i] == '<')
			++cnt1, ++i;
		while (i < n && s[i] == '>')
			++cnt2, ++i;					
		int mx = max(cnt1, cnt2);
		ans += cnt1 * (cnt1 - 1) / 2;
		ans += cnt2 * (cnt2 - 1) / 2;
		ans += mx;					
//		cerr << cnt1 << ' ' << cnt2 << endl;
//		cerr << mx << endl;
		--i;									
	}
	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5+7;
const ll mof = 1e9+7;
vector<int> g[maxn];
int dp[maxn];
bool vis[maxn];
void solve(int root,int k)
{
    if(!vis[root])
    {
        vis[root] = 1;
        dp[root] = k;
        int now = k-1;
        for(int ch:g[root])
        {
            if(!vis[ch])
            {
                vis[ch] = 1;
                dp[ch] = now--;
                solve(ch,k);
            }
        }
        return;
    }
    int now = k-2;
    for(int ch:g[root])
    {
        if(!vis[ch])
        {
            vis[ch] = 1;
            dp[ch] = now--;
            solve(ch,k);
        }
    }
}
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=2;i<=n;++i)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    solve(1,k);
    ll ans = 1;
    for(int i=1;i<=n;++i)
    {
        ans *= dp[i];
        ans %= mof;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9728
#include <stdio.h>

int main()
{
    int A;
    int H;
    int Res=0;
    
    scanf("%d %d", &H, &A);
    Res = (H/A);
    if(H%A)
    {
        Res++;
    }
    printf("%d", Res);

    return 0;
}

Measured memory_bytes: 128
def putm(m, h=m.size, w=m[0][size])
  h.times{ |i| p m[i][0,w] }
end

#p "a".ord #=> 97
s = gets.to_s.chomp.bytes.map{|t| t-97}
t = gets.to_s.chomp.bytes.map{|t| t-97}

a = s.size
b = t.size

s += s

nex = Array.new(200_010){ Array.new(26) }
26.times{ |j| nex[2*a][j] = nil }
# 0-indexの2|S|番目に同じ2|S|を埋めてる。
# Rubyならnilでも良さそう。

# putm(nex, 2*a+1,10)

(2*a-1).downto(0) do |i|
  nex[i] = nex[i+1].dup #ただもってきてるだけ。dupで良さそう。
  nex[i][s[i]] = i+1 # s[i]文字が、(i+1)番目に登場した。
end
# putm(nex, 2*a+1,10)

cur = 0
t.each do |c|
  
  r = cur % a
  idx = nex[r][c]
  
  if idx.nil?
    puts "-1"
    exit
  else
    cur += idx - r
  end
end

puts cur

# putm(nex, 5, 10)

Measured memory_bytes: 98800
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 2100

class union_find
{
	int *par, *nume;
	int _size, _setnum;

public:
	union_find(){
		par = nume = NULL;
	}
	
	union_find(int x){
		par = nume = NULL;
		resize(x);
	}
	
	~union_find(){
		clear();
	}
	
	void clear(){
		_size = _setnum = 0;
		delete par;
		delete nume;
		par = nume = NULL;
	}
	
	void init(){
		_setnum = _size;
		for(int i = 0; i < _size; i++){
			par[i] = i;
			nume[i] = 1;
		}
	}
	
	void resize(int x){
		clear();
		
		_size = x;
		
		par = new int[x];
		nume = new int[x];
		
		init();
	}

	int find(int x){
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
	
		if(x == y)return;
		
		_setnum--;
		
		if(nume[x] > nume[y]) std::swap(x,y);
		
		par[x] = y;
		nume[y] += nume[x];
	}
	
	bool same(int x, int y){
		return find(x) == find(y);
	}
	
	int numel(int x){
		return nume[find(x)];
	}
	
	int size(){
		return _size;
	}
	
	int setnum(){
		return _setnum;
	}
};


signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int H, W;
	vector<string> s;
	union_find uh[MAX], uw[MAX];
	int ans = 0;
	
	cin>>H>>W;
	
	s.resize(H);
	
	for(int i = 0; i < H; i++){
		cin>>s[i];
		uh[i].resize(W+10);
		for(int j = 1; j < W; j++){
			if(s[i][j-1] == '.' && s[i][j] == '.') uh[i].unite(j-1,j);
		}
	}
	
	for(int j = 0; j < W; j++){
		uw[j].resize(H+10);
		for(int i = 1; i < H; i++){
			if(s[i-1][j] == '.' && s[i][j] == '.') uw[j].unite(i-1,i);
		}
	}
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(s[i][j] == '.') ans = max(uh[i].numel(j)+uw[j].numel(i)-1, ans);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

int multi[100010], single[100010], hp[110];


int main(){
	int N;
	while (cin >> N && N){
		for (int i = 0; i < 100010; i++){
			multi[i] = 1e9; single[i] = 1e9;
		}
		multi[0] = 0; single[0] = 0;
		for (int i = 0; i < N; i++)cin >> hp[i];
		int M;
		cin >> M;
		for (int i = 0; i < M; i++){
			string name;
			int mp;
			string command;
			int dmp;
			cin >> name >> mp >> command >> dmp;
			if (command == "Single"){
				for (int j = 0; j <= 100000; j++){
					int s = min(100000, j + dmp);
					single[s] = min(single[s], single[j] + mp);
				}
			}
			else{
				for (int j = 0; j <= 100000; j++){
					int s = min(100000, j + dmp);
					multi[s] = min(multi[s], multi[j] + mp);
				}
			}
		}
		for (int i = 100000; i >= 0; i--){
			multi[i] = min(multi[i], multi[i + 1]);
			single[i] = min(single[i], single[i + 1]);
		}
		long long ans = 1e9;
		for (int i = 0; i <= 100000; i++){
			long long u = multi[i];
			for (int j = 0; j < N; j++){
				int v = max(0, hp[j] - i);
				u += single[v];
			}
			ans = min(u, ans);
		}
		cout << ans << endl;
	}
         return 0;
}

Measured memory_bytes: 1992
#include<iostream>
using namespace std;
int main ()
{
    int a,b,c;
    cin>>a>>b>>c;
    if ( (a==b && a!=c && b!=c ) || (b==c && b!=a && c!=a) || (a==c && a!=b && c!=b))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
using namespace std;
using ull = unsigned long long;

int main(){
  string s;
  cin >> s;
  int kt = s.length();
  ull sub = 1;
  for(int i = 1; i < kt; i++)
    sub *= 10;
  string nine(kt, '9');
  ull n = stoull(s);
  ull nines = stoull(nine);

  while( n < nines ){
    nines -= sub;
  }

  int ans = 0;
  while(nines){
    ans += nines%10;
    nines /= 10;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;

int main(void){
  int n;
  vector< vector<int> > vec;
  cin >> n;
  for(int i = 0;i < n;++i){
    vector<int> cnt(30,0);
    string s;
    cin >> s;
    for(int j = 0;j < (int)s.size();++j){
      ++cnt[s[j]-'a'];
    }
    vec.push_back(cnt);
  }
  for(int i = 0;i < 30;++i){
    int m = numeric_limits<int>::max();
    for(int j = 0;j < n;++j){
      m = min(m,vec[j][i]);
    }
    for(int j = 0;j < m;++j){
      cout << (char)('a'+i);
    }
  }
  cout << endl;
  return 0;
}


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

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    double seki = 1, sum = 0;
    vector<double> a(n);
    rep(i,n) {
        cin >> a[i];
        seki *= a[i];
    }
    rep(i,n) {
        sum += seki/a[i];
    }
    double ans = seki/sum;
    printf("%.6lf\n", ans);
    return 0;
}

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

bool cmp(pair<ll,ll>a,pair<ll,ll>b)
{
	if(a.first!=b.first)return a.first>b.first;
	return a.second<b.second;
}

int main()
{
	int n,k;
	cin >> n >> k;
	vector<pair<ll,ll>> cmt,a,b;
	map<ll,ll> mp;
	for(int i = 0;i<n;i++)

	{
		ll x,y;
		cin >> x >> y;
		cmt.emplace_back(y,x);
	}
	sort(cmt.begin(),cmt.end(),cmp);
	for(int i = 0;i<n;i++)
	{
		ll x;
		x = cmt[i].second;
		ll y ;
		y = cmt[i].first;
		if(mp[x]==0)
		{
			a.emplace_back(y,x);
			mp[x] = true;
		}
		else
		{
			b.emplace_back(y,x);
		}
	}
	set<int> st;
	
	sort(a.begin(),a.end(),cmp);
	sort(b.begin(),b.end(),cmp);
	vector<ll> asum(a.size()+1),bsum(b.size()+1);
	for(int i = 0;i<a.size();i++)
	{
		asum[i+1] += a[i].first+asum[i];
	}
	for(int i = 0;i<b.size();i++)
	{
		bsum[i+1] += b[i].first+bsum[i];
	}
	ll ans = 0;
	set<ll> A,B;
	
	for(int i = 1;i<=k;i++)
	{
		ll now = 0;

		if(i<asum.size())
		{
			now += asum[i];
			A.insert(a[i-1].second);
			if(B.find(a[i-1].second)!=B.end())
			{
				B.erase(B.find(a[i-1].second));
			}
		}
		else continue;
		if(k-i<bsum.size())
		{
			now += bsum[k-i];
			if(A.find(a[i-1].second)==A.end())B.insert(b[i-1].second);
		}
		else continue;
		ll x = A.size()+B.size();
		now += x*x;
		ans = max(ans,now);
	}
	cout<<ans<<endl;


}

Measured memory_bytes: 12784
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
long long n, k;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	long long sum = 0;
	for(long long i = k; i <= n + 1; i++){
		long long low = (i * (i - 1)) / 2;
		long long high = (i * (n + n - i + 1)) / 2;
		sum = (sum + (high - low + 1) % mod) % mod;
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 3656
import sys
# input = sys.stdin.buffer.readline
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getlist():
    return list(map(int, input().split()))
import math
import heapq
from collections import defaultdict, Counter, deque
MOD = 10**9 + 7
INF = 10**15

def main():
    s = input().strip()
    ans, ans2 = 0, 0
    tmp = 0
    for c in s:
        if c != str(tmp):
            ans += 1
        tmp = 1 - tmp
    tmp = 1
    for c in s:
        # print(tmp)
        if c != str(tmp):
            ans2 += 1
        tmp = 1 - tmp

    print(min(ans, ans2))
if __name__ == '__main__':
    main()

"""
9999
3

2916
"""

Measured memory_bytes: 41452
#include<stdio.h>

int main()
{
	char str[64];
	int value = 700;
	
	scanf("%s",str);
	
	if(str[0] == 'o')value += 100;
	if(str[1] == 'o')value += 100;
	if(str[2] == 'o')value += 100;
	
	printf("%d",value);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>


using namespace std;


int main()
{
  int n;
  cin >> n;
  int a[n], maxv=-1, minv=10000;

  for (int i=0; i<n; i++){
    cin >> a[i];
    if (a[i] > maxv) maxv = a[i];
    if (a[i] < minv) minv = a[i];
  }
  cout << maxv - minv << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define vvbool vector<vector<bool>>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int h,w;
  cin >> h >> w;
  vstring a(h);
  vvbool judge(h,vbool(w,true));
  rep(i,h) cin >> a[i];
  vbool judgeh(h,true);
  rep(i,h){
    int white = 0;
    rep(j,w){
      if(a[i][j] == '.') white++;
    }
    if(white == w){
      judgeh[i] = false;
      rep(j,w){
        judge[i][j] = false;
      }
    }
  }
  rep(i,w){
    int white = 0;
    rep(j,h){
      if(a[j][i] == '.') white++;
    }
    if(white == h){
      rep(j,h){
        judge[j][i] = false;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      if(judge[i][j]) cout << a[i][j];
    }
    if(judgeh[i]) cout << endl;
  }
}

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

#define NL '\n'
using ll = long long; 
#define rep(ii,aa,bb) for(ll (ii)=ll(aa);(ii)<(ll)(bb);++(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define mid ((l+r)>>1)
#define ldx ((idx<<1))
#define rdx ((idx<<1)|1)

const int N = 500009, W = 26;
int n, q, s[4*N][W];
string str;
char ch;
void build(int idx, int l, int r){
    if(l == r) { s[idx][str[l]-'a'] = 1; return; }
    build(ldx,l,mid);
    build(rdx,mid+1,r);
    rep(ix, 0, 26) s[idx][ix] = s[ldx][ix] + s[rdx][ix];
}
void update(int idx, int l, int r, int i, char cx){
    if(l > i || r < i) return;
    if(i == l && i == r) {
        s[idx][str[l]-'a'] = 0;
        str[l] = cx;
        s[idx][str[l]-'a'] = 1;
        return;
    }
    update(ldx,l,mid,i,cx);
    update(rdx,mid+1,r,i,cx);
    rep(ix, 0, 26) s[idx][ix] = s[ldx][ix] + s[rdx][ix];    
} 
vector<int> query(int idx, int l, int r, int i, int j) {
    vector<int> ret(26);
    rep(ix, 0, W) ret[ix] = 0;
    if(l > j || r < i) return ret;
    if(l >= i && r <= j) {
        rep(ix, 0, W) ret[ix] = s[idx][ix];
        return ret;
    }
    vector<int> q1 = query(ldx, l, mid, i, j);
    vector<int> q2 = query(rdx, mid+1, r, i, j);
    rep(ix, 0, W) ret[ix] = q1[ix] + q2[ix];
    return ret;
}

int main(){
    _fastIO();
    memset(s, 0, sizeof s);
    cin >> n;
    cin >> str;
    str = "*" + str;
    build(1, 1, n);
    cin >> q;
    while(q--){
        int t, u, v;
        cin >> t;
        if(t == 1) {
            cin >> u >> ch;
            update(1, 1, n, u, ch);
        }
        else{
            cin >> u >> v;
            vector<int> sln = query(1, 1, n, u, v);
            int ans = 0;
            rep(ix, 0, W) if(sln[ix] > 0) ans++;
            cout << ans << NL;
        }
    }
}


Measured memory_bytes: 204444
#include <bits/stdc++.h>
using namespace std;
inline void solve(){
	int n;cin>>n;
	int a[n];for(int i=0;i<n;i++)cin>>a[i];
	int dp[n];dp[0]=a[0];
	int c=1;
	for(int i=1;i<n;i++){
		dp[i]=min(dp[i-1],a[i]);
	}
	//for(int i=0;i<n;i++)cout<<dp[i]<<" ";
	for(int i=1;i<n;i++)if(a[i]<=dp[i])c++;
	cout<<c<<"\n";
	return;
}
signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
	return 0;
}

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

int main(){
  char a;cin>>a;
  if(a>'Z')cout<<'a';
  else cout<<'A';
}

Measured memory_bytes: 3564
N, M = [int(_) for _ in input().split()]
ab = [[int(_) - 1 for _ in input().split()] for _ in range(M)]

G = [[0] * N for _ in range(N)]

for a, b in ab:
    G[a][b] = 1
    G[b][a] = 1

count = 0


def dfs(G, a, x):
    a[x] = 1
    if all(a):
        return 1
    else:
        count = 0
        for j in range(N):
            if G[x][j] == 1 and a[j] == 0:
                count += dfs(G, a.copy(), j)
        return count


print(dfs(G, [0] * N, 0))


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

const int INF = 1e8;

int main() {
  string s[3]; rep(i, 3) cin >> s[i];
  
  int pos[3] = {}, turn = 0;  
  char winner = 'X';
  char list[3] = {'A', 'B', 'C'};
  
  while(true){
    if(pos[turn] >= s[turn].length()){ 
      winner = list[turn];
      break;
    }
        
    int next_turn;
    switch(s[turn][pos[turn]]){ 
      case 'a': next_turn = 0; break;
      case 'b': next_turn = 1; break;
      case 'c': next_turn = 2; break;
    }
    pos[turn]++;
    
    turn = next_turn;
    
    // cout << turn << endl;
    // rep(i, 3) cout << pos[i] << " ";
    // cout << endl;
  }
  
  cout << winner << endl;
}


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

void Main()
{
    int n;
    cin >> n;
    long sum = 0;
    for (long i = 1; i <= n; i++)
    {
        sum += i*(n-i+1);
    }
    for (int i = 0; i < n-1; i++)
    {
        long a, b;
        cin >> a >> b;
        if(a > b) swap(a, b);
        sum -= a*(n-b+1);
    }
   
    cout << sum << endl;
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3532
#include <iostream>

// #include <string>
// #include <iomanip>
// std::cout << std::fixed << std::setprecision(5);

int main()
{
    int dist[6] = {0}, k;
    for (int i = 0; i < 5; i++) std::cin >> dist[i];
    std::cin >> k;
    
    if (dist[4] - dist[0] > k) std::cout << ":(" << std::endl;
    else std::cout << "Yay!" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

#define _gp(l) const auto gcu{getchar##l}; const auto pcu{putchar##l}
#ifdef __linux
_gp(_unlocked);
#else
_gp();
#endif
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_T _DEF(T,in,){return in<T>(gcu());}
_DEF(int,in,){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?n=0,false:(n=in<T>(c),true);}
_SCAN(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=(char)c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);} _OUT(const char *s){while(*s)pcu(*s++);} _OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1; range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it { int v, s; it (int _v, int _s) : v(_v), s(_s) {} operator int()const{return v;} operator int&(){return v;} int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin() {return {b, s};} it end() {return {e, s};}};

struct S {
	int s, p, q, r;
};

int main() {
	for (int n; (n = in());) {
		vector<S> s(n);
		for (S &i: s)
			i = {in(), in(), in(), in()};
		int P {in()}, Q{in()}, R{in()}, C{in()}, e {};
		for (S i: s)
			if (i.p <= P && i.q <= Q && i.r <= R && (i.p + i.r) * 4 + i.q * 9 <= C) {
				outl(i.s);
				e++;
			}
		if (!e)
			outl("NA");
	}
}



Measured memory_bytes: 2548
kaz , a , b = map(int,input().split(" "))
cou = 0
mac = list(map(int,input().split(" ")))

for i in range(kaz-1):
    if (mac[i+1] - mac[i])*a > b:
        cou += b
    else:
        cou += (mac[i+1] - mac[i])*a
        
print(cou)

Measured memory_bytes: 14480
while True:
  a = int(input())
  ans,x=[0]*a,0
  if a==0: break
  for i in range(a):
    hoge=map(int,raw_input().split())
    for i in range(5):
      ans[x]+=hoge[i]
    else: x+=1
  else: print max(ans),min(ans)

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

using namespace std;
typedef long long ll;

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    ll ans = 0;
    for (int i = n-1; i >= 0; i--) {
        if (n - i <= k) continue;
        ans += h[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
n, x = map(int, input().split())
a = list(map(int, input().split()))
ar = a[::-1]
ans = [0, 0]
for i in range(1, n):
    if a[i] + a[i-1] > x:
        ans[0] += (a[i] + a[i-1]) - x
        a[i] = max(0, x - a[i-1])
    if ar[i] + ar[i-1] > x:
        ans[1] += (ar[i] + ar[i-1]) - x
        ar[i] = max(0, x - ar[i-1])

print(min(ans))

Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<long long>vec(n + 3);
    for(int i = 1; i <= n; i++){
        cin >> vec[i];
    }
    long long u = 0;
    for(int i = 3; i <= n; i++){
        u = u ^ vec[i];
    }
    long long v = vec[1] + vec[2];
    if(u > v){
        cout << "-1";
        return 0;
    }
    if(u % 2 != v % 2){
        cout << "-1";
        return 0;
    }
    long long x = (v - u)/2, y = (v + u)/2;
    if((x ^ y) != u){
        cout << "-1";
        return 0;
    }
    if(x > vec[1]){
        cout << "-1";
        return 0;
    }
    for(int i = 60; i >= 0; i--){
        int bt1 = (x >> i) & 1;
        int bt2 = (y >> i) & 1;
        if(bt1 == 0 && bt2 == 1){
            if(x + (1LL << i) <= vec[1]){
                x = x + (1LL << i);
            }
        }
    }
    long long ans = vec[1] - x;
    if(ans >= vec[1]){
        cout << "-1";
        return 0;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 158, task d, 2020/09/05
//ms,
/*
*/

int main(void){
  deque<char> s;
  deque<char> s_rev;
  int is_rev=0;
  string input_S;
  int q;

  cin >>input_S >>q;
  for(size_t i=0;i<input_S.size();i++){
    s.push_back(input_S[i]);
    s_rev.push_front(input_S[i]);
  }

  for(int i=0;i<q;i++){
    int t;
    cin >>t;
    if(t==1) is_rev++;
    else{//t==2
      int f;
      char c;
      cin >>f >>c;
      if((f+is_rev)%2==1){
        s.push_front(c);
        s_rev.push_back(c);
      }else{
        s.push_back(c);
        s_rev.push_front(c);
      }
    }
  }

  for(size_t i=0;i<s.size();i++) {
    if(is_rev%2==0) cout <<s[i];
    else cout <<s_rev[i];
  }

  return 0;
}
/*
愚直にやるとどうか。
反転がO(N=s.size())のオーダー。
全体がO(NQ)で、これは間に合わない。
なので、dequeで実装してsとs_revを両方持っておけばいい。
で、現在どちらが本命かのフラグをもっておく。
→正解！
*/


Measured memory_bytes: 4340
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const vList = input[1].split(' ').map(x => parseInt(x, 10));
    vList.sort((a, b) => a - b);

    var result = 0;
    while(vList.length !== 1) {
        var first = vList.shift();
        var next = vList.shift();
        vList.unshift((first + next) * 0.5);
    }

    console.log(vList[0]);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include <bits/stdc++.h> 
using namespace std; 
#define vll vector<long long>
#define mll map<long long,long long>
#define pb push_back
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[500005];
ll vis[500005],color[500005],I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false; 
    if (n<=3) return true; 
    if (n%2==0||n%3==0) return false; 
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false; 
    return true; 
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res*=n;
			po--;
		}
		else
		{
			n*=n;
			po/=2;
		}
	}
	return res;
}

ll binpow(ll n, ll po, ll mod)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

ll swap(ll a, ll b)
{
	a=a+b;
	b=a-b;
	a=a-b;
}

ll fact(ll n) { 
   if ((n==0)||(n==1))
      return 1;
   else
      return n*fact(n-1);
}

ll C(ll n, ll r) {
    if(r > n - r) r = n - r; 
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
        ans=ans%1000000007;
    }

    return ans;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}



int main()
{
	ll a,b;
	cin>>a>>b;
	if(b>=a) cout<<"unsafe";
	else cout<<"safe";
}


Measured memory_bytes: 15324
#include<iostream>
#include<cstdio>
#include<functional>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#include<ctime>
using namespace std;
typedef long long ll;
typedef long double ld;
const int maxn = 7e4+7;
const int inf = 1e5;
const int modn = 1e9+7;
const ld eps = 1e-8;
const long double PI = acos(-1.0);
void qRead(ll &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
void qRead(int &x){x = 0;char a;for(a = getchar();a <'0' || a > '9';a = getchar());for(;a >= '0' && a <= '9';a = getchar())x = x*10 + a-'0';}
ll qpow(ll a,ll b,ll mo = modn){
//    printf("%lld\n",mo);
    ll res = 1;
    while(b){
        if(b & 1)res = (res*a) % mo;
        a = (a*a) % mo;
        b >>= 1;
    }
    return res;
}
ld qpow(ld a,ll b){
    ld res = 1;
    while(b){
        if(b & 1)res *= a;
        a = a*a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
//ll vis[maxn],prime[maxn],cnt,smallP[maxn];
//void getPrime(int n){
//    cnt = 0;
//    for(int i = 1;i <= n;i++)vis[i] = 0;
//    for(ll i = 2;i <= n;i++){
//        if(!vis[i]){
//            prime[++cnt] = i;
//            smallP[i] = i;
//        }
//        for(int j = 1;j <= cnt && i*prime[j] <= n;j++){
//            vis[prime[j]*i] = 1;
//            smallP[prime[j]*i] = prime[j];
//            if((i % prime[j]) == 0)break;
//        }
//    }
//}
//ll cnm[maxn][maxn];
//void getCnm(){
//    cnm[0][0] = 1;
//    for(int i = 1;i < maxn;i++){
//        for(int j = 0;j <= i;j++){
//            cnm[i][j] = cnm[i-1][j];
//            if(j)cnm[i][j] += cnm[i-1][j-1];
//            cnm[i][j] %= (modn-1);
//        }
//    }
//}
//ll f[maxn],invF[maxn];
//void getF(){
//    f[0] = invF[0] = 1;
//    for(int i = 1;i < maxn;i++)f[i] = f[i-1]*i % modn;
//    invF[maxn-1] = qpow(f[maxn-1],modn-2);
//    for(int i = maxn-2;i >= 1;i--)invF[i] = invF[i+1]*(i+1) % modn;
//}
int main(){
    int n;
    scanf("%d",&n);
    int judge = n/100;
    int ans = judge*111;
    if(ans >= n)printf("%d\n",ans);
    else printf("%d\n",ans+111);
}


Measured memory_bytes: 256
N, M = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)] #親
        self.rank = [0 for _ in range(n)] #根の深さ

    #xの属する木の根を求める
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    #xとyの属する集合のマージ
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    #xとyが同じ集合に属するかを判定
    def same(self, x, y):
        return self.find(x) == self.find(y)


ways = []
for _ in range(M):
    a, b = map(int, input().split())
    ways.append([a-1, b-1])

ans = 0
for i in range(M):
    A, B = ways[i]
    tree = UnionFind(N)
    for j in range(M):
        if i != j:
            a, b = ways[j]
            tree.unite(a, b)
    if not tree.same(A, B):
        ans += 1

print(ans)

Measured memory_bytes: 9284