akhauriyash/Code-Regression huggingface dataset:
s = gets.chomp
result = true

if s[0] != "A"
    result = false
end

if result
    count = 0
    (2..(s.length-2)).each do |i|
        count += 1 if s[i] == "C"
    end
    if count != 1
        result = false
    end
end

if result
    small_alphabets = []
    ("a".."z").each do |alphabet|
        small_alphabets << alphabet
    end
    s.length.times do |i|
        if s[i] == "A" || s[i] == "C"
            next
        end
        if !(small_alphabets.include?(s[i]))
            result = false
            break
        end
    end
end

puts result ? "AC" : "WA"

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

void solve(void) {
  ll N; cin >> N;
  vector<ll> H(N);
  for(ll ni = 0; ni < N; ++ni) cin >> H[ni];

  for (ll ni = N-1; ni-1 >= 0; --ni) {
    if(H[ni-1] > H[ni]) H[ni-1]--;

    if(H[ni-1] > H[ni]) {
      cout << "No" << endl;
      return;
    }
  }

  cout << "Yes" << endl;
}

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

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int i,a,b,m,aa[100000],bb[100000],t,x,y,c,min,ma=1000000,mb=1000000;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&m);
  for(i=0;i<a;i++){
  	scanf("%d",&t);
    aa[i]=t;
    if(ma>t) ma=t;
  }
  for(i=0;i<b;i++){
  	scanf("%d",&t);
    bb[i]=t;
    if(mb>t) mb=t;
  }
  min=ma+mb;
  for(i=0;i<m;i++){
  	scanf("%d",&x);
  	scanf("%d",&y);
  	scanf("%d",&c);
    t=aa[x-1]+bb[y-1]-c;
    if(min>t) min=t;
  }
  printf("%d",min);
  return(0);
}


Measured memory_bytes: 896
#include<iostream>
#include<bitset>
#include <algorithm>
#include<string>
#include <cstdlib>
#include <queue>
#include <map>
#include <set>
#include<vector>
#include<stack>
#include <math.h>
using namespace std;
using ll = long long;

using Graph = vector<vector<int>>;

int main(){
  string s;
  cin >> s;
  int n = s.length();
  ll ans = 0;
  stack<int> st;
  for(int bit = 0; bit < (1 << (n - 1)); bit++) {
    ll tmp = 0;
    for(int i = 0; i < n; i++) {
      if(bit & (1<<i)){
        st.push(s[i] - '0');
      }else{
        st.push(s[i] - '0');
        ll digit = 1;
        while(!st.empty()) {
          tmp += st.top() * digit;
          st.pop();
          digit *= 10;
        }
      }
    }
    //cout << tmp << " ";
    ans += tmp;
  }
  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;


int N;
int A[6005];
int dp[2005][2005];
int buf[2005][2005];

int max_row[2005],max_col[2005],max_val;

int cx[]={0,1,2},cy[]={1,2,0},cz[]={2,0,1};

void assign(int k,int q){
    dp[k][q]=buf[k][q];
    max_row[k]=max(max_row[k],dp[k][q]);
    max_col[q]=max(max_col[q],dp[k][q]);
    max_val=max(max_val,dp[k][q]);
}

int main(){
    scanf("%d",&N);
    for(int i=1;i<=3*N;i++) scanf("%d",A+i);

    dp[A[1]][A[2]]=2;
    max_val=2;
    max_row[A[1]]=2;
    max_row[A[2]]=2;

    int offset=0;
    for(int i=0;i<N;i++){
        auto *cur=A+(i+1)*3;
        
        if (cur[0]==cur[1]&&cur[1]==cur[2]){
            offset++;
            continue;
        }

        for(int i=0;i<3;i++){
            int selx=cx[i],sely=cy[i],unsel=cz[i];
            if (cur[selx]!=cur[sely]) continue;
            int p=cur[selx],q=cur[unsel];
            for(int k=1;k<=N;k++)
                buf[k][q]=max(buf[k][q],max(dp[p][k]+1,dp[k][p]+1));
        }

        for(int i=0;i<3;i++){
            int sel=cx[i],unselx=cy[i],unsely=cz[i];
            int p=cur[sel],q=cur[unselx],l=cur[unsely];
            buf[q][l]=max(dp[p][p]+1,buf[q][l]);
        }

        for(int i=0;i<3;i++){
            int sel=cx[i],unselx=cy[i],unsely=cz[i];
            int p=cur[sel],q=cur[unselx],l=cur[unsely];
            buf[q][l]=max(max_val,buf[q][l]);
        }

        for(int i=0;i<3;i++){
            int p=cur[i];
            for(int k=1;k<=N;k++)
                buf[k][p]=max(buf[k][p],max_row[k]),buf[k][p]=max(buf[k][p],max_col[k]);
        }

        //

        for(int i=0;i<3;i++){
            int selx=cx[i],sely=cy[i],unsel=cz[i];
            if (cur[selx]!=cur[sely]) continue;
            int p=cur[selx],q=cur[unsel];
            for(int k=1;k<=N;k++){
                assign(k,q);
            }
        }

        for(int i=0;i<3;i++){
            int sel=cx[i],unselx=cy[i],unsely=cz[i];
            int p=cur[sel],q=cur[unselx],l=cur[unsely];
            assign(q,l);
        }

        for(int i=0;i<3;i++){
            int sel=cx[i],unselx=cy[i],unsely=cz[i];
            int p=cur[sel],q=cur[unselx],l=cur[unsely];
            assign(q,l);
        }

        for(int i=0;i<3;i++){
            int p=cur[i];
            for(int k=1;k<=N;k++)
                assign(k,p);
        }

    }

    printf("%d\n",max_val+offset-2);





    return 0;
}

Measured memory_bytes: 33120
n = int(input())
A =list(map(int, input().split()))
mod =10**9+7

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

l = lcm_list(A)
ans = 0
for i in range(n):
    ans += l//A[i]
ans %= mod
print(ans)


Measured memory_bytes: 5612
N,M = map(int,input().split())
if M != 0:
    chk = int(input())
else :
    chk = 0
ans1 = 1
count = 0
if chk == 1:
    ans2 = 0
    if M != 1:
        chk = int(input())
    count += 1
else:
    ans2 = 1
for i in range(N-1):
    if chk == i+2:
        ans1 = ans2
        ans2 = 0
        count += 1
        if count != M:
            chk = int(input())
    else:
        tempo = ans2
        ans2 = ans1 + ans2
        ans1 = tempo
print(ans2%1000000007)


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

using namespace std;

int main(void) {
  string S;
  cin >> S;

  int ans = 0;
  for (int i = 0; i < S.size(); i++) {
    ans += S[i] == '0' ? -1 : 1;
  }
  cout << S.size() - abs(ans) << endl;
}


Measured memory_bytes: 512
s = gets.chomp.split("").reverse
t = gets.chomp.split("").reverse
res = 1919810

(s.size - t.size + 1).times do |i|
    flag = true
    t.size.times do |j|
        next if s[i+j] == "?"
        if s[i+j] != t[j]
            flag = false
            break
        end
    end
    if flag then
        res = i
        break
    end
end

if res > 50
    puts "UNRESTORABLE"
else
    t.size.times do |i|
        s[res + i] = t[i]
    end
    puts s.reverse.join("").gsub(/\?/, "a")
end

Measured memory_bytes: 1788
import java.util.Scanner;


public class Main {
    private static int MOD = 1000000007;

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

        long a = sc.nextLong();
        long b = sc.nextLong();

        boolean exist = false;
        long x = b * 10;
        for (long i = x; i <= x + 9; i++) {
            long y = (i * 8) / 100;
            if (a == y) {
                System.out.println(i);
                return;
            }
        }
        System.out.println("-1");

        if (!sc.hasNext()) {
            return;
        }
    }
}


