akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<ll> a;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll d;
    for(int i=0;i<n;i++){
        cin>>d;
        a.push_back(d);
    }
    deque<ll> b;
    for(int i=0;i<n;i++){
        if(i%2==1){
            b.push_front(a[i]);
        }
        else{
            b.push_back(a[i]);
        }
    }
    if(n%2==1){
        for(int i=n-1;i>=0;i--){
            cout<<b[i]<<"\n";
        }
    }
    else{
        for(int i=0;i<n;i++){
            cout<<b[i]<<"\n";
        }
    }
}

Measured memory_bytes: 5360
#pragma comment(linker, "/STACK:36777216")
#include <bits/stdc++.h>

#define FOR(VAR,ST,END) for(int VAR=ST; VAR<END; ++VAR)
#define FORI(VAR,ST,END) for(int VAR=ST; VAR<=END; ++VAR)
#define ROF(VAR,ST,END) for(int VAR=ST; VAR>END; --VAR)
#define ROFI(VAR,ST,END) for(int VAR=ST; VAR>=END; --VAR)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define MAXI(a,b) (a=(a>b?a:b))
#define MINI(a,b) (a=(a<b?a:b))
#define ABS(a) ((a)>0?(a):-(a))
#define MINI_NZ(a,b) {if(a==0) a = b; else a = a<b?a:b;}
#define SWAP_IF(type,x,y,cond) if(cond) {type tmp=x; x=y; y=tmp;}
#define SWAP(type,x,y) {type tmp=x; x=y; y=tmp;}
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
#define MAX_NP1 (MAX_N+1)
#define MAX_NP2 (MAX_N+2)

using namespace std;

#define MAX_N 100000

int main()
{
    int a, b;
    cin >> a >> b;

    cout << 100 << " " << 100 << endl;
    --a; --b;
    // Black
    FOR(i, 0, 50)
    {
        FOR(j, 0, 100)
        {
            if ((i & 1) == 0 && (j & 1) == 0 && a)
            {
                cout << ".";
                --a;
            }
            else
                cout << "#";
        }
        cout << endl;
    }

    // White
    FOR(i, 50, 100)
    {
        FOR(j, 0, 100)
        {
            if ((i & 1) && (j&1) == 0 && b)
            {
                cout << "#";
                --b;
            }
            else
                cout << ".";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>


using namespace std;


long long kaijou(int n, int last = 1) {
	if (n <= last) return last;
	return kaijou(n - 1, last) * n;
}

long long ncm(int n, int m) {

	return kaijou(n, n - m + 1) / kaijou(m);
}


int main()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> index;
	long long answer = 0;


	for (int i = 0; i < n; i++) {
		int aaa; cin >> aaa;
		a[aaa]++;
		index.push_back(aaa);
	}

	for (int i = 0; i <= n; i++) {
		answer += ncm(a[i], 2);
	}

	for (int i = 0; i < n; i++) {
		cout << answer - ncm(a[index[i]], 2) + ncm(a[index[i]] - 1, 2) << endl;
	}
}

Measured memory_bytes: 4340
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a1, a2, a3, a4;
		int b1, b2, b3, b4;
		int hit, blow;

		while (sc.hasNext()) {
			a1 = sc.nextInt();
			a2 = sc.nextInt();
			a3 = sc.nextInt();
			a4 = sc.nextInt();
			b1 = sc.nextInt();
			b2 = sc.nextInt();
			b3 = sc.nextInt();
			b4 = sc.nextInt();
			hit = 0;
			blow = 0;
			
			if (a1 == b1) hit++;
			if (a2 == b2) hit++;
			if (a3 == b3) hit++;
			if (a4 == b4) hit++;
			if (a1 == b2) blow++;
			if (a1 == b3) blow++;
			if (a1 == b4) blow++;
			if (a2 == b1) blow++;
			if (a2 == b3) blow++;
			if (a2 == b4) blow++;
			if (a3 == b1) blow++;
			if (a3 == b2) blow++;
			if (a3 == b4) blow++;
			if (a4 == b1) blow++;
			if (a4 == b2) blow++;
			if (a4 == b3) blow++;
			System.out.println(hit + " " + blow);
		}
	}
}

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

