akhauriyash/Code-Regression huggingface dataset:
D,G = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(D)]
full_score = [0]*D

for i in range(D):
    p,c = pc[i]
    full_score[i] = 100 * (i+1) * p + c

ans = 10**10
from itertools import product
for case in product([0, 1], repeat=D):
    count, score = 0, 0
    for i in range(D):
        p, c = pc[i]
        count += p * case[i]
        score += full_score[i] * case[i]
    if 0 in case:
        i = D - 1 - case[::-1].index(0)
        p, c = pc[i]
        for j in range(p):
            if score >= G:
                break
            score += 100 * (i+1)
            count += 1
    if score >= G:
        ans = min(ans, count)

print(ans)



Measured memory_bytes: 3064
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[int(input())-1])


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int m, f, r;
int main() {
	while(1) {
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		else if(m == -1 || f == -1) cout << "F" << endl;
		else if(m + f >= 80) cout << "A" << endl;
		else if(m + f >= 65) cout << "B" << endl;
		else if(m + f >= 50) cout << "C" << endl;
		else if(m + f >= 30) {
			if(r >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();

            var N_IDCards = cin.nextInt();
            var M_Gates = cin.nextInt();

            int[] L = new int[M_Gates];
            int[] R = new int[M_Gates];
            for (int i = 0; i<M_Gates; i++)
            {
                L[i] = cin.nextInt();
                R[i] = cin.nextInt();
            }

            int oldL = L[0];
            int oldR = R[0];
            for(int i = 1; i < M_Gates; i++)
            {
                var a = oldL;
                var b = oldR;
                var c = L[i];
                var d = R[i];

                if(a < c && b < d)
                {
                    oldL = c;
                    oldR = b;
                }
                else if(a >= c && b >= d)
                {
                    oldL = a;
                    oldR = d;
                }
                else if (a >= c && b < d)
                {
                    oldL = a;
                    oldR = b;
                }
                else if( a < c && b >= d)
                {
                    oldL = c;
                    oldR = d;
                }
            }

            var ans = Math.Max(0, oldR - oldL + 1);
            Console.WriteLine(ans);
        }
    }
    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
}


Measured memory_bytes: 15824
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

void Main()
{
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<int> bs(n);
    for (int i = 0; i < n; i++)
    {
        bs[i] = 1 << (s[i]-'a');
    }
    for (int i = 0; i < q; i++)
    {
        int o;
        cin >> o;
        if(o == 1){
            int p;
            char c;
            cin >> p >> c;
            p--;
            bs[p] = 1 << (c-'a');    
        }else{
            int l, r;
            cin >> l >> r;
            l--; r--;
            int ck = 0;
            for (int j = l; j <= r; j++)
            {
                ck |= bs[j];
            }
            int ct = 0;
            for (int j = 0; j < 27; j++)
            {
                ct += (ck >> j) & 1;
            }
            cout << ct << endl;
        }
    }
}

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


Measured memory_bytes: 5832
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::collections::{HashMap, BinaryHeap, BTreeMap};

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// 十分に理解した、可愛いお手製のライブラリ達
macro_rules! p {
    ($t:expr) => {
        println!("{}", $t);
    };
}
macro_rules! debug {
    ($t:expr) => {
        println!("{:?}", $t);
    };
}
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    gcd(b, a % b)
}
fn lcm(a:usize, b:usize) -> usize {
    a / gcd(a, b) * b
}

// エントリーポイント
fn main() {
    input! {
        N:usize,
        M:usize,
        AB:[(usize, usize);N]
    }
    let items = {
        let mut items = BTreeMap::new();
        for ab in AB {
            let (a, b) = ab;
            if !items.contains_key(&a) {
                items.insert(a, b);
            } else {
                *items.get_mut(&a).unwrap() += b;
            }
        }
        items
    };
    let (mut m, mut cost) = (M, 0usize);
    for (price, count) in items {
        if m < count {
            cost += price * m;
            break;
        }
        cost += price * count;
        m -= count;
    }
    p!(cost);
}


