akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 105;

void pd(int&ret, int val){
  if(ret==-1||ret>val)ret=val;
}

int l[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  int n, a,b,c;
  cin>>n>>a>>b>>c;
  int ret=-1;
  for(int i=0;i<n;i++)cin>>l[i];
  for(int i=0;i<(1<<(n+n));i++){
    int ca=0,cb=0,cc=0,sa=0,sb=0,sc=0;
    for(int j=0;j<n+n;j+=2){
      int tmp=((i>>j)&3);
      if (tmp==1){
        ca++;
        sa+=l[j>>1];
      } else if(tmp==2){
        cb++;
        sb+=l[j>>1];
      } else if(tmp==3) {
        cc++;
        sc += l[j >> 1];
      }
    }
    if(ca&&cb&&cc){
      int tmp=(ca-1)*10+abs(sa-a)+(cb-1)*10+abs(sb-b)+(cc-1)*10+abs(sc-c);
      pd(ret,tmp);
    }
  }
  cout<<ret<<endl;
  return 0;
}

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

const int MAX_N = 200100;
int X[MAX_N], Y[MAX_N];

int main() {
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        cin >> X[i];
    }

    int *prev = X, *nxt = Y;
    while (K--) {
        memset(nxt, 0, sizeof(X));
        bool flg = true;
        for (int i = 0; i < N; ++i) {
            if ((0 < i - prev[i]) || (i + prev[i] + 1 < N)) {
                flg = false;
            }
            ++nxt[max(0, i - prev[i])];
            --nxt[min(N, i + prev[i] + 1)];
        }
        for (int i = 1; i <= N; ++i) {
            nxt[i] += nxt[i - 1];
        }
        swap(prev, nxt);
        if (flg) break;
    }

    for (int i = 0; i < N; ++i) {
        cout << prev[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5160
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            // 入力受け取り
            int n = cin.ReadInt;
            var wList = cin.ReadIntArray(n).ToList();
            //var lessList = new List<int>();
            //var overList = new List<int>();

            int less = 0;
            int over = 0;

            for (int i=0; i < n; i++)
            {
                if (less <= over)
                {
                    less += wList[0];
                    wList.RemoveAt(0);
                }else if(less > over)
                {
                    over += wList[wList.Count - 1];
                    wList.RemoveAt(wList.Count - 1);
                }
            }


            int abs1 = Abs(less - over);
            int abs2 = Abs(over - less);

            WriteLine(abs1 < abs2 ? abs1 : abs2);
            
        }

    }

        public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.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; }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(15);
vector<int> forintinput(int n) {
	vector<int> x;
	for(int i = 0;i < n;i++){
		int ia;
		cin >> ia;
		x.push_back(ia);
	}
	return x;
}
int main(){
	int a,b;
	cin >> a >> b;
	cout << a+b/2 << endl;
}

Measured memory_bytes: 3644
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, string.sub(k, i, i)) end local r = io.read local u = table.unpack return function() return r(u(a)) end end})
local N = read.n()
local a = (N + 1) // 2
local b = N
local ans = a / b
print(ans)


Measured memory_bytes: 1008
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt();
		String s = kb.next();
		String p = "";
		String q = "";
		String k = "Yes";
		if (s.length() % 2 == 1) {
			k = "No";
		} else {
			for (int i = 0; i < s.length() / 2; i++) {
				p += s.charAt(i);
			}
			for (int i = s.length() / 2; i < s.length(); i++) {
				q += s.charAt(i);
			}
			if (!p.equals(q))
				k = "No";
		}
		System.out.println(k);
		kb.close();
	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define ll long long
#define INF 2e9
using namespace std;

void Main() {
    int n, h;
    cin >> n;
    int H[n];
    rep(i, 0, n) { cin >> H[i]; }
    int cnt = 0, max = -INF, ans = 0;
    rep(i, 1, n) {
        if (H[i - 1] >= H[i]) {
            cnt++;
        } else {
            cnt = 0;
        }
        if (cnt > max) {
            max = cnt;
            ans = max;
        }
    }
    cout << ans << endl;
}

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

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

