akhauriyash/Code-Regression huggingface dataset:
bil_date = []
flag = 0
for i in range(4):
    bil_date.append([[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]])
all_date_amo = int(input())
for i in range(all_date_amo):
    date = [int(indate) for indate in input().split()]
    bil_date[date[0]-1][date[1]-1][date[2]-1] = bil_date[date[0]-1][date[1]-1][date[2]-1] + date[3]
    if bil_date[date[0]-1][date[1]-1][date[2]-1] < 0:
        bil_date[date[0]-1][date[1]-1][date[2]-1] = 0
    if bil_date[date[0]-1][date[1]-1][date[2]-1] > 9:
        bil_date[date[0]-1][date[1]-1][date[2]-1] = 9
        
for bil in bil_date:
    for flo in bil:
        for room in flo:
            print(' {}'.format(room),end='')
        print('')
    if flag == 3:
        pass
    else:
        for i in range(20):
            print('#',end='')
        print('')
    flag = flag + 1



Measured memory_bytes: 5636
#include<stdio.h>
#define max_n 10000010
int num[max_n]={0};
int prime_num[max_n]={0};
int snum[max_n]={0};
int main(){
	int n;
	scanf("%d",&n);
	for(int i=2;i<max_n;i++){
		if(num[i]==0){
	  		num[++num[0]]=i;
	  		snum[i] = 2;
	  		prime_num[i] = 1;
		}
		for(int j = 1; j <=num[0] ; j++){
				if(i * num[j] > max_n) break;
				num[i * num[j]]=1;
				if(i % num[j]==0){
					prime_num[i * num[j]]=prime_num[i] + 1;
					snum[i * num[j]] = snum[i] / (prime_num[i] + 1) * (prime_num[i] + 2);
					break;
				}else{
					snum[ i * num[j] ] = snum[i] * snum[num[j]];
					prime_num[ i * num[j] ] = 1;
				}
		}
	}
	long long ans=1;
	for(int i=1;i<=n;i++){
		ans+=1ll*i*snum[i];
	}
	printf("%lld\n",ans);
return 0;
}

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

int main(){
  int a, b, v, w, t;
  cin >> a >> v >> b >> w >> t;
  if((ll)abs(a-b) <= (ll)(v-w) * t) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 3636
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            char bk = ' ';
            int cnt = 1;
            for (int i = 0; i < s.length(); i++) {
                if (3 <= cnt) break;

                if (bk == s.charAt(i)) {
                    cnt++;
                } else {
                    cnt = 1;
                }
                bk = s.charAt(i);
            }

            System.out.println(3 <= cnt ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 21076
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

const int BITS_LEN = 62;

vector<ll> a;
vector<ll> sums;

void calc_sums(const ll N) {
    vector<ll> part_sums(N + 1, 0);
    for (int i = 0; i < N; i++) {
        part_sums[i + 1] = part_sums[i] + a[i];
    }

    int ind = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            sums[ind] = part_sums[j + 1] - part_sums[i];
            ind++;
        }
    }
}