Measured memory_bytes: 25044
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = set(list(map(int,readline().split())))

dic = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

# ある本数で作れる数
candi = [[],[],[1],[7],[4],[2,3,5],[6,9],[8]]

# たとえば2と3を両方作れるときに、2を作るメリットはない。
if 2 in A and 3 in A:
  A.remove(2)
if 2 in A and 5 in A:
  A.remove(2)
if 3 in A and 5 in A:
  A.remove(3)
if 6 in A and 9 in A:
  A.remove(6)

for i in range(len(candi)):
  for j in range(len(candi[i])-1,-1,-1):
    if candi[i][j] not in A:
      del candi[i][j]

# マッチをある本数使って作れる桁数の最大値をdp
# そのときの使用文字も記録
# 最大値が同じときは、大小比較
dp = [-1] * (N + 1)
ans = [""] * (N + 1)
dp[0] = 0
def to_num(x):
  return int("".join(sorted(x, reverse = True)))
for i in range(len(candi)):
  if not candi[i]:
    continue
  num = str(candi[i][0]) # i文字使って作る文字
  # i文字使って作る
  for j in range(len(dp)):
    if dp[j] == -1:
      continue
    #print("j",j)
    if j + i > N:
      continue
    if dp[j + i] < dp[j] + 1:
      dp[j + i] = dp[j] + 1
      ans[j + i] = ans[j] + num
    elif dp[j + i] == dp[j] + 1:
      if to_num(ans[j + i]) < to_num(ans[j] + num):
        ans[j + i] = ans[j] + num
    #print(dp)
    #print(ans)

print(to_num(ans[N]))

Measured memory_bytes: 34388
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
//桁数のカウント
//pow(x,n) == x^n
//sum = accumulate(v.begin(),v.end(),0);
using Graph = vector<vector<int>>;

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


int digsum(int n) {
      int res = 0;
      while(n > 0) {
          res += n%10;
          n /= 10;
      }
      return res;
  }
#include <iomanip>


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

int x,y;
cin >> x >> y;
for(int i = 0;i < x+1;i++){
    if((2*i + 4*(x-i)) == y){
        cout << "Yes" << endl;
        return 0;
    }
}
cout << "No" << endl;

// int x,n;
// cin >> x >> n;
// vi p(n);
// rep(i,n) cin >> p[i];
// Sort(p);

// if(n == 0){
//     cout << x << endl;
//     return 0;
// }

// int j = 0,m = 100,ans,temp;
// for(int i = -100;i < 100;i++){
//     if(i+1 == p[j]){
//         j++;
//     }else{
//         temp = m;
//         m = min(m,abs((i+1)-x));
//         if(temp != m) ans = i+1;
//     }
// }
// cout << ans << endl;



