akhauriyash/Code-Regression huggingface dataset:
///spaesk

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define pi acos(-1)
#define int long long int
#define ld long double
#define ar array
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

typedef vector<vector<int> > matrix ;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const int ths = 1LL << 40;
const int NN = 5e3 + 6;

const int maxN = 1003;

///
///

void solve()
{

    int n, m, k;
    cin>>n>>m>>k;
    int a[n] = {}, b[m] = {};
    for(int i = 0; i < n; i ++) {
        cin>>a[i];
        if(i != 0)
            a[i] += a[i - 1];
    }
    for(int i = 0; i < m; i ++) {
        cin>>b[i];
        if(i != 0)
            b[i] += b[i - 1];
    }

    int ans = 0;

    for(int i = 0; i < n; i ++) {
        if(a[i] <= k)
            ans = max(ans, i + 1);
        else
            break ;
        int id = lower_bound(b, b + m, k - a[i] + 1) - b;
        ans = max(ans, id + i + 1);
    }
    for(int i = 0; i < m; i ++) {
        if(b[i] <= k)
            ans = max(ans, i + 1);
    }
    cout<<ans;

    cout<<"\n";
    return ;
}

/*
*/

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n, x; cin>>n>>x;
    vector<int> m(n);
    int mmin=1e9;
    for(int i=0; i<n; i++){
        cin>>m[i];
        x-=m[i];
        mmin=min(mmin, m[i]);
    }
    cout << n+x/mmin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  b = a;
  ll sum1, sum2; sum1 = sum2 = 0;
  int i = 0;
  while (1) {
    int t;
    if (a[i] <= 0) {
      t = -a[i]+1;
      sum1 += t;
      a[i] = 1;
    }
    if (i < n-1) a[i+1] += a[i];
    i++;
    if (i == n) break;
    if (a[i] >= 0) {
      t = a[i]+1;
      sum1 += t;
      a[i] = -1;
    }
    if (i < n-1) a[i+1] += a[i];
    i++;
    if (i == n) break;
  }
  i = 0;
  while (1) {
    int t;
    if (b[i] >= 0) {
      t = b[i]+1;
      sum2 += t;
      b[i] = -1;
    }
    if (i < n-1) b[i+1] += b[i];
    i++;
    if (i == n) break;
    if (b[i] <= 0) {
      t = -b[i]+1;
      sum2 += t;
      b[i] = 1;
    }
    if (i < n-1) b[i+1] += b[i];
    i++;
    if (i == n) break;
  }
  dump(min(sum1, sum2));
  return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main{
	public static int count = 0;
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] node = new int[n];
		int[] k = new int[n];
		int[] parent = new int[n];
		int[] depth = new int[n];
		StringBuilder[] c = new StringBuilder[n];
		int sum = 0;
		int[][] childnode = new int[n][];

		for (int i = 0; i<n ;  i++) {
			String[] line = (br.readLine()).split(" ");
			int index = Integer.parseInt(line[0]);
			node[index] = index;
			k[index] = Integer.parseInt(line[1]);
			childnode[index] = new int[k[index]];
			c[index] = new StringBuilder();
			sum = sum + i;
			if (k[index] == 0) {
				continue;
			}else{
				for (int j = 2; j < (k[index]+2) ; j++) {
					childnode[index][j-2] = Integer.parseInt(line[j]);
					sum -= childnode[index][j-2];
					if (j==2) {
						c[index].append(childnode[index][j-2]);
					}else{
						c[index].append(", ").append(childnode[index][j-2]);
					}
				}
			}

		}

		for (int i = 0 ; i<n ; i++ ) {
			if (sum == node[i]) {

				parent[i] = -1;
				for (int j = 0; j<childnode[i].length ; j++ ) {
					parentdepthset(node,parent,depth,childnode,node[i],childnode[i][j]);
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i<n ; i++ ) {
			sb.append("node ").append(node[i]).append(": ");
			sb.append("parent = ").append(parent[i]).append(", ");
			sb.append("depth = ").append(depth[i]).append(", ");
			sb.append(root(parent[i],c[i]));
			sb.append(", [" + c[i] + "]\n");


		}

		System.out.print(sb);
	}






	public static void parentdepthset(int[] node,int[] parent,int[] depth,int[][] childnode,int parentnode,int child){
		for (int i = 0; i<node.length ; i++ ) {
			if (node[i] == child) {
				parent[i] = parentnode;
				depth[i] = (depth[parentnode]+1);
				if (childnode[i].length > 0) {
					for (int j = 0; j<childnode[i].length ; j++ ) {
						parentdepthset(node,parent,depth,childnode,node[i],childnode[i][j]);
					}
				}
			}

		}


	}
	public static String root(int parent,StringBuilder c){
		if (parent == -1) {
			return "root";
		}else if (c.length() == 0) {
			return "leaf";
		}else{
			return "internal node";
		}
	}


	public static StringBuilder toStringBuilder(int[] a){
		StringBuilder sb = new StringBuilder();
		sb.append(a[0]);
		for (int i = 1; i<a.length ; i++ ) {
			sb.append(" ").append(a[i]);
		}

		return sb;
	}

	public static void countingSort(int[] a,int[] b,int max){
		int[] c = new int[max+1];

		for (int j = 0; j<a.length ; j++ ) {
			c[a[j]]++;
		}

		for (int i = 1; i<=max ; i++ ) {
			c[i] = c[i] + c[i-1];
		}

		for (int j = a.length-1; j>=0 ; j-- ) {
			b[c[a[j]]-1] = a[j];
			c[a[j]]--;
		}


	}
}