int main(){
	int n, k;
  	string s; cin >> n >> k >> s;
  	if( s[k-1] == 'A' )
      	s[k-1] = 'a';
  	else if( s[k-1] == 'B' )
      	s[k-1] = 'b';
  	else
     	 s[k-1] = 'c';
  	cout << s;
  	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=200000+10,maxv=5000+10,mo=1000000007,inv2=(mo+1)/2;
int c[maxv][maxv],a[maxn],b[maxn],fac[maxv*2],inv[maxv*2];
int i,j,k,l,t,n,m,ans,mxa,mxb;
int qsm(int x,int y){
    if (!y) return 1;
    int t=qsm(x,y/2);
    t=(ll)t*t%mo;
    if (y%2) t=(ll)t*x%mo;
    return t;
}
int C(int n,int m){
    if (m<0||n<m) return 0;
    return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int main(){
    cin>>n;
    fo(i,1,n){
        scanf("%d%d",&a[i],&b[i]);
        mxa=max(mxa,a[i]);mxb=max(mxb,b[i]);
    }
    fac[0]=1;
    fo(i,1,mxa*2+mxb*2) fac[i]=(ll)fac[i-1]*i%mo;
    inv[mxa*2+mxb*2]=qsm(fac[mxa*2+mxb*2],mo-2);
    fd(i,mxa*2+mxb*2-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
    fo(i,1,n) c[mxa-a[i]][mxb-b[i]]++;
    fo(i,0,mxa*2)
        fo(j,0,mxb*2){
            if (j) (c[i][j]+=c[i][j-1])%=mo;
            if (i) (c[i][j]+=c[i-1][j])%=mo;
        }
    fo(i,1,n) (ans+=c[mxa+a[i]][mxb+b[i]])%=mo;
    fo(i,1,n) (ans-=C(a[i]*2+b[i]*2,a[i]*2))%=mo;
    ans=(ll)ans*inv2%mo;
    (ans+=mo)%=mo;
    printf("%d\n",ans);
}


Measured memory_bytes: 82176
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      // cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

const int MOD = 2019;
signed main() {
  string S;
  cin >> S;
  int N = sz(S);
  vector<int> m(N);
  m[N - 1] = S[N - 1] - '0';
  int p = 10;
  rrep(i, 0, N - 1) {
    m[i] = (p * (S[i] - '0') % MOD + m[i + 1]) % MOD;
    p *= 10;
    p %= MOD;
  }
  map<int, int> cnt;
  cnt[0] = 1;
  int ans = 0;
  rrep(i, 0, N) {
    ans += cnt[m[i]];
    cnt[m[i]]++;
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 5052
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
char str[N];
char Dream[5]= {'d','r','e','a','m'};
char Erase[5]= {'e','r','a','s','e'};
int main() {
    scanf("%s",str);
    int len=strlen(str);

    bool flag=true;
    for(int i=0; i<len; i++) {
        if(str[i]=='d') {
            int j=i;
            for(; j<=i+4; j++) {
                if(j>=len||str[j]!=Dream[j-i]) {//是否为dream或dreamer
                    flag=false;
                    break;
                }
            }
            if(j==i+5) {
                if(str[j]=='e'&&str[j+1]=='r'&&str[j+2]!='a')//dreamer，指针前移
                    i=j+1;
                else//dream，指针后移
                    i=j-1;
            }
        }
        else if(str[i]=='e') {
            int j=i;
            for(; j<=i+4; j++) {
                if(j>=len||str[j]!=Erase[j-i]) { //是否为erase或eraser
                    flag=false;
                    break;
                }
            }
            if(j==i+5) {
                if(str[j]=='r')//eraser，指针前移
                    i=j;
                else//erase，指针后移
                    i=j-1;
            }
        }
        else
            flag=false;

        if(!flag)
            break;
    }

    if(flag)
        printf("YES\n");
    else
        printf("NO\n");

    return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

int const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll x; cin >> x;
	ll kek = x / 500;
	ll ans = 0;
	ans += kek * 1000;
	ll y = x % 500;
	ans += (y / 5) * 5;
	cout << ans << endl;

	return 0;
}

/*
8 6

4 5 1 2 3 5 3 3

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1e18;

int N,M;
bool t[50];

bool check_dfs(int a[50][50],int u){
    t[u]=true;
    for(int i=0;i<N;i++){
        if(a[u][i]==1&&t[i]==false){
            if(!check_dfs(a,i)) return false;
        }
    }
    for(int i=0;i<N;i++){
        if(t[i]==false) return true;
        if(i==N-1) return false;
    }
}

int main(){
    cin >> N >> M;
    int a[50][50];
    vector<P> vec;
    memset(a,0,sizeof(a));
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >> y;
        x--,y--;
        vec.push_back(make_pair(x,y));
        a[x][y]=1;
        a[y][x]=1;
    }
    int count=0;
    for(int i=0;i<M;i++){
        memset(t,false,sizeof(t));
        t[0]=true;
        P p=vec[i];
        a[p.first][p.second]=0;
        a[p.second][p.first]=0;
        if(check_dfs(a,0)){
            count++;
        }
        a[p.first][p.second]=1;
        a[p.second][p.first]=1;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s, h;
	cin >> s;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == '0') h += "0";
		else if (s[i] == '1') h += "1";
		else if (s[i] == 'B'&&h.length() != 0) h.erase(--h.end());
	}

	cout << h << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    ll s = 1900 * M + (N - M) * 100;
    cout << s * pow(2, M);
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace codefestival_2016_qualB_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            string s = Console.ReadLine();
            int a = x[1] + x[2];
            for (int i = 0; i < x[0]; i++)
            {
                if (a > 0)
                {
                    switch (s[i])
                    {
                        case ('a'):
                            {
                                Console.WriteLine("Yes");
                                a--;
                                break;
                            }
                        case ('b'):
                            {
                                if (x[2] > 0)
                                {
                                    Console.WriteLine("Yes");
                                    a--;
                                    x[2]--;
                                }
                                else
                                {
                                    Console.WriteLine("No");
                                }
                                break;
                            }
                        default:
                            {
                                Console.WriteLine("No");
                                break;
                            }
                    }
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
            //Console.ReadLine();
        }
    }
}

Measured memory_bytes: 15840
// D - Lucky PIN
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp((i),0,(e))
#define all(x) (x).begin(),(x).end()
#define lbound(x,c) lower_bound(all(x),(c))-(x).begin()

int main(){
	int N; string S; cin>>N>>S; S = "-" + S;
	vector<vi> ix(10, vi());
	rp(i,1,N+1) ix[S[i]-'0'].push_back(i);
	int ans = 0;
	rpz(a, 10){
		int p = lbound(ix[a], 0);
		if(p >= ix[a].size()) continue;
		rpz(b, 10){
			int q = lbound(ix[b], ix[a][p]+1);
			if(q >= ix[b].size()) continue;
			rpz(c, 10) if(lbound(ix[c], ix[b][q]+1) < ix[c].size()) ans++;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 512
N,M = [int(i) for i in input().split()]
submissions = {str(i):[] for i in range(1,N+1)}
AC,WA = 0,0
for i in range(M):
    P,S = [j for j in input().split()]
    submissions[P].append(S)
for i in submissions:
    if 'AC' not in submissions[i]:
        continue
    for j in submissions[i]:
        if j == 'AC':
            AC+=1
            break
        WA +=1
print(AC,WA)

Measured memory_bytes: 31248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k, r, s, p;
	cin >> n >> k >> r >> s >> p;
	string T;
	cin >> T;

	//mod k
	vector<char> tabu(k);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (i < k) {
			tabu[i] = T[i];
			if (T[i] == 'r') ans += p;
			if (T[i] == 's') ans += r;
			if (T[i] == 'p') ans += s;
		}
		else {
			int a = i;
			a %= k;
			if (tabu[a] == T[i]) {
				tabu[a] = '0';
				continue;
			}
			tabu[a] = T[i];
			if (T[i] == 'r') ans += p;
			if (T[i] == 's') ans += r;
			if (T[i] == 'p') ans += s;
		}
	}

	dunk(ans);
	
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

using P = pair<int, int>;
using Edge = pair<int, P>;

signed main() {
  int N, M, S;
  cin >> N >> M >> S;

  vector<vector<Edge>> graph(N);
  REP(i, M){
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--; v--;
    graph[u].emplace_back(Edge(v, make_pair(a, b)));
    graph[v].emplace_back(Edge(u, make_pair(a, b)));
  }

  vector<int> c(N), d(N);
  REP(i, N) cin >> c[i] >> d[i];

  const int MAX = 2500;
  chmin(S, MAX);

  vector<vector<int>> dp(N, vector<int>(MAX+1, INF));
  dp[0][S] = 0;

  priority_queue<Edge, vector<Edge>, greater<Edge>> q;
  q.push({0, {0, S}});

  while(!q.empty()){
    auto p = q.top(); q.pop();
    int time = p.first;
    int v = p.second.first;
    int s = p.second.second;
    if(time > dp[v][s]) continue;

    if(s+c[v] <= MAX){
      int ns = s+c[v];
      int nt = time+d[v];
      if(chmin(dp[v][ns], nt)){
        q.push({nt, {v, ns}});
      }
    }

    for(auto e : graph[v]){
      if(s < e.second.first) continue;
      int nv = e.first;
      int ns = s-e.second.first;
      int nt = time+e.second.second;
      if(chmin(dp[nv][ns], nt)){
        q.push({nt, {nv, ns}});
      }
    }
  }

  FOR(i, 1, N){
    int ret = INF;
    REP(j, MAX) chmin(ret, dp[i][j]);
    cout << ret << "\n";
  }

  return 0;
}

Measured memory_bytes: 7348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S1, S2;
    cin >> S1 >> S2;
    reverse(all(S1));
    if (S1 == S2)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

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

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S;
    cin >> S;

    vector<int> mods(S.size()+1);
    unordered_map<int,int> counts;
    counts[0]++;
    mods[S.size()]  = 0;
    int keta = 1;
    ll total = 0;
    for(int i = S.size()-1; i >= 0; i-- ){
        int num = S[i] - '0';
        mods[i] = (num*keta + mods[i+1])%2019;
        total += counts[mods[i]];
        counts[mods[i]]++;
        keta = (keta*10)%2019;
        // DEBUG("mods[%d]=%d", i, mods[i]);
        // DEBUG("count at %d=%d", i, counts[mods[i]]);
    }

    cout << total << endl;
}


Measured memory_bytes: 4312
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<numeric>

using namespace std;

int main(void){

  string s;

  cin>>s;

  vector<unsigned long long> res_b(1);
  res_b[0]=0;
  unsigned long long tmp=0;
  unsigned long long val=0;
  for(int i=0;i<s.length();i++){
    if(s[i] == 'B'){
      tmp++;
    }
    else if(s[i] == 'W'){
      //res_b.push_back(tmp);
      val+=tmp;
    }
  }


  //cout << (unsigned long long)accumulate(res_b.begin(),res_b.end(),0) << endl;
  cout << val << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,a,b;
    cin>>k>>a>>b;
    if(k==1||a%k==0||b%k==0) cout<<"OK";
    else if(b/k - a/k>0) cout<<"OK";
    else cout<<"NG";
}


Measured memory_bytes: 3636
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    LONG H, W;
    cin >> H >> W;

    vector<vector<int>> S(H + 2, vector<int>(W + 2, 0));
    for(int i = 0; i < H; ++i){
        string s;
        cin >> s;

        for(int j = 0; j < W; ++j){
            if(s[j] == '#'){
                S[i+1][j+1] = 0;
            }
            else{
                S[i+1][j+1] = 1;
            }
        }
    }

    vector<vector<bool>> passed(H + 2, vector<bool>(W + 2, false));

    for(int i = 0; i < W; ++i){
        passed[0][i+1] = true;
        passed[H+1][i+1] = true;
    }
    for(int i = 0; i < H; ++i){
        passed[i+1][0] = true;
        passed[i+1][W+1] = true;
    }

    LONG num = 0;
    LONG sum = 0;
    int prev_start_x = 0;
    int prev_start_y = 1;

    while(num < H * W){

        int start_x = -1;
        int start_y = -1;

        for(int y = prev_start_y; y <= H; ++y){
            for(int x = prev_start_x + 1; x <= W; ++x){
                if(!passed[y][x]){
                    start_x = x;
                    start_y = y;
                    break;
                }
            }
            if(start_x != -1){
                break;
            }
            prev_start_x = 0;
        }

        if(start_x == -1){
            break;
        }

        prev_start_x = start_x;
        prev_start_y = start_y;

        queue<pair<int, int>> pos_q;
        pos_q.push({start_x, start_y});
        passed[start_y][start_x] = true;

        long long black_num = 0;
        long long white_num = 0;

        while(pos_q.size()){
            ++num;
            auto p = pos_q.front();
            pos_q.pop();
            int val = S[p.second][p.first];

            if(val == 0){
                ++black_num;
            }
            else{
                ++white_num;
            }

            if(S[p.second - 1][p.first] != val && !passed[p.second - 1][p.first]){
                passed[p.second - 1][p.first] = true;
                pos_q.push({p.first, p.second - 1});
            }
            if(S[p.second + 1][p.first] != val && !passed[p.second + 1][p.first]){
                passed[p.second + 1][p.first] = true;
                pos_q.push({p.first, p.second + 1});
            }
            if(S[p.second][p.first - 1] != val && !passed[p.second][p.first - 1]){
                passed[p.second][p.first - 1] = true;
                pos_q.push({p.first - 1, p.second});
            }
            if(S[p.second][p.first + 1] != val && !passed[p.second][p.first + 1]){
                passed[p.second][p.first + 1] = true;
                pos_q.push({p.first + 1, p.second});
            }
        }


        sum += white_num * black_num;
    }

    cout << sum;
}


Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String str = in.nextLine();
        final char[] s = (' ' + str).toCharArray();
        final int n = str.length();
        int cnt1 = 0;
        int cnt0 = 0;
        long res = 0;
        for (int i = 1; i <= n; ++i) {
            cnt1 += (s[i] == '1') ? 1 : 0;
            cnt0 += (s[i] == '0') ? 1 : 0;
        }
        for (int i = 1; i <= cnt1; ++i) {
            res += (i + 1) / 2;
        }
        for (int i = 1, now = 0, x = 0, y = 0; i <= n; ++i) {
            if (s[i] == '1') {
                ++now;
                ++y;
                if ((y & 1) == 1) {
                    res += x / 2;
                } else {
                    res += (x + 1) / 2;
                }
                if ((now & 1) == 1) {
                    res += cnt0 - x;
                }
            } else {
                ++x;
                if ((now & 1) == 1) {
                    ++now;
                }
            }
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 43988
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const int EPS = 1e-9;

//Union Find Tree
class UnionFindTree{
public:
  int treeCnt; //ツリーの数
  vector<int> rank,p;  //rank => 根の高さ, p => 親
  vector<int> num; //木の要素数
  UnionFindTree(){}
  UnionFindTree(int size){
    rank.resize(size,0);
    p.resize(size,0);
    num.assign(size,1);
    treeCnt = 0;
    REP(i,size){
      makeset(i);
    }
  }

  void makeset(int x){
    p[x] = x;
    rank[x] = 0;
    treeCnt++;
  }

  //同じ木に属しているか判定
  bool same(int x, int y){
    return findSet(x) == findSet(y);
  }

  //xとyが属している木をつなぐ
  void unite(int x, int y){
    link(findSet(x),findSet(y));
  }
  
  ///木と木を繋ぐ処理をする。(ついでに木の高さを調整)
  void link(int x, int y){
    if(!same(x,y)){
      if(rank[x] > rank[y]){
	p[y] = x;
	num[x] += num[y];
      }else{
	p[x] = y;
	if(rank[x] == rank[y]){
	  rank[y]++;
	}
	num[y] += num[x];
      }
      treeCnt--;
    }
  }

  //xが属している木の根を探る(ついでに木を操作)
  int findSet(int x){
    if(p[x] == x) return x;
    else return p[x] = findSet(p[x]);
  }

  int countTree(){
    return treeCnt;
  }

  int getNum(int a){
    return num[findSet(a)];
  }
};


int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y;
  while(cin >> x >>  y){
    TSTART();
    //union find 使うほどの問題ではない(?)と思うが練習
    //想定解は1~12の所属グループを全列挙
    UnionFindTree uft(12);
	//0-indexed
    uft.unite(0,2);
    uft.unite(4,2);
    uft.unite(6,2);
    uft.unite(7,2);
    uft.unite(9,2);
    uft.unite(11,2);
    uft.unite(3,5);
    uft.unite(8,5);
    uft.unite(10,5);

    string ans;
    if(uft.same(x-1,y-1))ans = "Yes";
    else ans = "No";
    
    cout << ans << endl;
    TSTOP();
  }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int MAX = 100100;
  vi is_prime(MAX,1);
  is_prime[0] = 0; is_prime[1] = 0;
  for (int i = 2; i < MAX; i++) {
    if(is_prime[i]) for(int j = 2*i; j < MAX; j += i) is_prime[j] = 0;
  }

  vi S(MAX+1);
  rep(i, MAX){
    if(is_prime[i] && is_prime[(i+1)/2]) S[i+1] = S[i] + 1;
    else S[i+1] = S[i];
  }

  int Q; cin >> Q;
  rep(q, Q){
    int l,r; cin >> l >> r;
    std::cout << S[r+1] - S[l] << '\n';
  }
}


Measured memory_bytes: 1408
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import numpy as np

def solve(H, W, K, S):
    ans = 1<<60
    for s in range(1<<H-1):
        an = 0
        f = True
        mapping = np.zeros(H, dtype=np.int64)
        for i in range(H-1):
            if s>>i&1:
                an += 1
                mapping[i+1] = mapping[i]+1
            else:
                mapping[i+1] = mapping[i]
        if an >= ans:
            continue
        Cnt = np.zeros(mapping[-1]+1, dtype=np.int64)
        for x in range(W):
            for y in range(H):
                m = mapping[y]
                c = S[y, x]
                Cnt[m] += c
            if (Cnt > K).any():
                Cnt[:] = 0
                an += 1
                if an >= ans:
                    f = False
                    break
                for y in range(H):
                    m = mapping[y]
                    c = S[y, x]
                    Cnt[m] += c
                if (Cnt > K).any():
                    f = False
                    break
            if not f:
                break
        if f:
            ans = an
    return ans

numba_compile([
    [solve, "i8(i8,i8,i8,i8[:,:])"],
])

def main():
    H, W, K = map(int, input().split())
    S = np.empty((H, W), dtype=np.int64)
    for y in range(H):
        S[y] = np.array(list(input()), dtype=np.int64)
    ans = solve(H, W, K, S)
    print(ans)

main()


Measured memory_bytes: 27496
#include<stdio.h>
#include<math.h>


int main()
{
	long int n, a, b, c=0;
	scanf("%ld", &n);
	a=n;
	while(a){
		b=a%10;
		c+=b;
		a=a/10;
	}
	
	if(n%c==0) printf("Yes\n");
	
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    Main abc150A = new Main();
    System.out.println(abc150A.solve(A, B));
  }

  public String solve(int k, int x){
    return 500 * k >= x ? "Yes" : "No";
  }
}


Measured memory_bytes: 21844
/* Simplicity and Goodness */

#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;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) { cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=a; i<(int)b; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int maxN = 2e5+2;

vi par(maxN), sz(maxN);

int find(int x)
{
    return par[x] == x ? x : par[x] = find(par[x]);
}

void merge(int a, int b)
{
    int x = find(a), y = find(b);

    if(x == y) return;

    par[x] = y;

    sz[y] += sz[x];
}

void solve()
{   
    int n, m;
    scn(n); scn(m);

    rep(i, 1, n + 1) {
        sz[i] = 1;
        par[i] = i;
    }

    rep(i, 0, m) {
        int a, b;
        scn(a); scn(b);

        merge(a, b);
    }

    int mx = 0;

    rep(i, 1, n + 1) {
        int p = find(i);

        mx = max(mx, sz[p]);
    }

    prin(mx);
} 

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;

ll factorial(ll n) {
    ll ans = 1;
    for(ll i = 1; i <= n; i++){
        ans *= i;
        ans %= MOD;
    }
    return ans % MOD;
}

int main() {
    ll n,m; cin >> n >>m;
    if(abs(n - m) > 1){
        cout << 0 << endl;
        return 0;
    }

    if(n == m){
        cout << factorial(n) * factorial(m) % MOD * 2 % MOD << endl;
    }else{
        cout << factorial(n) * factorial(m) % MOD << endl;
    }



    return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();

		int sum = 0;
		int check = N;
		while(N != 0) {
			sum += N % 10;
			N /= 10;
		}

		if(check % sum == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	int a_ = 0;
	long long ans = 0;
	while (n--) {
		int a; cin >> a;
		if (a_ > a)
			ans += a_ - a;
		else
			a_ = a;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define pb push_back
#define int long long int
#define INF 1e18
#define vec vector<int>
#define REP(i,a,b) for(i=a;i<b;i++)
using namespace std;
int32_t main()
{
  int t=1;
  //cin>>t;
  while(t--)
  {
    string s;
    int ans=0;
    cin>>s;
    int n=s.length();
    for(int i=0;i<n;i++)
        ans+=(int)s[i]-48;
    if(ans%9)
        cout<<"No\n";
    else cout<<"Yes\n";
  }
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n; cin>>n;
	map<string,ll> mp;
	rep(i,0,n){
		string s; cin>>s;
		mp[s]++;
	}
	ll m=0;
	for(auto c:mp){
		chmax(m,c.second);
	}
	cout<<endl;
	for(auto c:mp){
		if(c.second==m){
			cout<<c.first<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 19180
function main(input) {
  var data = input.split(" ");

  var r = data[0];
  var D = data[1];
  var x = data[2];

  for(i = 1; i< 11; i++){
    xp1 = r*x - D
    console.log(xp1);
    x = xp1;
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

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 FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll A, B; cin >> A >> B;
    ll c = A%2 + B%2;
    if(c==1){
        p("IMPOSSIBLE");
        return 0;
    }

    ll ans = (A+B)/2;
    p(ans);
    
    return 0;
}

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

unsigned long long N;
vector<unsigned long long>* edge;
bool* visit;
unsigned long long* black;
unsigned long long* white;

void dfs(unsigned long long u)
{
    for(unsigned long long v: edge[u]) if(!visit[v])
    {
        visit[v] = 1;
        dfs(v);
        black[u] = (black[u] * white[v]) % 1000000007;
        white[u] = (((black[v] + white[v]) % 1000000007) * white[u]) % 1000000007;
    }
}

int main()
{
    cin >> N;
    edge = new vector<unsigned long long>[N+1];
    visit = new bool[N+1];
    black = new unsigned long long[N+1];
    white = new unsigned long long[N+1];
    for(unsigned long long i = 1; i <= N; i++)
    {
        visit[i] = 0;
        black[i] = white[i] = 1;
    }
    unsigned long long x, y;
    for(unsigned long long i = 1; i <= N-1; i++)
    {
        cin >> x >> y;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }

    visit[1] = 1;
    dfs(1);

    cout << (black[1] + white[1]) % 1000000007 << '\n';
    return 0;
}


Measured memory_bytes: 11520
#include<iostream>
#include<cstdio>
#include<set>
#include<map> 
using namespace std;
map<pair<int ,int> ,int>mp;
int par[400010],rk[400010];
int s[400010];
int n,k,l;
int root(int x)
{
	if(par[x]==x)return x;else return par[x]=root(par[x]);
}
void un(int x,int y)
{
	x=root(x);y=root(y);
	if(x==y)return;
	if(rk[x]<rk[y])
	{
		par[x]=y;
		s[y]+=s[x];
	}
	else
	{
		if(rk[x]==rk[y])rk[x]++;
		par[y]=x;
		s[x]+=s[y];
	}
}
int main()
{
	scanf("%d%d%d",&n,&k,&l);
	for(int i=1;i<=n+n;i++)par[i]=i,s[i]=1;
	for(int i=1;i<=k;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		un(x,y);
	}
	for(int i=1;i<=l;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		un(x+n,y+n);
	}
	for(int i=1;i<=n;i++)
	{
		mp[make_pair(root(i),root(i+n))]++;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d ",mp[make_pair(root(i),root(i+n))]);
	}
	return 0;
}

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

int main(){
	int h, w;
	int a[26][26];
	int ANS = 999999999;
	int ans = 0;
	cin >> h >> w;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> a[i][j];
		}
	}
	for (int m = 1; m <= h; m++){
		for (int n = 1; n <= w; n++){
			for (int o = 1; o <= h; o++){
				for (int p = 1; p <= w; p++){
					ans += a[o][p] * min(max(o-m,m-o),max(p-n,n-p));
				}
			}
			ANS = min(ANS, ans);
			ans = 0;
		}
	}
	cout << ANS << endl;
	return 0;
}


Measured memory_bytes: 3116
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    if S[-1]=="s":
        print(S+"es")
    else:
        print(S+"s")
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27148
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
int w,h,n;
char tbl[30][30];
int G[10][10];
int id[30][30];
int dist[30];

int x[20],y[20];
typedef pair<int,int> P;
const int INF = 10000;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};

void bfs(int sx,int sy){
  int f[30][30];
  for(int i=0;i<h;++i)
    for(int j=0;j<w;++j)
      f[i][j]=INF;
  f[sy][sx]=0;
  queue<P> Q;
  Q.push(P(sx,sy));
  while(Q.size()){
    P d = Q.front(); Q.pop();
    for(int i=0;i<4;++i){
      int mx = d.first+dx[i];
      int my = d.second+dy[i];
      if(mx<0 || mx>=w) continue;
      if(my<0 || my>=h) continue;
      if(tbl[my][mx]=='x') continue;
      if(f[my][mx]<=f[d.second][d.first]+1) continue;
      f[my][mx]=f[d.second][d.first]+1;
      Q.push(P(mx,my));
    }
  }
  
  for(int i=0;i<n;++i)
    dist[i] = f[y[i]][x[i]];
}
int main(){
  while(cin>>w>>h,w||h){
    for(int i=0;i<h;++i) for(int j=0;j<w;++j) id[i][j]=-1;
    for(int i=0;i<h;++i) cin >> tbl[i];
    n=0;
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
	if(tbl[i][j]=='*'){
	  id[i][j]=n;
	  x[n]=j;
	  y[n]=i;
	  ++n;
	}

    int homedist[30]={};
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
	if(tbl[i][j]=='o') bfs(j,i);
    for(int i=0;i<n;++i) homedist[i] = dist[i];
    for(int i=0;i<n;++i){
      bfs(x[i],y[i]);
      for(int j=0;j<n;++j) G[i][j]=dist[j];
    }
    int ord[10];
    for(int i=0;i<n;++i) ord[i]=i;
    int ans = INF;

    do{
      int r = homedist[ord[0]];
      for(int i=0;i+1<n;++i)
	r+=G[ord[i]][ord[i+1]];
      ans=min(ans,r);
    }while(next_permutation(ord,ord+n));
    if(ans==INF) ans=-1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
string s;
ll dp[100005][15];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;

  dp[0][0] = 1;
  int l = (int)s.size();
  REP(i, l) {
    if(s[i] == '?') {
      REP(j, 13) REP(k, 10) {
        int t = (j * 10 + k) % 13;
        dp[i + 1][t] += dp[i][j];
        dp[i + 1][t] = dp[i + 1][t] % mod;
      }
    } else {
      REP(j, 13) {
        int st = s[i] - '0';
        int t = (j * 10 + st) % 13;
        dp[i + 1][t] += dp[i][j];
        dp[i + 1][t] = dp[i + 1][t] % mod;
      }
    }
  }

  cout << dp[l][5] << endl;
}


Measured memory_bytes: 15488
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

template<class T>bool chmax(T &a, const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}

template<class T>bool chmin(T &a, const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	int k;
	cin>>k;
	LL ans=0;
	for(int a=1;a<=k;a++){
		for(int b=1;b<=k;b++){
			for(int c=1;c<=k;c++){
				int tmp=gcd(a,b);
				ans+=gcd(tmp,c);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include "atcoder/all"
using namespace std;
using namespace atcoder;

///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,d;
    cin >> n >> d;
    Vi x(n),y(n);
    rp(i,n) cin >> x[i] >> y[i];
    two_sat ts(n);
    rp(i,n){
        repi(j,i+1,n){
            if(abs(x[i]-x[j]) < d){
                ts.add_clause(i,false,j,false);
            }
            if(abs(x[i]-y[j]) < d){
                ts.add_clause(i,false,j,true);
            }
            if(abs(y[i]-x[j]) < d){
                ts.add_clause(i,true,j,false);
            }
            if(abs(y[i]-y[j]) < d){
                ts.add_clause(i,true,j,true);
            }           
        }
    }
    if(!ts.satisfiable()){
        print("No");
        return;
    }
    print("Yes");
    vector<bool> ans=ts.answer();
    rp(i,n){
        if(ans[i]) print(x[i]);
        else print(y[i]);
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3748