int main() {
    int N,r;
    cin >> N;
    r = N;
    
    rep(i,N+1) {
        int c=0,t=i;

        while(t>0) {
            c += t%6;
            t /= 6;
        }
        t = N-i;
        while(t>0) {
            c += t%9;
            t /= 9;
        }

        r = min(r,c);
    }

    cout << r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double eps = 1e-9;
const int maxn = 2e5+9;
const double pi=3.14159265358979323846264;
const int inf = 1e9;
const ll mod = 998244353;
ll sol(ll x,ll n){
    ll ans=1;
    while(n){
        if(n&1) ans=ans*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ans;
}
ll op[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin>>n>>m>>k;
    op[0]=1;
    for(int i=1;i<=n;++i) op[i]=op[i-1]*i%mod;
    ll ans=0;
    for(int i=0;i<=k;++i){
        ans=(ans+op[n-1]*sol(op[n-i-1]*op[i]%mod,mod-2)%mod*m%mod*sol(m-1,n-i-1))%mod;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5144
variables_list = input()
variables_list =  list(map(int, variables_list.split(" ")))


def func(variables_list):
    if variables_list[0] + variables_list[1] > variables_list[2]:
        if variables_list[0] > variables_list[2]:
            return (variables_list[0] - variables_list[2], variables_list[1])
        else:
            return (0, variables_list[1] - (variables_list[2] -variables_list[0]))
        return variables_list[0] + variables_list[1] - variables_list[2]
    else:
        return (0, 0)


print(str(func(variables_list)[0]) + " " + str(func(variables_list)[1]))

Measured memory_bytes: 3064
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,x,y;vi a[N];pii dp[N];
int mul(int x,int y){
  return ((x%M)*(y%M))%M;
}
int add(int x,int y){
  return(((x%M)+(y%M)))%M;
}
void dfs(int u,int p=0){
  dp[u]={1,1};
  //black,white
  for(auto i:a[u])
    if(i!=p)
      {
        dfs(i,u);
        dp[u].F=mul(dp[u].F,dp[i].S);
        dp[u].S=mul(dp[u].S,add(dp[i].F,dp[i].S));
      }
}
void solve(){
  cin>>n;
  rep(i,0,n-2){
    cin>>x>>y;
    a[x].pb(y);
    a[y].pb(x);
  }
  dfs(1);
  cout<<add(dp[1].F,dp[1].S);
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 59264
fun main(args: Array<String>) {
    yahooProcon2019QualA_A()
}

fun yahooProcon2019QualA_A() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }

    val answer = if (1 + ((n - 1) / 2) >= k) "YES" else "NO"

    println(answer)
}


Measured memory_bytes: 38180
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans, cnt = 0;
  ll n, l, r;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  string s;
  cin >> s;
  fi(1, n) {
    if(s[i] == 'E')
      cnt++;
  }
  ans = cnt;
  
  fi(1, n) {
    if(s[i] == 'E')
      cnt--;
    if(s[i - 1] == 'W')
      cnt++;
    chmin(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

class vacation
{
private:
	map<pair<int,int>, long> memo;
	vector<int> activities;
	int days;
	long day_choice(pair<int,int>);
public:
	vacation();
};

vacation::vacation() {
	cin >> days;
	for (int i = 0; i < days; i++) {
		for (int j=0;j<3;j++){
			int x;
			cin >> x;
			activities.push_back(x);

		}
	}
	long value = day_choice(make_pair(-1, 0));
	cout << value;
}
long vacation::day_choice(pair<int, int> choice) {
	map<pair<int,int>,long>::iterator ii = memo.find(choice);
	if (ii == memo.end()) {
		int activity = choice.first;
		int day = choice.second;
		long max_value=0;
		pair<int, int> next_choice;
		for (int todays_activity = 0; todays_activity < 3; todays_activity++) {
			if (todays_activity == activity) {
				continue;
			}
			long temp_value = activities[day*3+todays_activity];
			if (day != days - 1) {
				temp_value += day_choice(make_pair(todays_activity, day + 1));
			}
			if (temp_value > max_value) {
				max_value = temp_value;
			}
		}
		memo[choice] = max_value;
		return max_value;
	}
	else {
		return ii->second;
	}
}
int main(){
  vacation* x = new vacation();
  return 0;}

Measured memory_bytes: 31088
#include <bits/stdc++.h>
#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, K, A[100000], B[100000], C;
ll MAX = 0, cnt;

int main(){
	cin >> N >> K;
	for (int i = 0; i != N; ++i) {
		cin >> A[i] >> B[i];
		if (K == (A[i] | K))
			MAX += B[i];
	}
	int k = K;
	for (int i = 1; i != 31; ++i) {
		if (k % 2) {
			K = K - K % (1 << (i - 1)) - 1;
			cnt = 0;
			for (int j = 0; j != N; ++j) {
				if (K == (A[j] | K))
					cnt += B[j];
			}
			MAX = max(MAX, cnt);
		}
		k /= 2;
	}
	cout << MAX << endl;
	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <cstdio>
using namespace std;
using W = double;
using P = complex<W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
constexpr W EPS = 1e-10;

namespace std {
  bool cmp_y(const P&a, const P&b){
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
}

W cross(const P&a, const P&b){ return a.X*b.Y - a.Y*b.X; }

Poly convex_hull(vector<P> v){
  int n = v.size(), k = 0;
  sort(v.begin(),v.end(),cmp_y);
  Poly r(2*n);
  for(int i = 0; i < n; ++i){
    while(k > 1 and cross(r[k-1]-r[k-2],v[i]-r[k-2]) < -EPS) --k;
    r[k++] = v[i];
  }
  for(int i = n-2, t = k; i >= 0; --i){
    while(k > t and cross(r[k-1]-r[k-2],v[i]-r[k-2]) < -EPS) --k;
    r[k++] = v[i];
  }
  r.resize(k-1);
  return r;
}

int main(){
  int V, R;
  cin >> V >> R;
  vector<P> v;
  for(int i = 0; i < V; ++i){
    W x, y;
    cin >> x >> y;
    v.emplace_back(x,y);
  }
  vector<vector<int>> G(V);
  for(int i = 0; i < R; ++i){
    int s, t;
    cin >> s >> t;
    --s,--t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  Poly C = convex_hull(v);
  vector<bool> used(V,false);
  for(int i = 0; i < V; ++i){
    bool f = false;
    for(auto c : C){
      if(abs(v[i]-c) > EPS) continue;
      f = true;
      break;
    }
    used[i] = f;
  }
  W ans = 0;
  int n = C.size();
  for(int i = 0; i < n; ++i){
    ans += abs(C[i]-C[(i+1)%n]);
  }
  //fprintf(stderr,"%.12f\n",ans);
  priority_queue<pair<W,int>> Q;
  for(int i = 0; i < V; ++i){
    if(not used[i]) continue;
    for(auto v_ : G[i]){
      if(not used[v_]){
        W cost = abs(v[i]-v[v_]);
        Q.emplace(-cost,v_);
      }
    }
  }
  while(Q.size()){
    W cost = -Q.top().first;
    int u = Q.top().second;
    Q.pop();
    if(used[u]) continue;
    used[u] = true;
    ans += cost;
    for(auto v_ : G[u]){
      if(used[v_]) continue;
      Q.emplace(-abs(v[v_]-v[u]),v_);
    }
  }
  printf("%.12f\n",ans);
}



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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    long long sum1 = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i] = a;
        sum1 += a;
    }

    long long sum2 = 0;
    for (int i = 1; i < N; i += 2)
        sum2 += A[i];

    vector<long long> res(N);
    res[0] = sum1 - 2 * sum2;
    for (int i = 1; i < N; i++) {
        res[i] = 2 * A[i - 1] - res[i - 1];
    }

    for (int i = 0; i < N; i++) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;

  vector<int> p(a);
  for (int i = 0; i < a; i++) cin >> p[i];
  sort(p.begin(), p.end(), greater<int>());

  vector<int> q(b);
  for (int i = 0; i < b; i++) cin >> q[i];
  sort(q.begin(), q.end(), greater<int>());

  vector<int> r(c);
  for (int i = 0; i < c; i++) cin >> r[i];

  for (int i = 0; i < x; i++) r.push_back(p[i]);
  for (int i = 0; i < y; i++) r.push_back(q[i]);
  sort(r.begin(), r.end(), greater<int>());

  ll ans = 0;
  for (int i = 0; i < x + y; i++) ans += r[i];
  cout << ans << endl;
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  ll l = s.size();
  vector<ll> cnt(13);
  if(s[l-1] == '?'){
    for(ll i = 0; i < 10; ++i) cnt[i] = 1;
  }
  else{
    ll i = s[l-1]-'0';
    cnt[i] = 1;
  }
  ll r = 10;
  for(ll i = l-2; i >= 0; --i){
    vector<ll> cnt2(13);
    if(s[i] == '?'){
      for(ll j = 0; j <= 9; ++j){
        for(ll k = 0; k < 13; ++k){
          cnt2[(k+j*r)%13] += cnt[k];
        }
      }
    }
    else{
      ll j = s[i]-'0';
      for(ll k = 0; k < 13; ++k){
        cnt2[(k+j*r)%13] += cnt[k];
      }
    }
    cnt = cnt2;
    for(ll k = 0; k < 13; ++k) cnt[k] %= MOD;
    r = (r*10)%13;
  }
  cout << cnt[5]%MOD;
  return 0;
}

Measured memory_bytes: 512
N, X, Y = map(int, input().split())
X -= 1
Y -= 1
K = [0] * N

for i in range(N-1):
    for j in range(i+1, N):
        a = abs(j - i)
        b = abs(X - i) + 1 + abs(j - Y)
        c = abs(Y - i) + 1 + abs(j - X)
        K[min(a, b, c)] += 1

for i in range(1, N):
    print(K[i])


Measured memory_bytes: 3444
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4] ={ 1,0,-1,0 };
int dy[4] ={ 0,1,0,-1 };

long long gcd(long long a, long long b){
	if(b > a) swap(a, b);
	long long tmp;
	while(b != 0){
		tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

ll A, B, X;

signed main() {
	cin >> A >> B;
	X = gcd(A, B);
	ll ans = 1;
	for(int i=2; i<=sqrt(X); i++){
		if(X % i == 0) ans++;
		while(X % i == 0) X /= i;
	}
	if(X > 1) ans++;
	cout << ans << endl;
}

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

int main() {
    int N;
    string S;

    cin >> N >> S;

    int maxcnt=0, cnt=0;
    for (int i=0; i<N; i++) {
        if (S[i]=='I') cnt++;
        else if (S[i]=='D') cnt--;

        maxcnt=max(maxcnt, cnt);
    }
    cout << maxcnt << endl;

    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using static Assistant.Input;
using System.Linq;
using Assistant;

namespace エクサウィザーズ2019D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = ReadInt;
            int X = ReadInt;
            int mod = 1000000007;

            List<int> S = ReadInts.OrderBy(x => -x).ToList();

            int xMax = Math.Max(S.Max(), X) + 1;
            long[,] dp = new long[N + 1, xMax + 1];
            dp[0, X] = 1;

            for (int i = 0; i < N; i++)
            {
                for (int j = 1; j < xMax; j++)
                {
                    dp[i + 1, j % S[i]] += dp[i, j];
                    dp[i + 1, j % S[i]] %= mod;

                    dp[i + 1, j] += dp[i, j] * (N - i - 1) % mod;
                    dp[i + 1, j] %= mod;

                }
                //DrawMapforDebug(dp);
            }

            long ans = 0;
            for (int x = 0; x < xMax; x++)
            {
                ans += dp[N, x] * x % mod;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }


        /// <summary>
        /// 二次元配列の可視化メソッド
        /// </summary>
        /// <param name="map"></param>
        static public void DrawMapforDebug(int[,] map, int mode = 1)
        {
            int W = map.GetLength(0);
            int H = map.GetLength(1);

            int[,] map2 = new int[W + 1, H + 1];
            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (i == 0 && j == 0) map2[i, j] = 0;
                    else if (i == 0) map2[i, j] = j - 1;
                    else if (j == 0) map2[i, j] = i - 1;
                    else map2[i, j] = map[i - 1, j - 1];
                }
            }

            for (int i = 0; i < W + 1; i++)
            {
                for (int j = 0; j < H + 1; j++)
                {
                    if (mode == 0) Console.Write(map2[i, j] % 10);
                    if (mode == 1) Console.Write(map2[i, j] + " ");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }


}

namespace Assistant
{
    static class Input
    {
        static List<string> line = new List<string>();
        static int index = 0;
        static String ReadNext()
        {
            if (line.Count <= index) line.AddRange(Console.ReadLine().Split());
            return line[index++];
        }
        public static int ReadInt => int.Parse(ReadNext());
        public static long ReadLong => long.Parse(ReadNext());
        public static int[] ReadInts => Console.ReadLine().Split().Select(int.Parse).ToArray();
        public static long[] NextLongs => Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    static class Debug
    {
        //drawmap
        //drawarray
    }
}


Measured memory_bytes: 169568
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, T;
    cin >> N >> T;
    VEC(int) A(N);
    READVEC(A);

    int best = 0, maxdiff = 0, bestpairs = 0;
    FORD(i, N - 2, -1) {
        best = max(best, A[i + 1]);
        int diff = best - A[i];
        if (diff == maxdiff) {
            bestpairs++;
        } else if (diff > maxdiff) {
            maxdiff = diff;
            bestpairs = 1;
        }
    }

    cout << bestpairs << endl;
    return 0;
};


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#define INF (1<<30)
using namespace std;

int pow(int a){
    return a*a;
}

int main(){
    int N,M;
    vector< vector<int> > dp(1<<8,vector<int>(20001,INF));
    vector<int> C(1<<4,0),X(20001,0);
    cin >> N >> M;
    while(N!=0 && M!=0){
        dp.at(128).at(0)=0;
        for(int i=0;i<M;i++) cin >> C.at(i);
        for(int i=1;i<=N;i++) cin >> X.at(i);
        for(int j=0;j<N;j++){
            for(int l=0;l<M;l++){
                int k=C.at(l);
                for(int i=0;i<256;i++){
                    int next=min(i+k,255);
                    next=max(next,0);
                    int cur = dp.at(next).at(j+1);
                    dp.at(next).at(j+1)
                    =min(cur,dp.at(i).at(j)+pow(X.at(j+1)-next));
                    //cout << i << " " << next<< " " << X.at(j+1) << endl;
                }
            }
        }
        int ans=INF;
        for(int i=0;i<256;i++){
            ans=min(ans,dp.at(i).at(N));
        }
        cout << ans << endl;
        /*
        cout << "aaaaaaaaaaaa" << endl;
        for(int j=0;j<=N;j++){
            for(int i=0;i<256;i++){
                cout << dp.at(i).at(j) << " ";
            }
            cout << endl;
        }
        cout << "bbbbbbbbbbbbb" << endl;
        */
        cin >> N >> M;
        for(int i=0;i<M;i++) C.at(i)=0;
        for(int i=1;i<=N;i++) X.at(i)=0;
        for(int i=0;i<256;i++){
            for(int j=0;j<=N;j++){
                dp.at(i).at(j)=INF;
            }
        }
    }
}


Measured memory_bytes: 23124
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL a,b,c,d,e,f;

int main(){
	ios::sync_with_stdio(false);
	cin >> a >> b >> c >> d;
	e = (c - 1) / b + 1;
	f = (a - 1) / d + 1;
//	cout << e << ' ' << f << endl;
	cout << (e > f ? "No" : "Yes") << '\n';
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#define endl '\n'
using namespace std;
typedef long long ll;
const int sz=1e6+10,mod=1e9+7;
ll n,dp[sz][2][2];
// 행: 0이 없을 때, 있을 때
// 열: 9가 없을 때, 있을 때

int main()
{
    ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    
    cin>>n;
    dp[1][0][0]=8;
    dp[1][0][1]=1;
    dp[1][1][0]=1;
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    for(int i=2;i<=n;++i){
        dp[i][0][0]=(dp[i-1][0][0]*8)%mod;
        dp[i][0][1]=(dp[i-1][0][0]+dp[i-1][0][1]*9)%mod;
        dp[i][1][0]=(dp[i-1][0][0]+dp[i-1][1][0]*9)%mod;
        dp[i][1][1]=(dp[i-1][0][1]+dp[i-1][1][0]+dp[i-1][1][1]*10)%mod;
    }
    cout<<dp[n][1][1]<<endl;
    return 0;
}


Measured memory_bytes: 34804
#include<iostream>
#include<stdio.h>
using namespace std;

int main() {
    bool card[4][14];
    char ch, mark;
    int x, n;
    
    for (int s = 0; s < 4; s++)
        for (int r = 1; r <= 13; r++)
            card[s][r] = 0;
            
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> ch >> x;
        if (ch == 'S') { card[0][x] = 1;}
        else if (ch == 'H') { card[1][x] = 1;} 
        else if (ch == 'C') { card[2][x] = 1;} 
        else if (ch == 'D') { card[3][x] = 1;}
    }
    for (int s = 0; s < 4; s++){
        for (int r = 1; r <= 13; r++){
            if (!card[s][r]) {
            if (s == 0)  mark = 'S';
            else if (s == 1) mark = 'H';
            else if (s == 2) mark = 'C';
            else if (s == 3) mark = 'D';
            cout << mark << " " << r << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3108
n = int(input())
nums = [int(i) for i in input().split()]
box = [-1] * n
for i in range(1, n + 1)[::-1]:
  C = i * 2
  BALL = nums[i-1]
  while C <= n:
    BALL = BALL ^ box[C-1]
    C += i
  box[i-1] = BALL 

print(box.count(1))
ball = []
for i in range(n):
  if box[i] == 1:
    ball.append(i + 1)
print(*ball)

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

int main(){
  int a=1,b=1,x=360,y;
  cin >> y;
  while(a*x!=b*y){
  	if(a*x<b*y){
      a++;
    }else{
      b++;
    }
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 3620
// Aizu Vol-1 0196: Baseball Championship
// 2017.8.3

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

char *gets(char *);
char buf[500], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p)) p++;
	return *p++ - '0';
}

char getStr(void)
{
	while (isspace(*p)) p++;
	return *p++;
}

typedef struct { char a; int k, w, l; } T;
T t[15];

int main()
{
	int i, j, k, n;
	T tmp, *tp, *tt;

	while (1) {
		gets(buf);
		if (!(n = atoi(buf))) break;
		for (i = 0, tp = t; i < n; i++, tp++) {
			gets(p = buf);
			tp->a = getStr(), tp->k = i, tp->w = tp->l = 0;
			for (j = 1; j < n; j++) {
				k = getInt();
				if (k == 0) tp->w++;
				else if (k == 1) tp->l++;
			}
		}
		for (i = 0; i < n; i++) {
			tp = t + i;
			for (j = i+1, tt = tp+1; j < n; j++, tt++) {
				if (tt->w > tp->w) tp = tt;
				else if (tt->w == tp->w) {
					if (tt->l < tp->l) tp = tt;
					else if (tt->l == tp->l && tt->k < tp->k) tp = tt;
				}
			}
			if (tp != t + i) {
				memcpy(&tmp, t+i, sizeof(tmp));
				memcpy(t+i, tp, sizeof(tmp));
				memcpy(tp, &tmp, sizeof(tmp));
			}
		}
		for (i = 0; i < n; i++) putchar(t[i].a), putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 520
#include <iostream>
using namespace std;
int main(void){
    int m, f, r;
    int sum;

    cin >> m >> f >>r;
    while( m >= 0 || f >= 0 || r >= 0 ){
        sum = m + f;
        if( m * f < 0 ) cout << 'F';
        else if( sum >= 80 ) cout << 'A';
        else if( sum >= 65 ) cout << 'B';
        else if( sum >= 50 ) cout << 'C';
        else if( sum >= 30 ){
            if ( r >= 50 ) cout << 'C';
            else cout << 'D';
        }
        else cout << 'F';
        
        cout << endl;

        cin >> m >> f >>r;
    }
}


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

int main() {
  char x[3];
  cin >> x;

  if (x[0]==x[1] && x[1]==x[2]) {
    cout << "Yes" << endl;
  }
  else if(x[1]==x[2] && x[2]==x[3]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

// a^b mod m
int powmod(int a,int b,int m)
{
	if(b==0) return 1;
	int x=powmod(a,b/2,m); x=x*x%m;
	return b&1?x*a%m:x;
}
int inv(int n,int m)
{
	return powmod(n,m-2,m);
}

int expr(const string& s,int m,int& i);

int fact(const string& s,int m,int& i)
{
	int n=s.size();
	if(s[i]=='('){
		i++;
		int res=expr(s,m,i);
		i++;
		return res;
	}
	int res=0;
	while(i<n && isdigit(s[i]))
		res=res*10+s[i++]-'0';
	return res;
}

int term(const string& s,int m,int& i)
{
	int n=s.size();
	int res=fact(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='*' && op!='/') break;
		int tmp=fact(s,m,++i);
		if(op=='*') res=res*tmp%m;
		if(op=='/'){
			if(tmp==0) throw "NG";
			res=res*inv(tmp,m)%m;
		}
	}
	return res;
}

int expr(const string& s,int m,int& i)
{
	int n=s.size();
	int res=term(s,m,i);
	while(i<n){
		int op=s[i];
		if(op!='+' && op!='-') break;
		int tmp=term(s,m,++i);
		if(op=='+') res=(res+tmp)%m;
		if(op=='-') res=(res-tmp+m)%m;
	}
	return res;
}

int main()
{
	for(int p;cin>>p,p;){
		cin.ignore();
		string s; getline(cin,s);
		// assert(s[0]==' ');
		s.erase(remove(all(s),' '),s.end());
		
		try{
			int i=0;
			int res=expr(s,p,i);
			printf("%s = %d (mod %d)\n",s.c_str(),res,p);
		}
		catch(const char*){
			puts("NG");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1416
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string s;
    cin >> s;
    ll n = s.size();
    vector<ll> dp(n);
    map<ll, ll> mp;
    dp[n-1] = s[n-1] - '0';
    ll ten = 10;
    mp[0] = 1;
    mp[dp[n-1]]++;
    for (ll i = n - 2; i >= 0; i--)
    {
        dp[i] = (dp[i+1] + (s[i] - '0') * ten) % 2019;
        ten = (ten * 10) % 2019;
        mp[dp[i]]++;
    }
    ll ans = 0;
    for (auto x:mp)
        ans += x.second*(x.second-1)/2;
    cout << ans;
    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	long long int ans = 0;
	for(int i = 1; i<=n; i++){
		if( (i % 3) != 0 && (i % 5) != 0)
			ans += i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll arr[n];
  ll ans = 0;
  for(ll i=0;i<n;i++){
    cin >> arr[i];
  }
  bool ok = true;
  while(true){
    for(ll i=0;i<n;i++){
      if(arr[i]%2==0)
        arr[i]/=2;
      else{
        ok=false;
        break;
      }
    }
    if(ok)
      ans++;
    else
      break;
  }
  cout << ans << endl;
}


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

using namespace std;

main(){
  int n, m, k;
  while(1){
    cin >> n >> m >> k;
    if(n==0 && m==0 && k==0) break;

    int num[10000];
    for(int i=1;i<=n;i++) num[i]=1;
    bool end=false;
    double ans=0;
    double a=pow((double)m, (double)n);
    for(;;){
      int sum=0;
      for(int i=1;i<=n;i++){
	sum+=num[i];
      }
      if(sum<=k){
	ans+=1.0/a;
      }else{
	ans+=1.0/a*(double)(sum-k);
      }
      if(num[n]==m){
	num[n]=0;
	for(int t=n-1;;){
	  if(t<=0){
	    end=true;
	    break;
	  }
	  if(num[t]<m){
	    num[t]++;
	    break;
	  }else{
	    num[t]=1;
	    t--;
	  }
	}
	if(end) break;
      }
      num[n]++;
    }
    printf("%.10f\n", ans);
  }
  return 0;
}

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

int main(){
	char a;

	cin >> a;

	if (a=='A'){
		cout<<'T'<<endl;
	}
	else if(a=='T'){
		cout<<'A'<<endl;
	}
	else if(a=='C'){
		cout<<'G'<<endl;
	}
	else if(a=='G'){
		cout<<'C'<<endl;
	}
	return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ull N, A, B;
	cin >> N >> A >> B;

	ull setNum = N / (A + B);
	ull rem = N - setNum * (A + B);

	ull ans = setNum * A + min(rem, A);

	cout << ans << "\n";

	return 0;
}


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

int main() {
  int a, b, i, j;
  cin >> a >> b;
  i = a % 2 ;
  j = b % 2 ;
  if (i * j == 1){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n,m;
bool f;
while(1){
scanf("%d%d",&n,&m);
f=true;
if(n==0)return 0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(f){
printf("#");
f=false;
}
else{
printf(".");
f=true;
}
}
if(m%2==0)f=!f;
printf("\n");
}
printf("\n");
}
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################

const int mod = 1000000007;
signed main(){
    int s;cin >> s;
    vector<int> dp(s+1);
    dp[0] = 1;
    auto add = [&](int &a,int b){
        a = (a+b)%mod;
    };
    rep(i,s+1){
        // if(i-1 >= 0)add(dp[i],dp[i-1]);
        if(i-3 >= 0)add(dp[i],dp[i-3]+dp[i-1]);
    }
    // trace(dp);
    cout << dp[s] << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	char a, b, c;
	map<char, bool> m;

	cin >> a >> b >> c;

	m[a] = true;
	m[b] = true;
	m[c] = true;

	if (m['a'] && m['b'] && m['c'])cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int r,c,m;
    cin >> r >> c >> m;
    vector<vector<char>> grid(r,vector<char>(c));
    vector<vector<int>> time(r,vector<int>(c)),on(r,vector<int>(c)),off(r,vector<int>(c));
    vector<pii> tasks(m);
    rep(i,0,r) rep(j,0,c) cin >> grid[i][j];
    rep(i,0,r) rep(j,0,c) cin >> time[i][j];
    rep(i,0,r) rep(j,0,c) cin >> on[i][j];
    rep(i,0,r) rep(j,0,c) cin >> off[i][j];
    for(auto& t:tasks) cin >> t.first >> t.second;

    vector<vector<vector<int>>> arrival(r,vector<vector<int>>(c));
    function<bool(const pii,const pii,const pii,const int)> dfs=[&](const pii prev,const pii curr,const pii end,const int d){
        if(curr==end){
            arrival[curr.first][curr.second].emplace_back(d);
            return true;
        }
        bool pass=false;
        rep(i,0,4){
            pii next(curr.first+dx[i],curr.second+dy[i]);
            if(next.first<0 or r<=next.first or next.second<0 or c<=next.second or next==prev or grid[next.first][next.second]=='#') continue;
            pass|=dfs(curr,next,end,d+1);
        }
        if(pass) arrival[curr.first][curr.second].emplace_back(d);
        return pass;
    };

    int elapsed=0;
    rep(i,0,m-1){
        dfs(tasks[i],tasks[i],tasks[i+1],elapsed);
        elapsed+=arrival[tasks[i+1].first][tasks[i+1].second].back()-elapsed;
    }

    int ans=0;
    rep(i,0,r) rep(j,0,c){
        if(arrival[i][j].empty()) continue;
        int cost=on[i][j]+off[i][j];
        rep(k,0,arrival[i][j].size()-1){
            int tmp1=off[i][j]+on[i][j];
            int tmp2=time[i][j]*(arrival[i][j][k+1]-arrival[i][j][k]);
            cost+=min(tmp1,tmp2);
        }
        dump(cost);
        ans+=cost;
    }

    cout << ans << endl;
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    solve();
    return 0;
}

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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

int main() {
	string s, t;
	cin >> s >> t;
	vector<set<int>> v(26);
	int n = int(s.size());
	rep(i, n) {
		v[s[i] - 'a'].insert(i + 1);
	}
	ll ans = 0;
	int id = 0;
	int m = int(t.size());
	rep(i, m) {
		int c = t[i] - 'a';
		if (v[c].empty()){
			cout << -1 << endl;
			return 0;
		}
		auto itr = v[c].lower_bound(id+1);
		if (itr == v[c].end()) {
			itr = v[c].begin();
			ans += ll(n - id + *itr);
		} else {
			ans += ll(*itr - id);
		}
		id = *itr;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	http://abc071.contest.atcoder.jp/tasks/arc081_a
*/

int n;
map<int, int> check;
LL solve()
{
	LL ret = 0, one = -1, two = -1;
	for(auto rit = check.rbegin(); rit != check.rend(); ++rit)
	{
		int len = rit->first, cnt = rit->second;
		if(cnt >= 2)
		{
			if(cnt >= 4)
				ret = max(ret, 1ll * len * len);
			if(one == -1) one = len;
			else if(two == -1)  {
				two = len;
				ret = max(ret, one * two);
			}
		}
	}	
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;

	REP(i, 0, n) {
		int x;
		cin >> x;
		++check[x];
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 4992
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

const long long MAXN = 1e6 + 1;
using namespace std;

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


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

map <pair <string, string>, int> m;

string s;
ll ans;

main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    cin >> s;
    for (int i = 0; i < (1 << n); i++) {
        string a = "";
        string b = "";
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                a.pb(s[j]);
            }
        }
        for (int j = n - 1; j >= 0; j--) {
            if (! ((i >> j) & 1)) {
                b.pb(s[j]);
            }
        }
        m[{a, b}] ++;
    }
    for (int i = 0; i < (1 << n); i++) {
        string a = "";
        string b = "";
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                a.pb(s[n+j]);
            }
        }
        for (int j = n - 1; j >= 0; j--) {
            if (! ((i >> j) & 1)) {
                b.pb(s[n+j]);
            }
        }
        ans += m[{b, a}];
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 91904