akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	int i;
	int	p;
	string S;
	string T;

	cin >> S >> T;

	n=S.size();
	p=0;

	for(i=0;i<n;i++){
		if(S.at(i)!=T.at(i)){
			p++;
		}
	}
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 3856
N = gets.chomp.to_i
V = gets.chomp.split.map(&:to_i)
C = gets.chomp.split.map(&:to_i)

$ans = -1010

def dfs(i, sel, value, cost)
  v = value
  c = cost
  if sel
    v += V[i]
    c += C[i]
  end

  $ans = [$ans, v - c].max

  if i == N - 1
    return
  end

  dfs(i + 1, true, v, c)
  dfs(i + 1, false, v, c)
end

dfs(0, true, 0, 0)
dfs(0, false, 0, 0)

puts $ans


Measured memory_bytes: 1916
#include <stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  
  int d[n+1];
  for(int i=1;i<=n;i++){
    scanf("%d",&d[i]);
  }
  
  long ans=0;
  
  for(int i=1;i<n;i++){
    for(int j=i+1;j<=n;j++){
      ans+=d[i]*d[j];
    }
  }
  
  printf("%ld",ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll n,t,k,f=0,a,b,d,c;
cin>>n;
f=0;
for(int i=1;i<=9;i++){
    if(n%i==0)
    if((n/i)>=1 && (n/i)<=9){
        f=1;
       // cout<<i<<"\n";
    }
}
    if(f==0)
    cout<<"No";
    else
    cout<<"Yes";
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	while(1){
		int i,j,k,w,h,a;
		char c[20][20];
		cin>>w>>h;
		if(w==0&&h==0)break;
		for(i=0;i<20;i++){
			for(j=0;j<20;j++){
				c[i][j]='\0';
			}
		}
		
		
		for(i=0;i<h;i++){
			cin>>c[i];
		}
		for(k=0;k<=w*h;k++){
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if(c[i][j]=='.'){
						if(i!=h-1){
							if(c[i+1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=w-1){
							if(c[i][j+1]=='@'){
								c[i][j]='@';
							}
						}
						if(i!=0){
							if(c[i-1][j]=='@'){
								c[i][j]='@';
							}
						}
						if(j!=0){
							if(c[i][j-1]=='@'){
								c[i][j]='@';
							}
						}
					}	
				}
			}
		}
		

		a=0;
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(c[i][j]=='@')a++;	
			}
		}
		cout<<a<<endl;
	}

    return 0;
}

Measured memory_bytes: 1164
#include<iostream>
#include<vector>
using namespace std;
int main() {
  long long N;
  int X,M;
  cin >> N >> X >> M;
  vector<long long> p(M,-1),A(M+3);
  A[0] = X;
  int i = 0,j;
  bool f = true;
  while(f) {
    i++;
    A[i] = (A[i-1]*A[i-1])%M;
    if(p[A[i]] > 0)f = false;
    else p[A[i]] = i;
  }
  long long ans = X;
  if(p[A[i]] < N)for(j=0;j<M;j++) {
    if(p[j] >= p[A[i]] && p[j] < i)ans += (N-p[A[i]])/(i-p[A[i]])*j;
    if(p[j] >= p[A[i]] && p[j] <= p[A[i]] + (N-p[A[i]])%(i-p[A[i]]) - 1)ans += j;
  }
  for(j=0;j<M;j++)if(p[j] > 0 && p[j] < min(p[A[i]],N))ans += j;
  cout << ans << endl;
}

Measured memory_bytes: 4840
h,w,d=map(int,input().split())
a=[]
adic={}
hh=1
saidai=0
for _ in range(h):
  temp=(list(map(int,input().split())))
  ww=1
  for item in temp:
    adic[item]=[hh,ww]
    ww+=1
    saidai=max(saidai,item)
  
  hh+=1
  
rdic={}
#print("saidai",saidai)
i=1
    

while i<=d:

  rdic[i]=0
  hoge=i+d
  while hoge<=saidai:
    tempi=adic[hoge-d]
    tempd=adic[hoge]
    rdic[hoge]=rdic[hoge-d]+abs(tempi[0]-tempd[0])+abs(tempi[1]-tempd[1])
    hoge+=d
  i+=1
#print(rdic)

q=int(input())
rl=[]
for _ in range(q):
  rl.append(list(map(int,input().split())))
  
for item in rl:
  print(rdic[item[1]]-rdic[item[0]])

Measured memory_bytes: 97884
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll gcd(ll a, ll b){
  if(b==0) return a;
  else gcd(b,a%b);
}
ll lcm(ll a, ll b){
  return a/gcd(a,b)*b;
}
using Graph = vector<vector<int>>;

struct UnionFind{
  vector<int>par;
  UnionFind(int n):par(n){
    rep(i,n) par[i]=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return par[x]=root(par[x]);
  }
  
  void unite(int x, int y){
    int rx=root(x);
    int ry=root(y);
    if(rx==ry)return;
    par[rx]=ry;
  }
  bool same(int x,int y){
    int rx=root(x);
    int ry=root(y);
    return rx==ry;
  }
};


