akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;
using static System.Math;

public class Hello{
    public static void Main(){
        int num = rint();
        int ans = 0;
        for(int i=1;i<=num;i+=2){
            int count = 0;
            for(int j=1;j<=i;j++){
                if(i%j == 0){
                    count++;
                }
            }
            if(count == 8){
                ans++;
            }
        }
        WriteLine(ans);
    }
    
    
    
    
    //各種読取
    static string rstr(){
        return ReadLine();
    }
    static int rint(){
        return int.Parse(ReadLine());
    }
    static string[] stra(){
        return ReadLine().Split(' ');
    }
    static int[] inta(){
        string[] read_str_array = ReadLine().Split(' ');
        int[] return_int_array = new int[read_str_array.Length];
        for(int countup_i=0;countup_i<read_str_array.Length;countup_i++){
            return_int_array[countup_i] = int.Parse(read_str_array[countup_i]);
        }
        return return_int_array;
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
int MAX=3e5+100;
v64 factorial(MAX+10,1);
v64 inv(MAX+10,1);
ll exp(ll n, ll e)
{
	if (e==0)
	{
		return 1;
	}
	ll temp=exp((n*n)%MOD,e/2);
	return e%2==0 ? temp : (temp*n)%MOD;
}
ll inverse(ll n)
{
	return exp(n,MOD-2);
}
struct point
{
	int r,c;
	point(int r1,int c1)
	{
		r=r1;
		c=c1;
	}
};
bool cmp(point &a,point &b)
{
	return p64(a.r,a.c) < p64(b.r,b.c);
}

ll choose(ll n, ll r)
{
	ll ans=(factorial[n]*inv[r])%MOD;
	ans=(ans*inv[n-r])%MOD;
	return ans;
}

ll cal(point a,point b)
{
	if (a.r<=b.r && a.c<=b.c)
	{
		int n=b.r-a.r+b.c-a.c;
		int r=b.r-a.r;
		return choose(n,r);
	}
	return 0;
}
void solve()
{
	// cout<<choose(3,3)<<" "<<factorial[5]<<endl;
	int h,w,n;
	cin>>h>>w>>n;
	vector<point> arr(n+1,point(0,0));
	for (int i=1; i<=n; i++)
		cin>>arr[i].r>>arr[i].c;
	arr.push_back(point(h,w));
	sort(arr.begin()+1,arr.end(),cmp);
	v64 dp(n+2,0);
	// cout
	// cout<<cal(point(1,1),point(2,1))<<" "<<choose(1,0)<<endl;
	for (int i=1; i<=n+1; i++)
	{
		// cout<<"a"<<endl;
		dp[i]=cal(point(1,1),arr[i]);
		for (int j=1; j<i; j++)
		{
			dp[i]-=(dp[j]*cal(arr[j],arr[i]))%MOD;
			dp[i]=(dp[i]+MOD)%MOD;
		}
		// cout<<i<<" "<<dp[i]<<endl;
	}
	cout<<dp[n+1]<<endl;
}
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	for (int i=1; i<=MAX; i++)
 	{
 		factorial[i]=(factorial[i-1]*i)%MOD;
 		inv[i]=inverse(factorial[i]);
 	}
    int t=1;
    while (t--)
    {
        solve();
    }
    return 0;   
} 

Measured memory_bytes: 4992
//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101

#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#define mp make_pair
#define pb push_back
#define pb push_back
#define fileOut freopen("out.txt","w",stdout)
#define fileIn freopen("in.txt","r",stdout)
#define testcases ll tc,t; cin >> tc; for(t=1; t<=tc; t++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pi acos(-1.0)
#define ll long long

using namespace std;


int main(){
	
	ll days, assignments, var, sum = 0;
	cin >> days >> assignments;
	while(assignments--){
		cin >> var;
		sum+=var;
	}
	if(sum <= days){
		cout << days - sum <<endl;
	}
	else{
		cout << -1 <<endl;
	}
	
return 0;
}

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

int main(){
  int n;
  cin >>n;
  vector<ll> a(n);
  rep(i,n) cin >>a[i];
  int cnt = 0;
  int curcnt = 0;
  for(int i = 1; i<n; i++){
    if(a[i-1]>=a[i]) {
      curcnt++;
      cnt = max(curcnt,cnt);
    }
    else curcnt=0;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n & 1)
    cout << n/2 << '\n';
  else
    cout << n/2 - 1 << '\n';
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
int amida[100000];
int main() {
	int N, Q;
	cin >> N >> Q;
	for (int i = 0; i < N; i++) {
		amida[i] = i;
	}
	vector<P> v;
	for (int i = 0; i < Q; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		v.push_back(P(A, B));
	}
	int zero = 0;
	set<int> ans;
	for (int i = 0; i < Q; i++) {
		if (zero > 0) ans.insert(amida[zero - 1]);
		if (zero < N - 1) ans.insert(amida[zero + 1]);
		if (amida[v[i].first] == 0) zero = v[i].second;
		else if (amida[v[i].second] == 0) zero = v[i].first;
		swap(amida[v[i].first], amida[v[i].second]);
	}
	if (zero > 0) ans.insert(amida[zero - 1]);
	if (zero < N - 1) ans.insert(amida[zero + 1]);
	cout << ans.size()+1 << endl;
}

Measured memory_bytes: 1784
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

def roof(n):
    return math.ceil(n/10) * 10

def mod(n):
    return n % 10

low = map(mod, [A,B,C,D,E])
top = map(roof, [A,B,C,D,E])

low = [i for i in low if i != 0]

if low == []: low = [10]
ans = sum(top) + min(low) - 10
print(ans)


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

string solve(string s, char start='a') {
  for(char c = start; c <= 'z'; c++) {
    int idx = -1;
    for(int i = 0; i < s.size(); i++) if(s[i] == c) idx = i;
    if(idx < 0) return s + c;
  }
  if(s.size() == 0) return "-1";
  return solve(s.substr(0, s.size()-1), s[s.size()-1]+1);
}
void solve() {
  string s;
  cin >> s;
  cout << solve(s) << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 256
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    a = r.split()
    #a = list(map(int, r.split()))
    #a, b = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    if int(''.join(a)) % 4 == 0:
        print('YES')
    else:
        print('NO')        

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [1000000000] * N
dp[0] = 0

for i in range(N - 1):
    for j in range(1, K + 1):
        if i + j < N:
            if dp[i + j] > abs(h[i + j] - h[i]) + dp[i]:
                dp[i + j] = abs(h[i + j] - h[i]) + dp[i]
        else:
            break

print(dp[N - 1])



Measured memory_bytes: 52448
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        long[] as = new long[N];

        for (int i = 0; i < N; i++) {
            long value = sc.nextLong();

            if (N % 2 == 0) {
                int index = (i % 2 == 0) ? N/2 + i/2 : N/2 - (i + 1)/2;
                as[index] = value;
            } else {
                int index = (i % 2 == 0) ? N/2 - i/2 : N/2 + (i + 1)/2;
                as[index] = value;
            }
        }

        System.out.println(Arrays.toString(as).replace("]", "").replace("[", "").replace(",", ""));
    }
}

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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> w(n);
    rep(i,0,n) cin >> w[i];