//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 3648
def bubble_sort(array)
  a = array.dup
  (0...a.size).each do |i|
    (i + 1...a.size).reverse_each do |j|
      if a[j][1] < a[j - 1][1]
        a[j], a[j - 1] = a[j - 1], a[j]
      end
    end
  end
  a
end

def selection_sort(array)
  a = array.dup
  (0...a.size).each do |i|
    mini = i
    (i...a.size).each do |j|
      mini = j if a[j][1] < a[mini][1]
    end
    a[i], a[mini] = a[mini], a[i]
  end
  a
end

n = gets.to_i
s = gets.split
b = bubble_sort(s)
s = selection_sort(s)

puts b.join(' ')
puts 'Stable'
puts s.join(' ')
puts s == b ? 'Stable' : 'Not stable'

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


int main(void){
    string s;
    cin >> s;
    int ans = 1000;
    for(int i = 0;i < s.size() - 2;i++){
        int t = stoi(s.substr(i,3));
        ans = min(ans,abs(t - 753));
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
// util
let scanInt () = stdin.ReadLine() |> int
let scanInts () = stdin.ReadLine().Split() |> Array.map int
let scanIntML n = [ for i in 1..n -> scanInt () ]
let scanIntsML n = [ for i in 1..n -> scanInts () ]
let frceil a b = a/b + (if a % b = 0 then 0 else 1)
let rec powerset = function
  | [] -> [[]]
  | x::xs -> let ps = powerset xs in ps @ List.map (List.append [x]) ps

// main
let [|D;G|] = scanInts ()

let alltup =
  scanIntsML D
  |> List.mapi (fun i a -> ((i+1)*100, a.[0], a.[1])) // (point, num, bonus)
  |> List.rev // （ボーナス抜きでの）コスパで並べる

// 完全回答組が与えられたとき 中途を（必要があれば）一つ選んで総回数を返す
let trySelect ctups =
  let cnt = List.sumBy (fun (_,n,_) -> n) ctups
  let scr = List.sumBy (fun (p,n,b) -> b+p*n) ctups
  match G - scr with
    | tgt when tgt <= 0 -> Some(cnt) // 中途を選ぶ必要がない
    | tgt ->
        alltup // 候補は完全組でなく, 単独で目標を達成しうるものの 先頭
        |> List.filter (fun t -> not (List.contains t ctups))
        |> List.filter (fun (p,n,_) -> tgt <= p*(n-1))
        |> List.map (fun (p,n,_) -> cnt + (frceil tgt p))
        |> List.tryHead // コスパソート済みなので先頭でよい

alltup
|> powerset
|> List.map trySelect
|> List.choose id
|> List.min
|> printfn "%d"

Measured memory_bytes: 17244
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),g=sc.nextInt();
		for(int i=1;i<n;i++) {
			int temp = sc.nextInt();
			g=gcd(temp,g);
		}
		sc.close();
		System.out.println(g);
	}

	static int gcd(int a, int b) {
		if(a<b) {
			int temp=b;
			b=a;
			a=temp;
		}
		int r=a%b;
		while(r!=0) {
			a=b;
			b=r;
			r=a%b;
		}
		return b;
	}
}

Measured memory_bytes: 48316
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<typename T>
void print(T &arr){
    ll sz = sizeof(arr)/sizeof(arr[0]);
    for(int i = 0;i < sz-1;i++){cout << arr[i] << ' ';}
    cout << arr[sz-1] << endl;
}