int main(void) {
    ll N, K;
    cin >> N >> K;

    a.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    ll sums_len = N * (N + 1) / 2;
    sums.resize(sums_len);
    calc_sums(N);

    // for (int i = 0; i < sums_len; i++) {
    //     cout << sums[i] << endl;
    // }
    // // sort by descending order
    // sort(sums.begin(), sums.end(), [](const ll &a, const ll &b) {
    //         return a > b;
    //         });

    ll cur = 0;
    for (int i = 40; i >= 0; i--) {
        ll ncur = cur + (1LL << i);
        int ok = 0;
        for (int j = 0; j < (int) sums.size(); j++) {
            if ((ncur & sums[j]) == ncur) ok++;
        }
        if (ok >= K) cur = ncur;
    }

    cout << cur << endl;

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll N;
  cin >> N;
  vvl F(N,vl(10));
  rep(i,N){
    rep(j,10){
      cin >> F[i][j];
    }
  }
  vvl p(N,vl(11));
  rep(i,N){
    rep(j,11){
      cin >> p[i][j];
    }
  }
  ll ans=-INF;
  FOR(i,1,1<<10){
    vl cnt(N,0);
    rep(j,N){
      rep(k,10){
        if((i>>k)%2==1){
          cnt[j]+=F[j][k];
        }
      }
    }
    ll d=0;
    rep(j,N){
      d+=p[j][cnt[j]];
    }
    ans=max(ans,d);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
count = 0
for i in range(K,N+2):
  min_1 = i*(i-1)//2
  max_1 = (2*N-i+1)*i//2
  num = max_1-min_1+1
  count += num
print(count%(10**9+7))

Measured memory_bytes: 8960
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val aa = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    val ans = mutableListOf<Int>()

    while (aa.size > 0) {
        var rightMostIdx = -1

        for (i in 1..aa.size) {
            if (aa[i-1] == i) rightMostIdx = i-1
        }

        if (rightMostIdx == -1) {
            println(-1)
            return
        }

        ans.add(aa[rightMostIdx])
        aa.removeAt(rightMostIdx)
    }

    println(ans.reversed().joinToString(separator = "\n"))
}

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

int main() {
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; ++i) {
    cin >> T.at(i);
  }
  int M;
  cin >> M;
  vector<int> P(M);
  vector<int> X(M);
  for (int i = 0; i < M; ++i) {
    cin >> P.at(i) >> X.at(i);
  }
  for (int i = 0; i < M; ++i) {
    vector<int> T2 = T;
    T2.at(P.at(i) - 1) = X.at(i);
    int sum = accumulate(T2.begin(), T2.end(), 0);
    cout << sum << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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 gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// 自分より前に自分以上のものしかないiの数
// -> 1個前までの最小値をもつ

int main () {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n) cin >> p[i];
  
  int ans = 0;
  int mi = INF;
  rep(i,n) {
    if (mi >= p[i]) ans++;
    chmin(mi, p[i]);
  }

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

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int y = scn.nextInt();

		if (x >= y) {
			System.out.println(calculate(x, y));
		} else if (x < y) {
			System.out.println(calculate(y, x));
		}
	}

	private static int calculate(int a, int b) {
		int tempt;
		while ((tempt = a % b) != 0) {
			a = b;
			b = tempt;
		}
		return b;
	}
}



Measured memory_bytes: 26092
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;
//typedef long long unsigned int ll;
typedef long long ll;
typedef pair<ll, ll> edge;
//typedef tuple<ll, ll, ll> tp;
const ll INF = 1e18;
const ll mod = 1e9+7;

int main() {
  ll k, x;
  cin >> k >> x;
  for (int i=x-k+1;i<=x+k-1;i++){
    //if (−1000000<=i && i<=1000000)
    cout << i << " ";
  }
  cout << endl;
}

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

int main() {
    int n, q, S[100010], T[50010], C = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> S[i];
    cin >> q;
    for (int i = 0; i < q; ++i) cin >> T[i];

    for (int i = 0; i < q; ++i) {
        int a = 0, b = n - 1;
        while (a <= b) {
            int m = (a + b) / 2;
            if (T[i] == S[m]) {
                ++C;
                break;
            }
            else if (T[i] > S[m]) a = m + 1;
            else b = m - 1;
        }
    }

    cout << C << endl;
    
    return 0;
}


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

int grid1() {

    int n, m;
    cin >> n >> m;
    int dp[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            dp[i][j] = -1;

    string str;
    for (int i = 0; i < n; i++) {
        cin >> str;
        for (int j = 0; j < m; j++)
            if (str[j] == '#')
                dp[i][j] = 0;
    }

    if (dp[0][0] == 0) return 0;
    bool flag = false;
    for (int i = 1; i < n; i++) {
        if (dp[i][0] == 0)
            flag = true;
        if (flag) dp[i][0] = 0;
        else dp[i][0] = 1;
    }
    flag = false;
    for (int i = 1; i < m; i++) {
        if (dp[0][i] == 0)
            flag = true;
        if (flag) dp[0][i] = 0;
        else dp[0][i] = 1;
    }

    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            if (dp[i][j] != 0)
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
        }
    }

    return dp[n - 1][m - 1];

}

int32_t main()
{
    cout << grid1();
    return 0;
}


Measured memory_bytes: 8064
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N =sc.nextInt();
		BigDecimal result =new BigDecimal(1);
		String S = sc.next();
		int Rcount=0,Gcount=0,Bcount=0;
		for (int i=0;i<N;i++) {
			if (S.charAt(i)=='R') {
				Rcount++;
			} else if (S.charAt(i)=='G'){
				Gcount++;
			} else {
				Bcount++;
			}
		}
		result = result.multiply(new BigDecimal(Rcount));
		result = result.multiply(new BigDecimal(Gcount));
		result = result.multiply(new BigDecimal(Bcount));
		int count =0;
		for (int i=0;i<N;i++) {
			for (int j=1;j<=N/2;j++) {
				if (i+j*2>=N) {
					continue;
				}
				if (S.charAt(i)!=S.charAt(i+j)&&S.charAt(i+j)!=S.charAt(i+j+j)&&S.charAt(i+j+j)!=S.charAt(i)) {
					count --;
				}
			}
		}
		result = result.add(new BigDecimal(count));
		System.out.println(result.toString());
	}
}