Measured memory_bytes: 107512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    queue<long long> x ;
    for(int i = 1; i< 10; i++)
        x.push(i);
    int k;
    cin >> k;
    for(int i = 0; i< k; i++)
    {
        long long tmp = x.front();
        x.pop();
        if(tmp%10)
            x.push(10*tmp+(tmp%10) - 1);
        x.push(10*tmp + tmp%10);
        if(tmp%10 != 9)
            x.push(tmp*10 + tmp%10 + 1);
            if(i==k-1)
                cout << tmp << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	int len_parity = s.length() % 2;
	int last_parity = (s.front() == s.back() ? 1 : 0);
	cout << (last_parity == len_parity ? "Second" : "First") << endl;
	return 0;
}

Measured memory_bytes: 512
a=Array.new(1000000,false)
s=gets.to_i
cnt=0
while true
	cnt+=1
	a[s-1]=true
	s=(s.even?)?(s/2):(3*s+1)
	if a[s-1]==true
		break
	end
	a[s-1]=true
end
puts cnt+1


Measured memory_bytes: 9596
def main
  n = gets.to_i
  a = gets.split("\s").map(&:to_i).select { |i| i % 2 == 0 }

  a.each do |i|
    if i % 3 != 0 && i % 5 != 0
      return 'DENIED'
    end
  end
  return 'APPROVED'
end

print main

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

#define pb push_back
#define ll long long
#define inf 1e9


using namespace std;


int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, k;
	cin>>n>>k;
	int a[n+1];

	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
	}

	long long dp[n+1];

	dp[n] = 0;
	for (int i = n-1; i >=1 ; --i)
	{
		dp[i] = inf;
	}

	for (int i = n-1; i >= 1; --i)
	{
		for (int j = i+1; j <= min(n, i+k); ++j)
		{
			dp[i] = min(dp[i], abs(a[j] - a[i]) + dp[j]);
		}
	}

	// long long nax = -1;
	// for (int i = 0; i < 3; ++i)
	// {
	// 	nax = max(nax, dp[n-1][i]);
	// }
	
	printf("%lld\n", dp[1]);
}




Measured memory_bytes: 1408
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int A, B, C;
    cin >> A >> B >> C;

    cout << max(C - (A-B),  0) << endl;

    return 0;
}

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

