akhauriyash/Code-Regression huggingface dataset:
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}
map<string,int> in;
void testcase(){
	int n;
	cin >> n;
	string p,q,cor;
	for(int i{0};i < n;i++){
		char c;
		cin >> c;
		p += c;
		cor += '1' + i;
	}
	for(int i{0};i < n;i++){
		char c;
		cin >> c;
		q += c;
	}
	int i{2};
	in[cor] = 1;
	while(next_permutation(cor.begin(),cor.end())){
		in[cor] = i++;
	}
	cout << abs(in[p] - in[q]);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 6716
#include <stdio.h>

int main()
{
    int N;
    int K;
    int i;
    double rate;
    int score;
    int count;

    scanf("%d %d", &N, &K);

    rate = 0.0;
    for(i = 1; i <= N; i++) {
        score = i;
        for(count = 0; score < K; count++) {
            score <<= 1;
        }
        //rate += (long double)1.0 / (1 << count);
        rate += (long double)1.0 / (1 << count) / N;
    }

    //printf("%.12Lf\n", rate / N);
    printf("%.12f\n", rate);

    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector <double> x(n), y(n);
    for (int i=0; i<n; i++) {
        cin >> x[i] >> y[i];
    }

    double ans=0;

    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            double dist = sqrt((x[i] - x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
            ans += dist/n;
        }
    }

    cout << fixed << setprecision(7) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import math
n,k=map(int,input().split())
h=list(map(int,input().split()))
dp=[math.inf for i in range(n)]
dp[0]=0
for i in range(1,n):
    for j in range(1,k+1):
        if i-j<0:
            continue
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i])
print(dp[n-1])

Measured memory_bytes: 91084
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
long long ans1, ans2, n;
vector<pii> vec;

bool cmp(pii a, pii b) {
	return a.first + a.second < b.first + b.second;	
}
bool flag = 0;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		vec.push_back(pii(a, b));
	}
	sort(vec.begin(), vec.end(), cmp);
	while(!vec.empty()) {
		if (!flag) {
			ans1 += vec.back().first;
		}
		else {
			ans2 += vec.back().second;
		}
		flag = !flag;
		vec.pop_back();
	}
	cout << ans1 - ans2;
	
	
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define pr pair<int, int>
#define v1d vector<int>
#define mp make_pair
#define pb push_back
#define v1p vector<pr>
#define vb vector<bool>
#define v2d vector<vector<int>>
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define S(v) sort(v.begin(), v.end())
#define RS(v) sort(v.rbegin(), v.rend())
#define eb emplace_back
#define endl "\n"
#define MOD 1000000007
#define pqx priority_queue <int>
#define pqn priority_queue <int, v1d, greater<int> >
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};



int32_t main() {
    fio
    int a, b, c, k; cin >> a >> b >> c >> k;
    if(k <= a) cout << 1 * k;
    else if(k <= a + b) cout << a;
    else {
        k -= a + b;
        cout << a - k;
    }
}


Measured memory_bytes: 3656
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll INF = 1<<29;
int main(){
ll n;cin>>n;
vector<ll> a(n);
vector<ll> b(n);
ll amax=0;
ll bmax=0;
rep(i,n){
    cin>>a[i];
    b[i]=a[i];
}
sort(all(a));
amax=a[n-1];
bmax=a[n-2];
rep(i,n){
    if(b[i]!=amax)cout<<amax<<endl;
    if(b[i]==amax){
        cout<<bmax<<endl;
    }
}
}

Measured memory_bytes: 4736
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var H = cin.ReadLong;
			var Res = 0L;
			var num = 1L;
			while(H > 1) {
				Res += num;
				H /= 2;
				num *= 2;
			}
			Res += num;
			Console.WriteLine(Res);
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x] = A[y];
			A[y] = tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  const int mm = 100001;
  vector<bool> flag(mm, true);
  flag[0] = flag[1] = false;
  for (int i = 2; i < sqrt(mm); i++) {
    if (flag[i]) {
      for (int j = 2; i * j < mm; j++) {
        flag[i * j] = false;
      }
    }
  }
  vector<int> v(mm, 0);
  for (int i = 2; i < mm; i++) {
    if (flag[i] && flag[(i + 1) / 2])
      v[i]++;
    v[i] += v[i - 1];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    cout << v[r] - v[l - 1] << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << (a - 1) * (b - 1) << endl;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(string, s);

    string ans = "~";

    const int N = s.length();
    int used[128] {};

    for (int len = 0; len <= N; ++len) {
        for (char ch = 'a'; ch <= 'z'; ++ch) {
            if (used[ch]) continue;
            const string t = s.substr(0, len) + ch;
            if (t > s) chmin(ans, t);
        }

        used[s[len]] = true;
    }

    if (ans == "~") {
        print(-1);
    } else {
        print(ans);
    }

    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

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


Measured memory_bytes: 256
#include<cstdio>

int n, cnt;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%d", &a);
    if (i % 2 == 1 && a % 2 == 1) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
}