Measured memory_bytes: 8444
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
#define MOD_CONST 1000000007
typedef long long int lli;

// int get_abs(int x);

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

    vector<vector<int>> num_bright;
    for(int i = 0; i < h; ++i){
        vector<int> bright_vec(w);
        int start = -1, finish = -1;
        
        for(int j = 0; j < w; ++j){
            if(start < 0 && s_vec[i][j] == '.'){
                start = j;
            }

            if(start >= 0 && (j + 1 == w || s_vec[i][j + 1] == '#')){
                finish = j;
                for(int k = start; k <= finish; ++k){
                    bright_vec[k] = finish - start + 1;
                }
                start = -1;
            }
        }

        num_bright.push_back(bright_vec);
    }

    // for(int i = 0; i < h; ++i){
    //     cout << "num_bright[" << i << "] : [";
    //     for(int j = 0; j < w; ++j){
    //         cout << " " << num_bright[i][j];
    //     }
    //     cout << " ]\n";
    // }

    int ans = 0;
    for(int i = 0; i < w; ++i){
        int start = -1, finish = -1;
        for(int j = 0; j < h; ++j){
            // cout << "(i, j) = (" << i << ", " << j << ")\n";
            // cout << "(start, finish) = (" << start << ", " << finish << ")\n";
            if(num_bright[j][i] > 0){
                // cout << "(i, j) = (" << i << ", " << j << ")\n";
                if(start < 0 && s_vec[j][i] == '.'){
                    start = j;
                    // cout << "(start, finish) = (" << start << ", " << finish << ")\n";
                }

                if(start >= 0 && (j + 1 == h || s_vec[j + 1][i] == '#')){
                    finish = j;
                    // cout << "(start, finish) = (" << start << ", " << finish << ")\n";

                    for(int k = start; k <= finish; ++k){
                        ans = max(ans, num_bright[k][i] + finish - start);
                    }
                    start = -1;
                    // cout << "(start, finish) = (" << start << ", " << finish << ")\n";
                }
            }
        }
    }

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

// int get_abs(int x){
//     return (x > 0)? x : -x;
// }

Measured memory_bytes: 22016
#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);
    }
}


// "A C G T" := "1 2 3 4";
ll memo[110][9999] = {};
int n;

bool ok(int x){
    assert(1000 <= x && x <= 9999);
    vector<int> t(4);
    rep(i,4){
        t[0] = x/1000; t[1] = (x - t[0] *1000)/100;
        t[2] = (x - (x/100)*100)/10; t[3] = x - (x/10)*10;
        if(i){
            int temp;
            temp = t[i-1]; t[i-1] = t[i]; t[i] = temp;
        }
        rep(j,2){
            if(t[j] == 1 && t[j+1] == 3 && t[j+2] == 2) return false;
        }
        // print(t);
    }
    return true;
}

ll dfs(int cur, int last3){
    assert(100 <= last3 && last3 <= 999);
    if(memo[cur][last3]) return memo[cur][last3];
    if(cur == n) return 1;
    ll ret = 0;
    for(int i = 1; i <= 4; i++){
        int last4 = last3 * 10 + i;
        if(ok(last4)){
            int next3 = last4 - (last4/1000)*1000;
            ret = (ret + dfs(cur + 1, next3)) % MOD;
        }
    }
    memo[cur][last3] = ret;
    return ret;
}