int main(){
    ll n,c; cin >> n >> c;
    vector<ll> x(n), v(n), sum(n+1,0);
    rep(i,n) cin >> x[i] >> v[i];
    for(int i = 1; i <= n;++i){
        sum[i] = sum[i-1] + v[i-1];
    }
    vector<ll> sum_right_max(n), sum_left_max(n);
    ll tmp_right_max = 0, tmp_left_max = 0;
    rep(i,n){
        tmp_right_max = max(tmp_right_max, sum[i+1] - x[i]);
        sum_right_max[i] = tmp_right_max;
        tmp_left_max = max(tmp_left_max, sum[n] - sum[n-i-1] - (c-x[n-i-1]));
        sum_left_max[n-i-1] = tmp_left_max;
    }

    ll res = 0;
    //  先に右に行く，右側固定 
    rep(i,n){
        // 折り返さない
        res = max(res, sum[i+1] - x[i]);
        // 折り返す
        if(i < n-1)res = max(res, sum[i+1] - 2*x[i] + sum_left_max[i+1]);
    }
    //  先に左に行く，左側固定 
    rep(i,n){
        // 折り返さない
        res = max(res, sum[n] - sum[i] - (c-x[i]));
        // 折り返す
        if(0 < i)res = max(res, sum[n] - sum[i] - 2*(c - x[i]) + sum_right_max[i-1]);
    }
    // print("sum");
    // print(sum);
    // print("sum_right");
    // print(sum_right_max);
    // print("sum_left");
    // print(sum_left_max);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
 
int table[100][100];
 
int main(void){
    int sum2,sum,i,j,r,c;
 
    scanf("%d %d",&r,&c);
 
    for(i = 0;i < r;i++){
        for(j = 0;j < c;j++){
            scanf("%d",&table[i][j]);
        }
    }
 
    sum2 = 0;
    for(i = 0;i < r;i++){
        sum = 0;
        for(j = 0;j < c;j++){
            sum += table[i][j];
            printf("%d ",table[i][j]);
        }
        sum2 += sum;
        printf("%d\n",sum);
    }
 
    for(i = 0;i < c;i++){
        sum = 0;
        for(j = 0;j < r;j++)
            sum += table[j][i];
        printf("%d ",sum);
    }
    printf("%d\n",sum2);
    return 0;
}


Measured memory_bytes: 2144
N=int(input())

def yomikata(N):
    N_firstdigit=N%10
    if N_firstdigit==3:
        print("bon")
    #elif N_firstdigit==0 or 1 or 6 or 8: このように条件は省略して書いてはだめらしい!
    elif N_firstdigit==0 or N_firstdigit==1 or N_firstdigit==6 or N_firstdigit==8:
        print("pon")
    else:
        print("hon")
        
yomikata(N)


Measured memory_bytes: 9028
#include <cstdio>
#include <cctype>
using namespace std;
const int N = 1e3+5;
char s[N], f[1<<8];
int main()
{
    scanf("%s", s);
    for(int i = 0; s[i]; ++i) f[s[i]] = 1;
    if(f['E']&&f['W']&&f['S']&&f['N']) puts("Yes");
    else if(f['E']&&f['W']&&!f['S']&&!f['N']) puts("Yes");
    else if(!f['E']&&!f['W']&&f['S']&&f['N']) puts("Yes");
    else puts("No");
    return 0;
}

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

using namespace std;

typedef long long ll;

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

	int n, k, c;
	cin >> n >> k >> c;

	string s;
	cin >> s;

	vector<int> vl(n, -1);
	int bef = -404040;
	int cnt = 0;
	rep(i, n){
		if(cnt >= k) break;
		if(s[i] == 'o' && i > bef + c){
			cnt++;
			vl[i] = cnt;
			bef = i;
		}
	}

	vector<int> vr(n, -1);
	bef = 404040;
	cnt = k+1;
	for(int i = n - 1; i >= 0; i--){
		if(cnt <= 1) break;
		if(s[i] == 'o' && i < bef - c){
			cnt--;
			vr[i] = cnt;
			bef = i;
		}
	}

	rep(i, n){
		if(vl[i] == vr[i] && vl[i] != -1){
			cout << (i + 1) << "\n";
		}
	}

}


Measured memory_bytes: 3348
while True:
  f,m,r =map(int, input().split())
  
  if f == m== r== -1:
    break
   
  if m==-1 or f ==-1:
    print('F')
  elif m+f >= 80:
    print('A')
  elif 65<= m+f < 80:
    print('B')
  elif 50<= m+f < 65:
    print('C')
  elif m+f < 30:
    print('F')
  elif 30<= m+f < 50:
   
    if r >=50:
      print('C')
    else:
      print('D')
  else:
    print('F')


Measured memory_bytes: 5596
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>
#include <list>
#include <math.h>
#include<string.h>
#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)


//	rep(i,10)cout << i << endl;
using namespace std;

