akhauriyash/Code-Regression huggingface dataset:
//package atcoder.beginner_170;

import java.io.*;
import java.util.HashSet;
import java.util.StringTokenizer;

public class Main {

    public static void main (String[] args) throws Exception {

        String s = "1 5\n" +
                "1 2 3 4 5";

//        br = new BufferedReader(new StringReader(s));
        br = new BufferedReader(new InputStreamReader(System.in));
        bw = new BufferedWriter(new OutputStreamWriter(System.out));

        rl(); int X=nin(), N=nin();
        HashSet<Integer> set = new HashSet<>();
        for (int i=0; i<=101; ++i) set.add(i);
        rl(); for (int i=0; i<N; ++i) set.remove(nin());
        int nearest = 1000;
        int diff = 1000;
        for (int v:set) {
            int _diff = Math.abs(X-v);
            if (_diff<diff) {
                diff=_diff;
                nearest = v;
            } else if (_diff==diff) {
                nearest = Math.min(nearest, v);
            }
        }

        bw.write(Integer.toString(nearest));
        bw.newLine();
        bw.flush();

    }

    static BufferedReader br;
    static BufferedWriter bw;
    static StringTokenizer st;
    static void rl() throws Exception{
        st = new StringTokenizer(br.readLine());
    }
    static long nlo(){
        return Long.parseLong(st.nextToken());
    }
    static int nin(){
        return Integer.parseInt(st.nextToken());
    }
    /*private static void te(){
      }*/
    static double ndo(){
        return Double.parseDouble(st.nextToken());
    }
    static char[] nca(){
        return st.nextToken().toCharArray();
    }
    static String nstr(){
        return st.nextToken();
    }
}

Measured memory_bytes: 32616
def main():
    N = int(input())
    print(N + N * N + N * N * N)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9136
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using E = System.Linq.Enumerable;
class Program
{

    static void Main(string[] args)
    {

        //var NX = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var NK = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        var N = NK[0];
        var K = NK[1];
        var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();

        var cumA = new long[N + 1];
        for (int i = 1; i < N + 1; i++)
        {
            cumA[i] = cumA[i - 1] + A[i - 1];
        }
        var Sums = new long[N*(N+1)/2];

        var count = 0;
        for (int l = 1; l <= N; l++)
        {
            for (int r = l; r <= N; r++)
            {
                Sums[count] = cumA[r] - cumA[l - 1];
                count++;
            }
        }
        Array.Sort(Sums);
        Array.Reverse(Sums);

        long ans = 0;
        var MaxNumBin = Convert.ToString(Sums[0], 2);
        for (int i = MaxNumBin.Length - 1; i >= 0; i--)
        {
            long now = ans + (long)Math.Pow(2, i);
            long OK = 0;
            foreach (var item in Sums)
            {
                if((item & now) > ans)
                {
                    OK++;
                }
            }

            if (OK >= K) ans = now;
        }
        Console.WriteLine(ans);
    }
}

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

const int N=2e5+100;
int mod=1e9+7;
typedef long long ll;
int a[N],b[N];
int main()
{

    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=1ll*(i+n/i*i)*(n/i)/2;
      //  cout<<ans<<endl;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    String inputStr = scanner.next();
    int bea = 0;
    if(inputStr.charAt(0) == '1') {
      bea++;
    }
    if(inputStr.charAt(1) == '1') {
      bea++;
    }
    if(inputStr.charAt(2) == '1') {
      bea++;
    }

    System.out.println(bea);


  }
}


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

int main(){
	int n,m; cin >> n >> m;
	int a[n][m],b[m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin >> b[i];
	}
	for(int i=0;i<n;i++){
		int sum=0;
		for(int j=0;j<m;j++){
			sum+=a[i][j]*b[j];
		}
		cout << sum << endl;
	}
}


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

int main(){
    string S;
    cin >> S;
    if(S[0] == S[1] || S[1] == S[2]) {
    	cout << "Bad" << endl;
    }
    else if(S[2] == S[3]) {
        cout << "Bad" << endl;
    }
    else {
        cout << "Good" << endl;
    }
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<(n);i++)
#define rep2(i, m, n) for(int i=m;i<(n);i++)
#define rrep(i, n, m) for(int i=n;i>=(m);i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

int dp[100005][13];

void Main() {
    string S;
    cin >> S;
    int N = S.length();
    dp[0][0] = 1;
    for (int i = 0; i < N; ++i) {
        char s = S[i];
        if (s == '?') {
            for (int j = 0; j < 10; ++j) {
                for (int k = 0; k < 13; ++k) {
                    dp[i + 1][(10 * k + j) % 13] += dp[i][k];
                    dp[i + 1][(10 * k + j) % 13] %= MOD;
                }
            }
        } else {
            int j = s - '0';
            for (int k = 0; k < 13; ++k) {
                dp[i + 1][(10 * k + j) % 13] += dp[i][k];
                dp[i + 1][(10 * k + j) % 13] %= MOD;
            }
        }
    }
    cout << dp[N][5] % MOD << endl;

}

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


