akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <functional>
#include <stdio.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef pair<int, int> Point;
typedef pair<int, Point> SP;
typedef vector<vector<int> > Mat;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
int n;
Mat mat;
vector<vector<bool> > used;
vector<SP> starts(0);
 
bool dfs(int cur, int sum, int x, int y) {
//  cout << x << ", "<< y << ", " << sum << endl;
  if (starts[cur].first == sum) {
    //cout << "ok " << cur << endl;
    cur++;
    sum = 0;
    if (cur >= starts.size()) {
      return true;
    }
    x = starts[cur].second.second;
    y = starts[cur].second.first;
  }
  else if (starts[cur].first < sum) {
    return false;
  }
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];

    if (0 <= nx && nx < n && 0 <= ny && ny < n && !used[ny][nx]) {
      used[ny][nx] = true;
      if (dfs(cur, sum + mat[ny][nx], nx, ny)) return true;
      used[ny][nx] = false;
    }
  }
  return false;
  
}
void solve() {
  mat = Mat(n, vector<int>(n));
  used = vector<vector<bool> >(n, vector<bool>(n, false));
  starts.clear();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int a;
      cin >> a;
      sum += a;
      if (a < 0) {
        a *= -1;
        used[i][j] = true;
        starts.push_back(SP(a, Point(i, j)));
      }
      mat[i][j] = a;
    }
  }
  bool ret = false;;
  if (sum != 0) {
    ret = false;
  }
  else if (starts.size() == 1) {
    ret = true;
  }
  else {
    ret = dfs(0, 0, starts[0].second.second, starts[0].second.first);
  }
  cout << (ret ? "YES" : "NO") << endl;
  return;
}


int main() {
  while (true) {
    cin >> n;
    if (n == 0) break;
    solve();
  }
  return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill( (T*)array, (T*)(array+N), val );};
template<class T>inline bool chmax(T& a,T b){if(a < b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a > b){a=b;return true;}return false;};



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

  int n;
  cin >> n;
  int p[n];
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  int res = 0;
  rep(i, n - 1) {
    if(p[i] == i) {
      swap(p[i], p[i + 1]);
      res++;
    }
  }
  if(p[n - 1] == n - 1) res++;

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

llong len[51] = {}, p[51];
llong n, x;

llong solve(int sou, llong num, llong sum){
  if(sou == 0) return sum+1;

  if(num == 1){
    return sum;
  }else if(num == len[sou-1]+2){
    return sum+1+p[sou-1];
  }else if(num == len[sou]){
    return sum + p[sou];
  }else if(num > 1 && num < len[sou-1]+2){
    return solve(sou-1, num-1, sum);
  }else{
    return solve(sou-1, num-2-len[sou-1], sum+p[sou-1]+1);
  }
}

int main(){

  cin >> n >> x;

  len[0] = 1;
  p[0] = 1;
  REP(i,50){
    len[i+1] = len[i] * 2 + 3;
    p[i+1] = p[i] * 2 + 1;
  }
  cout << solve(n,x,0) << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define F 110000
using namespace std;
 
vector<int> v[F];
int a,b,x,y,r;
 
int D(int t){
    int e=0;
    while(e*e<=r*r-t*t)e++;
    return e-1;
}
 
int main(){
     
    while(cin>>a>>b>>r&&a+b){
    for(int i=0;i<F;i++){
        v[i].clear();
    }
    r*=4;
    for(int i=0;i<a;i++){
        cin>>x>>y;
        v[x].push_back(y);
    }
    for(int i=0;i<a;i++){
        sort(v[i].begin(),v[i].end());
    }
    int n=0;
    while(b--){
        cin>>x>>y;
        for(int i=max(0,x-r);i<=min(F-100,x+r);i++){
            n+=lower_bound(v[i].begin(),v[i].end(),y+D(x-i)+1)-lower_bound(v[i].begin(),v[i].end(),y-D(x-i));
        }
    }
    cout<<n<<endl;
    }
    return 0;
}

Measured memory_bytes: 6952
import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
# MOD = 10 ** 9 + 7
# INF = float('inf')
# N = int(input())
# A = [int(x) for x in input().split()]
# A = [int(input()) for _ in range(N)]
# dp = [[0] * 100 for _ in range(100)]
# dp = defaultdict(lambda: float('inf'))
# print('hoge', file=sys.stderr)


n = int(input())
p = [int(x) for x in input().split()]

cnt = 0
for i in range(n - 2):
    L = [p[i], p[i + 1], p[i + 2]]
    L.sort()
    # print("{},{}".format(i,i + 2))
    if p[i + 1] == L[1]:
        cnt += 1

print(cnt)


Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<double> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    sort(v.begin(), v.end());
    
    double ans = v[0];
    for(int i = 0; i < n; i++) {
        ans = (ans + v[i]) / 2.0;
    }
    
    cout << setprecision(8) << ans << endl;
    
    return 0;
}