    int ans=INF;
    int s1=0,s2=0;
    rep(T,0,n){
        s1=0;
        s2=0;
        
        rep(i,0,T){
            s1+=w[i];
        }
        rep(j,T,n){
            s2+=w[j];
        }
        ans=min(ans,abs(s2-s1));
    }

    cout << ans ENDL;
    
    return 0;
}

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

int main(){
    string S, T; cin>>S>>T;
    int ans=0;

    if(S[0]==T[0]) ans++;
    if(S[1]==T[1]) ans++;
    if(S[2]==T[2]) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3572
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    long long N, A;
    cin >> N >> A;

    vector<long long> x(N);
    for (auto &_ : x) cin >> _;

    //dp[i+1][j][k]
    //i+1枚目まででj枚使って合計がkとなる組み合わせ
    vector<vector<vector<long long>>> dp(N + 1, vector<vector<long long>>(N + 2, vector<long long>(2560, 0)));
    dp[0][0][0] = 1;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= N; j++) {
            for (int k = 0; k <= 2500; k++) {
                if (k + x[i] <= 2502)dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }

    long long ans = 0;
    for (int i = 1; i <= N; i++) {
        ans += dp[N][i][A * i];
    }

    cout << ans << endl;

}













































Measured memory_bytes: 54400
#include <iostream>
using namespace std;
int main(){
string S;
int N,K;
string result;
cin>>N>>S>>K;
char replace = S[K-1];
for(int i=0; i<N; i++){
if((char)S[i]!=replace) result+="*";
else result+=S[i];
}
cout<<result;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> a1(n);
    rep(i,n){
        cin>>a[i];
        a1[i]=a[i];
    }
    sort(a1.begin(),a1.end());
    rep(i,n){
        if(a[i]==a1[n-1]){
            cout<<a1[n-2]<<endl;

        }else{
            cout<<a1[n-1]<<endl;
        }
    }

    return 0;
}


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