int main(){
    vector<int> x(5);
    int result;

    rep(i, 5){
        cin >> x.at(i);
    }
    rep(i,5){
        if(x.at(i) == 0){
            result = i + 1;
            break;
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=1e7+5;
const int mod=1e9+7;
int f[maxn];



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	for(int i=1;i<maxn;i++)
    {
        for(int j=i;j<maxn;j+=i)
        {
            f[j]++;
        }
    }
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=1ll*f[i]*i;
    }
    cout<<sum<<'\n';



}


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

vector<pair<int,int> > matrices;
vector<vector<int> > memoization;

int minCost(int i, int j) {
  if (j == i)
    return 0;
  if (memoization[i][j])
    return memoization[i][j];
  int current_min = INT_MAX;
  for (int k = i; k < j; k++) {
    int current_cost =
      matrices[i].first *
      matrices[k].second *
      matrices[j].second +
      minCost(i, k) + minCost(k+1, j);
    if (current_cost < current_min)
      current_min = current_cost;
  }
  memoization[i][j] = current_min;
  return memoization[i][j];
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  matrices = vector<pair<int,int> > (n, pair<int,int>(0,0));
  memoization = vector<vector<int> > (n, vector<int> (n, 0));
  for (int i = 0; i < n; i++)
    cin >> matrices[i].first >> matrices[i].second;
  cout << minCost(0, n-1) << endl;
  return 0;
}



Measured memory_bytes: 3264
#include <stdio.h>

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

Measured memory_bytes: 584
#include <bits/stdc++.h>  // ver1.9.5
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int n;
  cin >> n;
  
  Vi a(3*n);
  rep(i,0,3*n) cin >> a[i];
  int ans = 0;
  sort(ALL(a));
  reverse(ALL(a));
  rep(i,0,n){
    ans += a[2*i+1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main(){
  int n,m,sum=0,key,T[10001];
  int i,j,f=1;

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

  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d",&key);
    //LinearSearch                                                                                                                                          
    j=0;
    while(T[j] != key){
      if(j==n){
        f=0;
        break;
      }
      j++;
    }
    if(f)sum++;
    f=1;
  }

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

  return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

N,K = map(int, input().split())
a = list(map(int, input().split()))
cnt_d = defaultdict(lambda: 0)
for ai in a:
    cnt_d[ai] += 1

cnt_v = sorted([v for k,v in cnt_d.items()])
print(sum(cnt_v[:-K]))


Measured memory_bytes: 32540
#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() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans = -100100100;
    ans = max(a*c,b*d);
    ans = max(ans,a*d);
    ans = max(ans,b*c); 
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <algorithm>
using namespace std;
#define N (1010)
int n, a[N];
typedef long long LL;
int ans[N];
int allneg(){
    for (int i=1; i <= n; ++i){
        if (a[i] > 0){
            return 0;
        }
    }
    return 1;
}
int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", a+i);
    }
    if (allneg()){
        int pos = 1;
        for (int i = 2; i <= n; ++i){
            if (a[i] > a[pos]){
                pos = i;
            }
        }
        printf("%d\n%d\n", a[pos], n-1);
        for (int i = n; i > pos; --i) printf("%d\n", i);
        for (int i = 1; i < pos; ++i) printf("1\n");
        return 0;
    }
    LL s1 = 0, s2 = 0;
    for (int i = 1; i <= n; i += 2){
        s1 += max(0, a[i]);
        s2 += max(0, a[i+1]);
    }
    int x = s1 > s2 ? 1 : 2, lst = 0, cnt = 0, le = 0;
    for (; x <= n; x += 2){
        if (a[x] > 0){
            if (lst == 0){
                for (int i = 1; i < x; ++i){
                    ans[cnt++] = 1;
                }
                le = 1;
            }
            else {
                int len = x-lst>> 1, mid = le+(len);
                for (int i = 1; i <= len; ++i, mid--){
                    ans[cnt++] = mid;
                }
            }
            lst = x;
        }
    }
    for (int i = n; i > lst; --i){
        ans[cnt++] = le+i-lst;
    }
    printf("%lld\n%d\n", max(s1,s2), cnt);
    for (int i = 0; i < cnt; ++i){
        printf("%d\n", ans[i]);
    }
}

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

using namespace std;

int main() {
    int n;
    string str;
    cin >> n >> str;
    if (n < str.size()) {
        for (int i = 0; i < n; i++) {
            cout << str[i];
        }
        cout << "..." << endl;
    } else {
        cout << str << endl;
    }
    return 0;
}

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

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

  vector<int> l(N);
  vector<int> r(N);

  int sum = 0;

  for(int i = 0; i < N; i++){
    cin >> l.at(i) >> r.at(i);
  }

  for(int i = 0; i < N; i++){
    sum += (r.at(i)-l.at(i)+1);
  }

  cout << sum << endl;



}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;


void func(int X,int Y, int W,int H){
	int left,right,bottom,ceil,num_cat;

	if(W < 0){
		left = X + W;
		right = X;
	}else{
		left = X;
		right = X + W;
	}
	if(H < 0){
		bottom = Y + H;
		ceil = Y;
	}else{
		bottom = Y;
		ceil = Y + H;
	}

	int count = 0,x,y;
	scanf("%d",&num_cat);

	for(int i = 0; i < num_cat; i++){
		scanf("%d %d",&x,&y);
		if(x >= left && x <= right && y >= bottom && y <= ceil)count++;
	}
	printf("%d\n",count);
}


int main(){

	int n,X,Y,W,H;

	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d",&X,&Y,&W,&H);

		func(X,Y,W,H);
	}


    return 0;
}