Measured memory_bytes: 5584
#include<iostream>
using namespace std;
//Rahulbhatt
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b &b!=c)
	{
		cout<<"Yes";
	}
	else if(a==c && a!=b)
	{
		cout<<"Yes";
	}
	else if(b==c && a!=b)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>

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

using namespace std;
typedef long long ll;

int main(){
    int d, t, s;
    cin >> d >> t >> s;
    if(d <= t*s) cout << "Yes" << endl;
    else         cout << "No"  << endl;
    return 0;
}

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


ull gcd(ull a,ull b){
	if(!b) return a;
	return gcd(b,a%b);
}


int main(){
	int n,cnt = 0,type = 0;
	cin >> n;
	ll a[n],memo = 0;
	
	rep(i,0,n){
		cin >> a[i];
	}
	
	sort(a,a+n,greater<int>());
	
	rep(i,1,n){
		cnt++;
		if(a[i] != a[i-1]){
			if(type){
				if(cnt >= 2){
					cout << a[i-1]*memo << endl;
					return 0;
				}
			}
			else{
				if(cnt >= 4){
					cout << a[i-1]*a[i-1] << endl;
					return 0;
				}
				else if(cnt >= 2){
					memo = a[i-1];
					type++;
				}
			}
			cnt = 0;
		}
	}
	cnt++;
	if(type){
		if(cnt >= 2){
			cout << a[n-1]*memo << endl;
			return 0;
		}
	}
	else{
		if(cnt >= 4){
			cout << a[n-1]*a[n-1] << endl;
			return 0;
		}
	}
	
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

// a: 49

int main(int argc, const char * argv[]) {
    string s;
    cin >> s;
    int a[26] = {};
    bool flag = true;
    for (int i = 0; i < s.length(); i++) {
        a[s[i]-'0'-49]++;
        if (a[s[i]-'0'-49] >= 2) {
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << "yes" << endl;
    }else{
        cout << "no" << endl;
    }
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
template<typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> void chmax(T& a, T b) { if(a < b) a = b; }
template<class T> void chmin(T& a, T b) { if(a > b) a = b; }

int main() {
    int n; cin >> n;
    vector<ll> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];
    ll ans = t[0];
    for(int i = 1; i < n; i++){
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
}



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

int main() {
   long long X;
   cin >> X;
   long long x=100;
   long long i=1;
   while (true) {
    x+=x/100;
    if (x>=X) {
    cout << i << endl;break;
    }
    i++;
   }
}

Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int mx2[] = {1,0};
int my2[] = {0,1};

class AAtCoderContest {
public:
	void solve(istream& in, ostream& out) {
        string x,y,z;
        in >> x >> y >> z;
        char a = y[0];
        out << 'A' << a << 'C' << endl;
	}
};

int main() {
	AAtCoderContest solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int length;     cin >> length;

    int tot = 0;
    int brick[1000000];   int sen = 1;
    for (int i = 0; i < length; i++){
        cin >> brick[i];
        if (brick[i] != sen){
            tot++;
        }
        else{
            sen++;
        }
    }

    if (sen == 1){tot = -1;}
    cout << tot << endl;

    return 0;
}


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

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

    int l[n];
    for(int i = 0; i < n; i++)
        cin >> l[i];

    sort(l, l + n);

    int cnt = 0;
    for(int i = 0; i < n - 2; i++){
        for(int j = i + 1; j < n - 1; j++){
            for(int k = j + 1; k < n; k++){
                if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && (l[i] + l[j] > l[k]))
                    cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3648
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X, A = map(int, readline().split())
    if X<A:
        print('0')
    else:
        print('10')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits>
#include <numeric>
#include <cmath>

using namespace std;

template<class T>
class Input {
public:
    auto operator()() const {
        T v;
        cin >> v;
        return v;
    }
};

template<class L, class R>
class Input<pair<L, R>> {
public:
    auto operator()() const {
        L l;
        R r;
        cin >> l >> r;
        return make_pair(l, r);
    }
};

template<class U>
class Input<vector<U>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        return (*this)(n);
    }
    auto operator()(size_t n) const {
        vector<U> v;
        v.reserve(n);
        Input<U> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in();
            v.emplace_back(move(u));
        }
        return v;
    }
};

template<class U>
class Input<vector<vector<U>>> {
public:
    auto operator()() const {
        Input<size_t> in{};
        auto n = in();
        auto m = in();
        return (*this)(n, m);
    }
    auto operator()(size_t n, size_t m) const {
        vector<vector<U>> v;
        v.reserve(n);
        Input<vector<U>> in{};
        for (size_t i = 0; i < n; ++i) {
            auto u = in(m);
            v.emplace_back(move(u));
        }
        return v;
    }
};

class InputType
{
public:
    template<class T>
    operator T() const {
        Input<T> i{};
        return i();
    }
};

class InputType2
{
public:
    InputType2(size_t n)
        : n_(n)
    {}
    template<class T>
    operator T() const {
        Input<T> i{};
        return i(n_);
    }
private:
    size_t n_;
};

auto input() {
    return InputType();
}

template<class... Args>
auto input(Args&&... args) {
    return InputType2(std::forward<Args>(args)...);
}

size_t bitcount(size_t n) {
    size_t c = 0;
    while (n) {
        if (n & 1ull)
            ++c;
        n >>= 1;
    }
    return c;
}

auto make_order(size_t n) {
    vector<size_t> a(n, 0);
    iota(begin(a), end(a), 0);
    return a;
}

template<class T>
auto next_permutation(T&& x) {
    using std::begin;
    using std::end;
    return next_permutation(begin(x), end(x));
}

using ll = long long;
using ull = unsigned long long;

auto gcd(size_t l, size_t r) {
    if (r == 0)
        return l;
    return gcd(r, l % r);
}

auto gcd(size_t a, size_t b, size_t c) {
    return gcd(a, gcd(b, c));
}

int main() {
    size_t k = input();
    string s = input();
    if (s.length() > k) {
        for (size_t i = 0; i < k; ++i) {
            cout << s[i];
        }
        cout << "..." << endl;
    } else {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll a, b;
    cin >> a >> b;
    ll gcd = __gcd(a, b);
    cout << a*b/gcd << endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,h,k,p;
long long v[1001][1001],M=1000000007;
long long int sum;
double def;
int main(void)
{
	char s[1001],t[1001];
	cin>>s>>t;
	h=strlen(s);
	k=strlen(t);
	for(i=0;i<=h;i++) for(j=0;j<=h;j++) v[i][j]=0;
	for(i=0;i<h;i++) if(s[i]==t[0]) v[0][i]=1;
	for(p=0;p<k;p++){
		for(i=p;i<h;i++){
			if(s[i]==t[p]){
				for(j=i+1;j<h;j++){
					if(s[j]==t[p+1]){
						v[p+1][j]+=v[p][i];
						if(M<v[p+1][j]) v[p+1][j]%=M;
					}
				}
			}
		}
	}/*
	for(i=0;i<k;i++){
		for(j=0;j<h;j++) cout<<v[i][j]<<" ";
		cout<<endl;
	}*/
	sum=0;
	for(i=0;i<h;i++){
		sum+=v[k-1][i];
		if(M<sum) sum=sum%M;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 10964
#include <stdio.h>
int main(void)
{
    int n,k,i,j,sum=0,x;
    scanf("%d%d",&n,&k);
    int tot[n];
    for(i=0;i<n;i++)
        scanf("%d",&tot[i]);
    for(i=0;i<n-1;i++)
        for(j=n-1;j>i;j--)
            if(tot[j]>tot[j-1])
            {
                x=tot[j];
                tot[j]=tot[j-1];
                tot[j-1]=x;
            }
    for(i=0;i<k;i++)
        sum+=tot[i];
    printf("%d",sum);
    return 0;
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string s;
  cin >> s;

  int k = 0;
  while ((k = s.find("ST", k)) != string::npos) {
    s.erase(k, 2);
    if (k >= s.size()) break;
    if (k > 0) k--;
  }

  printf("%lu\n", s.size());
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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 LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0, 0,-1,1,-1, 1,-1};
int dy[]={0,1,-1, 0,1,-1,-1, 1};


int main(){
    int n;cin >> n;
    string s;cin >> s;
    vector<bool> f(n,false);
    for (int i = 0; i < n-1; i++) {
        if(s[i] == '0' && s[i+1] == '0'){
            f[i] = f[i+1] = true;
        }
    }
    vector<string> v;
    string t="";
    for (int i = 0; i < n; i++) {
        if(f[i]){
            if(t!=""){
                v.pb(t);
                t = "";
            }
        }
        else{
            t += s[i];
        }
        if(i==n-1&&t!=""){
            v.pb(t);
        }
    }
    int ans = 0;
    for(auto vp:v){
        vector<int> a,b;
        int N = vp.size();
        for (int i = 0; i < N; i++) {
            if(vp[i] == '0'){
                int cnta = 0,cntb = 0;
                for (int j = i-1; j >= 0; j--) {
                    if(vp[j] == '0') break;
                    else cnta++;
                }
                for (int j = i+1; j < N; j++) {
                    if(vp[j] == '0') break;
                    else cntb++;
                }
                if(cnta&&cntb){
                    a.pb(cnta);
                    b.pb(cntb);
                }
            }
        }
        int sz = a.size();
        vector<vector<vector<int>>> dp(sz+1,vector<vector<int>> (3,vector<int>(2,0)));
        for (int i = 0; i < sz; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 2; k++) {
                    chmax(dp[i+1][0][0], dp[i][j][k]);
                }
            }
            chmax(dp[i+1][1][b[i]==1], dp[i][0][0] + a[i]);
            chmax(dp[i+1][2][b[i]==1], dp[i][0][0] + b[i] - 1);
            chmax(dp[i+1][1][b[i]==1], dp[i][1][0] + (a[i] - 1));
            chmax(dp[i+1][2][b[i]==1], dp[i][1][0] + b[i] - 1);
            chmax(dp[i+1][2][b[i]==1], dp[i][2][0] + b[i] - 1);
            chmax(dp[i+1][2][1], dp[i][0][0] + b[i]);
            chmax(dp[i+1][2][1], dp[i][1][0] + b[i]);
            chmax(dp[i+1][2][1], dp[i][2][0] + b[i]);
        }
        int mx = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 2; j++) {
                chmax(mx,dp[sz][i][j]);
            }
        }
        ans += mx;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4992
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//223
	int ans=0;
	string s;
	cin>>s;
	for(char c:s) {
		if(c=='+')ans++;
		else ans--;
	}
	cout<<ans;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3632
// C + T = X
// 2 * C + 4 * T = Y
// T = X - C
// 2 * C + 4 * (X - C) = Y
// - 2 * C = Y - 4 * X
// C = 2 * X - Y / 2
// T = -X + Y / 2

using System;
// using System.Collections.Generic;
// using System.Linq;

class Program
{
    static void Main()
    {
        String[] arr = Console.ReadLine().Split();
        int X, Y;
        X = int.Parse(arr[0]);
        Y = int.Parse(arr[1]);
        int C, T;
        C = 2 * X - Y / 2;
        T = -X + Y / 2;
        Console.WriteLine(0 <= C && 0 <= T && C + T == X && 2 * C + 4 * T == Y ? "Yes" : "No");
        return;
    }
}

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

 
     
int main() {
     int N;
  long long int ans[87];
  cin >> N;
  ans[0] = 2LL; ans[1] = 1LL;
  for(int i = 2; i <= N; i++){
    ans[i] = ans[i-1] + ans[i-2];
  }
cout << ans[N] << endl;
  
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
string s1;
ll dp[10005][105][3];
int fun(ll i,ll sum,ll K,ll right)
{
    if(i>=s1.size())
    {  if(sum%K==0) return 1; else return 0;}
    if(dp[i][sum][right]!=-1) return dp[i][sum][right];
    if(right==1)
    {
        ll sum1=0,j;
        for(j=0;j<=s1[i]-'0';j++)
        {
            if(s1[i]-'0'==j)
            sum1+=fun(i+1,(sum+j)%K,K,1);
            else sum1+=fun(i+1,(sum+j)%K,K,0);
            if(sum1>=MOD) sum1-=MOD;
        }
        return dp[i][sum][right]=sum1;
    }
    if(right==0)
    {
        ll sum1=0,j;
        for(j=0;j<=9;j++)
        {
            sum1+=fun(i+1,(sum+j)%K,K,0); if(sum1>=MOD) sum1-=MOD;
        }
        return dp[i][sum][right]=sum1;
    }
}
int main()
{
    cin>>s1;
    ll i,K,ans=0; memset(dp,-1,sizeof dp);
    cin>>K;
    for(i=0;i<=s1[0]-'0';i++)
    {
        if(i==s1[0]-'0')
        ans+=fun(1,i,K,1);
        else ans+=fun(1,i,K,0);
        if(ans>=MOD) ans-=MOD;
    }
    ans=(ans-1+MOD)%MOD;
    cout<<ans<<'\n';

}


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

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

    if (N%10 == 2 || N%10 == 4 || N%10 == 5 || N%10 == 7 || N%10 == 9) {
        cout << "hon" << endl;
    } else if (N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

template<class T> void warshall_floyd(vector<T>& G){
    int N = G.size();
    REP(k,N){
        REP(i,N){
            REP(j,N){
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
}


int main() {
    int N,M,R; cin >> N >> M >> R;
    vector<int> r(R);
    REP(i,R){
        cin >> r[i];
        r[i]--;
    }

    sort(ALL(r));
    vector<vector<int>>  G(N,vector<int>(N,1e7));
    REP(i,M){
        int a,b,c; cin >> a >> b >> c;
        a--;
        b--;
        G[a][b] = c;
        G[b][a] = c;
    }
    REP(i,N){
        G[i][i] = 0;
    }
    warshall_floyd(G);

    int ans = INF;
    do{
        int num = 0;
        REP(i,R-1){
            //cout << r[i] << ", " << r[i+1] << endl;
            num += G[r[i]][r[i+1]];
        }
        ans = min(ans,num);
    }while(next_permutation(ALL(r)));
    cout<< ans << endl;


    return 0;
}

Measured memory_bytes: 3796
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		int K = sc.nextInt();
		int digit = N.length();
		int MAX = digit+1;
		long[][] com = new long[MAX][MAX];
		for(int i = 0; i < MAX; i++)
			com[i][0] = 1;
		for(int i = 1; i < MAX; i++)
			for(int j = 1; j <= i; j++)
				com[i][j] = com[i-1][j-1] + com[i-1][j];
		boolean ok = true;
		if(digit < K)
			ok = false;
		if(N.equals("10") && K == 2)
			ok = false;
		if(digit == 3 && K == 3)
			if(Integer.parseInt(N) < 111)
				ok = false;
		if(!ok) {
			System.out.println(0);
			return;
		}
		long ans = com[digit-1][K]*(long)Math.pow(9, K);
		ans += (Character.getNumericValue(N.charAt(0))-1) * com[digit-1][K-1] * (long)Math.pow(9, K-1);
		if(K == 1)
			ans++;
		else if(K == 2) {
			for(int i = 1; i < digit; i++) {
				int x = Character.getNumericValue(N.charAt(i));
				if(x != 0) {
					ans += x;
					ans += (digit-i-1)*9;
					break;
				}
			}
		}
		else {
			for(int i = 1; i < digit; i++) {
				int x = Character.getNumericValue(N.charAt(i));
				if(x != 0) {
					ans += com[digit-i-1][2] * 9 * 9;
					ans += (x-1) * (digit-i-1) * 9;
					for(int j = i+1; j < digit; j++) {
						int y = Character.getNumericValue(N.charAt(j));
						if(y != 0) {
							ans += y;
							ans += (digit-j-1) * 9;
							break;
						}
					}
				break;
				}		
			}
		}
		System.out.println(ans);

	}

}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
int main()
{

  int n,t,i,c=0,c1=0;
  int ara[10001];
  cin>>n>>t;
  vec.push_back(0);
  for(i=0;i<n;i++)
  {
      cin>>ara[i];
      c1+=ara[i];
      vec.push_back(c1);
  }
   for(i=0;i<vec.size();i++)
  {
     if(vec[i]<=t)
        c++;
  }
  cout<<c<<"\n";
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#define fol(i,n) for(int i=0;i<n;i++)
#define db(a) cout << a<< endl;
using namespace std;


int main(){
    int h,w,n,in;
    string ans;
    cin >>h>>w>>n;
    int a[n];
    fol(i,n) cin >>a[i];
    int k=0,j=1;
    fol(i,h){
        ans ="";
        k=0;
        if (i%2==0){
            while(k<w){
                if (a[j-1]==0) j++;
                ans += to_string(j)+" ";
                k++;a[j-1]--;
            }
        }else{
            while(k<w){
                if (a[j-1]==0) j++;
                ans = to_string(j)+" "+ans;
                k++;a[j-1]--;
            }
        }
        ans.pop_back();
        cout << ans<<endl;
    }
    return 0;
}


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

int main()
{
	vector<long long> left(2, 0), right(2, 0);
	for (auto &inum : left) {
		cin >> inum;
	}
	for (auto& inum : right) {
		cin >> inum;
	}
	long long max = -1000000000000000000;
	for(int i = 0; i < 2; i++){
		for (int j = 0; j < 2; j++) {
			long long expr = left[i] * right[j];
			if (expr > max) max = expr;
		}
	}

	cout << max;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	string s;cin>>s;
    int t[N+1]; t[0]=1;
	for(int i=N-1;i>=0;i--){
		t[N-i]=t[N-i-1]+(s[i]=='1' ? 0 : 1);
	}
    //print(t,N+1);
	deque<int> dq;
	int i=0;int j;
	while(i<N){
		if(t[min(i+M,N)]==t[i]){ cout<<-1<<endl; return 0; }
		j=upper_bound(t+i+1,t+min(i+M+1,N+1),t[min(i+M,N)]-1)-t;
		dq.push_back(j-i);
        i=j;
	}
	reverse(dq.begin(),dq.end());
	print(dq,dq.size());
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] title = new String[n];
        int[] time = new int[n];
        
        for (int i = 0; i < n; i++) {
            title[i] = sc.next();
            time[i] = sc.nextInt();
        }
        String sleep = sc.next();
        boolean after = false;
        
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (after) {
                cnt += time[i];
            }
            if (title[i].equals(sleep)) {
                after = true;
            }
        }
        
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
//abc051_a.cpp
//Fri Oct 19 22:55:11 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	for (int i=0;i<19;i++){
		if (i != 5 && i != 13){
			cout << s[i];
		}else {
			cout << " ";
		}
	}

	printf("\n");
}

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

using namespace std;

struct State{
  int x,y;
  int cnt;
  int rotate;
};

int main(void){
  int w,h;
  while(cin>>w>>h,w||h){
    int s[31][31],min[31][31][4];
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        cin>>s[i][j];
      }
    }
    int c[4];
    for(int i=0;i<4;++i){
      cin>>c[i];
    }
    for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        for(int k=0;k<4;++k){
          min[i][j][k]=(w+h)*10;
        }
      }
    }
    State initial;
    initial.x=0;initial.y=0;initial.cnt=0;initial.rotate=0;
    vector<State> qu;
    qu.push_back(initial);
    while(!qu.empty()){
      const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
      State b=qu.back();qu.pop_back();
      if(b.x<0 || w<=b.x || b.y<0 || h<=b.y) continue;
      if(min[b.y][b.x][b.rotate]>b.cnt)min[b.y][b.x][b.rotate]=b.cnt;
      else continue;
      State a;
      for(int i=0;i<4;++i){
        if(s[b.y][b.x]==i) a.cnt=b.cnt;
        else a.cnt=b.cnt+c[i];
        a.rotate=(b.rotate+i)%4;
        a.x=b.x+DX[a.rotate];a.y=b.y+DY[a.rotate];
        qu.push_back(a);
      }
    }
#if 0
     for(int i=0;i<h;++i){
      for(int j=0;j<w;++j){
        for(int k=0;k<4;++k){
          cerr<<min[i][j][k]<<" ";
        }
        cerr<<",";
      }
      cerr<<endl;
    }
#endif
    int ans=(w+h)*10;
    for(int i=0;i<4;++i){
    	if(ans>min[h-1][w-1][i])ans=min[h-1][w-1][i];
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1360
#include<stdio.h>

int main()
{
  int n, q, i, cnt=0;
  int mid, left, right;
  int s[100000], t[50000];

  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++)
    {
      left = 0;
      right = n;
      while(left < right)
	{
	  mid = (left+right)/2;
	  if(t[i] == s[mid])
	    {
	      cnt++;
	      break;
	    }
	  if(t[i] > s[mid])
	    {
	      left = mid+1;
	    }
	  else if(t[i] < s[mid])
	    {
	      right = mid;
	    }
	}
    }

  printf("%d\n", cnt);
  
  return 0;
}

Measured memory_bytes: 1184
n = int(input())
al = list(map(int, input().split())) 

ny =1000
nk =0

for i in range(n-1):
    if al[i] > al[i+1]:
        if nk >0:
            ny += nk*al[i]
            nk = 0
    elif al[i] < al[i+1]:
        bk = ny // al[i]
        nk += bk
        ny -= bk*al[i]
    else:
        pass

ny += nk*al[n-1]
print(ny)

Measured memory_bytes: 9200
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=200000;
int n;
struct node
{
	int a,b;
}k[N+5];
inline bool _cmp(node a,node b)
{
	return a.b != b.b ? a.b < b.b : a.a < b.a;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d",&k[i].a,&k[i].b);
	sort(k+1,k+n+1,_cmp);
	
	int t=0;
	for(int i=1;i<=n;i++)
	{
		if(t+k[i].a<=k[i].b)
			t+=k[i].a;	
		else
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

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

func main() {
	n, _ := strconv.Atoi(input())
	m, _ := strconv.Atoi(input())
	h := make([]int, n)
	a := make([]int, m)
	b := make([]int, m)
	for i := 0; i < n; i++ {
		h[i], _ = strconv.Atoi(input())
	}
	for i := 0; i < m; i++ {
		a[i], _ = strconv.Atoi(input())
		b[i], _ = strconv.Atoi(input())
	}

	isHigh := make([]bool, n)
	for i := 0; i < n; i++ {
		isHigh[i] = true
	}
	for i := 0; i < m; i++ {
		ai, bi := a[i], b[i]
		ai--
		bi--
		if h[ai] == h[bi] {
			isHigh[ai] = false
			isHigh[bi] = false
		} else if h[ai] < h[bi] {
			isHigh[ai] = false
		} else {
			isHigh[bi] = false
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		if isHigh[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 6128
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

k,n = MAP()
a = LIST()
a.sort()

mx = k-a[-1] + a[0]

for i in range(1, n):
    mx = max(mx, a[i]-a[i-1])

print(k-mx)

Measured memory_bytes: 103108
#include <ctype.h>
#include <stdio.h>
#include <string.h>
 
char
toswap(char c)
{
    if (islower(c)) return toupper(c);
    if (isupper(c)) return tolower(c);
    return c;
}
 
int
main()
{
    char s[1200];
    fgets(s, sizeof(s), stdin);
 
    int s_i;
    int s_len = strlen(s);
    for (s_i = 0; s_i < s_len; s_i++)
    {
        char c = toswap(s[s_i]);
        putchar(c);
    }
}

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

int K, N;
vector<int> D;

int main(void) {
	cin >> K >> N;
	D.resize(N);
	int a0, pre;

	cin >> a0;
	pre = a0;
	for (int i = 1; i < N; ++i) {
		int a;
		cin >> a;
		D[i - 1] = a - pre;
		pre = a;
	}
	D[N - 1] = (K - pre) + a0;
	vector<int>::iterator itr;
	itr = max_element(D.begin(), D.end());
	int ans = K - *itr;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll mod=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    vector<ll> arr(n);
    for(ll i=0;i<n;i++)arr[i]=i;
    map< vector<ll> , ll >mp;
    ll cnt=0;
    do{
        mp[arr]=cnt++;
    }while(next_permutation(arr.begin(),arr.end()));
    vector<ll> p(n),q(n);
    for(ll i=0;i<n;i++)cin>>p[i],p[i]--;
    for(ll i=0;i<n;i++)cin>>q[i],q[i]--;
    cout<<abs(mp[p]-mp[q]);
}


Measured memory_bytes: 6528
import math
def InsertionSort(A, N, g):
    global cnt
    for i in range(g, N):
        key = A[i]
        j = i-g
        while j >= 0 and A[j] > key:
            A[j+g] = A[j]
            j = j-g
            cnt += 1    
        A[j+g] = key
    return A

def ShellSort(A, N):
    G = []
    i = 1
    while True:
        if  3**i -1 > N*2:
            break
        G.insert(0, int((3**i-1)/2))
        i += 1


    for i in range(len(G)):
        InsertionSort(A, N, G[i])
    return G

N = int(input())
A = []
cnt = 0
for i in range(N):
    A.append(int(input()))
ShellSort(A,N)
print(len(ShellSort(A,N)))
print(*ShellSort(A,N))
print(cnt)
print(*A, sep='\n')

Measured memory_bytes: 63136
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<iomanip>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = 1e9 + 7;
int dx[8] = { 1,0,-1,0,1,1,-1,-1 };
int dy[8] = { 0,1,0,-1,1,-1,1,-1 };

ll solve(ll n) {
	if (n == 1) {
		return 1;
	}
	return n * solve(n - 1);
}


int main() {

	ll n;
	while (cin >> n) {

		cout << solve(n) << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
// skip until line 65
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
using namespace std;

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define MO(a) AS_MOD(a,mod)
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)
#define MIN(V, T) V=min(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
struct Vec;
//set<int, Comparator> S;

// solution below
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
int main() {
    cout.precision(15);
    cout << fixed;
    int h1,m1,h2,m2,k;
    cin >>h1>>m1>>h2>>m2>>k;
    cout<<h2*60+m2-h1*60-m1-k<<endl;
}


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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int h, w;
char c[71][71];

signed main() {
  while ( cin >> w >> h, w | h ) {
    vector<string> dp[71];
    Rep(i, h) dp[i] = vector<string>(71);
    Rep(i, h) Rep(j, w) {
      cin >> c[i][j];
      dp[i][j] = "0";
    }
  
    Rep(i, h) Rep(j, w) {  
      if ( '0' <= c[i][j] && c[i][j] <= '9' ) dp[i][j] = c[i][j];
    }
  
    for ( int i = 0; i < h; i++ ) {
      Rep(j, w) {
	if ( '0' <= c[i][j] && c[i][j] <= '9' ) {
	  if ( i && dp[i-1][j] != "0" ) {
	    if ( dp[i][j].size() <= dp[i-1][j].size() ) {
	      dp[i][j] = dp[i-1][j]+c[i][j];
	    } else if ( dp[i][j].size()-1 == dp[i-1][j].size() ) {
	      dp[i][j] = max(dp[i][j], dp[i-1][j]+c[i][j]);
	    }
	  }
	  if ( j && dp[i][j-1] != "0" ) {
	    if ( dp[i][j].size() <= dp[i][j-1].size() ) {
	      dp[i][j] = dp[i][j-1]+c[i][j];
	    } else if ( dp[i][j].size()-1 == dp[i][j-1].size() ) {
	      dp[i][j] = max(dp[i][j], dp[i][j-1]+c[i][j]);
	    }
	  }
	}
      }
    }

    string ans = "";
    Rep(i, h) Rep(j, w) {
      if ( ans.size() < dp[i][j].size() ) ans = dp[i][j];
      else if ( ans.size() == dp[i][j].size() ) ans = max(ans, dp[i][j]);
    }

    cout << ans << endl;
  }
  
}

Measured memory_bytes: 3256
#include <iostream>

//文字列の文字数を返す関数
int str_length(char* str)
{
	int length;
	for (length = 0; length < 20; length++)  //文字列は最大20文字のため、length < 20
	{
		if (str[length] == '\0')  //ヌル記号→文字列の終端
		{
			break;
		}
	}
	return length;  //ヌル記号の配列番号＝文字列の文字数
}

//文字列を逆順に出力する関数
void reverce_output(char* str){
	int length = str_length(str);  //文字列の文字数を調べる
	int str_end = length - 1;  //文字数-1 = char型配列の、最後の文字の番号
	for (int i = 0; i < length; i++)
	{
		std::cout << str[str_end - i];  //文字列を逆順に出力
	}
	std::cout << '\n';
}

int main(){
	char input_char[20];  //入力される文字列の変数
	std::cin >> input_char;
	reverce_output(input_char); //文字列を逆順に出力
}


Measured memory_bytes: 2940
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let h: usize = sc.read();
    let w: usize = sc.read();
    println!("{}", (n - h + 1) * (n - w + 1));
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
n=int(input())
s=int(input())
r=int(n**0.5)
for b in range(2,r+10):
	m=n
	t=0
	while m:
		t+=m%b
		m//=b
	if t==s:
		print(b)
		exit()
for p in range(1,r)[::-1]:
	q=s-p
	b=1+(n-s)//p
	if 1<=p<b and 0<=q<b and(n-s)%p==0:
		print(b)
		exit()
if n==s:
	print(n+1)
	exit()
print(-1)


Measured memory_bytes: 3188
def main():
    n = int(input())
    a = [int(s) for s in input().split(" ")]
    for v in a:
        if v % 2 == 0:
            if v % 3 != 0 and v % 5 != 0:
                print("DENIED")
                return
    print("APPROVED")


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
h,w = gets.chomp.split.map(&:to_i)
ary = []
h.times do
  ary << gets.chomp.split.map(&:to_i)
end

# h.times do |line|
#   (w-1).times do |num|
#     if ary[line][num]%2 == 1

ans = []

ary.each_with_index do |line, line_index|
  # puts(index.to_s+" "+line.to_s)
  line.each_with_index do |num, num_index|
    if num%2 == 1 && num_index != w-1
      ans << "#{line_index+1} #{num_index+1} #{line_index+1} #{num_index+2}"
      ary[line_index][num_index+1] += 1
    elsif num%2 == 1 && num_index == w-1 && line_index != h-1
      ans << "#{line_index+1} #{num_index+1} #{line_index+2} #{num_index+1}"
      ary[line_index+1][num_index] += 1
    end
  end
end

puts ans.length
ans.each do |i|
  puts(i)
end


Measured memory_bytes: 18172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            String str[] = br.readLine().split(" ");
            int ans = 3;
            int minus = 1;
            for (int i = 0; i < str.length; i++) {
                int temp = Integer.parseInt(str[i]);
                if (temp % 2 == 0) {
                    minus = minus * 2;
                }
                if (i != 0) {
                    ans = ans * 3;
                }
            }
            System.out.println(ans - minus);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 23252
#coding: utf-8
import math
import heapq
import bisect

MOD = 10**9+7

S = input()
ans = [1]+[0]*12
 
for c in S:
    dp=[0]*13
    for i in range(13):
        #dpはansを一桁ずらしたもの
        dp[(i*10)%13]=ans[i]%MOD
    #0~12と13~25と同じものを増設
    dp+=dp
 
    if c=='?':
        for i in range(13):
            #添字を13から26まで増やしたから、ここでこう楽な計算ができる。
            ans[i]=sum(dp[i+4:i+14])
    else:
        for i in range(13):
            ans[i]=dp[i+13-int(c)]

print(ans[5]%MOD)

Measured memory_bytes: 3316
n = int(input())
s = list(input())
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
alpha_list = list(alpha)
s_num = [alpha_list.index(i) for i in s]
ans_num = [(i + n) % 26 for i in s_num]
ans_list = [alpha_list[i] for i in ans_num]
ans = "".join(ans_list)
print(ans)

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

int main() {
  long long n,k;
  cin >> n >> k ;
  long long c=n,x;
  x=n/k;
  c=n-k*x;
  while( c>k/2){
    if(c>k){
     c=c-k;
    }
    else{
      c=k-c;
    }
    
  }
  cout<<c<<endl;
}

/*　答えはkの半分以下のいずれか。*/

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
LL n, m, a[100000] = {}, x[10000][3] = {}, ans = 0;
struct edge { int cost, to; };
int  par[100000];  // ?????????????????????????´? 
int find(int x) { if (par[x] == x)return x; par[x] = find(par[x]); return par[x]; }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; par[x] = y; }
bool same(int x, int y) { return find(x) == find(y); }
vector<edge>vec[10000];
string S[100],str1,str2;
int main() {
	while (cin >> n&&n) {
		ans = 0;
	for(int i=0;i<100000;i++)par[i]=i;  // ????????????????????????
		cin >> m;
		for (int i = 0; i < m; i++) {
			int  a, b, c;
			char z;
			cin >> a >> z >> b >> z >> c;
			x[i][0] = min(a, b), x[i][1] = max(a, b), x[i][2] = c / 100 - 1;
		}
		for (int i = 0; i < m; i++)
			for (int j = i + 1; j < m; j++) {
				if (x[i][2] > x[j][2]) {
					for (int h = 0; h < 3; h++) {
						int a = x[i][h];
						x[i][h] = x[j][h];
						x[j][h] = a;
					}
				}
			}
		for (int i = 0; i < m; i++) {
			if (find(x[i][0]) != find(x[i][1])) {
				unite(x[i][0], x[i][1]);
				ans += x[i][2];
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
long long gcd(long long a, long long b){
    return b?gcd(b,a%b):a;
}
long long lcm(long long a, long long b){
    return a*b/gcd(a,b);
}
int main(){
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    printf("%lld",(b-a+1)-((b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/lcm(c,d)-(a-1)/lcm(c,d))));
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n, y;
	scanf("%d %d", &n, &y);
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++){
			int k = (y - i * 10000 - j * 5000) / 1000;
			if(i + j + k == n && k >= 0){
				printf("%d %d %d\n", i, j, k);
				return 0;
			}
		}
	}
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 128
n = int(input())
plst = list(map(float, input().split()))
dp = [0] * (n + 1)
dp[0] = 1
for p in plst:
  for i in range(n, -1, -1):
    if i != 0:
      dp[i] = dp[i] * (1 - p) + dp[i - 1] * p
    if i == 0:
      dp[i] = dp[i] * (1 - p)
print(sum(dp[n // 2 + 1:]))

Measured memory_bytes: 44328
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    int t;
    t=1;
    while(t--)
    {
        int n,m,i,x,y,z;
        cin>>m>>n;
        int arr[n+1];
        map<int,int> mp;
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
            mp[arr[i]]++;
        }
        if(mp[m]==0)
            cout<<m<<endl;
        else{
            for(i=1;i<=1000;i++) {
                if(mp[m-i]==0) {
                    cout<<m-i<<endl;
                    return 0;
                }
                if(mp[m+i]==0) {
                    cout<<m+i<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3680