using namespace std;

using ll = long long;


void prime_factorize(ll N, vector<pair<ll, ll>> &res) {
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0)
            continue;
        ll e = 0;
        while (N % i == 0) {
            e++;
            N /= i;
        }
        res.push_back(make_pair(i, e));
    }
    if (N != 1)
        res.push_back(make_pair(N, 1));
}



int main(void) {
    ll N;
    cin >> N;
    ll ans = 0;
    vector<pair<ll, ll>> res;
    prime_factorize(N, res);
    for (auto r : res) {
        ll p = r.first;
        ll e = r.second;
        for (ll use = 1; use <= e; use++) {
            e -= use;
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		boolean flag = true;
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			if (arr[i] % 2 != 0) {
				flag = false;
				break;
			}
		}
		int count = 0;
		while (flag) {
			count++;
			for (int i = 0; i < n; i++) {
				arr[i] /= 2;
				if (arr[i] % 2 != 0) {
					flag = false;
					break;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21076
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 60
#define F(a,b,c) for(register int (a)=(b);(a)<=(c);(a)++)
#define SL(a,b,c) (a)[(b)][(c)]++
using namespace std;
int n,m,a[szxb][szxb];
char ct[szxb][szxb];
int main()
{
	scanf("%d%d",&n,&m);
	F(i,1,n){F(j,1,m){ct[i][j]=getchar();while((ct[i][j]-'.')&&(ct[i][j]-'#')){ct[i][j]=getchar();}}}
	memset(a,0,sizeof(a));
	F(i,1,n){F(j,1,m){if(!(ct[i][j]-'#')){SL(a,i-1,j-1);SL(a,i-1,j);SL(a,i-1,j+1);SL(a,i,j-1);SL(a,i,j);SL(a,i,j+1);SL(a,i+1,j-1);SL(a,i+1,j);SL(a,i+1,j+1);}}}
	F(i,1,n){F(j,1,m){((!(ct[i][j]-'#'))?(putchar('#')):(printf("%d",a[i][j])));}putchar(10);}
	return 0;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    string s,t;cin>>s>>t;
    int mn=t.size();
    for(int i=0;i<s.size();i++)
    {
        string x=s.substr(i,t.size());
        if(x.size()==t.size())
        {
            int cnt=0;
            for(int j=0;j<t.size();j++)
            {
                if(t[j]!=x[j]) cnt++;
            }
            mn=min(mn,cnt);
        }
    }
    cout<<mn<<endl;
    return 0;
}
/*


*/



Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>

using namespace std;

int N;

int in[300][300];
long long ans = 0;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cin >> in[i][j];
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (in[i][j] == 0)continue;
			int min = 2000000000;
			for (int k = 0; k < N; k++) {
				if (in[i][k] == 0 || in[k][j] == 0)continue;
				if (in[i][k] + in[k][j] < min) {
					min = in[i][k] + in[k][j];
				}
				if (in[i][j] == in[i][k] + in[k][j]) {
					goto kend;
				}
			}
			if (min > in[i][j] ) {
				if(i < j)ans += in[i][j];
			}
			else {
				cout << -1 << endl;
				return 0;
			}
		kend:;
		}
	}
		cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		if ((int)(1.08 * i) == N) {
			cout << i << "\n";
			return 0;
		}
	}

	cout << ":(" << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
int isvalid(int i,int j,int h,int k)
{
    if(i>=0 && i<h && j>=0 && j<k)
    {
        return 1;
    }
    return 0;
}
int main()
{
	int h,w;
  	cin >> h >> w;
  	int arr[h][w];
  	int i,j;
  	char ch;
  	for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin >> ch;
            if(ch == '.')
            {
                arr[i][j] = 0;
            }
            else
            {
                arr[i][j] = 1;
            }
        }
    }
    long long int a=0,b=0;
    long long int dp[h][w] = {1};
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            a = 0;
            b = 0;
            if(!arr[i][j])
            {
                if(isvalid(i-1,j,h,w))
                {
                    if(!arr[i-1][j])
                    {
                        a = dp[i-1][j];
                    }
                }
                if(isvalid(i,j-1,h,w))
                {
                    if(!arr[i][j-1])
                    {
                        b = dp[i][j-1];
                    }
                }
                if(i || j)
                dp[i][j] = (a%INF + b%INF)%INF;
            }

        }
    }
    cout << dp[h-1][w-1];
}


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