int main(){
    cin >> n;
    cout << dfs(0,444) << endl;
    return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int h, w, n, x, y;
string s, t;

void no () {
	cout << "NO" << endl;
	exit(0);
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> h >> w >> n >> x >> y >> s >> t;
	x--, y--;

	for (int i = 0, z = y; i < n; i++) {
		if (s[i] == 'L') z--;
		if (z < 0) no();
		if (t[i] == 'R' && z + 1 < w) z++;
	}

	for (int i = 0, z = y; i < n; i++) {
		if (s[i] == 'R') z++;
		if (z == w) no();
		if (t[i] == 'L' && z - 1 >= 0) z--;
	}

	for (int i = 0, z = x; i < n; i++) {
		if (s[i] == 'U') z--;
		if (z < 0) no();
		if (t[i] == 'D' && z + 1 < h) z++;
	}

	for (int i = 0, z = x; i < n; i++) {
		if (s[i] == 'D') z++;
		if (z == h) no();
		if (t[i] == 'U' && z - 1 >= 0) z--; 
	}

	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 920
#include<stdio.h>

int main()
{
    long long int a,b,k;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(k>a){

        b=b-(k-a);
        a=0;
        if(b<0){
            b=0;
        }

    }
    else if(k<a){
        a=a-k;
        b=b;

    }
    else if(k==a){
        a=0;
        b=b;

    }

    printf("%lld %lld",a,b);
}




Measured memory_bytes: 1708
# -*- coding: utf-8 -*-
import sys

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

if N >= M:
    print(0)
    sys.exit()
    
X.sort()
L = [0] * (M - 1)
for i in range(M-1):
    L[i] = X[i+1] - X[i]

L.sort()

ans = sum(L[:M-N])
print(ans)

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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

/*-----------------END TEMPLATE-----------------*/

int main() {
  FASTIO;
  ll n;
  cin >> n;
  vi a(n);
  rep(i, 0, n) { cin >> a[i]; }

  vi ans(n);
  ans[n - 1] = 0;
  ll ansx = 0;
  for (int i = n - 2; i >= 0; i--) {
    if (a[i] < a[i + 1])
      ans[i] = 0;
    else
      ans[i] += ans[i + 1] + 1;
    debug(ans[i]);
    ansx = max(ansx, ans[i]);
  }
  cout << ansx << endl;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main()
{
  int a,b,c;
  int n = 0;

 
  while(scanf("%d%d",&a,&b) != EOF){
    c = a + b;
    
    for(n = 0 ; c > 0 ; ++n ) 
      {
        c /= 10;
   }
   
     printf("%d\n",n);

  }
  
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  vector<int> p = {A,B,C};
  sort(p.begin(),p.end());
  cout << p[2] *10 + p[1] + p[0] <<endl;
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    int h, w;
    cin >> h >> w;
    vs s(h);
    rep(i, h) cin >> s[i];
    vector<vi> dp(h+1, vi(w+1, INF));
    dp[0] = vi(w+1);
    rep1(j, h) dp[j][0] = 0;
    rep(i, h) rep(j, w) {
        if (i==0 && j==0) {
            dp[i+1][j+1] = (s[i][j]=='.'?0:1);
            continue;
        }
        if (i-1>=0) {
            if (s[i][j]==s[i-1][j]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]);
            else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]+1);
        }
        if (j-1>=0) {
            if (s[i][j]==s[i][j-1]) dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]);
            else dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]+1);
        }
    }
    int ans = dp[h][w] + (s[h-1][w-1]=='.'?0:1);
    ans /= 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
       int x,y=360;
       cin>>x;
       int a=x,b=y;
       while(a!=0){
          b%=a;
          swap(a,b);
       }
       cout<<360/b<<endl;
      


     }


 


 






    





      

        


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

int main() {
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 3) {
        rep(j, 3) {
            cin >> a.at(i).at(j);
        }
    }
    int n; cin >> n;
    vector<int> b(n);
    rep(i, n) {
        cin >> b.at(i);
    }
    vector<vector<bool>> chk(3, vector<bool>(3));
    rep(i, n) {
        rep(j, 3) {
            rep(k, 3) {
                if (b.at(i) == a.at(j).at(k))
                    chk.at(j).at(k) = true;
            }
        }
    }
#if 0
cout << "----" << endl;
        rep(j, 3) {
            rep(k, 3) {
                cout << chk.at(j).at(k);
            }
            cout << endl;
        }