Measured memory_bytes: 2668
#include<cstdio>
#include<algorithm>
using namespace std;
int Solve(int n)
{
	int ret=0;
	while(n)
	{
		ret+=n%10;
		n/=10;
	}
	return ret;
}
int main()
{
	int n;
	int ans=1000000;
	scanf("%d",&n);
	for(int i=1;i<=n/2;i++)
	{
		int j=n-i;
		ans=min(ans,Solve(i)+Solve(j));
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int modP = 1000000007;

	static int[] mx = {-1,-1,-1,0,0,1,1,1};
	static int[] my = {-1,0,1,-1,1,-1,0,1};


	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int h = in.nextInt(), w = in.nextInt();
			char[][] map = new char[h][w];
			for (int i = 0; i < h; i++) {
				map[i] = in.nextString().toCharArray();
			}

			for (int ny = 0; ny < h; ny++) {
				for (int nx = 0; nx < w; nx++) {
					if (map[ny][nx] == '#') {
						continue;
					}
					int count = 0;
					for (int i = 0; i < 8; i++) {
						int ty = ny + my[i];
						int tx = nx + mx[i];
						if (ty < 0 || tx < 0 || ty >= h || tx >= w) {
							continue;
						}
						if (map[ty][tx] == '#') {
							count++;
						}
					}
					map[ny][nx] = (char) count;
				}
			}

			StringBuffer sb = new StringBuffer();
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (map[i][j] != '#') {
						sb.append((int)map[i][j]);
					} else {
						sb.append(map[i][j]);
					}
				}
				sb.append("\n");
			}

			out.print(sb.toString());

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21460
//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<int> inp;
int main(){
	int n;cin>>n;
	inp.resize(n);
	REP(i,0,n-1){cin>>inp[i];}
	std::vector<int> dp(n,0);
	if(n==1){cout<<0<<"\n";return 0;}
	dp[0]=0;dp[1]=MOD(inp[1]-inp[0]);
	for(int i=2;i<n;++i)
	{
		dp[i]=MIN((MOD(inp[i]-inp[i-1])+dp[i-1]),(MOD(inp[i]-inp[i-2])+dp[i-2]));
	}
	cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int H, W;
  cin >> H >> W;
  char field[50][50];
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      cin >> field[i][j];
    }
  }
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      if (field[i][j] == '.')
      {
        int count = 0;
        for (int k = -1; k < 2; ++k)
        {
          for (int l = -1; l < 2; ++l)
          {
            if (0 <= i + k && i + k < H && 0 <= j + l && j + l < W && field[i + k][j + l] == '#')
            {
              count++;
            }
          }
        }
        field[i][j] = '0' + count;
      }
    }
  }
  for (int i = 0; i < H; ++i)
  {
    for (int j = 0; j < W; ++j)
    {
      cout << field[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
using namespace std;

int main() {
	int j = 0, n;
	ll ans = 0, cou = 1;
	string s;
	cin >> n;
	vector<string> v(n);
	FOR(n)
	{
		cin >> s;
		sort(ALL(s));
		v[j++] = s;
	}
	int k = j;
	sort(ALL(v));
	FORR(0, k-1)
	{
		if (v[i] == v[i + 1])
			cou++;
		else
		{
			ans += cou * (cou - 1) / 2;
			cou = 1;
		}
	}
	ans += cou * (cou - 1) / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
import numpy as np

x1, y1, x2, y2 = map(int, input().split())

p1 = np.array([x1, y1])
p2 = np.array([x2, y2])

rotate = np.array([[0, 1], [-1, 0]])

p3 = p2 + np.dot((p2 - p1),rotate)
p4 = p3 + np.dot((p3 - p2),rotate)

print(p3[0], p3[1], p4[0], p4[1])

Measured memory_bytes: 20876
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int vector_finder(vector<int> vec, int number){
    int len = vec.size();
    int cnt = 0;
    rep(i,len){
        if (vec[i] == number) cnt++;
    }
    if (cnt >= 1) return 1;
    else return 0;
}

int main(){
    int X,N;
    cin >> X >> N;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    sort(all(vec));
    int sa = 0;
    while(true){
        if (vector_finder(vec,X - sa) == 0){
            cout << X - sa << endl;
            break;
        }
        else if (vector_finder(vec,X + sa) == 0){
            cout << X + sa << endl;
            break;
        }
        sa++;
    }
}

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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int64_t n;
  cin >> n;
  double x[n] = {};
  double y[n] = {};
  vector<int> index(n);
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
    index[i]=i;
  }
  int64_t count = 0;
  double dist = 0.0;
  do{
    for(int i=1;i<n;i++){
      dist += sqrt( 
        (x[index[i-1]]-x[index[i]])*(x[index[i-1]]-x[index[i]])
        +(y[index[i-1]]-y[index[i]])*(y[index[i-1]]-y[index[i]])
         );
    }
    count++;
  }while(next_permutation(index.begin(),index.end()));
         
  cout << fixed << setprecision(10) << dist/(double)count;    
  return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, M;
    int A[100];
    cin >> N >> M;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(A[i]*4*M >= sum) cnt++;
    }
    if(cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

void solve0(ll n) {
    V<ll> a(n);
    V<ll> sum0(n), sum1(n + 2);
    rep(i, n) {
        cin >> a[i];
        (i & 1 ? sum1 : sum0)[i] = a[i];
    }
    rep(i, n - 1) sum0[i + 1] += sum0[i];
    FORR(i, n - 1) sum1[i] += sum1[i + 1];

    ll ans = sum1[0];
    for(int i = 0; i < n; i += 2) {
        chmax(ans, sum0[i] + sum1[i + 2]);
    }
    cout << ans << endl;
    exit(0);
}

void solve1(ll n) {
    ll sum = 0;
    V<ll> a(n + 1);
    FOR(i, 1, n + 1) cin >> a[i], sum += a[i];
    V<V<ll>> dp(n + 1, V<ll>(2, inf));
    dp[0][0] = 0;
    FOR(i, 1, n + 1) {
        if(i & 1) {
            chmin(dp[i][1], dp[i - 1][0] + a[i]);
            if(i > 1) chmin(dp[i][1], dp[i - 2][1] + a[i]);
        } else {
            chmin(dp[i][0], min(dp[i - 1][0], dp[i - 2][0]) + a[i]);
            chmin(dp[i][1], min(dp[i - 1][1], dp[i - 2][1]) + a[i]);
        }
    }
    cout << sum - min(dp[n - 1][1], dp[n][1]) << endl;

    exit(0);
}

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

    ll n;
    cin >> n;
    if(n % 2 == 0) solve0(n);
    solve1(n);

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int N1000 = N / 1000;
  int N100  = N % 1000 / 100; 
  int N10   = N % 100  / 10;
  int N1    = N % 10;

  if (N1000 == N100 && N100 == N10) {
    cout << "Yes" << endl;
  }else if (N100 == N10 && N10 == N1) {
    cout << "Yes" << endl;
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
solveSub [_] = 0
solveSub (a:b:s) | a >= b = 1 + (solveSub (b:s))
                 | otherwise = 0

solve [] = []
solve as = g : solve (drop (g+1) as)
           where
               g = solveSub as

main = do
    n <- readLn :: IO Int
    hn <- map read . words <$> getLine :: IO [Int]
    print $ maximum (solve hn)

Measured memory_bytes: 61036
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
ll fac[400005];
ll inv[400005];
ll exp(int a, int x){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){
        p *= a;
        p %= mod;
    }
    return p;
}
ll choose(int n, int k){
    return ((fac[n]*inv[n-k])%mod*inv[k])%mod;
}
ll ways(int n, int k){
    return (choose(n,k)*choose(n-1,k))%mod;
}
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    fac[0] = inv[0] = 1;
    for (int i = 1; i <= 400000; i++){
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = (inv[i-1]*exp(i,mod-2))%mod;
    }
    if (k >= n-1){
        printf("%lld",choose(n+n-1,n-1));
    }
    else{
        ll ans = 0;
        for (int i = 0; i <= k; i++){
            //printf("ways %d %d = %lld\n",n,i,ways(n,i));
            ans += ways(n,i);
            ans %= mod;
        }
        if (k == 1) ans--;
        printf("%lld",ans);
    }
}


Measured memory_bytes: 6528
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]
 
n = int(input())
 
for _ in range(n):
    (b,f,r,v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v
 
for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    if b < 3:
        print('#' * 20)

Measured memory_bytes: 6720
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, M; cin >> N >> M;
  int MAX = M/N;
  for (int i=MAX;i>=1;i--){
    if ((M - i*N)%i==0) {
      cout << i << endl;
      return 0;
    }
  }
  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3616
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1166&lang=jp
from collections import deque
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    ans = []

    while True:
        w, h = map(int, readline().split())
        if (w, h) == (0, 0):
            break
        
        c = [[0]*(2 * w + 1) for _ in range(2 * h + 1)]
        for j in range(2 * w + 1):
            c[0][j] = 1
            c[2*h][j] = 1
        for i in range(1,2*h):
            c[i][0] = 1
            c[i][2*w] = 1
        for i, _ in enumerate(range(2 * h - 1)):
            if i % 2 == 0:
                S = [int(x) for x in readline().split()]
                for j, s in zip(range(2,2*w+1,2), S):
                    c[i+1][j] = s
            else:
                S = [int(x) for x in readline().split()]
                for j, s in zip(range(1,2*w+1,2), S):
                    c[i+1][j] = s
        
        seen = [[-1]*w for _ in range(h)]
        
        # bfsによる最短経路探索
        queue = deque([(0, 0)])
        seen[0][0] = 1
        possible = False
        while queue:
            x, y = queue.popleft()
            cx, cy = 2*x + 1, 2*y + 1
            if (x, y) == (h-1, w-1):
                possible = True
                ans.append(seen[x][y])
                break

            dx = [1, 0, -1, 0]
            dy = [0, 1, 0, -1]
            for i in range(4):
                nx = x + dx[i]
                ny = y + dy[i]
                ncx = cx + dx[i]
                ncy = cy + dy[i]
                
                if c[ncx][ncy] == 0 and seen[nx][ny] == -1:
                    seen[nx][ny] = seen[x][y] + 1
                    queue.append((nx, ny))

        if not possible:
            ans.append(0)
    
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


Measured memory_bytes: 6064
def main():
    N = int(input())
    C, S, F = [0]*(N-1), [0]*(N-1), [0]*(N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    for i in range(N-1):
        cur, t = i, 0
        while cur < N-1:
            t += (F[cur] - t) % F[cur]
            t = max(t, S[cur])
            t += C[cur]
            cur += 1
        print(t)
    print(0)


if __name__ == "__main__":
    main()


Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) R a[i];
  ll dp[n];
  fill(dp,dp+n,MAX);
  dp[0]=0;
  rep(i,n) {
    REP(j,i+1,min(i+1+m,n)) dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
  }
  pr(dp[n-1]);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 1792
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[100010],ab[100010],ac[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1000][1000];
vector<ll> va,vb,vc;

int main(){
    cin>>ca;
    C (ca=='a' or ca=='u' or ca=='e' or ca=='i' or ca=='o' ? "vowel":"consonant") E;
}

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

public class Main {
    static final long MOD = 1000000007L;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        long[][][] dp = new long[N+1][N+1][2605];
        dp[0][0][0] = 1;
        for(int i= 0; i <N; i++) {
            for(int j = 0; j <= i; j++) {
                for(int k = 0; k <= K; k++) {
                    if (dp[i][j][k] == 0) continue;
                    //close previously opened segment
                    if (j > 0 && k + j * 2 <= K) {
                        dp[i+1][j][k + j * 2] = (dp[i+1][j][k+j*2] + dp[i][j][k] * 2 * j) % MOD;
                    }
                    //base of putting self
                    dp[i+1][j][k+j*2] = (dp[i+1][j][k+j*2] + dp[i][j][k]) %MOD;
                    //close with cur already set
                    if (j> 0 && k + (j-1)*2 <= K) {
                        dp[i+1][j-1][k+(j-1)*2] = (dp[i+1][j-1][k+(j-1)*2] + dp[i][j][k] * j * j) % MOD;
                    }
                    //open new
                    if (k + (j+1)*2 <= K) {
                        dp[i+1][j+1][k+(j+1)*2] = (dp[i+1][j+1][k+(j+1)*2] + dp[i][j][k]) % MOD;
                    }
                }
            }
        }
        out.println(dp[N][0][K]);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

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

  int cntA = 0, cntB = 0;
  for(int i = 0; i < 3; i++) {
    if(S.at(i) == 'A') {
      cntA++;
    } else {
      cntB++;
    }
  }

  if(cntA == 0 || cntB == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
int main()
{
	int a,b,c,x;
	int t=0;
	int i,j,k;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if(500*i+100*j+50*k==x)
					t++;
			}
		}
	}
	printf("%d\n",t);
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#N = int(input())
A, B = map(int, input().split())
S = str(input())

if S[A] != "-" :
  print ("No")
  exit()

#print (S[0:A])
#print (S[A+1:])

try:
  d1 = int(S[0:A])
  d2 = int(S[A+1:])
except:
  print ("No")
  exit()

if d1 < 0 or d2 < 0 :
  print ("No")
  exit()
    
print ("Yes")


Measured memory_bytes: 38356
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
     int N ,a[100001] ;
     memset(a,0,sizeof(a)) ;
     cin >> N ;
     int n = N ;
     
     for(int i=0;i<N;i++){
          int t ;
          cin >> t ;
          a[t]++ ;
          if(a[t]==3){
               a[t] -= 2 ;
               n -=  2 ;
          }
     }
     
     int count = 0 ;
     for(int i=1;i<=100000;i++){
          if(a[i]==2){
               count++ ;
          }
     }
     
     if(count%2==0){
          cout << n - count << endl ; 
     }else{
          cout << n - 2 * (count / 2) - 2  << endl ;
     }
     
    
}


Measured memory_bytes: 640
#include <iostream>
#include <deque>

using namespace std;

#define MAX_H 100
#define MAX_W 100
#define MAX_A 10

struct State{
  int m,x,y,p,q,d;
  State(int m,int x,int y,int p,int q,int d) :
    m(m),x(x),y(y),p(p),q(q),d(d) {}
};

int H,W,A;
char field[MAX_H][MAX_W];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
bool visited[MAX_H][MAX_W][MAX_A][MAX_A][4];

inline bool canMove(int x,int y,int d){
  if(0 <= x && x < W && 0 <= y && y < H){
    if(field[y][x] == 'S' && d == 1){
      return false;
    }else if(field[y][x] != '#'){
      return true;
    }
  }
  return false;
}

int bfs(int sx,int sy,int gx,int gy){
  deque<State> Q;
  Q.push_back(State(0,sx,sy,A,A,3));
  visited[sy][sx][A][A][3] = true;
  
  while(!Q.empty()){
    State s = Q.front(); Q.pop_front();
    int x = s.x, y = s.y;
    if(x == gx && y == gy){ return s.m; }
    int nx = x+dx[s.d], ny = y+dy[s.d];
    if(canMove(nx,ny,s.d) && !visited[ny][nx][s.p][s.q][s.d]){
      visited[ny][nx][s.p][s.q][s.d] = true;
      Q.push_front(State(s.m,nx,ny,s.p,s.q,s.d));
    }
    if(s.p > 0 && field[y][x] == '.'){
      int ndir = (s.d & 1 ? s.d+3 : s.d+1)%4;
      if(!visited[y][x][s.p-1][s.q][ndir]){
        visited[y][x][s.p-1][s.q][ndir] = true;
        Q.push_back(State(s.m+1,x,y,s.p-1,s.q,ndir));
      }
    }
    if(s.q > 0 && field[y][x] == '.'){
      int ndir = (s.d & 1 ? s.d+1 : s.d+3)%4;
      if(!visited[y][x][s.p][s.q-1][ndir]){
        visited[y][x][s.p][s.q-1][ndir] = true;
        Q.push_back(State(s.m+1,x,y,s.p,s.q-1,ndir));
      }
    }
  }
  return -1;
}

int main(){
  int sx,sy,gx,gy;
  cin >> H >> W >> A;
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      cin >> field[i][j];
      if(field[i][j] == 'S'){
        sx = j; sy = i;
      }else if(field[i][j] == 'G'){
        gx = j; gy = i;
      }
    }
  }
  cout << bfs(sx,sy,gx,gy) << endl;
  return 0;
}