Measured memory_bytes: 1724
require 'prime'

n = gets.to_i
dividors = n.prime_division
tmp = Array.new(dividors.size) { Array.new }
dividors.each_with_index do |(d1, d2), index|
  0.upto(d2) do |i|
    tmp[index] << d1 ** i
  end
end
ans = [[1]]
tmp.each do |t|
  a = ans.shift
  b = []
  t.each do |tt|
    a.each do |aa|
      b << tt * aa
    end
  end
  ans << b
end
mins = []
ans[0].each do |a|
  another = n / a
  answer = a + another - 2
  mins << answer
end
puts mins.min


Measured memory_bytes: 4092
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=200005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli ap[MaxN];
	void solve(){
		lli N,Q,i,j,p,q,tot=0;
		cin>>N;
		for(i=0;i<N;i++){
			cin>>p;
			ap[p]+=1;
			tot+=p;
		}
		cin>>Q;		
		lli dif;
		while(Q--){
			cin>>p>>q;
			dif=q-p;
			tot+=dif*ap[p];
			ap[q]+=ap[p];
			ap[p]=0;
			cout<<tot<<"\n";
		}
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,j,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
	
}


Measured memory_bytes: 3976
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[]str = Console.ReadLine().Split();
		int[]A = new int[N];
		int ans = 0;
		for(var i=0;i<N-1;i++){
			A[i] = int.Parse(str[i]);
		}
		ans += A[0];
		ans += A[N-2];
		for(var i=0;i<N-2;i++){
			ans += Math.Min(A[i],A[i+1]);
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}
template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> imos(n + 1, 0);
    REP (i, 0, m) {
        int a, b;
        cin >> a >> b;
        imos[a - 1]++;
        imos[b]--;
    }
    REP (i, 0, n ){
        imos[i + 1] += imos[i];
    }
    int ans = 0;
    REP (i, 0, n + 1){
        ans += (imos[i] == m);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, a[200005] = {}, b[200005] = {};
    ll z = 0;
    map<int, int> m;
    m[0] = 1;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i]--, a[i] %= k;
    for (int i = 1; i <= n; i++) {
        if (i >= k) m[b[i - k]]--;
        b[i] = (b[i - 1] + a[i]) % k, z += m[b[i]], m[b[i]]++;
    }
    cout << z;
}


Measured memory_bytes: 14584
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 long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

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

			char[] s = in.nextString().toCharArray();
			int n = s.length;
			long[][] dp = new long[n+1][4];
			dp[0][3] = 1;
			for (int i = 0; i < n; i++) {

				for (int j = 0; j < 4; j++) {
					dp[i+1][j] += dp[i][j];

					if (s[i] == '?') {
						dp[i+1][j] += 2 * dp[i][j];
					}
					dp[i+1][j] %= MOD;
				}

				if (s[i] == 'A' || s[i] == '?') {
					dp[i+1][0] += dp[i][3];
				}

				if (s[i] == 'B' || s[i] == '?') {
					dp[i+1][1] += dp[i][0];
				}

				if (s[i] == 'C' || s[i] == '?') {
					dp[i+1][2] += dp[i][1];
				}

			}
			out.println(dp[n][2] % MOD);

		}
	}

	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 int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			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 long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

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

}


Measured memory_bytes: 29576
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

print(ans)

Measured memory_bytes: 9200
#include <iostream>

using namespace std;

int main(void){
	int n,d;
	
	cin >> n;
	cin >> d;
	
	int cnt = 0;
	for(int i = 0; i < n; i=i+(2*d+1)){
		cnt++;
	}		
	cout << cnt << endl;
	return 0;
}

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

long long m,n,x,y;
long long f[12]={0,9,18,108,198,1098,1998,10998,19998,109998,199998,1099998};    //预处理从1到10^i-1之间共有f[i]个回文数