Measured memory_bytes: 256
use proconio::input;
use std::i64;
fn main() {
    input! { dd : usize , c : [ i64 ; 26 ] , s : [ [ i64 ; 26 ] ; dd ] , }
    let mut select = Vec::new();
    let mut last = [0; 26];
    for d in 0..dd {
        let mut maxvalue = i64::MIN;
        let mut maxi = 0;
        for i in 0..26 {
            let mut value = 0;
            {
                let lastlast = last[i];
                last[i] = d + 1;
                value += s[d][i];
                #[allow(clippy::needless_range_loop)]
                for i in 0..26 {
                    value -= c[i] * (d + 1 - last[i]) as i64;
                }
                last[i] = lastlast;
            }
            if value > maxvalue {
                maxvalue = value;
                maxi = i;
            }
        }
        last[maxi] = d + 1;
        select.push(maxi);
    }
    for contest in select {
        println!("{}", contest + 1);
    }
}



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

typedef long long ll;
typedef pair<int,int> pii;
int main(){
  int ans = 0;
  int N,K;
  cin >> N;
  cin >> K;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    ans += min(tmp, K-tmp);
  }
  cout << ans*2 << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC167
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ')
                .Select(i => int.Parse(i)).ToArray();

            if(input[0]>input[1])
            {
                Console.WriteLine("safe");
                return;
            }
            Console.WriteLine("unsafe");

        }
    }
}


Measured memory_bytes: 28036
# AOJ 1591 Graph Making
# Python3 2018.7.13 bal4u
 