Measured memory_bytes: 37736
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


int main() {
    ll h = 0, n = 0;
    cin >> h >> n;
    ll number = 0;
    ll res = 0;
    for(int i = 0; i < n; ++i){
        cin >> number;
        res+=number;
    }
    if(res >= h){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
} 


Measured memory_bytes: 256
def power(n,m):
    if m == 0:
        return 1
    if m % 2 == 0:
        return power(n*n%1000000007,m//2)
    else:
        return n * power(n,m-1) % 1000000007
        
n,m = map(int, input().split())
print(power(n,m))

Measured memory_bytes: 7720
num = input()
one_num = len(num) - 1
if (num[one_num] == "3"):
  print("bon")
elif (num[one_num] == "0" or num[one_num] == "1" or num[one_num] == "6" or num[one_num] == "8"):
  print("pon")
else:
  print("hon")

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;


int main() {
    int N;
    cin >> N;
    string S[N];
    rep(i,N) cin >> S[i];
    
    set<string> a;
    rep(i,N) a.insert(S[i]);

    cout << a.size();
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


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

bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}
double distance(double x1, double y1, double x2, double y2)
{
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    for (size_t i = 0; i < n; i++)
    {
        int b;
        cin >> b;
        if (i == 0)
        {
            a[i] = b;
        }
        else
        {
            a[i] = a[i - 1] + b;
        }
    }
    ll ans = INT64_MAX;
    for (size_t i = 0; i < n - 1; i++)
    {
        ll b = abs(a[n - 1] - a[i] * 2);
        ans = min(ans, b);

        /* code */
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int x,y;
    cin >> x >> y;
    string result = "No";
    for(int i = 0; i <= x; ++i)
    {
        for(int j = 0; j <= x; ++j)
        {
            if(i + j == x
            && 2*i+4*j == y)
            {
                result = "Yes";
            }
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
//const int MAX=;
const ll MOD=1e9+7;


int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	ll ct[26];
	rep(i,26)ct[i]=1;
	rep(i,N){
		int a=S[i]-'a';
		ct[a]++;
	}
	ll ans=1;
	rep(i,26)ans=(ans*ct[i])%MOD;
	ans--;
cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>

using namespace std;
typedef long long ll;

int N = 0;
int W = 0;

int main(){
    //ナップサック問題　荷物の価値を最大化
    cin >> N;
    cin >> W;

    vector<vector<ll> > T;
    //重量：価値
    T = vector<vector<ll> >(N + 1, vector<ll>(2, 0));
    //初期化
    T[0][0] = 0;
    T[0][1] = 0;

    for(int i = 1; i <= N; i++){
        for(int j = 0;  j < 2; j++){
            cin >> T[i][j];
        }
    }

    //dp
    vector<vector<ll> > dp;
    dp = vector<vector<ll> >(N + 1, vector<ll>(W + 1, -1));
    dp[0][0] = 0;

    //答え
    ll ans = 0;

    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= W; j++){
            if(dp[i - 1][j] > -1){
                //直下を更新
                if(dp[i][j] <= dp[i - 1][j]){
                    dp[i][j] = dp[i - 1][j];
                }
                //荷物を足し合わせたところを更新
                if(dp[i][j + T[i][0]] <= dp[i - 1][j] + T[i][1] && j + T[i][0] <= W){
                    dp[i][j + T[i][0]] = dp[i - 1][j] + T[i][1];
                    //ans確認
                    if(ans < dp[i - 1][j] + T[i][1]) ans = dp[i - 1][j] + T[i][1];
                }
            }          
        }

    }

    cout << ans << endl;

    //確認
    /*
    for(int i = 0; i < N + 1; i++){
        for(int j = 0; j < W + 1; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    

}

Measured memory_bytes: 80256
import sys, math, re
from functools import lru_cache
from collections import deque
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    S = input()
    if S[-1] == 's':
        print(S+'es')
    else:
        print(S+'s')

if __name__ == "__main__":
    main()

Measured memory_bytes: 9884
#include<bits/stdc++.h>
using namespace std;
int val[5];
int main()
{
for(int i=0;i<6;i++)
{
int data;
  cin>>data;
  val[data]++;
}
int flag=0;
  for(int i=1;i<=4;i++)if(val[i]==3)flag++;
if(flag)cout<<"NO";
  else cout<<"YES";
}

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

int main() {
  
  int N, A, M;
  cin >> N >> A;
  
  M = N % 500;
  
  if (M <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int H, W;
string S[55];
bool visit[55][55];
int dp[55][55];

int ans = INF;
/*==================================================*/
/*function*/

void dfs(int y, int x, int step){
    if(dp[y][x] <= step){
        return;
    }else{
        dp[y][x] = step;
    }

    if(y == H-1 && x == W-1){
        ans = min(ans, step);
        return;
    }

    REP(k,0,4){
        int ny = y + dy[k], nx = x + dx[k];
        if(CK(ny, 0, H) && CK(nx, 0, W)){
            if(S[ny][nx] == '#' || visit[ny][nx]) continue;
            visit[ny][nx] = true;
            dfs(ny, nx, step+1);
            visit[ny][nx] = false;
        }
    }

    return;
}

/*==================================================*/

int main() {
    cin>>H>>W;
    int bcnt = 0;
    REP(i,0,H){
        cin>>S[i];
        REP(j,0,W) if(S[i][j] == '#') bcnt++;
    }

    REP(i,0,H)REP(j,0,W) dp[i][j] = INF;
    visit[0][0] = true;
    dfs(0,0,1);

    if(ans == INF) cout<<-1<<endl;
    else cout<<H*W - ans - bcnt<<endl;

    return 0;
}


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

int main() {
  int n,ans = 0;
  cin >> n;
  vector<pair<int,int>> data(n);
  for(int i = 0;i < n;i++){
    cin >> data[i].first;
    data[i].second = 1;
  }
  if(n == 1 && data[0].first == 1){
    cout << 0 << endl;
    return 0;
  }
  sort(data.begin(),data.end());
  for(int i = 0;i < n;i++){
    if(i < n-1){
      if(data[i].first == data[i+1].first){
        data[i+1].second += data[i].second;
      }
      else{
        if(data[i].first > data[i].second) ans += data[i].second;
        else if(data[i].first < data[i].second) ans += data[i].second-data[i].first;
      }
    }
    else{
      if(data[i].first == data[i-1].first){
        if(data[i].first > data[i].second) ans += data[i].second;
        else if(data[i].first < data[i].second) ans += data[i].second-data[i].first;
      }
      else{
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], koware[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
pair<long long int, long long int>pairs[101],pointkaku[10000000];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a ;
	rep(i,a) {
		cin >> x >> y;
	
		pairs[i]=make_pair(x, y);
	}
	std::sort(pairs, pairs + a);
/*	sx = pairs[0].first;
	sy = pairs[0].second;
*/
	rep(i, a) {
		for (int j = i+1; j < a; j++) {
			pointkaku[counter] = make_pair( pairs[j].first-pairs[i].first, pairs[j].second-pairs[i].second);
			counter++;
		}
	}
	rep(i, counter) {
		z = 1;
		for (int j = i+1; j < counter; j++) {
			if (pointkaku[i] == pointkaku[j]) {
				z++;
			}
    }
		maxy = std::max(maxy, z);
}

	cout << a - (maxy+1)+1 << endl;
}


Measured memory_bytes: 2304
#include<stdio.h>
#include<string.h>
int main(){
    int i, r;
    char moji1[101] = {}, moji2[101] = {}, tmp1, tmp2, *a;

    scanf("%s%s", moji1, moji2);
    for( i = 0; i < strlen(moji1); i++ ){
        for( r = 0; r < strlen(moji1); r++ ){
            if( r == 0 ){
                tmp1 = moji1[r];
            }else if( r == strlen(moji1) - 1 ){
                moji1[r - 1] = moji1[r];
                moji1[r] = tmp1;
            }else{
                moji1[r - 1] = moji1[r];
                tmp2 = moji1[r];
            }
        }
        a = strstr( moji1, moji2 );
        if( a != NULL ){
            printf("Yes\n");
            break;
        }else if( i == strlen(moji1) - 1 ){
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n;cin>>n;
    ll s=1;
    while(s*2<n){
        s*=2;
    }
    rep(i,n){
        REP(j,i+1,n){
            ll k=s;
            ll cnt=1;
            while(i/k==j/k){
                k/=2;
                cnt++;
            }
            cout<<cnt<<' ';
        }
        cout<<endl;
    }
}

Measured memory_bytes: 512
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
const long long md=1e9+7;
long long n,dp[3030][3030],sum[3030],ans;
string s;
int main()
{
	cin>>n>>s;
	dp[1][1]=1;
	for(int i=2;i<=n;i++)
	{
		sum[0]=dp[i-1][0];
		for(int j=1;j<=n;j++)
		{
			sum[j]=sum[j-1]+dp[i-1][j];
			sum[j]%=md;
		}
		for(int j=1;j<=i;j++)
		{
			if(s[i-2]=='<')
			{
				dp[i][j]=sum[j-1];
			}
			else
			{
				dp[i][j]=(sum[i]-sum[j-1]+md)%md;
			}
		}
	}/*
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout<<dp[i][j]<<' ';
		}
		cout<<endl;
	}*/
	for(int i=1;i<=n;i++)
	{
		ans+=dp[n][i];
		ans%=md;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 70272
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<set>
#include<iomanip>
#include<algorithm>
using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  if(a!=2 && b!=2){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(void){
  int i,no,input;
  int prime[10000];
  int ptr=0,c=0;
  int flag=0;
  int last;
  
  while(cin>>input){
    flag=ptr=c=0;
    prime[ptr++]=2;
    prime[ptr++]=3;
    for(no=5;;no+=2){
      if(flag==2){break;}
      if(input+1<=no){flag=1;c++;}
      if(c==1){if(input==prime[ptr-1])last =ptr-2;else last=ptr-1;}
      for(i=1;i<ptr;i++){
	if(no%prime[i]==0)break;
      }
      if(ptr==i){
	prime[ptr++]=no;
	if(flag==1){flag=2;}
      }
    }
    
    printf("%d %d\n",prime[last],prime[ptr-1]);
  }
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <string>
#include <cstring>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
#include <tuple>

using namespace std;
mt19937_64 rng(58);
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = ""; for (const auto &x : v) { if (!first) res += ", "; first = false; res += to_string(x); } return "{" + res + "}"; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    long long n, k;
    cin >> n >> k;
    cout << min(n % k, (k - (n % k))) << endl;
}

Measured memory_bytes: 888
//In The Name Of GOD

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 2*1001+1;

#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);

int main(){
	int n;
	cin >> n;
	const int m = n;
	pair<int,int> A[m];
	int where[m];
	for(int i=0;i<m;i++){
		cin>>A[i].X;
		A[i].Y=i;
	}
	sort(A,A+m);
	for(int i=0;i<n;i++){
		where[ A[i].Y ] = i;
	}
	int l = A[n/2-1].X, r = A[n/2].X;
	for(int i=0;i<n;i++){
		if(where[i]<n/2){
			cout << r << endl;
		}else{
			cout << l << endl;
		}
	}



}

Measured memory_bytes: 4480
//   __      __       .__           .____________                   __________        __ ________   __                 
//  /  \    /  \ ____ |_________  __| _\______   \__ __  ____  _____\______   \__ ___/  |\_____  \ |  | ______  ___.__.
//  \   \/\/   _/ __ \|  \_  __ \/ __ | |    |  _|  |  \/ ___\/  ___/|    |  _|  |  \   __/   |   \|  |/ \__  \<   |  |
//   \        /\  ___/|  ||  | \/ /_/ | |    |   |  |  / /_/  \___ \ |    |   |  |  /|  |/    |    |    < / __ \\___  |
//    \__/\  /  \___  |__||__|  \____ | |______  |____/\___  /____  >|______  |____/ |__|\_______  |__|_ (____  / ____|
//         \/       \/               \/        \/     /_____/     \/        \/                   \/     \/    \/\/     

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

using namespace std;

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector <ll> e[n + 1];
    ll par[n + 1], dis[n + 1];
    for(ll i = 0; i < m; i++)
    {
        ll u, v;
        cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }
    for(ll i = 1; i <= n; i++)
        dis[i] = 1e18;
    dis[1] = 0;
    queue <ll> bfs;
    bfs.push(1);
    while(!bfs.empty())
    {
        ll x = bfs.front();
        bfs.pop();
        for(auto v : e[x])
            if(dis[v] > dis[x] + 1)
            {
                dis[v] = dis[x] + 1;
                par[v] = x;
                bfs.push(v);
            }
    }
    cout << "Yes" << endl;
    for(ll i = 2; i <= n; i++)
        cout << par[i] << endl;
}

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q = 1;
	//cin >> q;
	for(int i = 1; i <= q; i++)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 13740
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,k;
	cin>>n>>k;
	ll ans=0;
	REP(i,k,n+2){
		ans=(ans+(ll)(n*2+1-i)*i/2-(ll)(i-1)*i/2+1)%1000000007;
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3636
N = readline.to_i

points = N.times.map do |i|
  readline.split.map(&:to_i)
end

def calc_ch(p, cx, cy)
  (cx-p[0]).abs + (cy-p[1]).abs + p[2]
end

if N==1
  puts points[0].join(' ')
else
  positives = points.select {|x|x[2]>0}
  cand = []
  101.times do |cx|
    101.times do |cy|
      h1 = calc_ch(positives[0], cx, cy)
      cand << [cx,cy,h1]
    end
  end
  positives[1..-1].each do |point|
    cand.select! {|c| c[2] == calc_ch(point, c[0], c[1]) }
  end
  zeros = points.select {|x| x[2] == 0}
  zeros.each do |point|
    cand.select! {|c| c[2] <= calc_ch(point,c[0],c[1])}
  end
  puts cand[0].join(' ')
end



Measured memory_bytes: 2300
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<stack>
#include<vector>
#include<map> 
#define maxn 100005
#define INF 1000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll x,y,a,b,c,arr[maxn],brr[maxn],crr[maxn],rec[maxn],cnt[5];

ll ans=0;

int main()
{
	cin>>x>>y>>a>>b>>c;
	for(int i=1;i<=a;i++)
	{
		scanf("%d",arr+i);
	}
	sort(arr+1,arr+a+1);
	for(int i=1;i<=b;i++)
	{
		scanf("%d",brr+i);
	}
	sort(brr+1,brr+b+1);
	for(int i=1;i<=c;i++)
	{
		scanf("%d",crr+i);
	}
	sort(crr+1,crr+c+1);
	cnt[1]=a;
	cnt[2]=b;
	cnt[3]=c;
	cnt[4]=1;
	for(int i=1;i<=x+y;i++)
	{
		if(cnt[1]==(a-x))
		{
			ll tmp;
			if(brr[cnt[2]]>=crr[cnt[3]])
			{
				tmp=brr[cnt[2]];
				cnt[2]--;
			}else{
				tmp=crr[cnt[3]--];
			}
			ans+=tmp;
			//printf("\n%d ",ans);
		}else if(cnt[2]==(b-y))
		{
			ll tmp;
			if(arr[cnt[1]]>=crr[cnt[3]])
			{
				tmp=arr[cnt[1]];
				cnt[1]--;
			}else{
				tmp=crr[cnt[3]--];
			}
			ans+=tmp;
			//printf("\n%d ",ans);
		}else{
			ll tmp;
			ll fl;
			if(arr[cnt[1]]>brr[cnt[2]])
			{
				tmp=arr[cnt[1]];
				fl=1;
			}else if(arr[cnt[1]]==brr[cnt[2]]){
				if(arr[cnt[1]-1]>=brr[cnt[2]-1])
				{
					fl=1;
					tmp=arr[cnt[1]];
				}else{
					fl=2;
					tmp=brr[cnt[2]];
				}
			}else{
				fl=2;
				tmp=brr[cnt[2]];
			}
			if(crr[cnt[3]]>tmp)
			{
				fl=3;
				tmp=crr[cnt[3]];
			}
			cnt[fl]--;
			ans+=tmp;
			//printf("\n%d ",ans);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<int> t(d+1,0);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  rep1(i,d)cin>>t[i];
  int res=calc(t,last_list);
  int m;cin>>m;
  vector<int> bres(m);
  rep(i,m){
    int d,q;cin>>d>>q;
    bres[i]=change(d,q,res,t,last_list);
  }
  rep(i,m){
    cout<<bres[i]<<"\n";
  }
  //cout<<calc(t)<<"\n";
  return 0;
}


Measured memory_bytes: 4144
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <utility>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

#define all(a) (a).begin(),(a).end()
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
// #define in(v) if (scanf("%d", &v)<1);
// #define out(v) printf("%d\n", v)
const int MOD = 1e9+7;
const int INF = numeric_limits<int>::max();
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Iterator>void print(const Iterator &s, const Iterator &t) { for(auto it=s;it+1!=t;++it)cout<<*it<<" ";cout<<*(t-1)<<"\n"; }
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; in(N);
  int sum = 1;
  int k = 1;
  while (sum < N) {
    ++k;
    sum += k;
  }
  vi v;
  rrep(i, k) {
    if (N - i >= 0) {
      v.push_back(i);
      N -= i;
    }
    if (N == 0)
      break;
  }
  reverse(all(v));
  iter(it, v) out(*it);

  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String input = sc.nextLine();
        String[] inputs = input.split(" ");
        int a = Integer.valueOf(inputs[0]);
        int b = Integer.valueOf(inputs[1]);
        int k = Integer.valueOf(inputs[2]);
        int totalBet = b-a+1;
        if( totalBet<=2*k) {
            printAll(a,b);
            return;
        }
        printKSmallest(a,k);
        printKLargest(b,k);

    }

    private static void printAll(int a, int b) {
        for(int i = a; i<=b ; i++) {
            System.out.println(i);
        }
    }

    private static void printKSmallest(int a, int k) {
        for( int i = a; i<a+k; i++ ) {
            System.out.println(i);
        }
    }

    private static void printKLargest(int b,int k) {
        for ( int i = b - k +1; i<=b ; i++) {
            System.out.println(i);
        }
    }

}


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

int main() {
  int N,K;
  int sum=0;
  cin >> N;
  cin >> K;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    if(K-x<x){
      sum+=(K-x)*2;
    }else{
      sum+=x*2;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

vector<vector<char>> table(22,vector<char>(22,'#'));
vector<vector<int>> dist(22,vector<int>(22,0));
vector<vector<bool>> seen(22,vector<bool>(22,0));
int h,w;

void init_seen(){
  rep1(i,h) rep1(j,w) seen[i][j] = 0;
}

void init_dist(){
  rep1(i,h) rep1(j,w) dist[i][j] = 0;
}

int main(){
  cin >> h >> w;
  rep1(i,h) rep1(j,w) cin >> table[i][j];
  
  int ans = 0;
  rep1(i,h){
    rep1(j,w){
      
  init_dist();
  init_seen();
  queue<pair<int,int>> q;
  pair<int,int> p = make_pair(i,j);
  q.push(p);
  while(!q.empty()){
    int a = q.front().first;
    int b = q.front().second;
    q.pop();
    if(seen[a][b]) continue;
    seen[a][b] = 1;
    if(a<1 || a>h) continue;
    if(b<1 || b>w) continue;
    if(table[a][b] == '#') continue;
    if(table[a+1][b] == '.' && !seen[a+1][b]){
      dist[a+1][b] = dist[a][b]+1;
      pair<int,int> next = make_pair(a+1,b);
      q.push(next);
    }
    if(table[a-1][b] == '.' && !seen[a-1][b]){
      dist[a-1][b] = dist[a][b]+1;
      pair<int,int> next = make_pair(a-1,b);
      q.push(next);
    }
    if(table[a][b+1] == '.' && !seen[a][b+1]){
      dist[a][b+1] = dist[a][b]+1;
      pair<int,int> next = make_pair(a,b+1);
      q.push(next);
    }
    if(table[a][b-1] == '.' && !seen[a][b-1]){
      dist[a][b-1] = dist[a][b]+1;
      pair<int,int> next = make_pair(a,b-1);
      q.push(next);
    }
  }
  int tmp = 0;
  rep1(i,h)rep1(j,w) tmp = max(tmp,dist[i][j]);
  ans = max(ans,tmp);
      
    }
  }
  cout << ans << endl;
}

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

int a[10000];

int judge(int n)
{
    int i,a=1;
    for(i=2;i<sqrt(n)+1;i++)
        if(n%i==0 &&n!=2) a=0;
    return a;
}

int main()
{
    int i,n,count;
    
    while(~scanf("%d",&n))
    {
        count = 0;
        while(n--) scanf("%d",&a[count++]);
        int ans=0;
        for(i=0;i<count;i++) if(judge(a[i])) ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n, k; scanf("%d %d", &n, &k); std::vector<i64> a(n);
	for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
	
	std::vector<i64> vec;
	for(int i = 0; i < n; i++) {
		i64 sum = 0;
		for(int j = i; j < n; j++) {
			sum += a[j];
			
			vec.push_back(sum);
		}
	}
	assert(vec.size() == n * (n + 1) / 2);
	
	i64 ans = 0;
	std::vector<i64> A, B;
	for(int j = 59; j >= 0; j--) {
		for(auto v : vec) {
			if(v >> j & 1) A.push_back(v);
			else B.push_back(v);
		}
		if(A.size() >= k) {
			vec.swap(A);
			ans |= 1LL << j;
		}
		A.clear();
		B.clear();
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11504
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int S, h, m, s;
	scanf("%d", &S);

	h = S/(60*60);
	m = (S-h*60*60)/60;
	s = S-h*60*60-m*60;

	printf("%d:%d:%d\n", h, m, s);

	return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

struct mint{
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a){
    (x += a.x) %= mod;
    return *this;
  }
  mint& operator-=(const mint a){
    (x -= mod-a.x) %= mod;
    return *this;
  }
  mint& operator*=(const mint a){
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

};

mint c[4005][4005];


void init(){
  c[0][0] = 1;
  for(int i = 0;i <= 4000;i++){
    for(int j = 0;j <= i;j++){
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}

mint comb(int n,int k){
  return c[n][k];
}

mint f2(int n,int k){
  return comb(n+k-1,k-1);
}
mint f(int n,int k){
  if(n < k)return 0;
  if(n == 0 && k == 0)return 1;
  if(k < 1)return 0;
  return f2(n-k,k);
}

int main(){
  init();
  int n,k; cin >> n >> k;
  for(int i = 1;i <= k;i++){
    mint blue = f(k,i);
    mint red = 0;
    {
      red += f(n-k,i-1);
      red += f(n-k,i);
      red += f(n-k,i);
      red += f(n-k,i+1);
    }
    mint ans = blue*red;
    printf("%lld\n",ans.x);
  }
}


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

typedef long long int ll;
ll MOD = 1000000007;

// ====================================================================

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n + 1);
  for (int i = 0; i < n; i++) cin >> v[i + 1];

  ll dp[n + 1][k + 1] = {};  // i番目(1-index)までの人に合計j個渡す組み合わせの数のMOD
  dp[0][0] = 1;

  for (int i = 1; i <= n; i++) {
    ll rui[k + 2] = {};  // 一つ前の累積をとる
    for (int j = 0; j <= k + 1; j++)
      rui[j + 1] = (rui[j] + dp[i - 1][j]) % MOD;
    for (int j = 0; j <= k; j++)
      dp[i][j] = (rui[j + 1] - rui[max(0ll, j - v[i])] + MOD) % MOD;
  }

  cout << dp[n][k] % MOD << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

int getKeta(int n){
    int ret = 0;
    while(n > 0){
        n /= 10;
        ret++;
    }
    return ret;
}

int main() {
    ll K, X;
    cin >> K >> X;

    for(ll i = X - K + 1; i <= X + K - 1; i++){
        cout << (i == X - K + 1 ? "" : " ") << i;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long K = scn.nextLong();
		long A = scn.nextLong();
		long B = scn.nextLong();
		long ans = 1;
		if(B < A+2) {
			ans = K+1;
		}else {
			if(K <A+1) {
				ans = K+1;
			}else {
				ans = A;
				K -= A-1;
				while(K >= 2) {
					K-=2;
					ans += B-A;
				}
				ans += K;
			}
		}



		System.out.println(ans);
	}

}


Measured memory_bytes: 24916
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>

using namespace std;

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

int main()
{
  int K, A, B;
  cin >> K >> A >> B;
  if ((A - 1) / K - B / K + 1 > 0)
  {
    cout << "NG" << endl;
  }
  else
  {
    cout << "OK" << endl;
  }
}


Measured memory_bytes: 3632
# int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# [int(i) for i in input().split()] # 配列で数字
k = int(input())
s = input()

if len(s) <= k:
    print(s)
else:
    print(s[:k] + '...')

Measured memory_bytes: 9160
inf = 10**9
n, m, x = map(int, input().split())
a = [0] * n
c = [0] * n
y = [0] * n
for i in range(n):
    data = list(map(int, input().split()))
    c[i] = data[0]
    a[i] = data[1:]
ans = inf
for i in range(2**n):
    lis = [0]*n
    k = i
    money = 0
    know = [0] * m
    for j in range(n):
        if (k >> j) & 1:
            money += c[j]
            for l in range(m):
                know[l] += a[j][l]
    for z in know:
        if z < x:
            break
    else:
        ans = min(ans, money)

if ans == inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 68432