int main(void){
	int n,m,k[11],s[11][11],p[11];
	int bit[11];
	cin >> n >> m;
	rep(i,m){
		cin >> k[i];
		bit[i] = 0;
		rep(j,k[i]){
			cin >> s[i][j];
			bit[i] += 1 << (s[i][j]-1);
		}
		//cout << "bit " << bit[i] << endl;
	}
	int ans = 0;
	rep(i,m) cin >> p[i];
	rep(i,1<<n){
		int cnt = 0;
		rep(j,m){
			int temp_bit = bit[j] & i;
			int bit_count = 0;
			//cout << temp_bit << endl;
			while(temp_bit) {
				bit_count += temp_bit%2;
				temp_bit /= 2;
			}
			if(bit_count%2 == p[j]) cnt++;
			//cout <<bit_count<< "temp " << temp_bit << " " << i << " " << bit[j] << endl;
		}
		if(cnt == m) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

/*
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/



//************** StrAnge.R *********************

#define ll              long long int
#define ull             unsigned long long
#define ld              long double
#define lll             __int128
#define vi              vector<int>
#define vl              vector<ll>
#define vvi             vector<vector<int> >
#define pii             pair<int,int>
#define piii            pair<int,pair<int,int> >
#define pll             pair<ll,ll>
#define vii             vector<pii>

#define sz(v)           ((int)(v).size())
#define all(s)          s.begin(),s.end()
#define allr(s)         s.rbegin(),s.rend()
#define unq(c)          (sort(all(c)), c.resize(distance(c.begin(),unique(all(c)))))
#define get_pos(c,x)    (lower_bound(all(c),x)-c.begin())

#define MS0(v)          memset((v), 0, sizeof((v)))
#define MS1(v)          memset((v), -1, sizeof((v)))
#define LEN(v)          strlen(v)

#define MP              make_pair
#define pb              push_back
#define pob             pop_back
#define ff              first
#define ss              second
#define sc              scanf
#define pf              printf
#define endl            "\n"

#define TEST_CASE       int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define PRINT_CASE      printf("Case %d: ",cs)

#define vpf(v)          for(int i=0;i<v.size();i++){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<"\n";}
#define vsc(v)          for(int i=0;i<v.size();i++)cin>>v[i];

#define REP(i, n)       for (int i = 0; i < (n); i++)
#define REPP(i, a, b)   for (int i = (a); i < (b); i++)
#define FOR(i, a, b)    for (int i = (a); i <= (b); i++)
#define FORS(i, s)      for (int i = 0; s[i]; i++)

#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileio          freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)

#define intlim          2147483648
#define infinity        (1LL<<50)
#define intmx           INT_MAX
#define PI              3.14159265358979323846264338327950L // acos(-1.0)

#define gcd(a, b)       __gcd(a, b)
#define lcm(a, b)       ((a)*((b)/gcd(a,b)))


int on_bit(int N,int pos){return N = N | (1<<pos);}
int off_bit(int N,int pos){return N = N & ~(1<<pos);}
bool check_bit(ll N,int pos){return (bool)(N & (1<<pos));}


#define start_clock     clock_t tStart = clock()
#define end_clock       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC)

template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}


//******************* my code starts here **********************************


int main(){
    
    int n;
    cin >> n;
    vi v(n+10);

    for(int i = 2; i <= n; i++) {
        int x; cin >> x;

        v[x]++;
    }

    for(int i = 1; i <= n; i++) cout << v[i] << "\n";
    

    return 0;
}


Measured memory_bytes: 4048
import sys
def input():
    return sys.stdin.readline()[:-1]
N,M=map(int, input().split())
l=[0]*N
w=[0]*N
for i in range(M):
    p,S=input().split()
    p=int(p)
    if S=="AC":
        l[p-1]=1
    else:
        if not l[p-1]:
            w[p-1]+=1
W=0
for i in range(N):
    W+=l[i]*w[i]
print(sum(l),W)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,x,i;
cin>>n>>x;
int arr[n];
for(i=0; i<n; i++)
cin>>arr[i];
int count=1; int sum=0;
for(i=0; i<n; i++)
{
  sum+=arr[i];
  if(sum<=x)
  count++;
}
cout<<count;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> av(a), bv(b);
    int ans = 1e+8;
    int am = 1e+8, bm = 1e+8;
    for(auto &z: av) {
        cin >> z;
        am = min(am, z);
    }
    for(auto &z: bv){
        cin >> z;
        bm = min(bm, z);
    } 
    ans = am + bm;
    int x,y,c;
    for(int i=0;i<m;i++){
        cin >> x >> y >> c;
        ans = min(ans, av[--x] + bv[--y] - c);
    }
    cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  if(S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I'){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    int a[200100];
    int dp[200100];
    cin >> n >> k;

    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(int i=0;i<=k;i++)
    {
        dp[i]=0;
    }
    for(int i =0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0 && dp[i-a[j]]==0)
            {
                dp[i]=1;
            }
        }
    }
    if(dp[k]==1)
    cout << "First\n";
    else
    cout << "Second\n";

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
      	int ab = a*b;
      	if(ab%2 ==0){
      		System.out.println("Even");
    	}else{
        System.out.println("Odd");
		}
    }
}


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

constexpr int mod = 998244353;
long long D[3010][6010];


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, S; cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    D[0][0] = 1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= S; j++) {
            D[i][j] %= mod;
            D[i+1][j+A[i]] += D[i][j];
            D[i+1][j] += D[i][j] * 2;
        }
    }
    cout << D[N][S] % mod << "\n";
    return 0;
}

Measured memory_bytes: 97696
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,ma,count = 1;
  int h[105];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  ma = h[0];
  for(int i=1; i<n; i++){
    if(ma <= h[i]) count++;
    ma = max(ma,h[i]);
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static Scanner scanner;

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

        long n = nextLong();
        long d = nextLong();
        long dd = d*d;
        int c = 0;
        long a,b;
        for (int i = 0; i < n; i++) {
            a = nextLong();
            b = nextLong();
            if (dd >= a*a + b * b) {
                c++;
            }
        }
        out.println(c);
        out.flush();
    }

    public static int pow2(int i) {
        return i*i;
    }

    public static void println(Object o) {
        System.out.println(o);
    }

    public static void print(Object o) {
        System.out.print(o);
    }

    public static void printf(String format, Object... o) {
        System.out.printf(format, o);
    }

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

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

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

    public static short nextShort() {
        return Short.parseShort(scanner.next());
    }

    public static float nextFloat() {
        return Float.parseFloat(scanner.next());
    }

    public static void printYes() {
        System.out.println("Yes");
    }

    public static void printYES() {
        System.out.println("YES");
    }

    public static void printNo() {
        System.out.println("No");
    }

    public static void printNO() {
        System.out.println("NO");
    }

    public static void nextLine() {
        scanner.nextLine();
    }

    public static double distance(double x, double y, double x2, double y2) {
        return Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
    }

    public static int MOD = 1_000_000_007;
    public static int MAX = 100000;
    public static long[] fac = new long[MAX];
    public static long[] finv = new long[MAX];
    public static long[] inv = new long[MAX];

    public static void combinit() {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    public static long combination(int n, int k) {
        if (n < k || n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }

    public static long factorial(long n) {
        return n <= 0 ? 1 : n * factorial(n - 1);
    }
}

Measured memory_bytes: 52744
#include <iostream>
using namespace std;
int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;
    int a1 = a + b;
    int b1 = a + c;
    int c1 = c + b;
    if (a1 >= b1 && b1 >= c1 || b1 >= a1 && a1 >= c1)
    {
        cout << c1 << endl;
    }
    else if (b1 >= c1 && c1 >= a1 || c1 >= b1 && b1 >= a1)
    {
        cout << a1 << endl;
    }
    else
    {
        cout << b1 << endl;
    }
}

Measured memory_bytes: 504
//***********************
//Author:kibi11
//Quarantine Days
//***********************

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define fr(i, n) for(int i = 0; i < n; i++)
#define fr1(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,k) for(int i=a;i>=k;i--)
#define same int t;cin>>t;while(t--)
#define check(x) cout << (#x) << " is " << (x) << endl;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define f first
#define s second
#define XOX
#define pi = 3.14159265358979323846

//////////////////////////////////////////////////////////////////////////
/////////////////DEBUGING ZONE//////////////////////////////

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
///////////////////////////////////////////////////////////////////////////
 
ll powermod(ll base, ll exp, ll mod) {
	ll result = 1;
	while (exp != 0) {
		if ((exp % 2) == 1) {
			result = (result * base) % mod;
		}
		base = (base * base) % mod;
		exp /= 2;
	}
	return result;
}

///////////////////////////////////////////////////////////////////////////
//Fuctions if any:





///////////////////////////////////////////////////////////////////////////
int main() 
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = clock();
//ios_base& scientific (ios_base& str);

double n,d;
cin>>n>>d;
int count=0;
fr(i,n)
{
	double a,b;
	cin>>a>>b;
	double ans= sqrt((a*a)+(b*b));
	if(ans<=d)
	{
		count++;
	}
}
cout<<count<<endl;
cerr << "TIME = " << (double) 1.0 * (clock() - tt) / CLOCKS_PER_SEC << " seconds" << endl;
return 0;
}

Measured memory_bytes: 3832
using System;

	public class Class1
	{
		public static void Main()
		{   int h=0;
			int w=0;
			
			while(true)
			{
				string dataSet=Console.ReadLine();
				string[] data=dataSet.Split();
				 h=int.Parse(data[0]);
				 w=int.Parse(data[1]);
				
				 if(h==0&&w==0)
				 {
				 	break;
				 }
				for( int i=0;i<h;i++)
				{   
					
					for(int j=0;j<w;j++)
					{
						if((i+j)%2==0)
						{
							Console.Write("#");						
							
						}
						else
						{
							Console.Write(".");
						}
						
					}
					
					Console.Write("\r\n");
						
				}
				Console.Write("\r\n");
				
			}
				
		}
	}

Measured memory_bytes: 8784
#include<stdio.h>
#define N 10000
#define Q 500
int main()
{
  int i, j, n, q, s[N], t[Q], c=0;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&s[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&t[i]);
  }

  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(t[i] == s[j]){c++; break;}
    }
  }
  
 

  printf("%d\n",c);

  return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >>C;
  if((A < C && C<B) || (B<C && C<A)){
    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
a=[int(input()) for _ in range(n)]
a.sort()
h=a[0]
ans=1
for i in a[1:]:
    if i!=h:
        ans+=1
        h=i
    else:
        ans-=1
        h=pow(10,10)    
print(ans) 

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

#define N 10

char ok[N];

int good(int n) {
	return n == 0 ? 1 : good(n / 10) && ok[n % 10];
}

int main() {
	int n, k, x;

	scanf("%d%d", &n, &k);
	memset(ok, 1, sizeof ok);
	while (k--) {
		int d;

		scanf("%d", &d);
		ok[d] = 0;
	}
	for (x = n; !good(x); x++)
		;
	printf("%d\n", x);
	return 0;
}


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

int main() {
	int n; cin >> n;
	map<string, int>s;
	int maxi = 0;
	for (int i = 0; i < n; i++) {
		string ss; cin >> ss;
		s[ss]++;
		if (maxi < s[ss])maxi = s[ss];
	}
	for (auto&& x : s) {
		if (x.second == maxi)cout << x.first << endl;
	}
	return 0;
}

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

int main() {
    long n, a, b, ans;
    cin >> n >> a >> b;
    ans = a * (n / (a + b));
    ans += min(n - (n / (a + b)) * (a + b), a);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);

signed main(){
    long long n;
    cin>>n;
    long long res=2*(n/11);
    if(n%11==0)cout<<res<<endl;
    else if(n%11>6)cout<<res+2<<endl;
    else cout<<res+1<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[200010],b[200010];
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(b,0,sizeof(b));
		for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
		if(m>=n)
		{
			printf("0\n");
			continue;
		}
		sort(a,a+n);
		int h=0;
		int s=1;
		for(int i=1;i<n;i++)
		{
			if(a[i]==a[i-1])
			s++;
			else
			b[h++]=s,s=1;
		}
		b[h++]=s;
		sort(b,b+h);
		int sum=0;
		for(int i=0;i<h-m;i++)
		sum+=b[i];
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int P[100001];
long long A[100001], B[100001], C[100001];
int D[100001];

int main() {
	int N,M;
	long long R=0;

	cin>>N>>M;
	for(int i=1; i<M+1; i++)cin>>P[i];
	for(int i=1; i<N; i++)cin>>A[i]>>B[i]>>C[i];

	for(int i=1; i<M; i++){
		if(P[i]<P[i+1]){
			for(int j=P[i]; j<P[i+1]; j++)D[ j ] += 1;
		}else{
			for(int j=P[i+1]; j<P[i]; j++)D[ j ] += 1;
		}
	}

	for(int j=1; j<N; j++) R += min(D[ j ]*B[ j ]+C[ j ],  D[ j ]*A[ j ]);
	cout<<R<<endl;
	return 0;
}



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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}


signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;

    vector<int> ans;
    while(n != 0){
        vector<int> train_time(86400, 0);
        for(int i=0; i<n; i++){
            int h, m, s;
            char a, b;
            cin >> h >> a >> m >> b >> s;
            int t = h * 3600 + m * 60 + s;
            train_time[t]++;

            cin >> h >> a >> m >> b >> s;
            t = h * 3600 + m * 60 + s;
            train_time[t]--;
        }

        for(int i=0; i<86400-1; i++){
            train_time[i+1] += train_time[i];
        }
        sort(train_time.begin(), train_time.end());
        reverse(train_time.begin(), train_time.end());
        ans.push_back(train_time[0]);

        cin >> n;
    }

    for(int i=0; i<ans.size(); i++){
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3840
#coding:utf-8
#1_9_C 2015.4.10
n = int(input())
taro = 0
hanako = 0

for i in range(n):
    cards = input().split()
    if cards[0] < cards[1]:
        hanako += 3
    elif cards[0] > cards[1]:
        taro += 3
    else:
        hanako += 1
        taro += 1
print(taro,hanako)

Measured memory_bytes: 6724
import math as m

n,k = map(int,input().split())
a = list(map(int,input().split()))
prev = 1
for i in range(k):
  prev += m.log(a[i])
for i in range(k,n):
  cur = prev + m.log(a[i])
  cur -= m.log(a[i-k])
  print("Yes" if cur > prev else "No")
  prev = cur

Measured memory_bytes: 32952
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

def divs(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)
    divisors.sort()
    return divisors

n = INT()

divs = divs(n)

res = divs[len(divs)//2 -1] + divs[len(divs)//2] -2

print(res)


Measured memory_bytes: 38640
// Problem : 
// 			C - Skill Up
// 			Editorial
// 		
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,m,x;
	cin>>n>>m>>x;
	int a[12][13];
	loop(i,n)
		loop(j,m+1)
		cin>>a[i][j];
		int sol=INT_MAX;
		//cout<<m*x<<nl;
		for(int j=0;j<1<<n;j++)
		{
			int ans=0;
			vi val(m,0);
			int sum=0;
			loop(k,n)
			{
				bool flag =true;
				l00p(l,1,m+1)
				{
					if((j>>k)&1)
					{
						ans+=a[k][l];
						if(flag)
						sum+=a[k][0];
						flag =false;
						val[l-1]+=a[k][l];
					}
				}
			}
			bool flag=true;
			trav(i,val)
			{
				if(i<x)
				flag=0;
			}
			if(flag)
			{
				sol=min(sum,sol);
				//cout<<sol<<nl;
			}
		}
		if(sol==INT_MAX)
		cout<<-1;
		else 
		cout<<sol;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3648
import math, string, fractions, heapq, re, array, bisect, sys, random, time, copy
import itertools as it
import collections as cl
import functools as ft

def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x) - 1, input().split()))
def LF(): return list(map(float, input().split()))
def LS(): return input().split()
def I(): return int(input())
def F(): return float(input())
def S(): return input()

a, b = LI()
print((a-1)*(b-1))

Measured memory_bytes: 7824
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
ll N,M;
const ll MOD=998244353,MAX_M=5e5,MAX_N=1e6;
ll fact[3*MAX_M+MAX_N],ifact[3*MAX_M+MAX_N];
void sub(ll &a,ll b){
	a+=MOD-b;
	if(a>=MOD)a-=MOD;
}
ll comb(ll n,ll m){
	if(n<0 || m<0 || n<m)return 0;
	return fact[n]*ifact[m]%MOD*ifact[n-m]%MOD;
}
ll zyuhuku(ll n,ll m){
	return comb(n+m-1,n);
}
ll mpw(ll n,ll m){
	ll r=1;
	while(m){
		if(m&1){
			r*=n;
			r%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return r;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>M;
	fact[0]=1;
	REP(i,3*M+N-1){
		fact[i+1]=fact[i]*(i+1)%MOD;
	}
	ifact[3*M+N-1]=minv(fact[3*M+N-1]);
	for(ll i=3*M+N-2;i>=0;i--){
		ifact[i]=ifact[i+1]*(i+1)%MOD;
	}
	ll ans=0;
	ans=zyuhuku(3*M,N);
	FOR(i,2*M+1,3*M+1){
		sub(ans,N*zyuhuku(3*M-i,N-1)%MOD);
	}
	REP(i,M){
		sub(ans,zyuhuku(i,N)*comb(N,3*M-2*i)%MOD);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 39296
#include <stdio.h>

int main ()
{
	int x, y, w, h, r;
	scanf("%d %d %d %d %d",&w, &h, &x, &y, &r);
	
	if( (x+r<=w && x-r>=0) && (y+r<=h && y-r>=0))
	{
		printf("Yes\n");
	} 
	else
	{
		printf("No\n");
	}
	return 0; 
} 


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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N,i,flag=0;
  cin>>N;
  for(i=1;i<=9;i++){
    if(N%i==0 && (N/i)<=9){
      flag=1;
    }
  }
  if(flag==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))
sum = 0

for num in range(1,n):
  if lis[num] < lis[num - 1]:
    sum += lis[num - 1] - lis[num]
    lis[num] = lis[num - 1]
    
print(sum)

Measured memory_bytes: 32184
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;

///---program start---///

#define arr (int)(1e5+10)

map<vi,bool> win;

bool get_win(vi a)
{
    if (a.empty()){
        return 1;
    }
    if (win.count(a)){
        return win[a];
    }
    bool res=0;
    vi b;

    b=a;
    b.pop_back();
    res|=(!get_win(b));

    b=a;
    reverse(all(b));
    while (!b.empty()&&b.back()==1){
        b.pop_back();
    }
    reverse(all(b));
    for (auto& i:b){
        i--;
    }
    res|=(!get_win(b));
    win[a]=res;

    return res;
}

string solve(int a)
{
    if (a==1){
        return "First";
    }
    else{
        return "Second";
    }
}

bitset<arr> reversed(bitset<arr> a)
{
    bitset<arr> res;
    for (int i=0;i<arr;i++){
        res[i]=a[arr-i-1];
    }
    return res;
}

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    bool debug=0;
    int n;
    vi a;

    if (debug){
        srand(time(0));
        n=5;
        a.resize(n);
        for (auto& i:a){
            i=rand()%5+1;
        }
    }
    else{
        cin>>n;
        a.resize(n);
        for (auto& i:a){
            cin>>i;
        }
    }
//    cout<<n<<"\n";
//    for (auto i:a){
//        cout<<i<<" ";
//    }
//    cout<<"\n";

    sort(all(a));
//    cout<<"naive :: "<<solve(get_win(a))<<"\n";

    bitset<arr> wins;
    bitset<arr> buf;
    bitset<arr> all_gamebale;
    for (auto& i:a){
        if (i>=arr){
            i=(arr-2)+((arr-2)%2!=i%2);
        }
    }
    for (int i=a[0];i>=0;i-=2){
        wins[i]=1;
    }
    for (int i=0;i<=a[0];i++){
        all_gamebale[i]=1;
    }
    for (int i=1;i<n;i++){
//        cout<<"before i :: "<<reversed(wins)<<"\n";
        buf=wins;
        wins=wins^all_gamebale;
        for (int j=a[i-1]+(a[i-1]%2!=a[i]%2);j<=a[i];j+=2){
            wins[j]=1;
        }
        for (int j=a[i-1];j<arr&&j<=a[i];j++){
            all_gamebale[j]=1;
        }
        wins=wins|((buf&(wins>>1))>>1);
//        cout<<" after i :: "<<reversed(wins)<<"\n";
    }


    cout<<solve(wins[0])<<"\n";
}


Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <assert.h>

using namespace std;

const int nax = 1e5 + 5;
vector<int> edges[nax];
int inDegree[nax];
int dist[nax];
bool visited[nax];

void DFS(int a)
{
	assert(!visited[a]);

	visited[a] = true;
 	for (int b : edges[a])
 	{
 		dist[b] = max(dist[b], dist[a] + 1);
 		inDegree[b]--;

 		if (inDegree[b] == 0)
 		{
 			DFS(b);
 		}
 	}
}

int main()
{
	int n, m;
	cin >> n >> m;

	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;

		edges[u].push_back(v);
		inDegree[v]++;
	}

	for (int i = 1; i <= n; i++)
	{
		if (!visited[i] && inDegree[i] == 0)
		{
			DFS(i);
		}
	}
	int answer = 0;
	for (int i =1 ; i <= n; i++)
	{
		answer = max(answer, dist[i]);
	}
	cout << answer << endl;

}

Measured memory_bytes: 9728
#pragma GCC optimize ("O2")
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG 1
#define dd if (DEBUG)

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, A) for (auto & a : A)
#define all(a) (a).begin (), (a).end ()
#define rall(a) (a).rbegin (), (a).rend ()
#define sz(a) (int) (a).size ()
#define szl(a) (int) (a).length ()
#define FASTIO cin.sync_with_stdio (0); cin.tie (0); cin.exceptions (cin.failbit);

typedef long long ll;
typedef pair <int, int> pii;
#define f first
#define s second
#define mp(a, b) make_pair((a), (b))
typedef vector <int> vi;
#define pb(a) push_back ((a))

const ll MOD = 1e+9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INFi = 0x3f3f3f3f;
const ll MAXN = 1e+6+7;

int main ()
{
    FASTIO;
    ll i, j, n, k;
    cin >> n >> k;
    vi h (n), dp (n);
    trav (a, h)
        cin >> a;
    for (i = 1; i < n; i++)
    {
        for (j = 1, dp[i] = INFi; j <= k && i - j >= 0; j++)
        {
            dp[i] = min (dp[i], dp[i - j] + abs (h[i] - h[i - j]));
        }
    }
    cout << dp[n - 1] << "\n";

    return 0;
}



Measured memory_bytes: 1024