cout << "----" << endl;
#endif
    //int i, j;
    bool ans;
    rep(i, 3) {
       ans = true;
       rep(j, 3) {
            if (chk.at(i).at(j) != true) {
                ans = false;
                break;
            }
        }
        if (ans == true) {
            puts("Yes");
            return 0;
        }
    }

    ans == true;
    rep(i, 3) {
        ans = true;
        rep(j, 3) {
            if (chk.at(j).at(i) != true) {
                ans = false;
                break;
            }
        }
        if (ans == true) {
            puts("Yes");
            return 0;
        }
    }

    ans = true;
    rep(i, 3) {
        //cout << chk.at(i).at(i) << endl;
        if (chk.at(i).at(i) != true){
            ans = false;
            break;
        }
    }
    if (ans == true) {
        //cout << 3 << endl;
        puts("Yes");
        return 0;
    }
    ans = true;
    rep(i, 3) {
        if (chk.at(i).at(2-i) != true){
            ans = false;
            break;
        }
    }
    if (ans == true) {
        puts("Yes");
        return 0;
    }

    puts("No");
}

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

using namespace std;

int main(){
  int n, sum=0;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n; i++){
    sum = sum + a[i];
  }
  double avg = (double)sum / (double)n;
  double sa = abs(avg - a[n-1]);
  // printf("sa=%f\n",sa);
  int ans = n;
  for (int i = n-1; i>= 0; i--){
    // printf("i=%d\n",i);
    // printf("ans=%d\n",ans);
    if(sa >= abs(avg - a[i])){
      sa = abs(avg - a[i]);
      //printf("sa=%f\n",sa);
      ans = i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

	int val = 1;
	for (int i = 0; i < n; i++) {
		val = min(val * 2, val + k);
	}
	cout << val << endl;
	return 0;
}


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

const int N = 1e3 + 5;

typedef pair<int, int> pii;

char g[N][N];
int vis[N][N], d[N][N];
int h,w;

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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>h>>w;
    queue<pii> q;
    
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin>>g[i][j];
            if(g[i][j]=='#'){
                vis[i][j] = 1;
                d[i][j] = 0;
                q.push({i,j});
            }
        }
    }
    
    int mxd = 0;
    while (!q.empty()) {
        pii u = q.front();
        q.pop();
        
        for (int i = 0; i < 4; i++){
            int nx = u.first + dx[i];
            int ny = u.second + dy[i];
            if(nx<0||nx>=h)continue;
            if(ny<0||ny>=w)continue;
            if(!vis[nx][ny]){
                d[nx][ny] = d[u.first][u.second] + 1;
                vis[nx][ny] = 1;
                q.push({nx,ny});
                mxd = max(mxd, d[nx][ny]);
            }
        }
        
    }
    
    
    cout<<mxd<<endl;
    
    return 0;
}



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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////



ll printNcR(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...

    long long p = 1, k = 1;


    if(n-r<0)
        return 0;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify product
            // division by their gcd saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}


int main()
{
    FASTIO;


    ll n , m;

    cin >> n >> m;


    cout << printNcR(n,2) + printNcR(m,2) << endl;





    return 0;
}



Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
*a, = map(int, input().split())

c = Counter(a)
kv = sorted(c.items(), key=lambda x: x[1], reverse=True)

if n <= k:
    print(0)
else:
    ls = c.most_common(k)
    ans = n
    for k, v in ls:
        ans -= v

    print(ans)

Measured memory_bytes: 39352
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int num1,num2;
	num1 = c/b + (c % b == 0?0:1);
	num2 = a/d + (a % d == 0?0:1);
	puts(num1 <= num2?"Yes":"No");
	return 0;
}

Measured memory_bytes: 3764
#!/usr/bin/env python3
import sys
from collections import defaultdict