Measured memory_bytes: 3396
import java.util.Scanner;

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

    while (in.hasNext()){
      int max = Integer.MIN_VALUE;
      int min = Integer.MAX_VALUE;

      for (int i = 0; i < 3; ++i) {
        int a = in.nextInt();
        max = Math.max(max, a);
        min = Math.min(min, a);
      }

      System.out.println(max - min);
    }
  }
}


Measured memory_bytes: 21844
N = int(input())
A = list(map(int, input().split()))

#%%
def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]    # これからソートしたい1つの数字（i番目）
        j = i - 1   # ソート済み(i-1番目まで)のインデックス
        print(' '.join(map(str, A)))

        # j以下のものを順番に右にずらしていきながら、挿入する値のインデックスを決める
        while j >= 0 and A[j] > v:
            A[j+1] = A[j] # 値を上書きしていく（右にずらしていく処理）
            j -= 1  # jがi-1を始点として、先頭に向かって減少する
        A[j+1] = v # いい感じのところで[..., 3, 3, ...]みたいになるので、左側を上書きする
    
    return A

a = insertionSort(A[:], N)
print(' '.join(map(str, a)))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
ll mod = 1000000007;
int main(){
  ll n,m; cin >> n >> m;
  set<ll> holes;
  rep(i,m){
    ll a; cin >> a;
    holes.insert(a);
  }
  vector<ll> dp(n+1);
  dp[0]=1;dp[1]=(holes.count(1)>0 ? 0 : 1);
  for(ll i=2; i<=n; i++){
    if(holes.count(i)>0) dp[i]=0;
    else dp[i]=(dp[i-1]+dp[i-2])%mod;
  }
  cout << dp[n] << endl;
  return 0;
}