int main(){
  int n;
  cin >> n;
  bool ok=false;
  rep(i,n){
    char c;
    cin >> c;
    if(c=='Y')ok=true;
  }
  if(ok)cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}


Measured memory_bytes: 256
X, Y = [int(_) for _ in input().split()]
mod = 10**9 + 7

#a(1, 2) + b(2, 1) = (X, Y)
#a=(2*Y-X)//3
#b=(2*X-Y)//3

if (2 * Y - X) % 3 == (2 * X - Y) % 3 == 0:
    a = (2 * Y - X) // 3
    b = (2 * X - Y) // 3
    if a < 0 or b < 0:
        print(0)
        exit()
    f = [1] * (a + b + 1)
    for i in range(1, a + b + 1):
        f[i] = i * f[i - 1] % mod
    fi = [1] * (a + b + 1)
    fi[-1] = pow(f[-1], mod - 2, mod)
    for i in range(a + b - 1, 1, -1):
        fi[i] = (i + 1) * fi[i + 1] % mod

    def comb(x, y):
        return (f[x] * fi[y] * fi[x - y]) % mod

    print(comb(a + b, b))
    exit()
print(0)


Measured memory_bytes: 55796
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (!cin) return false;

	ll tot = n / (a + b);
	ll res = tot * a;

	if (tot * (a + b) + a <= n) res += a;
	else res += n - (tot * (a + b));

	cout << res << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int i = a;i <= b;++i) cout << ary[i] << (b == i ? "]\n" : ", "); } while(0)
#define p_map(map,it) do {cout << "{";for (auto it = map.begin();;++it) {if (it == map.end()) {cout << "}\n";break;}else cout << "" << it->first << "=>" << it->second << ", ";}}while(0)

typedef long long ll;

const ll mod = 998244353;

const int MAX_N = 100010;
ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N];