long long abs1(long long x)
{

    if(x<0)
        return -1*x;
    return x;
}

long long a[200005];
int main()
{
    int n;
    cin>>n;
    long long sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    long long pr=a[0],ans=abs1(sum-pr-pr);
    for(int i=1;i<n-1;i++)
    {
        pr+=a[i];
        ans=min(ans,abs1(sum-2*pr));
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const double pi=3.14159265358979323846;
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b){
    if (a % b == 0){
        return(b);
    }else{
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
bool isprime(int n){
    if (n < 2) return false;
    else if (n == 2) return true;
    else if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2){
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
void sayYes(bool f) {
    if (f) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
void sayYES(bool f) {
    if (f) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

int main() {
  int a,b;
  cin >> a >> b;
  int ans=0;
  if(4-a>0){
    ans+=(4-a)*1e5;
  }
  if(4-b>0){
    ans+=(4-b)*1e5;
  }
  if(a==1&&b==1){
    ans+=4e5;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import queue
def bfs(sx,sy):
  #init
  dist = [[-1 for _ in range(w)] for __ in range(h)]
  dist[sx][sy] = 0
  q = queue.Queue()
  q.put([sx,sy])
  res = 0
  
  while not q.empty():
    vx,vy = q.get()
    
    for dx,dy in [(0,1),(1,0),(-1,0),(0,-1)]:
      x = vx+dx
      y = vy+dy
      if 0<=x<h and 0<=y<w and S[x][y] == "." and dist[x][y]==-1:
        q.put([x,y])
        dist[x][y] = dist[vx][vy]+1
        res = max(res, dist[x][y])
  return res


h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
ans = 0

for i in range(h):
  for j in range(w):
    if S[i][j] == '.':
      ans = max(ans, bfs(i,j))
print(ans)

Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int i=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

typedef long long ll;

ll solve(ll N, vector<pair<ll, ll>> &A){
    sort(A.begin(), A.end());
    priority_queue<ll, vector<ll>, greater<ll>> pq;
    ll ret = 0;
    for(auto x : A){
        ll k = x.first;
        ll v = x.second;

        ret += v;
        pq.push(v);
        if(pq.size() > k){
            ret -= pq.top();
            pq.pop();
        }
    }
    return ret;
}

int main(){
    ll T;
    cin >> T;
    REP(t, T){
        ll N;
        cin >> N;
        ll tot = 0;
        vector<pair<ll, ll>> A;
        vector<pair<ll, ll>> B;
        REP(i, N){
            ll K, L, R;
            cin >> K >> L >> R;
            if(L > R){
                A.emplace_back(K, L-R);
                tot += R;
            }else{
                B.emplace_back(N-K, R-L);
                tot += L;
            }
        }
        cout << tot + solve(N, A) + solve(N, B) << endl;
    }

    return 0;
}

Measured memory_bytes: 8336
A = []
C = 0
B = int(input())
for i in range(B):
    A.append(int(input()))
A.sort()
ans=sum(A)
if ans % 10 == 0:
    for i in range(B):
        if A[i] % 10  == 0:
            pass
        else:
            ans -= A[i]
            print(ans)
            exit()
else:
    print(ans)
    exit()
print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  long long ans=0;
  for(int bit=0;bit<(1<<s.size()-1);bit++){
    long long a=0;
    for(int i=0;i<s.size();i++){
      a=a*10+(s.at(i)-'0');
      if(bit&(1<<i)){
        ans+=a;
        a=0;
      }
    }
    ans+=a;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
import java.util.*;

class Main{

  public static void main(String args[]){

    Scanner s=new Scanner(System.in);
    String S=s.next();
    String T=s.next();
	char[] Sc=S.toCharArray();
	char[] Tc=T.toCharArray();
    int ans=0;
    for(int i=0;i<Sc.length;i++) if(Sc[i]!=Tc[i]) ans+=1;
    System.out.println(ans);

  }  
}

Measured memory_bytes: 41772
#include<bits/stdc++.h>
using namespace std;
int n,m,t,ans;
string s;
int main(){
  cin>>n;
  cin>>s;
  char c=s[0];
  ans=1;
  for(int i=1;i<n;i++){
    if(s[i]==c) continue;
      else {
        c=s[i];
        ans++;
      }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {

  int N;
  cin >> N;
  
  vector<int> B(N-1);
  for (int i=0; i<N-1; i++) {
    cin >> B.at(i);
  }
  
  int sum = B.at(0) + B.at(N-2);
  for (int j=0; j<N-2; j++) {
    sum += min(B.at(j), B.at(j+1));
  }
  
  // 結果の出力
  cout << sum << endl;
}

Measured memory_bytes: 256
n, m = map(int, raw_input().split())
edges = [map(lambda x: int(x) - 1, raw_input().split()) for _ in xrange(m)]
 
q = input()
vv = [None] * q
dd = [None] * q
cc = [None] * q
dp = [[-1 for j in xrange(11)] for i in xrange(n)]
for i in xrange(q):
    vv[i], dd[i], cc[i] = map(int, raw_input().split())
    dp[vv[i] - 1][dd[i]] = i
 
for i in reversed(range(1, 11)):
    for j in xrange(n):
        dp[j][i - 1] = max(dp[j][i - 1], dp[j][i])
    for u, v in edges:
        dp[u][i - 1] = max(dp[u][i - 1], dp[v][i])
        dp[v][i - 1] = max(dp[v][i - 1], dp[u][i])
 
for i in xrange(n):
    if dp[i][0] == -1:
        print('0')
    else:
        print(cc[dp[i][0]])

Measured memory_bytes: 66716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;

int n, m, q;
vector<int> a, b, c, d;
int ans;
void dfs(vector<int> A){
  if(A.size()==n+1) {
    int now = 0;
    rep(i,q){
      if(A[b[i]]-A[a[i]]==c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }
  A.push_back(A.back());
  while(A.back()<=m){
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin>> n >> m >> q;
  a=b=c=d=vector<int>(q);
  rep(i,q){
    cin >>a[i]>>b[i]>>c[i]>>d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
import math
N=int(input())

def get_circle_2p(p1,p2):
  x1,y1=p1
  x2,y2=p2
  
  x=(x1+x2)/2
  y=(y1+y2)/2  
  r=math.sqrt((x1-x2)**2+(y1-y2)**2)/2
  return x,y,r

def get_circle_3p(p1,p2,p3):
  x1,y1=p1
  x2,y2=p2
  x3,y3=p3
  d=2*((y1-y3)*(x1-x2)-(y1-y2)*(x1-x3))  
  
  if d==0:
    rad1=math.sqrt((x1-x2)**2+(y1-y2)**2)/2
    rad2=math.sqrt((x1-x3)**2+(y1-y3)**2)/2
    rad3=math.sqrt((x2-x3)**2+(y2-y3)**2)/2
    
    if rad1>=rad2 and rad1>=rad3:
      x=(x1+x2)/2
      y=(y1+y2)/2
      return x,y,rad1
    elif rad2>=rad1 and rad2>=rad3:
      x=(x1+x3)/2
      y=(y1+y3)/2
      return x,y,rad2
    elif rad3>=rad1 and rad3>=rad2:
      x=(x2+x3)/2
      y=(y2+y3)/2
      return x,y,rad3      
  else:
    x=((y1-y3)*(y1**2-y2**2+x1**2-x2**2)-(y1-y2)*(y1**2-y3**2+x1**2-x3**2))/d
    y=((x1-x3)*(x1**2-x2**2+y1**2-y2**2)-(x1-x2)*(x1**2-x3**2+y1**2-y3**2))/-d
    r=math.sqrt((x-x1)**2+(y-y1)**2)
    return x,y,r
  
xylist=[]
for i in range(N):
  xi,yi=map(int,input().split())
  xylist.append((xi,yi))
  
#print(xylist)

if N==2:
  x,y,r=get_circle_2p(xylist[0],xylist[1])
  print(r)
else:
  min_radius=float("inf")
  for i in range(N):
    for j in range(i+1,N):
      #print(xylist[i],xylist[j])
      x,y,r=get_circle_2p(xylist[i],xylist[j])
      #print(x,y,r)
      if r>min_radius:
        continue
      
      for l in range(N):
        if l==i or l==j:
          continue
          
        xl,yl=xylist[l]
        diff_xl=xl-x
        diff_yl=yl-y
        if math.sqrt(diff_xl**2+diff_yl**2)>r:
          break
      else:
        min_radius=r
  
  for i in range(N):
    for j in range(i+1,N):
      for k in range(j+1,N):
        #print(xylist[i],xylist[j],xylist[k])
        x,y,r=get_circle_3p(xylist[i],xylist[j],xylist[k])
        #print(x,y,r)
        if r>min_radius:
          continue
        
        for l in range(N):
          if l==i or l==j or l==k:
            continue
            
          xl,yl=xylist[l]
          diff_xl=xl-x
          diff_yl=yl-y
          if math.sqrt(diff_xl**2+diff_yl**2)>r:
            break
        else:
          min_radius=r
  
  print(min_radius)

Measured memory_bytes: 3192
#include <cstdio>
#include <cmath>
typedef long long ll;

ll n, k;

int main(){
	
	scanf("%lld", &n);
	k = (ll)sqrt(n);
	for(ll i = k; i >= 1; i--){
		if(n % i == 0){
			printf("%lld\n", i + n / i - 2);
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
using namespace std;

int main() {

	long A, B, C;
	cin >> A >> B >> C;

	long ans = B / A;
	if (ans > C) {
		cout << C << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
#define int ll
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

#ifdef RUS_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif

const double PI = 2 * acos(0.0);
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1>
inline istream & operator >> (istream &in, pair<T0, T1> &a) {
    return in >> a.first >> a.second;
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void smain();



signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
#ifdef RUS_HOME
    freopen("input", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\n\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

const int N=3010;

vvi dp(N,vi(N,-1));
vi a(N);

int lazy(int l, int r){
    if(dp[l][r]!=-1)
        return dp[l][r];
    return dp[l][r]=max(-lazy(l+1,r)+a[l],-lazy(l,r-1)+a[r]);
}

void smain() {
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        dp[i][i]=a[i];
    }

    cout<<lazy(0,n-1);



}


Measured memory_bytes: 71296
import itertools

n, k = list(map(int, input().split()))
ab = [[] for _ in range(n)]
for i in range(n):
    ab[i] = list(map(int, input().split()))
ab.sort(key=lambda x: x[0])
az, bz = list(zip(*ab))

accb = list(itertools.accumulate(bz))
idx = 0
for j, v in enumerate(accb):
    if k <= v:
        idx = j
        break
print(az[idx])


Measured memory_bytes: 35104
require 'prime'
N,M=gets.chomp.split(" ").map { |e| e.to_i }

a=M.prime_division

def comb(n,x)
  c = 1
  a = 1
  for i in 1..x do
    c *= n
    a *= i
    n = n-1
  end
  return c/a
end



def sum_prime_number(a,n)
  leng = a.length
  sum = 1
  for i in 0..leng-1  do
    sum *= comb(a[i][1]+n-1,a[i][1])
  end

return sum

end

sum = sum_prime_number(a,N)

puts sum % (10**9+7)

Measured memory_bytes: 2556
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N, K;
	cin >> N >> K;
	if((N + 1) / 2 >= K) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  k=I()
  d={}
  for x in l:
    if x in d:
      d[x]+=1
    else:
      d[x]=1

  sm=sum(l)

  ans=[]
  for _ in range(k):
    a,b=LI()
    if a in d:
      x=d[a]
      d[a]=0

      aa=a*x
      bb=b*x

      sm+=(bb-aa)
      ans.append(sm)

      if b in d:
        d[b]+=x
      else:
        d[b]=x

    else:
      ans.append(sm)

  for x in ans:
    print(x)

main()
# print(main())


Measured memory_bytes: 22272
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n'; cout << fixed << setprecision(10);
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
    cout<<(s[2] == s[3] && s[4] == s[5]?"Yes":"No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int a, b, c;
    cin>>a>>b>>c;
    cout<<a + b + c - max({a, b, c})<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL)
bool compare(pair<string,pair<int,int>>p,pair<string,pair<int,int>>pp)
{
	if(p.first<pp.first)
	 return true;
	else if(p.first>pp.first)
	  return false;
	 else 
	   return p.second.first>pp.second.first; 
}
int main() {
     string s;
     int n;
     int t;cin>>t;
	vector<pair<string,pair<int,int>>>v;
    f(i,0,t)
    {    
	cin>>s>>n;
	v.push_back(make_pair(s,make_pair(n,i)));	
	}
	sort(v.begin(),v.end(),compare);
	f(i,0,t)
	cout<<v[i].second.second+1<<"\n";
}



Measured memory_bytes: 256
import sys

ary=[]
ans=[]
def gcd(a,b):
    x=sorted([a,b])
    while x[1]%x[0]!=0:
        dif=x[1]%x[0]
        x[1]=x[0]
        x[0]=dif
    return x[0]
for i in sys.stdin:
    ary.append(list(map(int,i.split())))
    ans.append([gcd(*ary[-1]),int(ary[-1][0]*ary[-1][1]/gcd(*ary[-1]))])
for i in range(len(ans)):
    print('{0:d} {1:d}'.format(*ans[i]))

Measured memory_bytes: 7756
"use strict"
let input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.split('\n');
let N = input.shift();
let Nums = input[0].split(' ').map(x=> x*1);
let ans = Nums[0]+Nums[N-2];
for(let i = 0; i < N - 2; i++){
  ans += Math.min(Nums[i],Nums[i+1]);
}   
console.log(ans);

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

int calc(int n){
  int tes =0;
  while(n>0){
    tes += n%10;
    n /= 10;
  }
  return tes;
}

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  int sum = 0;
  for(int i=1; i<=n; i++){
    int che = calc(i);
    if(a<=che && che <=b){
      sum += i;
    }
  }
  cout << sum <<endl;
}


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

int main() {
	int X;
  	cin >> X;
  
  	if (X>=30) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
# n = int(raw_input())
# a = [int(raw_input()) for i in xrange(n)]
# print "".join(["a","b"])

# print "Yes" if 3 > 0 else "No"

li = list()

h, w = map(int, raw_input().split())

flag = False

def isField(i, j):
    if i >= 0 and j >= 0 and i < h and j < w:
        return True
    else:
        False

for i in xrange(h):
    a = list(raw_input())
    li.append(a)

for (i,hh) in enumerate(li):
    for (j,ww) in enumerate(hh):
        flag = False
        if ww == "#":
            if isField(i-1, j):
                if li[i-1][j] == "#": 
                    flag = True
            if isField(i, j-1):
                if li[i][j-1] == "#":
                    flag = True
            if isField(i+1, j):
                if li[i+1][j] == "#":
                    flag = True
            if isField(i, j+1):
                if li[i][j+1] == "#":
                    flag = True
            if flag == False:
                print "No"
                exit(0)
print "Yes"



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

int mod = 1000000007;

int main()
{
    string S;
    cin >> S;
    vector<int> list;
    for (int i = 0; i < 4; i++)
    {
        list.emplace_back(S[i] - '0');
    }

    for (int i = 0; i < (1 << 3); i++)
    {
        int ans = list[0];
        for (int j = 0; j < 3; j++)
        {
            if (i & (1 << j))
                ans += list[j + 1];
            else
                ans -= list[j + 1];
        }
        if (ans == 7)
     
        {
            cout << list[0];
            for (int j = 0; j < 3; j++)
                cout << (i & (1 << j) ? "+" : "-") << list[j + 1];
            cout << "=7";
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define gif(a,b) (a/b +(a%b?1:0))
#define pi 3.14159265358
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n";
#define float long double
using namespace std;

int32_t main()
{   
    cin.tie(NULL);
    std::ios::sync_with_stdio(false);
   	int n , sum = 0 ;
   	cin >> n;
    int m;
	cin >> m;
	int a[m];
	for(int i = 0; i < m; ++i)
	{
		cin >> a[i];
		sum += a[i];
	}
	if(n - sum >= 0)
   	cout << n - sum;
    else
   	cout << "-1";
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define N 200100
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
#define INF 100000000000000
#define pii pair<int,int>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(int x,int y){
    int res=1LL;
    while(y){
        if(y&1){
            res=(res*x)%MOD;
        }
        x=(x*x)%MOD;
        y=(y>>1);
    }
    return res;
}

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

    
    
    
    return 0;
}

Measured memory_bytes: 256
def main():
    N, A, B  = map(int, input().split())
    sum_v = 0
    for i in range(1, N+1):
        v = sum([int(s) for s in str(i)])
        if v >= A and v <= B:
            sum_v += i
    print(sum_v)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double 
ld dp[305][305][305];

ld find(ll x,ll y,ll z, ld n)
{
    if(x<0||y<0||z<0)
    return 0;
    else if(x==0&&y==0&&z==0)
    return 0;
    else if(dp[x][y][z]!=0)
    return dp[x][y][z];
    else
    {dp[x][y][z]=(x*find(x-1,y,z,n)+y*find(x+1,y-1,z,n)+z*find(x,y+1,z-1,n))/(x+y+z)+n/(x+y+z);
    return dp[x][y][z];}
}

int main() {
	ll n;
	cin>>n;
	ll a;
	ll x=0,y=0,z=0;
	
	for(ll i=0;i<n;i++)
	{
	   cin>>a;
	   if(a==1)
	   x++;
	   if(a==2)
	   y++;
	   if(a==3)
	   z++;
	}
	
	
	
	
	
	
    cout<<setprecision(10)<<find(x,y,z,n);
	

	
	

	
	return 0;
}


Measured memory_bytes: 436480
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n,m;
int c[20];
int dp[20010][256];
int main(){
	while(1){
		cin>>n>>m;
		if(n==0&&m==0)break;
		REP(i,20010)
			REP(j,256)
			dp[i][j]=1e8;
		REP(i,m)cin>>c[i];
		dp[0][128]=0;
		for(int i=1;i<=n;i++){
			int x;
			cin>>x;
			for(int j=0;j<=255;j++){
				for(int k=0;k<m;k++){
					if(dp[i-1][j]==1e8)continue;
					int nl=j+c[k];
					if(nl>255)nl=255;
					if(nl<0)nl=0;
					dp[i][nl]=min(dp[i-1][j]+(x-nl)*(x-nl),dp[i][nl]);
				}
			}
		}
		int ans=1e8;
		for(int i=0;i<256;i++){
			ans=min(ans,dp[n][i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 23000
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
map<int,int> m;
vector<int> v;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		if(m[x]==0)
		{
			m[x]=1;
			v.push_back(x);
		}
		else m[x]++;
	}
	int ans=0;
	for(int i=0;i<v.size();i++)
	{
		if(v[i]>m[v[i]]) ans+=m[v[i]];
		else ans+=m[v[i]]-v[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5112
n, k, *D = map(int, open(0).read().split())
D = list({0,1,2,3,4,5,6,7,8,9} - set(D))
N = list(map(int, str(n)))
d0 = D[0]

def dfs(M, i, f):
    if i == len(N):
        print(*M, sep='')
        exit()
    if f:
        dfs(M+[d0], i+1, 1)
    for d in D:
        if d == N[i]:
            dfs(M+[d], i+1, 0)
        elif d > N[i]:
            dfs(M+[d], i+1, 1)
            break
    if d0:
        dfs([d0], 0, 1)
    else:
        dfs([D[1]], 0, 1)
dfs([], 0, 0)

Measured memory_bytes: 9176
public class Main {

  private static void solve() {
    int k = ni();
    char[] s = ns();

    if (s.length <= k) {
      System.out.println(s);
    } else {
      System.out.println(new String(s, 0, k) + "...");
    }


  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 37160