n, d = map(int, input().split())
if d == 1: print(n*(n-1)//2)
else: print((n-1)+(n-d-1)*n-((n-d-1)*(n+d-2)//2))


Measured memory_bytes: 5596
n = int(input())
a = list(map(int, input().split()))
accu = 0
tmp = 0
for i in range(n):
    accu += a[i]
    if i%2==0:
        if accu<=0:
            tmp += 1-accu
            accu = 1
    else:
        if accu>=0:
            tmp += accu+1
            accu = -1
ans = tmp
accu = 0
tmp = 0
for i in range(n):
    accu += a[i]
    if i%2==1:
        if accu<=0:
            tmp += 1-accu
            accu = 1
    else:
        if accu>=0:
            tmp += accu+1
            accu = -1
ans = min(tmp, ans)
print(ans)

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

using namespace std;

#define pb push_back
#define nl '\n'
#define pi 2.0*acos(0.0)
#define mod 1e9+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll n,ans = 0,gcd;
    scanf("%lld", &n);
    FOR(i,1,n+1){
        FOR(j,1,n+1){
            FOR(k,1,n+1){
                gcd = __gcd(__gcd(i,j),k);
                ans += gcd;
            }
        }
    }
    cout<< ans <<nl;
}


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

using ll = long long;
using P = pair<int, int>;
using PP = pair<int, P>;
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define rep0(i,n) for (int i=0; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#ifdef _DEBUG
string _format(string args) { string r = "", t; istringstream s(args); while (getline(s, t, ',')) r += t+":%d "; return r + "\n"; }
#define debug(...) do{printf(_format(#__VA_ARGS__).c_str(), __VA_ARGS__);}while(0)
#define FAST_IOSTREAM() do{}while(0);
#else
#define debug(...) do{}while(0)
#define FAST_IOSTREAM() do{std::ios::sync_with_stdio(false); std::cin.tie(nullptr);}while(0)
#endif

int main() {
    FAST_IOSTREAM();

    int n;
    cin >> n;
 
    ll ans = 0;
    rep1(i, n) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

int n;
int ans;

int main(){

  n = in();
  ans = n * ( n + 1 ) / 2;

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


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

#define max 10000

int main(){
  int *X, *Y;
  int Z[max+1];
  int n, i;

  scanf("%d", &n);
  X=malloc(sizeof(int)*n+1);
  Y=malloc(sizeof(int)*n+1);
  for(i=0 ; i<=max ; i++)Z[i]=0;
  for(i=0 ; i<n ; i++){
    scanf("%d", &X[i+1]);
    Z[X[i+1]]++;
  }
  for(i=1 ; i<=max ; i++)Z[i]=Z[i]+Z[i-1];
  for(i=0 ; i<=n ; i++){
    Y[Z[X[i]]]=X[i];
    Z[X[i]]--;
  }
  printf("%d",Y[1]);
  for(i=2 ; i<=n ; i++){
    printf(" %d",Y[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 17412
#include <cstdio>
#include <algorithm>
#include <functional>

int n;
int S[1<<18];
int Q[19];


int main(){
  scanf("%d",&n);
  for(int i=0;i<(1<<n);i++) scanf("%d",S+i);
  std::sort(S, S+(1<<n), std::greater<int>());
  int k = 0;
  for(int i=0;i<(1<<n);){
    int j = i;
    for(i++; S[i] == S[j]; i++) ;
    S[k++] = i-j;
  }
  Q[n] = 1;
  for(int i=0;i<k;i++){
    int l;
    int a=0;
    for(l=n;l>=0 && a < S[i];l--) a += Q[l];
    if(a<S[i]){
      puts("No");
      return 0;
    }
    l++;
    for(int t=0;t<l;t++) Q[t] += Q[l]-a+S[i];
    Q[l++] = a-S[i];
    for(; l<n; l++){
      for(int t=0;t<l;t++) Q[t] += Q[l];
      Q[l] = 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 1152
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.InputStream;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner();

        final int N = fs.nextInt();
        final int T = fs.nextInt();

        int min = Integer.MAX_VALUE;

        for (int i = 0; i < N; i++) {
            int c = fs.nextInt();
            int t = fs.nextInt();

            if (t <= T) min = Math.min(min, c);
        }

        System.out.println(min == Integer.MAX_VALUE ? "TLE" : min);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23124
#include <iostream>

int main()
{
	int x, y;
	std::cin >> x >> y;

	while (x > 0 && y > 0)
	{
		if (x >= y)
		{
			x = x % y;
		}
		else
		{
			y = y % x;
		}
	}

	int answer = (x == 0) ? y : x;
	std::cout << answer;
	std::cout << std::endl;
}

Measured memory_bytes: 3032
def main():
    n = int(input())
    words = {}
    for _ in range(n):
        a = input()
        if a in words:
            words[a] += 1
        else:
            words[a] = 1

    max_val = max(words.values())
    words_sorted = sorted(words.items(), key=lambda x: x[0])
    for key, value in words_sorted:
        if value != max_val:
            continue
        else:
            print(key)


if __name__ == "__main__":
    main()


Measured memory_bytes: 46556
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

A,B=get_i
puts max(A-B*2,0)

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<string>> S(H, vector<string> (W));
  REP(i,H)REP(j,W) cin >> S[i][j];
  string res;
  REP(i,H)REP(j,W) {
    if(S[i][j] == "snuke") {
      res += 'A' + j;
      if(i < 10) res += '1' + i;
      else {
        res += '0' + (i + 1) / 10;
        res += '0' + (i + 1) % 10;
      }
      break;
    }
  }
  cout << res << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
void print(vector<T> vec)
{
    int n = vec.size();
    for (int i = 0; i < n; i++)
    {
        cout << vec[i] << (i == n - 1 ? "\n" : " ");
    }
}

int x, a, b;

int main()
{
    cin >> a >> b;
    if (a > b)
        x += a, a--;
    else
        x += b, b--;
    cout << x + max(a, b) << endl;
}

Measured memory_bytes: 256
def max(a,b); a > b ? a : b; end
def min(a,b); a < b ? a : b; end

H,W = gets.split.map(&:to_i)

if H % 3 == 0 || W % 3 == 0
  puts 0
else
  puts  [ H, W,
        ((W / 3 * 2) .. (W - W / 3)).map{|w| max((H - H / 2) * w, H * (W - w)) - min(H / 2 * w, H * (W - w)) }.min ,
        ((H / 3 * 2) .. (H - H / 3)).map{|h| max((W - W / 2) * h, W * (H - h)) - min(W / 2 * h, W * (H - h)) }.min ].min
end


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

using namespace std;

bool kaibun(string s){
    size_t len = s.length();
    for(int i = 0; i < len/2; i++){
        if(s[i] != s[len-i-1]) return false;
    }
    return true;
}

int main(){
    long long int N=0;
    long long int sum=0;
    cin >> N;
    for(long int i = 1; i < N + 1; i++){
        if(i%3 == 0){
            continue;
        }
        if(i%5 == 0){
            continue;
        }
        sum += i;
        //cout << i << endl;
    }
    cout << sum << endl;

    return 0;
}

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

const int MAXN = 200000 + 10;

int32_t main() {
    ios_base::sync_with_stdio(0);


    int n;
    cin >> n;

    vector<pair<int, int>> r(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> r[i].first >> r[i].second;
    }

    for (int i = 0; i < n; i++) {
        cin >> b[i].first >> b[i].second;
    }

    sort(begin(r), end(r));

    sort(begin(b), end(b));

    int res = 0;

    for (int i = 0; i < n; i++) {
        auto blue = b[0];
        //cerr << "rozwazam " << blue.first << " " << blue.second << "\n";

        pair<int, int> best{-1, -1};
        for (auto z: r) {
            if (z.first > blue.first) break;
            if (z.second > blue.second) continue;
            if (z.second > best.second) {
                best = z;
            }
        }

        if (best.first > -1) {
            r.erase(find(begin(r), end(r), best));
            res++;
        }

        b.erase(begin(b));
    }

    cout << res << "\n";


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	double x = 0, y = 0;
	double dist, ang = 0, d;

	while(scanf("%lf,%lf", &dist, &d)) {
		if(!dist && !d) break;
		x += sin(ang * M_PI / 180) * dist;
		y += cos(ang * M_PI / 180) * dist;
		ang += d;
	}

	cout << (int)x << endl << (int)y << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

//不便さの数え方が分からなくて解説見た

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

ll Combination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}


int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(m), b(m);
    rep(i,m) cin >> a[i] >> b[i];

    vector<ll> ans;
    ll com = Combination(n,2);

    UnionFind UF(n+1);
    for(long long i = m-1; i >= 0; i--){
        ll cnt = com;

        ans.push_back(com);

        if(!UF.issame(a[i],b[i])){
            com -= UF.size(a[i]) * UF.size(b[i]);
        }
        UF.merge(a[i],b[i]);
    }
    reverse(ans.begin(),ans.end());
    for(auto x:ans) put(x);
}

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

int main(){
	int n;
	cin >> n;
	vector<int> absa(n);
	bool exist0 = false;
	int cntminus = 0;
	rep(i,n){
		int tmp;
		cin >> tmp;
		if(tmp==0) exist0 = true;
		else if(tmp < 0) cntminus++;
		absa[i] = abs(tmp);
	}
	
	ll res = 0;
	rep(i,n) res += absa[i];
	
	if(exist0 || cntminus % 2 == 0){
		cout << res << endl;
		return 0;
	}
	
	sort(absa.begin(), absa.end());
	
	cout << res - 2*absa[0] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k;
unordered_set<P, pairhash> memo, memof, memot;
bool check(int n, int t) {
    P p = make_pair(n, t);
    if (memof.count(p) > 0) return false;
    if (memot.count(p) > 0) return true;
    if (memo.count(p) > 0) return false;
    memo.insert(p);
    //cerr << n << " " << t << endl;
    if (t <= 0) return false;
    int s = 0, m = n;
    while (m > 0) {
        s += m % 10;
        m /= 10;
    }
    if (s <= t) return true;

    for (int i = 0; i < 10; i++) {
        m = k * i + n;
        if (check(m / 10, t - m%10)) {
            memot.insert(p);
            return true;
        }
    }
    memof.insert(p);
    return false;
}

int solve() {
    while (k % 10 == 0) k /= 10;
    if (k == 1) return 1;
    int lb = 0, ub = 45;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        bool f = false;
        for (int i = 1; i < 10; i++) {
            memo.clear();
            int m = k * i;
            if (check(m / 10, mid - m%10)) {
                f = true;
                break;
            }
        }
        if (f) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub;
}

void input() {
    cin >> k;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

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

    int ans = N;
    for (int i = 0; i <= N; i++) {
        int cc = 0;
        int t = i;
        while (t > 0) cc += t % 6, t /= 6;
        t = N - i;
        while (t > 0) cc += t % 9, t /= 9;
        ans = min(ans, cc);
    }

    cout << ans << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
num_count = 0

for num in 1..n do
  count = 0
  if (num % 2) == 1
    for i in 1..num do
      if (num % i) == 0
        count += 1
      end
    end
  end
  if count == 8
    num_count += 1
  end
end

puts num_count


Measured memory_bytes: 1788
#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;
    vector<int> a(n);
    int mx=0, mx2=0;
    rep(i,n) {
        cin >> a[i];
        if (a[i] >= mx) {
            mx2 = mx;
            mx = a[i];
        } else if (a[i] >= mx2) {
            mx2 = a[i];
        }
    }

    rep(i,n) {
        if (a[i]==mx) {
            cout << mx2 << endl;
        } else {
            cout << mx << endl;
        }
    }

    return 0;
}


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

int main() {
    int N, K;
    string S;
    vector<int> v = {0};
    vector<int> v2;

    cin >> N >> K;
    cin >> S;

    //0->1に変わるポイントをvectorに代入
    int pos = S.find("01", 0);
    while(pos != string::npos) {
        v.push_back(pos + 1);
        pos = S.find("01", pos + 2);
    }

    //1->0に変わるポイントを代入
    if(S[0] == '0') v2.push_back(0);
    pos = S.find("10", 0);
    while(pos != string::npos) {
        //cout << pos + 1 << endl;
        v2.push_back(pos +1);
        pos = S.find("10", pos + 2);
    }
    v2.push_back(S.length());

    int size = v2.size();
    int left = 0, right = min(size - 1, K);
    int maxv = 0;
    while(true) {
        maxv = max(maxv, v2[right] - v[left]);
        //cout << left << ", " << right << ".." << v2[right] << ", " <<v[left] << endl;
        if(right + 1 >= v2.size()) break;
        right = right + 1;
        left = left + 1;
    }

    cout << maxv << endl;

}

Measured memory_bytes: 1020
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long N; cin >> N;
  long step = 1e13;
  
  for (long i=1; i <= sqrt(N); i++) {
    if (N % i != 0) continue;
    
    long new_step = (i - 1) + (N / i - 1);
    
    if (step < new_step) continue;
    step = new_step;
  }
  
  cout << step << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
	int n, m;
	while(cin>> n >> m, n || m){
		vector<int> p_freq(11);
		for(int i = 0; i < n; i++) {
			int d, p;
			cin >> d >> p;
			p_freq[p] += d;
		}
		
		int count = 0;
		for(int i = 10; i > 0; i--) {
			if(m >= p_freq[i])
				m -= p_freq[i];
			else {
				count += (p_freq[i] - m) * i;
				m = 0;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
int main()
{
	int n, k=INT_MIN, c=0, maxi=INT_MIN;
	cin>>n;
	vector<int>A(n);
	rep(i,0,n)cin>>A[i];
	rep2(j,n,0)
	{
		if(A[j]>=k)
			c++;
		else
			c=1;
			maxi=max(maxi, c);
			k=A[j];
	}
	cout<<maxi-1<<endl;
}


Measured memory_bytes: 640
def main():
    N = int(input())  # 文字列または整数(一変数)


    max_a = 0
    min_b = None

    for i in range(N):
        a, b = map(int, input().split())
        if a > max_a:
            max_a = a
            min_b = b

    answer = max_a + min_b
    print(answer)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 5; i++) {
            int a = sc.nextInt();
          if(a==0) System.out.println(i+1);
        }
    }
}
       

Measured memory_bytes: 35680
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
        	int n = sc.nextInt();
            int x = sc.nextInt();
            if(n + x == 0) break;
            int ans = 0;
            for(int a = 1; a <= n - 2; a++)
                for(int b = a + 1; b <= n - 1; b++)
                    for(int c = b + 1; c <= n; c++) {
                        if(a + b + c == x) ans++;
                    }
            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 26920
#include <iostream>

using namespace std;

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

    long long numar = 0;
    if((n & 1))
    {
        cout << 0;
        return 0;
    }
        
    for (long long ierom = 5; n / ierom >= 1; ierom *= 5)
        numar += ((n / ierom) >> 1);

    cout << numar;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  String s = sc.next();
	    int[] charCnt = new int[26];
	  	
	    for (char c: s.toCharArray()) {
	      charCnt[c - 'a']++;
	    }
	    
	    for (int i = 0; i < 26; i++) {
	      if (charCnt[i] == 0) {
	        System.out.println((char)(i + 'a'));
	        System.exit(0);
	      }
	    }
	    
	    System.out.println("None");
	    System.exit(0);
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


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

int main() {
    int64_t a; cin >> a;
    string bs; cin >> bs;
    int64_t bi = (bs[0]-'0')*100+stoi(bs.substr(2));
    int64_t ans = a*((int64_t)bi)/100ll;
    //cout << bi << endl;
    cout << ans << endl;
}

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

int main(){
  int x,y;
  cin >> y;
  x = y;
  int f_x =0;
  rep(i,8){
    int temp =x%10;
    f_x += temp;
    x /=10;
  }

  if (y%f_x==0){
    cout << "Yes"<<endl;
  }
  else cout<< "No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
long long v[110],w[110];
long long N,W;

int main(){
    cin>>N>>W;
    vector<long long> mem(100010);
    for(int i=0;i<N;i++){
        long long w,v;
        cin>>w>>v;
        for(int c=W-w;c>=0;c--){
            mem[c+w]=max(mem[c+w],mem[c]+v);
        }
    }
    long long ans=0;
    for(int i=0;i<=W;i++){
        ans=max(ans,mem[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, x, ans = 0; cin >> a >> b >> x;
	if (a < b * 2) {
		ans += x / 1000 * a;
	}
	else {
		ans += x / 1000 * b * 2;
	}
	if (x % 1000 <= 500 && x % 1000 != 0) {
		ans += min(a, b);
	}
	else if(x % 1000 != 0){
		ans += min(a, b * 2);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
using namespace std;

#define INF 100000

int n, W;
int r[12];
double bitDP[12][(1<<12)]; // [??????????????£???] , [?????£?????±?????????bit??§??????]

bool inputData() {
	string str;
	getline(cin, str);
	if(cin.eof()) {
		return false;
	}
	
	str += ' ';
	
	int i, tmp = 0;
	for(i = 0; i < str.size(); i++) {
		if('0' <= str[i] && str[i] <= '9') {
			tmp  = tmp * 10 + str[i] - '0';
		} else {
			W = tmp;
			i++;
			break;
		}
	}
	
	n = tmp = 0;
	while(i < str.size()) {
		if('0' <= str[i] && str[i] <= '9') {
			tmp  = tmp * 10 + str[i] - '0';
		} else {
			r[n++] = tmp;
			tmp = 0;
		}
		
		i++;
	}
	
	return true;
}

int main()
{
	while(inputData()) {
		for(int i = 0; i < n; i++) {
			for(int bit = 0; bit < (1 << n); bit++) {
				bitDP[i][bit] = INF;
			}
			bitDP[i][(1 << i)] = (double)r[i];
		}
		
		for(int bit = 0; bit < (1 << n); bit++) {
			for(int i = 0; i < n ; i++) {
				for(int j = 0; j < n; j++) {
					if(bit& (1 << j)) {
						continue;
					}
					
					double distance_r = r[i] + r[j];
					double distance_y = (r[i] - r[j] >= 0)? r[i] - r[j]: r[j] - r[i];
					double cost = distance_r * cos(asin(distance_y / distance_r));
					bitDP[j][bit| (1 << j)] = min(bitDP[j][bit| (1 << j)], bitDP[i][bit] + cost);
				}
			}
		}
		/*
		for(int i = 0; i < n ; i++) {
			for(int bit = 0; bit < (1 << n); bit++) {
				if(bitDP[i][bit] == INF) cout << -1 << " ";
				else cout << bitDP[i][bit] << " ";
			}cout << endl;
		}*/
		
		double ans = INF;
		for(int i = 0; i < n; i++) {
			ans = min(ans, bitDP[i][(1 << n)-1] + (double)r[i]);
		}
		//cout << ans << " " << W << endl;
		cout << ((ans <= W)? "OK": "NA") << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1600
#include <bits/stdc++.h>
#define N 100010
#define Q 50001
using namespace std;
int n,m;
int A[N],B[Q];

bool search(int x){
  int L = 0,R = n;
  while(L<R){
    int M = (L+R)/2;
    if(A[M]>=x) R = M;
    else L = M+1;
  }

  return L<n&&A[L] == x;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>A[i];
  cin>>m;
  for(int i=0;i<m;i++) cin>>B[i];

  int cnt=0;
  for(int i=0;i<m;i++)cnt+=search(B[i]);
  cout<<cnt<<endl;
    

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

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

	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return a[i] + b[i] > a[j] + b[j];
	});
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i & 1) {
			ans -= b[ind[i]];
		} else {
			ans += a[ind[i]];
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5184
N = int(input())
line = [int(i) for i in input().split()]


#sum
#count : 組み合わせの個数
#tmp : L番目の要素で始まる組み合わせの個数

count = 0
sum = line[0]
r = 1
count_tmp = 1

for L in range(N-1):
  #ビットが被るまで右端を伸ばす。かぶったら終了
  for r in range(r,N):
    if sum+line[r] == sum ^ line[r]:
      sum += line[r]
      count_tmp += 1
      if r == N-1:
        r += 1
    else:
      break
  count += count_tmp
  count_tmp -= 1
  sum -= line[L]

#L=N, r=Nの分を１つ追加する
print(count+1)

Measured memory_bytes: 23560
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define mk make_pair
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    fastIO;
    ll n;
    cin>>n;
    string str;
    ll x,y,val,val1;
    vector<string>v;
    map<string,ll>m;
    for(int i=0;i<n;i++)
    {
        cin>>str>>x;
        v.pb(str);
        m.insert(mk(str,x));
    }
    string str1;
    cin>>str1;
    ll pos;
    pos=find(v.begin(),v.end(),str1)-v.begin();
    ll ans=0;
    for(int i=pos+1;i<n;i++)
    {
        auto itr=m.find(v[i]);
        ans+=itr->second;
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int GCD(int, int);

int main () {
  int a = 0, b = 0, div = 0;

  scanf("%d%d",&a,&b);

    
  if(a > b) div = GCD(a,b);
  
  else div = GCD(b,a);
    
  printf("%d\n",div);
  return 0;
}

int GCD(int a, int b) {
  
  int sum = 0;
  sum = a % b;
  
  if(sum == 0) return b;
  else sum = GCD(b,a%b);
  
}



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

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

  vector<int> A(4); for (ll i = 0; i < 4; i++) cin >> A[i];
  sort(A.begin(), A.end());
  if (A[0] == 1 && A[1] == 4 && A[2] == 7 && A[3] && 9) {
    cout << "YES" << '\n';
  } else {
    cout << "NO" << '\n';
  }
  return 0;
}

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

int main() {
  long long  a,b,c,k;
  cin>>a>>b>>c>>k;
  long long ans=0;
  if(a>=k){
  ans=k;
  }else if(a<k && k<=a+b){
    ans=a;
    }else if(k>a+b &&k<=a+b+c){
     ans=a-(k-(a+b));
    }else{
     ans=a-c;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3632
N = int(input())
L = list(map(int, input().split()))

from bisect import bisect_right

L = sorted(L, reverse=True)
L = [-L[i] for i in range(N)]

cnt=0
for i in range(N-2):
    for j in range(i+1, N-1):
        diff = L[i]-L[j]
        idx = bisect_right(L, diff-1, j+1, N)
        cnt+=(idx-j)-1
    
print(cnt)

Measured memory_bytes: 43372
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int n; cin >> n;

  int i = 1;
  while (++i <= n) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (x) {
	if (x % 10 == 3) {
	  cout << " " << i;
	  break;
	} else {
	  x /= 10;
	}
      }
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n;cin>>n;
  vector<P> p(n);
  rep(i,n){
    int x,l; cin>>x>>l;
    p[i].fs=x+l;
    p[i].sc=x-l;
  }
  sort(ALL(p));

  int sum=1;
  int r=p[0].fs;
  rep(i,n){
    if(r<=p[i].sc){
      r=p[i].fs;
      sum++;
    }
  }
  cout<<sum<<endl;


  return 0;
}


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

typedef long long int ll;
typedef double d;

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)

#define be(a) a.begin(),a.end()
#define sz(x) x.size()

#define nl cout<<"\n";
#define sp cout<<" ";

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    su;
    string s,t;
    cin>>s>>t;
    int len=sz(t);
    s+=t[len-1];
    if(s==t)
        cout<<"Yes";
    else
        cout<<"No";
    nl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
int ans=1e18;
int n;
vector<int> a(n);
signed main(){
	ios_base::sync_with_stdio(0);
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<=100;i++){
		int cur=0;
		for(int j=0;j<n;j++) cur+=(a[j]-i)*(a[j]-i);
		ans=min(ans,cur);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3668
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

typedef pair <int, int> P;

class PrimalDual {
    const int INF = 1 << 30;

    struct Edge {
        int to, cap, cost, rev;
    };

    int n;
    vector<vector<Edge>> G;
    vector<int> potential; // ポテンシャル
    vector<int> dist; // 最短距離
    vector<int> prevv, preve; // 直前の頂点と辺

    void dijkstra(int s) {
        fill(dist.begin(), dist.end(), INF);
        priority_queue<P, vector<P>, greater<P>> q;
        dist[s] = 0;
        q.push(P(0, s));
        while (!q.empty()) {
            P p = q.top();
            q.pop();
            int v = p.second;
            if (dist[v] < p.first) continue;
            for (int i = 0; i < G[v].size(); i++) {
                Edge &e = G[v][i];
                if (e.cap > 0 && dist[e.to] + potential[e.to] > dist[v] + e.cost + potential[v]) {
                    dist[e.to] = dist[v] + e.cost + potential[v] - potential[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    q.push(P(dist[e.to], e.to));
                }
            }
        }
    }

public:
    PrimalDual(int n) : n(n), G(n), potential(n), dist(n), prevv(n), preve(n) {}

    void add_edge(int from, int to, int cap, int cost) {
        G[from].push_back({to, cap, cost, (int)G[to].size()});
        G[to].push_back({from, 0, -cost, (int)G[from].size() - 1});
    }

    int min_cost_flow(int s, int t, int flow) {
        fill(potential.begin(), potential.end(), 0);
        int ret = 0;
        while (flow) {
            dijkstra(s);
            if (dist[t] == INF) return -1;
            for (int v = 0; v < n; v++) potential[v] += dist[v];
            int f = flow;
            for (int v = t; v != s; v = prevv[v]) f = min(f, G[prevv[v]][preve[v]].cap);
            flow -= f;
            ret += f * potential[t];
            for (int v = t; v != s; v = prevv[v]) {
                Edge &e = G[prevv[v]][preve[v]];
                e.cap -= f;
                G[v][e.rev].cap += f;
            }
        }
        return ret;
    }
};

int main() {
    int V, E, F;
    cin >> V >> E >> F;

    PrimalDual pd(V);
    for (int e = 0; e < E; e++) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        pd.add_edge(u, v, c, d);
    }

    cout << pd.min_cost_flow(0, V - 1, F) << "\n";
    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define erep(i, a, b) for (int i = a; i <= (int)(b); i++)
#define per(i, a, b) for (int i = (b)-1; i > (a); i--)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; i--)
#define pb push_back
#define mp make_pair
#define INF (1 << 30) - 1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int n, f[110][10], p[110][11];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  rep(i, 0, n) rep(j, 0, 10) { cin >> f[i][j]; }
  rep(i, 0, n) erep(j, 0, 10) { cin >> p[i][j]; }
  int ans = -INF;
  rep(i, 1, 1 << 10) {
    int t = 0;
    rep(j, 0, n) {
      int cnt = 0;
      rep(k, 0, 10) {
        if (((i >> k) & 1) && f[j][k])
          cnt++;
      }
      t += p[j][cnt];
    }
    ans = max(ans, t);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256