Measured memory_bytes: 5760
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int n, ans;

int main() {

	cin >> n;
	REP(i, 1, n + 1) {
		int cnt = 0;
		int tmp = i;
		while (tmp != 0) {
			tmp /= 10;
			cnt++;
		}
		if (cnt % 2 == 1)ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    static char ShiftChar(char c, int s) {
        char res = (char)(c + s);
        if (res > 'z')  res -= 26;
        return res;
    }

    static StringBuilder ShiftString(StringBuilder str, int s) {
        StringBuilder res = new StringBuilder(str.toString());
        for (int i = 0; i < str.length(); i++) {
            char c = res.charAt(i);
            if ('a' <= c && c <= 'z') {
                res.setCharAt(i, ShiftChar(c, s));
            }
        }
        return res;
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);
        StringBuilder line;

        while (true) {
            try {
                line = new StringBuilder(sc.nextLine());
            } catch (NoSuchElementException e) {
                break;
            }
                
            int shift = -1;
            boolean solved = false;
                    
            while (!solved) {
                shift += 1;
                 
                String[] words = ShiftString(line, shift).toString().split(" ");    
                for(int i = 0; i < words.length - 1; i++) {
                    if (words[i].equals("the") || words[i].equals("this") || words[i].equals("that")) {
                        solved = true;         
                    }
                }

            }

            System.out.println(ShiftString(line, shift));
        }

    }
}