long long find(long long x)
{
	if (x==0) return 0;		//边界情况
	if (x<10) return x;		//小于10时每个数字都是一个回文数
	long long w,i,ans,t,na,a,b,nx;
	w=0;
	nx=x;
	while (nx)			//求数x的位数
	{
		w++;
		nx/=10;
	}
	ans=f[w-1];			//ans初始化
	t=1;
	for (int k=1;k<=(w/2);k++) t*=10;
	if (w%2==0)     //处理位数为偶数的数
	{
		a=(x/t);
		b=(x%t);
		t=t/10;
		ans=ans+(a-t);
		na=0;
		while (a)
		{
			na=na*10+a%10;
			a/=10;
		}
	}
	else           //处理位数为奇数的数
	{
		a=(x/t);
		t*=10;
		b=(x%t);	
		t=t/10;
		ans=ans+(a-t);
		na=0;
		while (a)
		{
			na=na*10+a%10;
			a/=10;
		}
	}
	if (b>=na) ans++;            
	return ans;
	
}

int main()
{
	while (cin>>m>>n)
	{
		m=m-1;		
		x=find(m);  //求1到m有多少个回文数
		y=find(n);  //求1到n有多少个回文数
		cout<<y-x<<endl;
	}
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <utility>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;

const int dx[4] = { 1,  0, -1,  0 };
const int dy[4] = { 0,  1,  0, -1 };
const int INF = (int)2e9;
int H, W;
int sx, sy;
int gx, gy;
int bk_cnt = 0;
vector<string> M;
vector<vi> dst;

void input_data(void) {
	cin >> H >> W;
	M.resize(H);
	for (int j = 0; j < H; ++j) {
		cin >> M[j];
		for (int i = 0; i < W; ++i) {
			if (M[j][i] == '#')
				++bk_cnt;
		}
	}
	sx = sy = 0;
	gx = W - 1; gy = H - 1;
	dst.resize(H, vi(W, INF));
}

int bfs(void) {
	queue<pi> que;
	que.push(pi(sx, sy));
	dst[sy][sx] = 0;
	while (que.size()) {
		pi p = que.front();
		que.pop();
		if (p.first == gx && p.second == gy)
			break;
		for (int i = 0; i < 4; ++i) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (0 <= nx && nx < W && 0 <= ny && ny < H && M[ny][nx] != '#' && dst[ny][nx] == INF) {
				que.push(pi(nx, ny));
				dst[ny][nx] = dst[p.second][p.first] + 1;
			}
		}
	}
	if (dst[gy][gx] == INF)
		return -1;
	return dst[gy][gx] + 1;
}

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

	input_data();
	int ans = bfs();
	if (ans != -1)
		ans = H * W - bk_cnt - ans;

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


Measured memory_bytes: 256
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  std::ostringstream oss; 
  int a, b, d, e = 1, f, g;
  cin >> a >> b;
  oss << b; 
  string c;
  c = oss.str().c_str();
  d = c.length();
  for (int i = 0; i < d; i++) {
    e *= 10;
  }
  f = a * e + b;
  g = sqrt(f);
  if (f == g * g) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd

H,W,T = map(int,read().split())

MOD = 10 ** 9 + 7

a = gcd(H,T); b = gcd(W,T)

H //= a; W //= b

x = pow(2,H,MOD) + pow(2,W,MOD) + pow(2,gcd(H,W),MOD) - 3
answer = pow(x,a*b,MOD)
print(answer)

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

int mi[4]={-1,0,1,0};
int mj[4]={0,-1,0,1};