def solve(N: int, P: int, S: str):
    if 10%P == 0:
        sum = 0
        for i in range(1,N+1):
            if int(S[-i]) % P == 0:
                sum += (N-i)+1
        print(sum)
        return
    else:
        current = 0
        C = 1
        counts = defaultdict(int)
        for i in range(1,N+1):
            if i == 1:
                current = int(S[-1])%P
            else:
                current = (int(S[-i])*C + current)%P
            counts[current]+=1
            C=C*10%P
        sum = 0
        for k in counts:
            c = counts[k]
            sum += int((c*(c-1)/2))
        sum += counts[0]
        print(sum)

    # sum = 0
    # for i in range(N):
    #     sDiv = 0
    #     coeff = 1
    #     for j in range(i,N):
    #         sDiv= (sDiv*coeff + arr[j])%P
    #         coeff*=10
    #         if sDiv == 0:
    #             sum+=1
    # print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    S = next(tokens)  # type: int
    solve(N, P, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4612
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		int n=sc.nextInt();
		Map<String,Integer> words = new LinkedHashMap<>();
		char[] ini=new char[n];
		char[] end =new char[n];

		for(int i=0; i<n; i++) {
			String s=sc.next();
			if(words.get(s)!=null) {
				System.out.println("No");
				return;
			}else {
				words.put(s,1);
				ini[i]=s.charAt(0);
				end[i]=s.charAt(s.length()-1);
			}
		}

		for(int i=0;i<n-1;i++) {
			if(end[i]!=ini[i+1]) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lldd long double
int main()
{
  ll n,sum=0;
  cin>>n;
  ll a[n];
  for(ll i=0; i<n; i++)
    cin>>a[i];
  for(ll i=0; i<n-1; i++)
  {
    if(a[i+1]<a[i]){
       sum+=a[i]-a[i+1];
       a[i+1]=a[i];}
  }
                cout<<sum;
}

Measured memory_bytes: 5172
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
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 TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, T = MAP()
AB = [LIST() for _ in range(N)]
AB.sort(key = lambda x:x[0])
t = [0]*T
ans = 0

for A, B in AB:
	for i in range(T-1, 0, -1):
		if t[i]:
			if T <= i+A:
				ans = max(ans, t[i]+B)
			else:
				t[i+A] = max(t[i+A], t[i]+B)
	if T <= A:
		ans = max(ans, B)
	else:
		t[A] = max(t[A], B)

ans = max(ans, max(t))
print(ans)

Measured memory_bytes: 76060
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def dijkstra(s,n,g):
    dis = [10**10]*n
    dis[s] = 0
    que = deque([])
    que.append(s)
    while que:
        go = que.pop()
        for i in range(len(g[go])):
            if dis[g[go][i]] <= dis[go] + 1:
                continue
            dis[g[go][i]] = dis[go] + 1
            que.append(g[go][i])
    return dis

def main():
    n,x,y = inpm()
    x -= 1
    y -= 1
    g = [[] for _ in range(n)]
    for i in range(n-1):
        a = i
        b = i+1
        g[a].append(b)
        g[b].append(a)
    g[x].append(y)
    g[y].append(x)
    ans = [0 for _ in range(n-1)]
    for i in range(n-1):
        d = dijkstra(i,n,g)
        for j in range(i+1,n):
            ans[d[j]-1] += 1
    for i in range(n-1):
        print(ans[i])
        
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 70232
N = int(input())
W = input()
Wlist = [W]
a = 0

for n in range(N-1):
  w = W[-1]
  W = input()
  if w != W[0] or W in Wlist:
    a = 0
    break
  else:
    Wlist.append(W)
    w = W[-1]
    a = 1

if a == 1:
  print("Yes")
else:
  print("No")

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> F(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      int f; cin >> f;
      F[i].push_back(f);
    }
  }
  vector<vector<int>> P(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 11; j++) {
      int p; cin >> p;
      P[i].push_back(p);
    }
  }
  int ans = 0;
  for (int i = 1; i < 1024; i++) {
    vector<int> C(N, 0);
    for (int j = 0; j < 10; j++) {
      if (i >> j & 1) {
        for (int n = 0; n < N; n++) {
          C[n] += F[n][j];
        }
      }
    }
    int tmp = 0;
    for (int n = 0; n < N; n++) {
      tmp += P[n][C[n]];
    }
    if (i == 1) ans = tmp;
    else ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
program bitter_alchemy
  implicit none
  integer :: n, x, m, s, t, i
  read(*,*) n, x
  s = 0
  t = 1001
  do i = 1, n
    read(*,*) m
    s = s + m
    if (t.gt.m) t = m
  end do
  write(*,'(i0)') n + (x-s)/t
  stop
end program bitter_alchemy

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <vector>
using namespace std;

int n;
vector<int> tetora;
vector<int> dp(1000001, 10000);
vector<int> dp2(1000001, 100000);

void msk()
{
    dp[0] = dp2[0] = 0;

    for (int i = 1;; i++)
    {
        int tmp = i * (i + 1) * (i + 2) / 6;
        if (tmp > 1000000)
            break;

        for (int j = tmp; j < 1000001; j++)
        {
            dp[j] = min(dp[j], dp[j - tmp] + 1);
            if (tmp % 2 != 0)
            {
                dp2[j] = min(dp2[j], dp2[j - tmp] + 1);
            }
        }
    }
}

int main()
{
    msk();
    while (1)
    {
        scanf("%d", &n);
        if (n == 0)
            return 0;
        printf("%d %d\n", dp[n], dp2[n]);
    }
}


Measured memory_bytes: 9812
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


int main(void){
    ll n; cin >> n;
    ll ulimit = 1e6+1;
    vector <bool> ok(ulimit, false);
    vector <ll> cnt(ulimit, 0);
    REP(i, n){
        ll a; cin >> a;
        cnt[a]++;
        ok[a] = true;
    }
    for(int i=1; i<ulimit; i++){
        if (!ok[i]){
            continue;
        }
        for(ll j=i*2; j<ulimit; j+=i){
            ok[j] = false;
        }
    }
    ll ans = 0;
    for(int i=1; i<ulimit; i++){
        if (ok[i] && (cnt[i]==1)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11148
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int test[123456];
int main(){
  int n, m, ans = 0; string s; cin >> n >> s;
  for(int h=0;h<=9;h++){
    for(int i=0;i<=9;i++){
      for(int j=0;j<=9;j++){
        int sum = 0;
        for(int k=0;k<n;k++){
          if(sum==0&&s[k]-'0'==h){
           sum++; 
          }
          else if(sum==1&&s[k]-'0'==i){
           sum++; 
          }
          else if(sum==2&&s[k]-'0'==j){
           ans++; sum++;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  int n,m;
  cin>>n>>m;
  
  vector<int> A(m,0);
  
  int k,a;
  rep(i,n){
    cin>>k;
    rep(j,k){
      cin>>a;
      a--;
      A[a]++;
    }
  }
  
  int ans=0;
  rep(i,m){
    if(A[i]==n) ans++;
  }
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int n;
struct A{
	int a[10];
	bool operator<(A a_) const {
		rep(i,n){
			if(a_.a[i] < this->a[i])return true;
			if(a_.a[i] > this->a[i])return false;
		}
		return false;
	}
	bool operator==(A a_) const {
		rep(i,n){
			if(a_.a[i] != this->a[i])return false;
		}
		return true;
	}
};

set<pair<A,int>> S;

A R(A x,int i,int j){
	A ret = x;
	for(int k = i ; k <= j ; k ++){
		ret.a[k] = x.a[i+j-k];
	}
	return ret;
}

int main(){
	scanf("%d",&n);
	
	A a; rep(i,n)a.a[i] = i;
	S.insert(pair<A,int>(a,0));
	rep(ppp,4){
		for(set<pair<A,int>>::iterator itr = S.begin() ; itr != S.end() ; itr ++){
			if(itr->sc != ppp)continue;
			rep(i,n){
				for(int j = i+1 ; j < n ; j ++){
					a = R(itr->fr,i,j);
					if(!(S.lower_bound(pair<A,int>(a,0))->fr == a)){
						S.insert(pair<A,int>(a,ppp+1));
					}
				}
			}
		}
		//cout << ppp << " " << S.size() << endl;
	}
	
	rep(i,n){
		int aa;
		scanf("%d",&aa);
		a.a[i] = aa-1;
	}
	
	int ret = n-1;
	for(set<pair<A,int>>::iterator itr = S.begin() ; itr != S.end() ; itr ++){
		A b;
		rep(i,n)b.a[i] = a.a[itr->fr.a[i]];
		set<pair<A,int>>::iterator it = S.lower_bound(pair<A,int>(b,0));
		if(it->fr == b)ret = min ( ret , itr->sc + it->sc );
	}
	cout << ret << endl;
}

Measured memory_bytes: 25068
import java.util.Scanner;

public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int  H= sc.nextInt();
			int  W= sc.nextInt();
			if(H==0 && W==0) break;
			for (int i=0 ;i<H ;i++) {
				for (int j=0; j < W ; j++) {
					if((i==0 || i == H-1) || (j == 0 || j == W-1)) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
					System.out.println();
				}
				System.out.println();
			}

		}
	}


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

//----------素因数分解----------
vector<ll> prime_factorization(ll n){
  vector<ll> factors(n+1,0);
  rep3(i,n+1){
    if(i<=1) continue;
    while(n%i==0){
      n/=i;
      factors[i]++;
    }
  }
  return factors;
}

int main() {
  string s;
  cin>>s;
  if(s[0]=='R'){//1
    if(s[1]=='R'){//2
      if(s[2]=='R'){//3
        cout<<3<<endl;//000
        return 0;
      }
      else{//3
        cout<<2<<endl;//001
        return 0;
      }
    }
    else{//2
      if(s[2]=='R'){//3
        cout<<1<<endl;//010
        return 0;
      }
      else{//3
        cout<<1<<endl;//011
        return 0;
      }
    }
  }
  else{//1
    if(s[1]=='R'){//2
      if(s[2]=='R'){//3
        cout<<2<<endl;//100
        return 0;
      }
      else{//3
        cout<<1<<endl;//101
        return 0;
      }
    }
    else{//2
      if(s[2]=='R'){//3
        cout<<1<<endl;//110
        return 0;
      }
      else{//3
        cout<<0<<endl;//111
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3628
/*
 * Author : Sadi
 * Wed 15/07/2020
 * 20:08:42.04
 */
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    int n;
    cin >> n;
    if(n & 1) {
        cout << "No" << endl;
    }
    else {
        string str;
        cin >> str;
        bool flag = true;
        for(int i = 0; i < (n >> 1); ++i) {
            if(str[i] == str[i + (n >> 1)]) {
                continue;
            }
            else {
                flag = false;
                break;
            }
        }
        if(flag) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using namespace std;

int main() {

	int i, j, k;
	ll int n;
	cin >> n;
	ll int ans = 0;
	int ansi, ansj;
	int flag = 0;
	rep(i, 1, 3501) {
		rep(j, 1, i + 1) {
			if ((4 * i*j - i*n - j*n) > 0) {
				if ((n*i*j) % (4 * i*j - i*n - j*n) == 0) {
					ans = (n*i*j) / (4 * i*j - i*n - j*n);
					ansi = i;
					ansj = j;
					flag = 1;
					break;
				}
			}
		}
		if (flag == 1) {
			break;
		}
	}
	cout << ansi <<" "<< ansj <<" "<< ans << endl;
	return 0;
}

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

using namespace std;

int getMinutes (int h, int m)
{
    return h * 60 + m;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

int h1, m1, h2, m2, k;
scanf ("%d %d %d %d %d", &h1, &m1, &h2, &m2, &k);
int ans = getMinutes (h2, m2) - getMinutes (h1, m1) - k;
if (ans < 0)
    ans = 0;
printf ("%d\n", ans);
return 0;
}


Measured memory_bytes: 3812
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 36

typedef struct {
    int value[N];
    char mark[N];
} data;

int n;


data bblesort(data);
data selectsort(data);
void inputdata(data);
int check(data,data);


int main()
{
  int i,che;
  char ch[3];

  /*nに要素数を入力*/
  scanf("%d",&n);

  /*構造体作成,C値入力*/
  data C,b,s;
  for(i=0;i<n;i++){
    scanf("%s",ch);
    C.mark[i]= ch[0];   
    C.value[i]= atoi(ch+1);
  }

  /*bblesortで変換*/
  b=bblesort(C);
  s=selectsort(C);

  inputdata(b);
  printf("Stable\n");
  
  inputdata(s);
  che=check(s,b);

  if(che==1)printf("Not stable\n");
  else printf("Stable\n");


  return 0;
}

data bblesort(data b)
{
  int i,cpv,j;
  char cpm;

  for(i=0;i<n;i++)
    {
      for(j=n-1;j>i;j--)
	{
	  if(b.value[j]<b.value[j-1]){
	    cpv=b.value[j];
	    cpm=b.mark[j];
	    b.value[j]=b.value[j-1];
	    b.mark[j]=b.mark[j-1];
	    b.value[j-1]=cpv;
	    b.mark[j-1]=cpm;
	  }
	}
    }
  
  return b;
}

data selectsort(data s)
{
  int i,j,minj,cpv;
  char cpm;

  for(i=0;i<n;i++)
    {
      minj=i;
      for(j=i;j<n;j++)
	{
	  if(s.value[j]<s.value[minj])
	    {
	      minj=j;
	    }
	}
      cpv=s.value[i];
      cpm=s.mark[i];
      s.value[i]=s.value[minj];
      s.mark[i]=s.mark[minj];
      s.value[minj]=cpv;
      s.mark[minj]=cpm;  
    }
  return s;
}


void inputdata(data b)
{
  int i;
  
  for(i=0;i<n;i++){
    if(i==n-1)
      printf("%c%d\n",b.mark[i],b.value[i]);
    else
      printf("%c%d ",b.mark[i],b.value[i]);
  }
}

int check(data b,data c)
{
  int i;
  for(i=0;i<n;i++)
    {
	if(b.value[i]==c.value[i]){
	  if(strcmp(&b.mark[i],&c.mark[i])!=0){
	    return 1;
	  }
	  
	}
    }
  return 0;
}


  



Measured memory_bytes: 2048
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    ll N, D;
    cin >> N >> D;
    D = D*2+1;
    print((N+D-1)/D);
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
typedef pair<lint,int>pli;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

int main(){
  int n;
  cin>>n;
  vector<lint>a(n);
  rep(i,n)cin>>a[i];
  vector<pli>b(n);
  rep(i,n)b[i]=pli(a[i],i);
  sort(b.rbegin(),b.rend());
  vector<lint>ans(n);
  int mi=n;
  rep(i,n){
    if(i==n-1||b[i].first!=b[i+1].first){
      mi=min(b[i].second,mi);
      lint diff=b[i].first-(i==n-1?0:b[i+1].first);
      ans[mi]+=diff*(i+1);
    }
  }
  rep(i,n)cout<<ans[i]<<endl;
}


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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10E9
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)
#define PI 3.141592653589793


int f(vector<int> arr){
  int size = (int)arr.size() - 1;
  int k;
  k = ((size + 1) * (size + 2)) / 2; 
  forn(i , 0 , size) k -= arr[i];
  return k;
}
                                       
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;  

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
   
  int n; cin >> n;
  int a; cin >> a;
  int b; cin >> b;
  cout << min(n * a , b) << endl << endl;

#ifdef LOCAL_DEFINE 
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
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; }

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    
    int now = 1e9;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (chmin(now, A[i])) ans++;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#encoding:utf-8 No.0510 2014.11.10
score_A = 0
score_B = 0

gets.chomp.split.map{|n| score_A += n.to_i}
gets.chomp.split.map{|n| score_B += n.to_i}

puts score_A >= score_B ? score_A : score_B

=begin

if score_A >= score_B
  puts score_A
else
  puts score_B
end

は、上のように表記することも可能

=end

Measured memory_bytes: 6092
#include <bits/stdc++.h>
using namespace std;
string s;
int t[123],c;
int main()
{
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
        int x=s[i];
        t[x]++;
    }
    for(int i=97;i<123;i++)if(t[i]!=0)c++;
    if(c==s.length())cout<<"yes";
    else cout<<"no";

}


Measured memory_bytes: 256