Measured memory_bytes: 12000
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N,M;cin>>N>>M;
  ll a[M];
  ll i,j;
  rep(i,M) cin>>a[i];
  ll dp[N+1];
  for(i=0;i<=N;i++) dp[i]=-1;
  dp[0]=1;
  dp[1]=1;
  rep(i,M) dp[a[i]]=0;
  //rep(i,N) cout<<dp[i]<<endl;
  for(i=2;i<=N;i++){
    if(dp[i]!=-1) continue;
    dp[i]=dp[i-1]+dp[i-2];
    dp[i]%=mod;
  }
  //repn(i,N) cout<<dp[i]<<endl;
  cout<<dp[N]<<endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
 
/*
struct SegmentTree{
   
  vector<lol> SumV(1000005,0);
  vector<lol> MaxV(1000005,0);
  vector<lol> MinV(1000005,0);
  int N;
   
  void update(int i,int x){
    i += N - 1;
    minv[i] = x;
    maxv[i] = x;
    sumv[i] = x;
    while(i > 0){
      i = (i - 1)/2;
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
    }
  }
   
  void add(int i,int x){
    i += N - 1;
    sumv[i] += x;
    maxv[i] += x;
    minv[i] += x;
    while(i > 0){
      i = (i - 1)/2;
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
    }
  }
   
  int getmax(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return -INF;
    if(a <= l && r <= b) return maxv[k];
    else{
      int c1 = getmax(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmax(a,b,2*k+2,(l+r)/2,r);
      return max(c1,c2);
    }
  }
   
  int getmin(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return minv[k];
    else{
      int c1 = getmin(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmin(a,b,2*k+2,(l+r)/2,r);
      return min(c1,c2);
    }
  }
   
  int getsum(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sumv[k];
    else{
      int c1 = getsum(a,b,2*k+1,l,(l+r)/2);
      int c2 = getsum(a,b,2*k+2,(l+r)/2,r);
      return c1+c2;
    }
  }
}
*/
 
//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int a[n + 5], b[n + 5], c[n + 5];
  rep(i, n){
    cin >> a[i] >> b[i] >> c[i];
    if(a[i] > b[i]){
      swap(a[i], b[i]);
    }
    if(b[i] > c[i]){
      swap(b[i], c[i]);
    }
    if(a[i] > b[i]){
      swap(a[i], b[i]);
    }
  }
  int ans = 0;
  bool nasu[n + 5] = {false};
  rep(i, n){
    for(int j = i + 1;j <= n;j ++){
      if(a[i] == a[j] && b[i] == b[j] && c[i] == c[j]){
	if(!nasu[j]){
	  ans ++;
	  nasu[j] = true;
	}
      }
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3228