int main()
{
  int H,W;scanf("%d %d",&H,&W);
  char S[H][W];string ans="Yes";  
  bool check[H][W];for(int i=0;i<H;i++)fill(check[i],check[i]+W,false);
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>S[i][j];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)
  {
    if(check[i][j]||S[i][j]=='.')continue;
    queue<pair<int,int>> que;
    que.push({i,j});
    int count=1;
    while(!que.empty())
    {
      int I=que.front().first,J=que.front().second;que.pop();
      for(int k=0;k<4;k++)
      {
        int mI=I+mi[k],mJ=J+mj[k];
        if(mI<0||mI>H-1||mJ<0||mJ>W-1)continue;
        if(S[mI][mJ]=='.'||check[mI][mJ])continue;
        check[mI][mJ]=true;count++;
        que.push({mI,mJ});
      }
    }
    if(count==1)ans="No";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    reverse(s1.begin(), s1.end());
    if (s1 == s2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        Point[] xy = new Point[n];
        for (int i = 0; i < n; i++) {
            xy[i] = new Point(in.nextInt(), i);
        }
        Arrays.sort(xy, Comparator.<Point>comparingInt(p -> -p.x).thenComparing(p -> -p.y));
        int min = 0xfffffff;
        long[] ans = new long[n];
        for (int i = 0; i < n; i++) {
            long v = (long)(i + 1) * (xy[i].x - (i + 1 == n ? 0 : xy[i + 1].x));
            xy[i].x -= v;
            min = Math.min(min, xy[i].y);
            ans[min] += v;
        }
        for (int i = 0; i < n; i++) {
            out.println(ans[i]);
        }
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

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

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

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

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 55360
#include <cstdio>
#include <vector>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define P(a) printf("%d", a)
#define INF 1000000000
using namespace std;
typedef long long ll;

int N;

vector<int> sieve(int n) {
    vector<int> prime(n);
    vector<bool> is_prime(n + 1);
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return prime;
}

int main() {
	S(N);
    if (N > 99991) P(100003);
    vector<int> ans = sieve(99991);
    R(i, ans.size()) {
        if (ans[i] >= N) {
            P(ans[i]);
            break;
        }
    }
}



Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n,x; cin >> n >> x;
  ll a[n]; REP(i,n) cin >> a[i];
  ll ans = 0;
  REP(i,n){
    ll diff;
    if(i==0){
      diff = max((ll)0,a[0]-x);
    }else{
      diff = max((ll)0,max(a[i]+a[i-1]-x,a[i]-x));
    }
    ans += diff;
    a[i] -= diff;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	int n,p;
	cin >> n >> p;
	//cout<<endl;
	vector<int> a(n);
	rep(i,n)
	{
		cin >> a[i];
		a[i]%=2;
	}
	ll one = 0;
	ll zero = 0;
	rep(i,n)
	{
		if(a[i]==1)one++;
		else zero++;
	}
	//cout<<one<<endl<<(1<<zero)<<endl;
	ll ans = 0;
		if(one)ans += ((1LL)*1<<(one-1));
		if(ans==0&&p==0)ans=1;
		//cout<<ans<<endl;
		ans *= ((1LL)*1<<zero);
	
	

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;


int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int x,n;
    cin >> x >> n;
    map<int, int> mp;
    vector<int> p(n);
    rep(i, n){
        cin >> p[i];
        mp[p[i]]++;
    }
    sort(all(p));
    int ans = INF;
    rep(i, 102){
        if(mp[i]) continue;
        chmin(ans, abs(x - i));
    }
    if(mp[x - ans])print(x + ans);
    else print(x - ans);

}





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

#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;

int main()
{
	// freopen("input.in", "r", stdin);
	
	long a, b, k;
	scanf("%lld %lld %lld", &a, &b, &k);

	if(a > k) printf("%lld %lld\n", a-k, b);
	else printf("%lld %lld\n", 0LL, max(0LL, b-k+a));

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int MAX = 200000;
const int inf = 2e9;

int L[MAX/2+2], R[MAX/2+2];

ll merge(int A[], int left, int mid, int right){
    ll cnt = 0;
    int n1 = mid-left;
    int n2 = right-mid;
    for(int i=0; i<n1; ++i) L[i] = A[left+i];
    for(int i=0; i<n2; ++i) R[i] = A[mid+i];
    L[n1] = R[n2] = inf;
    int i=0, j=0;
    for(int k=left; k<right; ++k){
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }
        else{
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }

    return cnt;
}

ll mergeSort(int A[], int left, int right){
    int mid;
    ll v1, v2, v3;
    if(left+1 < right){
        mid = (left+right)/2;
        v1 = mergeSort(A, left, mid);
        v2 = mergeSort(A, mid, right);
        v3 = merge(A, left, mid, right);
        return v1+v2+v3;
    }

    return 0;
}

int main(){
    int A[MAX], n;
    cin >> n;
    for(int i=0; i<n; ++i) cin >> A[i];

    ll ans = mergeSort(A, 0, n);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n,ans=1;
	cin >> n;
	while (ans * 2 <= n) {
		ans *= 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// Aizu 2369: CatChecker
// 2017.9.27 bal4u@uu

#include <stdio.h>

char buf[502];

char *check(char *p)
{
	if (!*p || *p++ != 'm') return NULL;
	if (!*p) return NULL;
	if (*p == 'm' && (p = check(p)) == NULL) return NULL;
	if (!*p || *p++ != 'e') return NULL;
	if (!*p) return NULL;
	if (*p == 'm' && (p = check(p)) == NULL) return NULL;
	if (!*p || *p++ != 'w') return NULL;
	return p;
}

int main()
{
	char *p;
	scanf("%s", buf);
	puts((p = check(buf)) != NULL && !*p ? "Cat" : "Rabbit");
	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

struct UnionFind
{
    vector<int> par, sz;
    int n_cc;

    UnionFind(int N){
        par = vector<int>(N);
        REP(i, N) par[i] = i;
        sz = vector<int>(N, 1);
        n_cc = N;
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(sz[x] < sz[y]) swap(x, y);

        par[y] = x;
        sz[x] += sz[y];
        n_cc--;
    }

    bool is_union(int x, int y){
        x = find(x);
        y = find(y);
        return x == y;
    }

    int union_size(int x){
        return sz[find(x)];
    }

};


signed main(){

    int N, Q; cin >> N >> Q;
    UnionFind UF(N);
    REP(_, Q){
        int t, u, v; cin >> t >> u >> v;
        if(t == 0) UF.unite(u, v);
        else chOut(UF.is_union(u, v), 1, 0);
    }

    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

using pii = pair<int, int>;

int n, m;
int a[111], b[111];

int main() {
   while (1) {
      cin >> n >> m;
      if (n == 0 && m == 0) return 0;
      int A = 0, B = 0;
      rep (i, n) { cin >> a[i]; A += a[i]; }
      rep (i, m) { cin >> b[i]; B += b[i]; }

      map<int, pii> mp;
      rep (i, n) { // aはiを差し出す
         rep (j, m) { // bはjを差し出す
            int x = A - a[i] + b[j], y = B - b[j] + a[i];
            if (x == y) {
               mp[a[i]+b[j]] = {a[i], b[j]};
            }
         }
      }

      int ans1 = 0, ans2 = 0, sum = 1e8;
      for (auto x : mp) {
         int s = x.second.first, t = x.second.second;
         if (s + t < sum) {
            ans1 = s, ans2 = t;
            sum = s + t;
         }
      }

      if (sum == 1e8) {
         cout << -1 << endl;
      } else {
         printf("%d %d\n", ans1, ans2);
      }

   }

   return 0;
}


Measured memory_bytes: 3144
def main():
    M, D = map(int, input().split())
    count = 0
    for m in range(1, M+1):
        for d in range(20, D+1):
            s = str(d)
            d1 = s[0]
            d0 = s[1]
            if int(d0) >=2 and int(d1) >=2 and m == int(d1) * int(d0):
                count += 1
    return count

if __name__ == '__main__':

    print(main())

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 998244353;

int main(){
	ll n,s; cin >> n >> s;
	vl a(n); rep(i,n) cin >> a[i];
	vvl dp(n+1,vl(s+1,0));
	dp[0][0] = 1;
	rep(i,n){
		for(ll j=s; j>=0; j--){
			dp[i+1][j] += dp[i][j];
			dp[i+1][j] %= mod;
			if(j+a[i]>s) continue;
			if(j != 0) dp[i+1][j+a[i]] += dp[i][j];
			else dp[i+1][j+a[i]] += dp[i][j] + i;
			dp[i+1][j+a[i]] %= mod;
		}
	}
	ll ans = 0;
	rep(i,n+1){
		ans += dp[i][s];
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 70784
from math import gcd

K = int(input())

s = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        d = gcd(a, b)
        if d == 1:
            s += K
            continue
        else:
            for c in range(1, K+1):
                s += gcd(d, c)

print(s)

Measured memory_bytes: 9184
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define SORT(x) sort(all(x))
#define RSORT(x) sort(all(x),greater<ll>())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define sprint(X) printf("%f\n", (X)) // 小数点の出力
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
#define case(X) cout << "Case #" << (X) + 1 << ":" << "\n"
static const int INF = 1e+9+7;

int main(){

  ll N;
  cin >> N;
  
  bool flag = false;
  rep(i,1,10){
    rep(j,1,10){
      if(i * j == N){
        flag = true;
      }
    }
  }

  if(flag) Yes;
  else No;

 return 0;
}


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

int main(){
    int r,c;
    cin>>r>>c;

    int num[101][101]={};
    for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) cin>>num[i][j];

    for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) num[r][c]+=num[i][j];

    for(int i=0;i<r;i++){
        int sum=0;
    for(int j=0;j<c;j++) sum+=num[i][j];
    num[i][c]=sum;
    }

    for(int j=0;j<c;j++){
        int sum=0;
    for(int i=0;i<r;i++) sum+=num[i][j];
    num[r][j]=sum;
    }

    for(int i=0;i<=r;i++){
        for(int j=0;j<=c;j++){
            if(j) cout<<" ";
            cout<<num[i][j];
        }
        cout<<endl;
    }
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<string> s(n);
    map<string,int> m;
    for(int i=0;i<n;i++) cin>>s[i];
    sort(s.begin(),s.end());
    for(int i=0;i<n;i++)
    {
        m[s[i]]++;
    }
    int max=0;
    for(int i=0;i<n;i++)
    {
        if(max<m[s[i]]) max=m[s[i]];
    }
    for(auto x:m)
    {
        if(max==x.second)cout<<x.first<<endl;
    }
}

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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int a[300000];
int main(){
	int n,K;cin>>n>>K;
	rep(i,n)scanf("%d",&a[i]);
	for(int i=K;i<n;i++){//[i-k+1,i]
		if(a[i]>a[i-K]){
			puts("Yes");
		}
		else puts("No");
	}
}

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

using namespace std;

int main(){
  string s,t;
  cin>>s>>t;
  int mini=INT_MAX;
  int tmp=0;
  for(int i=0;i<t.size();i++)tmp+=t[i]!=s[i];
  mini=min(mini,tmp);
  for(int i=t.size();i<s.size();i++){
    tmp=0;
    for(int j=0;j<t.size();j++)tmp+=t[j]!=s[i+j-t.size()+1];
    mini=min(mini,tmp);
  }
  cout<<mini;
}


Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
int T, card[16];

bool is_same_number(int a, int b, int c) {
  return (a == b) && (b == c);
}

bool is_sequence(int a, int b, int c) {
  return (a == b-1) && (b == c-1);
}

bool is_good_set(int a, int b, int c) {
  return is_same_number(a, b, c) || is_sequence(a, b, c);
}

bool is_all_good_set() {
  return (is_good_set(card[0],card[1],card[2]) && is_good_set(card[3],card[4],card[5]) && is_good_set(card[6],card[7],card[8]));
    }

int win() {
  sort(card,card+9);
  do {
    if(is_all_good_set()) return 1;
  }while (next_permutation(card, card+9));
  return 0;
}

int main() {
{
map<string, int> table;
table["R"] = 0;
table["G"] = 10;
table["B"] = 20;
  cin >> T;
  for (int t=0; t<T; ++t) {
    for (int i=0; i<9; ++i) {
      cin >> card[i];
    }
    string color;
   for (int i=0; i<9; ++i) {
      cin >> color;
      card[i] = card[i] + table[color];
    }
   cout << win() << endl;
  }
}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int ac = a.size(),bc = b.size(),cc = c.size();
  char now = 'a';
  while(a.size() >= 0 && b.size() >= 0 && c.size() >= 0){
    if(now == 'a'){
      if(a.size() == 0){
        cout << 'A' << endl;
        break;
      }      
      else if(a.at(0) == 'a'){
        a.erase(0,1);
        now = 'a';
        continue;
      }
      else if(a.at(0) == 'b'){
        a.erase(0,1);
        now = 'b';
        continue;
      }
      else{
        a.erase(0,1);
        now = 'c';
        continue;
      }
    }
    else if(now == 'b'){
      if(b.size() == 0){
        cout << 'B' << endl;
        break;
      }      
      else if(b.at(0) == 'a'){
        b.erase(0,1);
        now = 'a';
        continue;
      }
      else if(b.at(0) == 'b'){
        b.erase(0,1);
        now = 'b';
        continue;
      }
      else{
        b.erase(0,1);
        now = 'c';
        continue;
      }
    }
    else if(now == 'c'){
      if(c.size() == 0){
        cout << 'C' << endl;
        break;
      }
      else if(c.at(0) == 'a'){
        c.erase(0,1);
        now = 'a';
        continue;
      }
      else if(c.at(0) == 'b'){
        c.erase(0,1);
        now = 'b';
        continue;
      }
      else{
        c.erase(0,1);
        now = 'c';
        continue;
      }
    }
  }
}

Measured memory_bytes: 256