ll pow(ll a,ll b) {
    ll ret;
    if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

void create_table(int n) {
    fact[0] = 1;fact[1] = 1;
    for (int i = 2;i <= n;++i) fact[i] = fact[i-1]*i%mod;
    fact_inv[n] = pow(fact[n],mod-2);
    for (int i = n;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod;
}

ll combi(ll a, ll b) {
    return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod;
}

int main() {
    ll k, n;
    cin >> k >> n;
    create_table(4000);
    for (int i = 2;i <= 2*k;++i) {
        ll ret = 0, cnt = 0;
        for (int j = 1;j <= k;++j) {
            if (i-j > 0 && i-j <= k) cnt++;
            if (i == j*2) cnt++;
        }
        cnt /= 2;
        for (int j = 0;j <= min(cnt,n/2);++j) {
            ret += combi(k+n-1-2*j,n-2*j)*combi(cnt,j)*(j%2 ? -1 : 1)%mod;
            ret = (ret+mod)%mod;
            //cout << ret << " ";
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin >> n;
    string ans = "";
    while(n){
        int remain = n % 26;
        if(remain == 0){
            ans += 'z';
            n /= 26;
            n--;
        }
        else{
            ans += char(96 + remain);
        n /= 26;
        }
    }
    
    reverse(ans.begin(), ans.end());
    cout << ans;
   
}









Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repf(i, j, n) for (int i = (j); i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

signed main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto&& u : s) cin >> u;
  int l[h][w], r[h][w], u[h][w], d[h][w];
  rep(i, h) rep(j, w) {
    if (i == 0) u[i][j] = (s[i][j] == '.');
    if (j == 0) l[i][j] = (s[i][j] == '.');

    if (s[i][j] == '.') {
      if (i > 0) u[i][j] = u[i - 1][j] + 1;
      if (j > 0) l[i][j] = l[i][j - 1] + 1;
    } else {
      u[i][j] = 0;
      l[i][j] = 0;
    }
  }
  repr(i, h) repr(j, w) {
    if (i == h - 1) d[i][j] = (s[i][j] == '.');
    if (j == w - 1) r[i][j] = (s[i][j] == '.');

    if (s[i][j] == '.') {
      if (i < h - 1) d[i][j] = d[i + 1][j] + 1;
      if (j < w - 1) r[i][j] = r[i][j + 1] + 1;
    } else {
      d[i][j] = 0;
      r[i][j] = 0;
    }
  }
  int res = 0;
  rep(i, h) rep(j, w) {
    if (s[i][j] == '.')
      res = max(res, u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3);
  }
  cout << res << endl;

  // rep(i, h) {
  //   { rep(j, w) cout << l[i][j] << " " << r[i][j] << endl; }
  //   cout << endl;
  // }
  // //   cout << endl;
  //   rep(j, w) cout << u[j] << " " << r[j] << endl;
}

Measured memory_bytes: 129408
#include<stdio.h>
#define N 100

int main(){
  int i, j, n, u, k, v;
  int V[N][N];
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      V[i][j] = 0;
    }
  }

  for(i = 0; i < n; i++){
    scanf("%d%d", &u, &k);
    for(j = 0; j < k; j++){
      scanf("%d", &v);
      V[u-1][v-1] = 1;
    }
  }

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j) printf(" ");
      printf("%d", V[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

int gcd(int a, int b) {
  int t;
  while( b ) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
 
int main(void) {
  int n, a, b, c, temp, i;
  scanf("%d%d%d", &n, &a, &b);
  if(n == 3) scanf("%d", &c);
  temp = gcd(a, b);
  if(n == 3) temp = gcd(temp, c);
  for(i = 1; i <= temp; ++i) if(!(temp % i)) printf("%d\n", i);
  return 0;
}


Measured memory_bytes: 2724
N = int(input())

lst = []
for i in range(10):
    if 6 ** i > 100000:
        break
    lst.append(6 ** i)
for j in range(1, 9):
    if 9 ** j > 100000:
        break
    lst.append(9 ** j)

DP = [N for i in range(N + 1)]
DP[0] = 0

for i in lst:
    for j in range(i, N + 1):
        DP[j] = min(DP[j], DP[j - i] + 1)

print(DP[N])


Measured memory_bytes: 7064
MOD = 10 ** 9 + 7

n = gets.to_i
a = gets.chomp.split.map(&:to_i)

s = Array.new(n, 0)
(n - 1).step(0, -1) do |i|
  if i == n - 1
    s[i] = a[i]
  else
    s[i] = s[i + 1] + a[i]
  end
end

res = 0
(n - 1).times do |i|
  res = (res + a[i] * s[i + 1]) % MOD
end
puts res

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

typedef long long lli;
int N, M;
int P[20];

lli gcd(lli a, lli b) { return b == 0 ? a : gcd(b, a%b); }
lli lcm(lli a, lli b) { return a*b/gcd(a,b); }

double solve() {
  lli A = 0;
  lli nA = 0;
  lli U = (lli)N*(N+1)/2LL;
  lli nU = N;
  for(int s = 1; s < (1<<M); ++s) {
    lli t = 1;
    lli d = -1;
    for(int i = 0; i < M; ++i) {
      if(s & (1<<i)) {
	t = lcm(t, P[i]);
	d *= -1;
      }
    }
    lli tn = N/t;
    nA += d*tn;
    lli ts = (lli)tn*(tn+1)/2LL;
    A += d*ts*t;
  }
  if(nU == nA) return 0;
  return (double)(U-A)/(nU-nA);
}

int main() {
  while(cin >> N >> M && (N || M)) {
    for(int i = 0; i < M; ++i) cin >> P[i];
    printf("%.10f\n", solve());
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[26] = {0};
    string w; cin >> w;
    rep(i, w.size()) a[w[i] - 'a']++;
    rep(i, 26) {
        if (a[i] % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
const int N = 200006;
int dst[N];
int vis[N];
void solve(){
    int k;
    cin>>k;
    for(int i=0;i<=k;i++)dst[i] = 1e9;
    priority_queue<pair<int,int > > pq;
    for(int i=1;i<=9;i++){
        pq.push({-i,i});
        dst[i] = i;
    }
    while(!pq.empty()){
        int x = pq.top().second;
        pq.pop();
        if(vis[x])continue;
        vis[x] = true;
        for(int i=0;i<=9;i++){
            int nx = (x*10+i)%k;
            if(dst[nx]>dst[x]+i){
               dst[nx] = dst[x]+i;
               pq.push({-dst[nx],nx});
            }
        }
    }
    int ans = dst[0];
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
#define F(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
template<class T>inline void read(T &x) {
    x=0; int ch=getchar(),f=0;
    while(ch<'0'||ch>'9'){if (ch=='-') f=1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    if(f)x=-x;
}
const int inf=0x3f3f3f3f;
const int maxn=650;
int n,m;
double f[maxn];
vector<int> e[maxn];
double ans=inf;
void calc(int p)
{
	for(int i=0;i<=n;i++) f[i]=0;
	for(int i=n-1;i>=1;i--)
	{
		int num=e[i].size();
		double maxx=0.0,sum=0.0;
		for(int j=0;j<e[i].size();j++)
		{
			int v=e[i][j];
			sum+=f[v];
			maxx=max(maxx,f[v]);
		}
		
		if(i==p&&num>1) sum-=maxx,num--;
		
		f[i]=(sum/(double)num)+1;
	}
	ans=min(ans,f[1]);
}
int main()
{
	read(n),read(m);
	for(int i=1;i<=m;i++)
	{
		int x,y;read(x),read(y);
		e[x].push_back(y);
	}
	for(int i=1;i<=n-1;i++) calc(i);
	printf("%.8lf\n",ans);
	return 0;
}


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

int main() {
  int n, l; cin >> n >> l;
  //l+i-1
  int sum = 0;
  rep(i, n) {
    sum += l+i;
  }
  if (l <= 0 && l+n-1 >= 0) cout << sum << endl;
  else if (l > 0) cout << sum - l << endl;
  else cout << sum - (l+n-1) << endl;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

string vow = "aeiou";

void solve ( int test_case )
{
    int n , k ;
    cin >> n >> k ;

    priority_queue < int > q ;
    while ( n-- )
    {
        int temp ; cin >> temp ;
        q.push ( temp ) ;
    }

    while ( k-- )
    {
        int t = q.top() ;
        q.pop() ;

        t >>= 1 ;
        q.push ( t ) ;
    }

    ll ans = 0 ;
    while ( !q.empty() )
    {
        ll t = q.top() ;
        q.pop() ;

        ans += t ;
    }

    cout << ans ; line

}

int main()
{
    int t = 1;
    //cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll N, Z, W;
vector<ll> A;

void input() {
    cin >> N >> Z >> W;
    A.resize(N);
    for (auto& a : A)
        cin >> a;
}

void solve() {
    if (N == 1) {
        cout << abs(A.back() - W) << endl;
    } else {
        cout << max(abs(A.back() - W), abs(A[N - 2] - A[N - 1])) << endl;
    }
}


int main() {
    input();
    solve();
    
    return 0;
}



Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		ArrayList<String> ary = new ArrayList<String>();
		int x,y;
		int cnt = 0;
		Scanner sc = new Scanner(System.in);
//		sc.useDelimiter("\\r\\n");

		x = sc.nextInt();
		y = sc.nextInt();
		ary.add(ArrayAdder(x,y));
		cnt++;

		while(x!=0 || y!=0){
			sc.hasNext();
			x = sc.nextInt();
			y = sc.nextInt();
			ary.add(ArrayAdder(x,y));
			cnt++;
		}

		for(int i=0;i<cnt-1;i++){
			System.out.println(ary.get(i));
		}
		sc.close();
	}

	public static String ArrayAdder(int x,int y){
		String str;
		if(x > y){
			str = y +" "+ x;
		}else{
			str = x +" "+ y;
		}
		return str;
	}

}

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

int main(){
    deque<int> A;
    int q;
    scanf("%d", &q);
    int query,x,d,p;
    for (int i = 0; i < q; i++)
    {        
        scanf("%d", &query);
        switch (query){
            case 0:
                scanf("%d %d", &d,&x);
                if(d==0){
                    A.push_front(x);
                }else{
                    A.push_back(x);
                }              
                break;
            case 1:
                scanf("%d", &p);
                cout<<A[p]<<endl;
                break;
            case 2:
                scanf("%d", &d);
                if(d==0){
                    A.pop_front();
                }else{
                    A.pop_back();
                }
                break;
            default:
                break;
        }
    }
    return 0;
}


Measured memory_bytes: 4640
#include <stdio.h>
#define SIZE 10
#define binary(A,B) (((A>>B)&1!=0)?1:0)

int main(void){
	int t, i;
	while(scanf("%d",&t)==1){
		for(i=0; i<SIZE; i++) if(binary(t,i)){
			printf("%d",1<<i), t-=1<<i;
			if(t!=0) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{

	int temp, v = 0;
	for (int i = 0; i < 4; i++) {
		scanf("%d", &temp);
		v += temp;
	}

	printf("%d\n", v / 60);
	printf("%d\n", v % 60);

	return 0;
}

Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
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; }
int N, M, Q;
vector<ll> a, b, c, d;

ll calc(vector<int> &A){
    ll res = 0;
    for (int i = 0; i < Q; i++)
    {
        if(A[b[i]]-A[a[i]]==c[i])res+=d[i];
    }
    return res;
}

void dfs(vector<int> &A, ll &res){
    if(A.size() == N+1){
        ll tmp = calc(A);
        chmax(res, tmp);
        return;
    }
    ll ba = A.back();
    for (int i = ba; i <= M; i++)
    {
        A.push_back(i);
        dfs(A, res);
        A.pop_back();
    }
}
long long solve() {
    long long res = 0;
    vector<int> A({1});
    dfs(A, res);
    return res;
}
 
int main() {
    while (cin >> N >> M >> Q) {
        a.resize(Q); b.resize(Q); c.resize(Q); d.resize(Q);
        for (int i = 0; i < Q; ++i) cin >> a[i]>>b[i]>>c[i]>>d[i];
        cout << solve() << endl;
    }
}

Measured memory_bytes: 3548
N = int(input())

ans = 0

for i in range(1, N+1):
    if i % 2 == 1:
        cnt = 0
        for j in range(1, i+1):
            if i % j == 0:
                cnt += 1
        
        if cnt == 8:
            ans += 1

print(ans)

Measured memory_bytes: 9148
N, M = map(int, input().split())

AB = [(list(map(int, input().split()))) for _ in range(N)]
AB.sort()

ans = 0
c = 0
for a, b in AB:
    if c + b < M:
        c += b
        ans += a * b
    else:
        i = M - c
        ans += a * i
        break

print(ans)

Measured memory_bytes: 27756
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll sum;
    if(k<=a)
       sum=k;
       else if(k>a && k<=a+b)
        sum=a;
       else
        sum=a-(k-(a+b));
       cout<<sum<<endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; string s;
    cin >> n >> s;
    bool flag = 1;
    if (n & 1)
        flag = 0;
    else {
        if (s.substr(0, s.length() / 2) != s.substr(s.length() / 2, s.length()))
            flag = 0;
    }
    if (flag)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;   
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define piil pair<pii, ll>
#define F first
#define S second
#define pb push_back

const int P = 1e9+7;

using namespace std;

int n, h, w;
pii p[3030];
ll dp[3030], f[202020];

ll pow(ll a, ll b){
	if(!b) return 1;
	ll u = pow(a, b/2);
	u = (u*u)%P;
	if(b&1) u = (a*u)%P;
	return u;
}

ll abCb(ll a, ll b){
	return (f[a+b]*((pow(f[b], P-2LL)*pow(f[a], P-2LL))%P))%P;
}

int main(){


	cin >> h >> w >> n;
	for(int i=1; i<=n; i++) cin >> p[i].F >> p[i].S;
	p[n+1] = {h, w};
	sort(p, p+n+2);

	f[0] = 1;
	for(int i=1; i<=h+w; i++) f[i] = (f[i-1]*i)%P;

	dp[0] = 1;

	for(int i=1; i<n+2; i++){
		dp[i] = abCb(p[i].F-1, p[i].S-1);
		for(int j=1; j<i; j++){
			if(p[j].S <= p[i].S){
				ll pth = abCb(p[i].F-p[j].F, p[i].S-p[j].S);
				dp[i] = (dp[i]-dp[j]*pth)%P;
				dp[i] = (dp[i]+P)%P;
			}
		}
	}

	cout << dp[n+1] << endl;

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define _   int v, int tl, int tr, int l, int r
#define tm  (tl + tr >> 1)
#define sol v+v, tl, tm, l, r
#define sag v+v+1, tm+1, tr, l, r
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 2e5 + 5;    

int dp[N],nex[N],yaz[N],L[32];
char s[N];

signed main(){  
    scanf(" %s", s+1);
	int n = strlen(s+1);
	for(int i=0; i<26; i++) L[i] = n+1;

    dp[n+1] = 0;
    for(int i=n; i>=0; i--){
        dp[i] = n;
        for(int j=0; j<26; j++)
        	if(dp[i] > dp[ L[j] ] + 1){
                dp[i] = dp[ L[j] ] + 1;
                nex[i] = L[j];
                yaz[i] = j;
            }
        L[ s[i]-'a' ] = i;
    }
    
   	for(int i=0; i<=n; i = nex[i])
        printf("%c", yaz[i]+'a');
    	
    return 0;
}

Measured memory_bytes: 2816
n, a, b = gets.chomp.split.map(&:to_i)
c = 0
(1..n).each do |x|
    keta = 0
    temp_x = x
    while x>0
        keta+=x%10
        x/=10
    end
    c+=temp_x if (a..b).include?(keta)
end
p c

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
const int oo = 1e9 + 7;
const int mod = 1e9 + 7;
const double PI = acos(-1);

ll f(ll n){
    while (n > 9){
        n/=10;
    }
    return n;
}

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

    vector<vector<ll>> a(10, vector<ll> (10, 0)), b(10, vector<ll> (10, 0));

    for (int i=1; i<=n; i++){
        ll last = i%10, first = f(i);
        if (last != 0){
            a[first][last]++;
            b[last][first]++;
        }
    }

    ll ans = 0;
    for(int i=1; i<10; i++){
        for (int j=1; j<10; j++){
            ans += (a[i][j])*(b[i][j]);
        }
    }

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

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

signed main(void)
{
	ll a, b, c, d;
	ll ans;
	cin >> a >> b >> c >> d;
	ans = a * c;
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
//#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>
//#include <map>

using namespace std;


int main(){

	int m, buf;
	string s ;

	while (cin >> m){
		buf = 1;
		s = "";

		for (int i = 0; i < 10; i++){
			if (m % 2 == 1) {
				cout << s << buf;
				s = " ";
			}
			m >>= 1;
			buf *= 2;
		}
		cout << endl;

	}

	return 0;
}

Measured memory_bytes: 1196
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]).sort!"a > b"();
    int ans;
    foreach (i ; 0 .. n) {
        if (i & 1) ans -= a[i];
        else ans += a[i];
    }
    writeln(ans);
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
using namespace std;

int ctoi(const char c){
	switch(c){
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default : return -1;
	}
}


int main(){
	string str;
	cin >> str;
	int str_num;
	for(int i=0; i<4; i++){
		if(i == 0){
			str_num = ctoi(str[i]);
		}else{
			int str_num2 = ctoi(str[i]);
			if(str_num == str_num2){
				cout << "Bad";
				return 0;
			}
			str_num = str_num2;
		}
	}

	cout << "Good";
	
}



Measured memory_bytes: 256
#-*- coding:utf-8 -*-

if __name__ == "__main__":
    S = input()
    is_a = False
    is_b = False
    is_c = False

    for i in range(3):
        if S[i] == "a":
            is_a = True
            continue
        elif S[i] == "b":
            is_b = True
            continue
        elif S[i] == "c":
            is_c = True
            continue

    if is_a and is_b and is_c:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 3060
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i=n-1;i>=x;i--)
#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1000000007
#define L LONG_MAX
#define fastio ios_base::sync_with_stdio(false)


int main()
{
    fastio;
    ll a,b,c;
    cin>>a>>b>>c;

    if(a==b && a!=c)
        cout<<"Yes";
    elif(b==c && a!=b)
        cout<<"Yes";
    elif(a==c && a!=b)
        cout<<"Yes";
    else
        cout<<"No";
}


    

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define QUE queue<int>
#define DEQ deque<int>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

ll factorial(ll N, ll quotient) {
	if (N == 0) return 0LL;
	ll N_factorial = 1ll;
	for (ll i = 1; i <= N; i++) {
		N_factorial *= i;
		N_factorial %= quotient;
	}
	return N_factorial;
}

int main() {
	ll N,M;
	cin >> N >> M;
	if (abs(N - M) > 1LL) {
		cout << 0 << endl;
		return 0;
	}
	cout << (((N==M)?2LL:1LL)*factorial(N, MOD)*factorial(M, MOD))%MOD << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int apples = sc.nextInt();
          int apple = sc.nextInt();
          int ap = apples * 3;
          int applepyes = ap + apple;
          System.out.println(applepyes / 2);
        }
      }

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

#define INF 100000;

int main() {
  int x1, x2;
  std::cin >> x1 >> x2;

  std::cout << std::abs(x1-x2) << "\n";

  return 0;
}



Measured memory_bytes: 3100
#include<stdio.h>

int main(){
  char s[5];
  int n = 0;
  int i;

  scanf("%s", s);

  for(i = 0; i < 4; i++){
    if(s[i] == '+'){
      n++;
    }
    else{
      n--;
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long N = sc.nextLong(); 
        long K = sc.nextLong(); 
        sc.nextLine();
        long n = N % K;
        long k = Math.abs(n-K);
        if (n > k) {
            System.out.println(k);
        } else {
            System.out.println(n);
        }
    }
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int N, M, C;
    int A[20], B[20];
    cin >> N >> M >> C;
    REP(i, M) cin >> B[i];
    int ans = 0;
    REP(i, N){
        REP(j, M) cin >> A[j];
        int sum = 0;
        REP(j, M) sum += A[j] * B[j];
        sum += C;
        if(sum > 0) ans++;
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(int, input().split()))

now = A[0]
root_set = set([now])
root_array = [now]
if k<= n:
    for i in range(k-1):
        now = A[now-1]
        root_set.add(now)
        root_array.append(now)
    print(root_array[-1])
else:
    for i in range(n-1):
        now = A[now-1]
        if not now in root_set:
            root_set.add(now)
            root_array.append(now)
        else:
            index = root_array.index(now)
            f = root_array[:index]
            loop = root_array[index:]
            break
    len_f = len(f)
    len_loop = len(loop)
    print(loop[(k-len_f)%len_loop-1])

Measured memory_bytes: 32280
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>

using namespace std;
int main(){
    
    int a,b,c,x;
    cin >>a >>b >>c;
    x=a+b+c;
    if(x>=22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }



}

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

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N), B(N);
  long long result = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i]-(i+1);
  }
  sort(B.begin(), B.end());
  long long med;
  if (B.size() % 2 == 0) {
    med = (B[N/2-1]+B[N/2])/2;
  } else {
    med = B[N/2];
  }
  long long m = 1000000000000000000;
  for (long long i = med-1; i < med+2; i++) {
    result = 0;
    for (long long j = 0; j < N; j++) {
      result += abs(A[j]-i-(j+1));
    }
    m = result > m ? m : result;
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 1)
  {
    cout << "Odd" << endl;
  }
  else
  {
    cout << "Even" << endl;
  }
}

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

int main(int argc, const char * argv[]) {
    int k;
    cin>>k;
    int a = k%10;
    int b = (k%100-a)/10;
    int c = (k-k%100)/100;
    int ans = (10-c)*100 + (10-b)*10 + (10-a);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <climits>
#include <map>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

using Pair = pair<int, int>;
using lint = long long;

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

// const int mod = 1e9 + 7;
// const int mod = 998244353;

template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }

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

int main(){
  int n;
  cin >> n;
  int cnt = 0;
  for (lint i = 1; i < n; i++) {
    cnt += (n-1) / i;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int h, n, a, sum=0;
 cin >> h >> n;
 for(int i=0;i<n;i++){
   cin >> a;
   sum+=a;
 }
 if(sum>=h) cout << "Yes";
 else cout << "No";
 return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    d = defaultdict(lambda: 0)
    for _ in range(N):
        a = int(input())
        d[a] += 1

    ans = 0
    for key in d:
        if d[key] % 2 == 1:
            ans += 1

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 15460
/* lca_doubling.cpp
    最近共通祖先(LCA:Lowest Common Ancestor)をダブリングにより求める
    (u,v の2^k先の親が同じかどうかを二分探索で調べる)

    verified: AOJ GRL_5_C
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C
 */

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    long long to;
};
using Graph = vector<vector<Edge>>;

/* LCA(G, root): 木 G に対する根を root として Lowest Common Ancestor を求める構造体
    query(u,v): u と v の LCA を求める。計算量 O(logn)
    dist(u,v): u と v の距離を求める。計算量 O(logn)
    is_on_path(u,v,a): u, v を繋ぐパス上に a が存在するかを判定する。計算量 O(logn)
    前処理: O(nlogn)時間, O(nlogn)空間
*/
struct LCA {
    vector<vector<int>> parent;  // parent[k][u]:= u の 2^k 先の親
    vector<int> depth;           // root からの深さ
    LCA(const Graph &G, int root = 0) { init(G, root); }
    void init(const Graph &G, int root = 0) {
        int V = G.size();
        int K = 1;
        while ((1 << K) < V) K++;
        parent.assign(K, vector<int>(V, -1));
        depth.assign(V, -1);
        dfs(G, root, -1, 0);  // initialization of parent[0] & depth
        // initialization of parent
        for (int k = 0; k + 1 < K; k++) {
            for (int v = 0; v < V; v++) {
                if (parent[k][v] < 0) {
                    parent[k + 1][v] = -1;
                } else {
                    parent[k + 1][v] = parent[k][parent[k][v]];
                }
            }
        }
    }
    void dfs(const Graph &G, int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;
        for (auto e : G[v]) {
            if (e.to != p) dfs(G, e.to, v, d + 1);
        }
    }
    int query(int u, int v) {
        if (depth[u] > depth[v]) swap(u, v);
        int K = parent.size();
        for (int k = 0; k < K; k++) {
            if ((depth[v] - depth[u]) >> k & 1) {
                v = parent[k][v];
            }
        }
        if (u == v) return u;
        for (int k = K - 1; k >= 0; k--) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }
    int dist(int u, int v) { return depth[u] + depth[v] - 2 * depth[query(u, v)]; }
    bool is_on_path(int u, int v, int a) { return dist(u, a) + dist(a, v) == dist(u, v); }
};

// 深さ優先探索
vector<bool> seen;  // 既に見たことがある頂点か記録
void dfs(const Graph &G, int v, int &count) {
    seen[v] = true;
    count++;
    for (auto e : G[v]) {
        if (!seen[e.to]) {  // 訪問済みでなければ探索
            dfs(G, e.to, count);
        }
    }
}

int main() {
    int N;
    cin >> N;
    Graph G(N);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    LCA lca(G, 0);

    int d = (lca.dist(0, N - 1) - 1) / 2;
    int now = N - 1;
    for (int i = 0; i < d; i++) {
        now = lca.parent[0][now];
    }
    seen.assign(N, false);  // 初期化
    seen[lca.parent[0][now]] = true;
    int count = 0;
    dfs(G, now, count);
    // cout << count << " " << N - count << endl;
    if (count >= N - count) {
        cout << "Snuke" << endl;
    } else {
        cout << "Fennec" << endl;
    }
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int w, h;
vector<string> tile(20);
int dist[11][11];
bool visited[20][20];
int dd[] = {1, 0, -1, 0, 1};

bool range(int x, int y) {
  return 0 <= x && x < w && 0 <= y && y < h;
}

void wfs(PIP s, vector<PIP> &v) {
  rep(i, h)rep(j, w) visited[i][j] = false;
  visited[s.se.fi][s.se.se] = true;

  priority_queue<PIP, vector<PIP>, greater<PIP>> q;
  q.push(PIP(0, s.se));

  while(!q.empty()) {
    PIP p = q.top(); q.pop();

    repl(i, 1, v.size()) {
      if (p.fi > 0 && p.se == v[i].se) dist[s.fi][i] = p.fi;
    }

    rep(i, 4) {
      int y = p.se.fi + dd[i], x = p.se.se + dd[i + 1];
      if (range(x, y) && !visited[y][x] && tile[y][x] != 'x') {
        q.push(PIP(p.fi + 1, P(y, x)));
        visited[y][x] = true;
      }
    }
  }
}

int main(){
  cin.sync_with_stdio(false);
  while(cin >> w >> h, w | h) {
    vector<PIP> v;
    int num = 1;
    rep(i, h) {
      cin >> tile[i];
      rep(j, w) {
        if (tile[i][j] == '*') v.pb(PIP(num++, P(i, j)));
        else if (tile[i][j] == 'o') v.pb(PIP(0, P(i, j)));
      }
    }
    sort(all(v));

    rep(i, num)rep(j, num) dist[i][j] = INF;

    bool ok = true;
    rep(i, num) {
      wfs(v[i], v);
      if (i == 0) {
        repl(j, 1, num) if (dist[0][j] == INF) ok = false;
        if (!ok) break;
      }
    }

    if (ok) {
      vector<vector<int>> dp(1 << (num - 1), vector<int>(num - 1, INF));
      repl(i, 1, num) dp[(1 << (i - 1))][i - 1] = dist[0][i];

      rep(i, dp.size()) {
        repl(j, 1, num) {
          if (i & (1 << (j - 1))) {
            repl(k, 1, num) {
              if (!(i & (1 << (k - 1)))) minch(dp[i + (1 << (k - 1))][k - 1], dp[i][j - 1] + dist[j][k]);
            }
          }
        }
      }

      int ans = INF;
      rep(i, num - 1) minch(ans, dp[dp.size() - 1][i]);
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3044
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = sc.next()
        val B = sc.next()
        val C = sc.next()

        var ans = 0
        for (i in 0 until N) {
            ans += arrayOf<Char>(A[i], B[i], C[i]).distinct().count() - 1
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 36160
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a[86];
    a[0]=2;a[1]=1;
    int n;
    cin>>n;
    for(int i=2;i<=86;i++){
        a[i]=a[i-1]+a[i-2];
    }
    cout<<a[n]<<endl;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
# 範囲を絞る時は，反対の値も見るべき(M/iのこと)
print(max([j for i in range(int(M**0.5), 0, -1) for j in [i, int(M/i)] if M % j == 0 and M / N >= j]))


Measured memory_bytes: 3064
// ITP1_2_D ????????¢??????????????????????????????
#include<stdio.h>

int main()
{
	int f,w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);

	f=0;
	if(x-r>=0 && x+r<=w){
		if(y-r>=0 && y+r<=h){
			f=1;		
		}
	}

	if(f==1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;

}

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


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

    









Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
S=sum(a_list)
x=0
ans=10**20
for i in range(n-1):
    x+=a_list[i]
    y=S-x
    temp=abs(x-y)
    ans=min(ans,temp)
print(ans)


Measured memory_bytes: 71760
using System;

namespace b119B {
    class Program {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var res = 0.0;
            for (int i = 0; i < n; i++) {
                var input = Console.ReadLine().Split(' ');
                if (input[1] == "JPY") {
                    res += int.Parse(input[0]);
                } else {
                    res += 380000.0 * Double.Parse(input[0]);
                }
            }

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 11220
//import java.io.File;
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args) {
try{
  //Scanner scan = new Scanner(new File("in.txt"));
  Scanner scan = new Scanner(System.in);

  int input1 = scan.nextInt();
  int input2 = scan.nextInt();

  while(input1!=0||input2!=0) {
    int[] arr = new int[input2];
    ArrayList<Integer> log = new ArrayList<>();
    int result = input1;
    log.add(result);

    for(int k = 0; k <= 20; k++) {
      for(int i = 0; i < input2; i++) {
        arr[i] = result % 10;
        result /= 10;
      }

/*
      //debug
      for(int i = 0; i < arr.length; i++) {
        System.out.print(arr[i]);
      }
      System.out.println();
      */

      //sort
      int[] maxArr = new int[arr.length];
      int ite = 0;
      for(int i = 0; i < 10; i++) {
        for(int j = 0; j < arr.length; j++) {
          if(arr[j] == i) {
            maxArr[ite] = i;
            ite++;
          }
        }
      }
      int[] minArr = new int[arr.length];
      ite = 0;
      for(int i = 9; i >= 0; i--) {
        for(int j = 0; j < arr.length; j++) {
          if(arr[j] == i) {
            minArr[ite] = i;
            ite++;
          }
        }
      }
      //endsort

/*
            //debug
            for(int i = 0; i < maxArr.length; i++) {
              System.out.print(maxArr[i]);
            }
            System.out.println();
                  //debug
                  for(int i = 0; i < minArr.length; i++) {
                    System.out.print(minArr[i]);
                  }
                  System.out.println();
                  */

      for(int i = 0; i < arr.length; i++) {
        arr[i] = maxArr[i] - minArr[i];
        if(arr[i] < 0) arr[i+1]--;
      }

      int ten = 1;
      for(int i = 0; i < arr.length; i++) {
        result += arr[i]*ten;
        ten *= 10;
      }

      if(log.contains(result)) {
        int _index = log.indexOf(result);
        System.out.println(_index+" "+result+" "+(k-_index+1));
        break;
      }else {
        log.add(result);
        //System.out.println(" "+result);
      }
    }

    input1 = scan.nextInt();
    input2 = scan.nextInt();
  }

}catch(Exception e) {
  e.printStackTrace();
}
  }
}

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

int main()
{
  int64_t N;
  cin >> N;
  vector <int64_t> A(N);
  for (int64_t i=0;i<N;i++){
    cin >> A.at(i);
  }
  map<int64_t,int64_t>tmp;
  int64_t ans=0;
  for(int64_t i=0;i<N;i++){
    ans+=tmp[i-A.at(i)];
    tmp[i+A.at(i)]++;
  }
  cout << ans <<endl;
}

Measured memory_bytes: 27452
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		for(int i=0;i<str.length();i++){
			if(str.charAt(i)=='9'){
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

ll mp(ll a,ll b) {
	ll ans = 1;
	while (b) {
		if (b % 2)
			ans *= a;
		a *= a;
		a %= MOD;
		ans %= MOD;
		b /= 2;
	}
	return ans;
}

ll modwari(ll a,ll b) {
	a %= MOD;
	return (a*mp(b, MOD - 2)) % MOD;
}

ll nCk(ll n, ll k) {
	ll ans = 1;
	for (int i = 0;i < k;i++) {
		ans *= n - i;
		ans = modwari(ans, i + 1);
		ans %= MOD;
	}
	return ans;
}

int main() {
	ll N, M, K;
	cin >> N >> M >> K;
	ll N2 = (N * N) % MOD;
	ll M2 = (M * M) % MOD;
	ll q = nCk(N*M - 2, K - 2);
	ll x = 0, y = 0;
	for (ll i = 1;i < M;i++) {
		x += ((i * (i + 1) / 2)%MOD*N2)%MOD;
		x %= MOD;
	}
	for (ll i = 1;i < N;i++) {
		y += ((i * (i + 1) / 2)%MOD*M2)%MOD;
		y %= MOD;
	}
	cout << ((x + y) % MOD * q) % MOD << endl;
}

Measured memory_bytes: 256