akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int n;

int find(int x) {
	int l = 1;
	int r = n + 1;
	while (r - l > 1) {
		int m = (r + l) >> 1;
		if (n / m >= x) l = m;
		else r = m;
	}
	return l;
}

int sz;
vector<int> ip;
vector<int> mt;
vector<int> cn;

void init() {
	ip.push_back(1);
	while (true) {
		if (n == ip.back()) break;
		int v = n / (ip.back() + 1);
		// cerr << "fn " <<  << endl; 
		ip.push_back(find(v));
	}
	int tt = ip.size();
	for (int i = 0; i < tt; i++) {
		ip.push_back(n / ip[i]);
	}
	sort(ip.begin(), ip.end());
	ip.resize(unique(ip.begin(), ip.end()) - ip.begin());
	// cerr << "ip: " << endl;
	// for (auto t : ip) {
	// 	cerr << t << ' ';
	// }
	// cerr << endl;
	cn.resize(ip.size());
	mt.resize(ip.size());
	cn[0] = 1;
	for (int i = 1; i < (int)ip.size(); i++) {
		cn[i] = ip[i] - ip[i - 1];
	}
	for (int i = 0; i < (int)ip.size(); i++) {
		int v = lower_bound(ip.begin(), ip.end(), n / ip[i]) - ip.begin();
		assert(ip[v] == n / ip[i]);
		mt[i] = v;
	}
	sz = ip.size();
}

vector<int> dp;
vector<int> ndp;
vector<int> ps;

void rc() {
	ps[0] = dp[0];
	for (int i = 1; i < sz; i++) {
		ps[i] = add(ps[i - 1], dp[i]);
	}
	for (int i = 0; i < sz; i++) {
		ndp[i] = mul(cn[i], ps[mt[i]]);
	}
	for (int i = 0; i < sz; i++) {
		dp[i] = ndp[i];
		ndp[i] = 0;
	}
}

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

	int k;
	cin >> n >> k;
	// cout << find(1) << endl;
	init();
	dp.resize(sz, 0);
	ndp.resize(sz, 0);
	ps.resize(sz, 0);
	dp[0] = 1;
	for (int i = 0; i < k; i++) {
		rc();
	}
	int ans = 0;
	for (auto t : dp) {
		ans = add(ans, t);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3700
#include <stdio.h>
 
int main(){
  
  int N,ans;
  scanf("%d",&N);
  
  if(N % 2 == 0){
    ans = N;
  }else{
    ans = N * 2;
  }
  
  printf("%d",ans);
  
  return 0;
  
}
  

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int r;
	cin >> r;
	if( r < 1200 ) cout << "ABC" << endl;
	else if( r < 2800 ) cout << "ARC" << endl;
	else cout << "AGC" << endl;
	ret 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
    int n, ans = 0;
    scanf("%d", &n);
    int temp = n / 500;
    n %= 500;
    ans += temp * 1000;
    ans += n / 5 * 5;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  cout << max(0, a-b*2);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
const int MOD=1000000007;
typedef long long ll;
int n, arr[100010], cnt[100010], ans[100010];
int fac[100010], inv[100010];
inline int rd(){
	int a=0; char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) (a*=10)+=c-'0', c=getchar();
	return a;
}
int C(int n, int m){
	return (ll)fac[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int main(){
	n=rd();
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=n+1;i++)
		fac[i]=(ll)fac[i-1]*i%MOD, inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
	for(int i=2;i<=n+1;i++)
		inv[i]=(ll)inv[i-1]*inv[i]%MOD;
	int sp;
	for(int i=1;i<=n+1;i++){
		arr[i]=rd();
		if(cnt[arr[i]]) sp=arr[i];
		cnt[arr[i]]++;
	}
	int st=-1, ed;
	for(int i=1;i<=n+1;i++)
		if(arr[i]==sp){
			if(st==-1) st=i;
			else ed=i;
		}
	for(int i=1;i<=n+1;i++)
		ans[i]=C(n+1, i);
	for(int i=1;i<=n-ed+st+1;i++)
		ans[i]=(ans[i]-C(n-ed+st, i-1)+MOD)%MOD;
	for(int i=1;i<=n+1;i++)
		printf("%d\n", ans[i]);
	return 0;
}

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

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


// std::vector Declaration
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...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

void dfs(const auto& G, auto& color, int v, int p, int c) {
   color[v] = c;
   for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      int u = e.to, w = e.cost;
      if (u == p) continue;
      dfs(G, color, u, v, (w % 2 ? -c : c));
   }
}

int main()
{
   int n; cin >> n;
   vector<vector<edge>> G(n);
   for (int i = 0; i < n-1; ++i) {
      int u, v, w; cin >> u >> v >> w;
      --u; --v;
      G[u].push_back({v,w});
      G[v].push_back({u,w});
   }

   vector<int> color(n);
   dfs(G, color, 0, -1, 1);

   for (int i = 0; i < n; ++i) {
      cout << (color[i] == 1 ? 1 : 0) << endl;
   }

   return 0;
}


Measured memory_bytes: 9728
from collections import deque
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
dxdy = [(-1,0), (0,-1), (0,1), (1,0)]
seen = [[False]*w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if seen[i][j]:
            continue
        q = deque([(j, i)])
        cnt = [0, 0]
        cnt[int(s[i][j]=='#')] += 1
        seen[i][j] = True
        while q:
            x, y = q.popleft()
            for dx, dy in dxdy:
                if not (0<=x+dx<w and 0<=y+dy<h):
                    continue
                if seen[y+dy][x+dx] or s[y][x]==s[y+dy][x+dx]:
                    continue
                cnt[int(s[y+dy][x+dx]=='#')] += 1
                seen[y+dy][x+dx] = True
                q.append((x+dx, y+dy))
        ans += cnt[0]*cnt[1]
print(ans)

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

ll nCr(int n, int r, int dup){
    int nn;
    ll* a = (ll*)calloc(n,sizeof(ll));
    ll retv;
    nn = (dup) ? (n+r-1) : n;
    if ( nn-r < r ) r = nn-r;
    if ( r == 0 ) return 1;
    if ( r == 1 ) return nn;
    for ( int i=1; i<r; i++ ) a[i] = i+2;
    for ( int i=3; i<=nn-r+1; i++ ) {
        a[0] = i;
        for ( int j=1; j<r; j++ ) a[j] += a[j-1];
    }
    retv = a[r-1];
    free(a);
    return retv;
}

int main(){
    ll N, P;
    cin >> N >> P;
    ll tmp, odd = 0, even = 0;
    for(int i=0;i<N;i++){
        cin >> tmp;
        if(tmp%2 == 0)
            even++;
        else
            odd++;
    }
        
    ll ans = 0;
    if(P == 0){
        // 奇数の袋を偶数個選ぶ
        for(int i=0;i<=odd;i+=2)
            ans += nCr(odd,i,0);
        ans = ans*pow(2, even);
    }else{
        // 奇数の袋を奇数個選ぶ
        for(int i=1;i<=odd;i+=2)
            ans += nCr(odd,i,0);
        ans = ans*pow(2, even);
    }

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

Measured memory_bytes: 256
N,K,L=map(int,input().split())

class UnionFind():
  def __init__(self,N):
    self.parents=list(range(N))
    self.size=[1]*N
  def find(self,x):
    if self.parents[x]==x:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def union(self,x,y):
    x,y=self.find(x),self.find(y)
    if x==y:
      return 
    if self.size[x]<self.size[y]:
      self.size[y]+=self.size[x]
      self.parents[x]=y
    else:
      self.size[x]+=self.size[y]
      self.parents[y]=x

uf1=UnionFind(N)
uf2=UnionFind(N)
for i in range(K):
  x,y=map(int,input().split())
  uf1.union(x-1,y-1)
for j in range(L):
  x,y=map(int,input().split())
  uf2.union(x-1,y-1)

keys=[(uf1.find(x),uf2.find(x)) for x in range(N)]
count={}
for key in keys:
  if key in count:
    count[key]+=1
  else:
    count[key]=1
print(*[count[key] for key in keys])

Measured memory_bytes: 58664
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
long long n,h,w;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>h>>w;
cout<<(n-w+1)*(n-h+1)<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/





Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <iostream>
using namespace std;
#define ref(i,x,y)for(int i=x;i<=y;++i)
typedef long long LL;
typedef pair<LL,LL> PII;
const int mod=1e9+7;
LL fib[101],x,y;
vector<PII> s[101];
int Q;
void dfs(int x,LL a,LL b){
	if(x>88)return;
	if(a<0||b<0)printf("error\n");
	if(a>=fib[x]&&b>=fib[x+1])return;
	s[x].push_back(make_pair(a,b));
	dfs(x+1,b,b+a);
	dfs(x+1,b,b*2+a);
}
int main(){
	fib[0]=fib[1]=1;
	ref(i,2,90)fib[i]=fib[i-1]+fib[i-2];
	dfs(1,1,1);
	scanf("%d",&Q);
	ref(i,1,Q){
		scanf("%lld%lld",&x,&y);
		if(x>y)swap(x,y);
		int ans=0;LL sum=0;
		ref(i,1,100)if(fib[i]>x||fib[i+1]>y){ans=i-1;break;}
		if(ans<=1){
			if(x==1)sum=y%mod;else if(x==2)sum=4;
			printf("1 %lld\n",sum);
			continue;
		}
		int sz=s[ans].size();
		ref(i,0,sz-1){
			PII p=s[ans][i];
			if(p.second<=x&&y>=p.first)(sum+=(y-p.first)/p.second)%=mod;
			if(p.second<=y&&x>=p.first)(sum+=(x-p.first)/p.second)%=mod;
		}
		printf("%d %lld\n",ans,sum);
	}
}

Measured memory_bytes: 4224
class Dice(object):
    def __init__(self, s1, s2, s3, s4, s5, s6):
        self.s1 = s1
        self.s2 = s2
        self.s3 = s3
        self.s4 = s4
        self.s5 = s5
        self.s6 = s6
    def east(self):
        prev_s6 = self.s6
        self.s6 = self.s3
        self.s3 = self.s1
        self.s1 = self.s4
        self.s4 = prev_s6
    def west(self):
        prev_s6 = self.s6
        self.s6 = self.s4
        self.s4 = self.s1
        self.s1 = self.s3
        self.s3 = prev_s6
    def north(self):
        prev_s6 = self.s6
        self.s6 = self.s5
        self.s5 = self.s1
        self.s1 = self.s2
        self.s2 = prev_s6
    def south(self):
        prev_s6 = self.s6
        self.s6 = self.s2
        self.s2 = self.s1
        self.s1 = self.s5
        self.s5 = prev_s6
    def rotate(self):
        prev_s2 = self.s2
        self.s2 = self.s4
        self.s4 = self.s5
        self.s5 = self.s3
        self.s3 = prev_s2
    def top(self):
        return self.s1
    def front(self):
        return self.s2
    def right(self):
        return self.s3

    def isSameDice(self, anotherDice):
        if self.s1 == anotherDice.s1 and \
           self.s2 == anotherDice.s2 and \
           self.s3 == anotherDice.s3 and \
           self.s4 == anotherDice.s4 and \
           self.s5 == anotherDice.s5 and \
           self.s6 == anotherDice.s6:
            return True
        return False


dices = []
n = int(input())
for i in range(n):
    s1, s2, s3, s4, s5, s6 = map(int, input().split())
    dices.append(Dice(s1, s2, s3, s4, s5, s6))

flag = False
for idx1, dice1 in enumerate(dices):
    for idx2, dice2 in enumerate(dices):
        if idx1 == idx2:
            continue

        for i in range(6):
            if i % 2 == 0:
                dice2.north()
            else:
                dice2.west()

            for j in range(4):
                dice2.rotate()
                if dice2.isSameDice(dice1):
                    flag = True
                    break
            if flag:
                break
        if flag:
            break
    if flag:
        break

if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 6820
/**
*    author:  yuya1234
*    created: 09.07.2020 11:11:54
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define ALL(v) (s).begin(), (s).end()
#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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

  int n,k;
  cin>>n>>k;

  double ans=0;
  int tmp=0;
  REPD(i,n)
  {
    while(k>(i+1)*pow(2,tmp))
    {
      tmp++;
    }
    if(tmp==0)ans+=(1.0/n);    
    else ans+=(1.0/n)*pow(0.5,tmp);    
  }

  printf("%.12lf\n",ans);

  return 0;
}

Measured memory_bytes: 4180
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        double[] foodValues = new double[n];
        for (int i = 0; i < n; i++) {
            foodValues[i] = sc.nextDouble();
        }

        Arrays.sort(foodValues);
        double value = foodValues[0];

        for (int i = 1; i < n; i++) {
            value = (value + foodValues[i])/2;
        }

        System.out.println(value);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

const char * a2()
{
    int a, b;
    cin >> a >> b;

    if(a < 1 && -1 < b)
        return "Zero";

    if(0 < a)
        return "Positive";

    const auto k = b - a + 1;
    return k & 1 ? "Negative" : "Positive";
}

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

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<std::pair<std::pair<LL, LL>,LL>>xy;

// 素集合データ構造
struct UnionFind
{
	// par[i] := データ i が属する木の親の番号
	// i == par[i]のとき、データiは木の根ノード
	std::vector<LL> par;

	// sizes[i] := 根ノード i の木に含まれるデータの数
	// i が根ノードでない場合は無意味な値となる
	std::vector<LL> sizes;

	UnionFind(LL n) : par(n), sizes(n, 1)
	{
		// 最初は全てのデータ i がグループ i に存在するものとして初期化
		rep(i, n) { par[i] = i; }
	}

	// データ x が属する木の根を得る
	LL find(LL x)
	{
		if (x == par[x]) { return x; }
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータ x, y が属する木をマージする
	void unite(LL x, LL y)
	{
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) { return; }

		// x の木が y の木より大きくなるようにする
		if (sizes[x] < sizes[y]) std::swap(x, y);

		// x が y の親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
	}

	// 2つのデータ x, y が属する木が同じなら true を返す
	bool same(LL x, LL y)
	{
		return find(x) == find(y);
	}

	// データ x が含まれる木の大きさを返す
	LL size(LL x)
	{
		return sizes[find(x)];
	}
};

// 頂点 a, b をつなぐコスト cost の（無向）辺
struct Edge
{
	LL a, b, cost;

	// コストの大小で順序定義
	bool operator<(const Edge& o) const
	{
		return cost < o.cost;
	}
};

// 頂点数と辺集合の組として定義したグラフ
struct Graph
{
	LL n;					// 頂点数
	std::vector<Edge> es;	// 辺集合

	// クラスカル法で無向最小全域木のコストの和を計算する
	// グラフが非連結のときは最小全域森のコストの和となる
	LL kruskal()
	{
		// コストが小さい順にソート
		std::sort(es.begin(), es.end());

		UnionFind uf(n);
		LL min_cost = 0;

		rep(ei, es.size())
		{
			Edge& e = es[ei];
			if (!uf.same(e.a, e.b))
			{
				// 辺を追加しても閉路ができないなら、その辺を採用する
				min_cost += e.cost;
				uf.unite(e.a, e.b);
			}
		}
		return min_cost;
	}
};

// グラフの辺を張る
Graph input_graph()
{
	Graph g;
	g.n = N;
	std::sort(xy.begin(), xy.end(), [](auto&l, auto&r) {return l.first.first < r.first.first; });
	rep(i, N - 1)
	{
		Edge e;
		e.a = xy[i].second;
		e.b = xy[i + 1].second;
		e.cost = std::min(abs(xy[i].first.first - xy[i + 1].first.first), abs(xy[i].first.second - xy[i + 1].first.second));
		g.es.push_back(e);
	}
	std::sort(xy.begin(), xy.end(), [](auto&l, auto&r) {return l.first.second < r.first.second; });
	rep(i, N - 1)
	{
		Edge e;
		e.a = xy[i].second;
		e.b = xy[i + 1].second;
		e.cost = std::min(abs(xy[i].first.first - xy[i + 1].first.first), abs(xy[i].first.second - xy[i + 1].first.second));
		g.es.push_back(e);
	}
	return g;
}

int main()
{
	in >> N;
	rep(i, N)
	{
		LL x_tmp, y_tmp;
		in >> x_tmp >> y_tmp;
		xy.push_back({ { x_tmp,y_tmp }, i });
	}

	Graph g = input_graph();

	out << g.kruskal() << std::endl;
	return 0;
}

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



int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("maxflow.out", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a,b;
    cin>>a>>b;
    if((a+b)%2==1){
        cout<<"IMPOSSIBLE"<<endl;
    }
    else{
        cout<<(a+b)/2<<endl;
    }
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  cout << a[0] + a[1] << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
 
#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)
 
using namespace std;

const int N = 200010;

int a[N], b[N], n;

bool check(int k)
{
	Rep(i, n * 2 - 1) b[i] = (a[i] >= k);
	int ll = n, rr = n;
	while (ll > 1 && b[ll - 1] != b[ll]) ll --;
	while (rr < n * 2 + 1 && b[rr + 1] != b[rr]) rr ++;
	if (ll == 1 && rr == n * 2 + 1)
		return (n & 1) ? b[n] : (b[n] ^ 1);
	return n - ll < rr - n ? b[ll] : b[rr];
}

int main()
{
	scanf("%d", &n);
	Rep(i, n * 2 - 1) scanf("%d", &a[i]);
	int l = 1, r = n * 2 - 1;
	while (l != r) {
		int mid = (l + r) >> 1;
		if (check(mid)) l = mid + 1;
		else r = mid;
	}
	if (!check(l)) l --;
	printf("%d\n", l);
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
 
template<typename T> struct edge{
    int from, to; T cost;
    edge(int f, int t, T c): from(f), to(t), cost(c){}
};
 
template<typename T> struct Graph{
    vector<vector<edge<T>>> G;
    int n;
 
    Graph(int n_): n(n_){
        G.resize(n);
    }
 
    void add_edge(int f, int t, T c){
        G[f].emplace_back(f, t, c);
    }
};

template<typename T> 
pair<bool, vector<int>> topological_sort(Graph<T> &gr){
    vector<int> ret(gr.n, -1), in(gr.n, 0);
    rep(i, gr.n)for(edge<T> &e: gr.G[i]) ++in[e.to];
    int cur = 0;
    stack<int> st;
    rep(i, gr.n)if(!in[i]) st.push(i);
    if(st.empty()) return make_pair(false, ret);
    while(!st.empty()){
        int v = st.top(); st.pop();
        ret[cur++] = v;
        for(edge<T> &e: gr.G[v]){
            if(!in[e.to]) return make_pair(false, ret);
            --in[e.to];
            if(!in[e.to]) st.push(e.to);
        }
    }
    return make_pair(cur == gr.n, ret);
}

template<typename T> 
bool has_cycle(Graph<T> &gr){
    return !topological_sort(gr).fi;
}

int main(){
    int m, n;
    scanf("%d%d", &m, &n);
    int lb[m][n], ub[m][n];
    rep(i, m)rep(j, n) lb[i][j] = -1, ub[i][j] = mod;
    rep(i, m){
        int K;
        scanf("%d", &K);
        rep(_, K){
            int s; string cond; int t;
            cin >> s >> cond >> t;
            --s;
            if(cond == ">=") chmax(lb[i][s], t);
            else chmin(ub[i][s], t);
            if(lb[i][s] > ub[i][s]){
                puts("No");
                return 0;
            }
        }
    }

    Graph<int> gr(m);
    rep(i, m)For(j, i+1, m){
        int dir = 0; // 1: i -> j, 0: no edge, -1: i <- j
        rep(k, n){
            if(ub[i][k] < lb[j][k]){
                if(dir == -1){
                    puts("No");
                    return 0;
                }
                dir = 1;
            }
            else if(ub[j][k] < lb[i][k]){
                if(dir == 1){
                    puts("No");
                    return 0;
                }
                dir = -1;
            }
        }
        if(dir == 1) gr.add_edge(i, j, 1);
        else if(dir == -1) gr.add_edge(j, i, 1);
    }

    puts(!has_cycle(gr) ? "Yes" : "No");
}


Measured memory_bytes: 3376
#include <iostream>
#include <vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define MAXN 200005

using namespace std;

vector<int> conn[MAXN];

// depth, vertex
pair<int,int> dfs(int a, int p) {
  pair<int,int> ans(0, a);
  for (auto x: conn[a]) {
    if (x != p) {
      auto d = dfs(x, a);
      d.first++;
      ans = max(ans, d);
    }
  }
  return ans;
}

signed main() {
  IOS;
  int N,i=0;
  string ans;
  cin >> N;
  int a,b;
  for (i = 0; i < N-1; i++) {
    cin >> a >> b;
    conn[a].push_back(b);
    conn[b].push_back(a);
  }
  auto d1 = dfs(1, 0);
  auto d2 = dfs(d1.second, 0);
//  cout << d1.first << " " << d1.second << endl;
//  cout << d2.first << " " << d2.second << endl;

  ans = (d2.first % 3 == 1) ? "Second" : "First";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 26880
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int n = input.nextInt();
		
		String s = input.next();
		int count=0;
		for(int i=0;i<n-2;i++) {
			if(s.charAt(i)=='A' && s.charAt(i+1)=='B' && s.charAt(i+2)=='C') {
				count++;
				i=i+2;
			}
		}
		
		System.out.println(count);
		
		
	}

}


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

using namespace std;

int main(){

int len,k=0;
cin>>len;
string A,B,C;
cin>>A>>B;
vector<char> ans;
for(int i=0;i<len;i++){
    		ans.push_back(A[i]);
		ans.push_back(B[i]);
}
for(int i=0;i<ans.size();i++){
    cout << ans[i];
}






}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
//const lint MOD = pow(10, 9) + 7;

int main() {
	double a, b, c;
	cin >> a >> b >> c;
	c = c * 2 * 3.141592653589795028 / 360;
	double S = a * b * sin(c)/2;
	double L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(c));
	double h = 2 * S / a;
	cout <<setprecision(20)<< S << endl;
	cout << setprecision(20) << L << endl;
	cout <<setprecision(20)<< h << endl;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 1;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a) cin >> e;
  vector<vector<int>> g(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }

  vector<int> r(n), t(n, INF);
  auto dfs = [&](auto &&dfs, int i, int j) -> void {
    auto it = lower_bound(t.begin(), t.end(), a[j]);
    auto p = *it;
    *it = a[j];
    r[j] = lower_bound(t.begin(), t.end(), INF) - t.begin();

    for (auto e : g[j]) {
      if (e == i) continue;
      dfs(dfs, j, e);
    }

    *it = p;
  };
  dfs(dfs, 0, 0);

  for (auto e : r) cout << e << endl;
}


Measured memory_bytes: 30836
import decimal
import numpy as np
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

N,K = LI()
A = LI()

ans = []

for i in range(K,N):
    if A[i-K] < A[i]:
        ans.append('Yes')
    else:
        ans.append('No')

print('\n'.join(ans))

Measured memory_bytes: 50136
import math

def main():
  h, w = map(int, raw_input().split())
  grid = []
  for _ in xrange(h):
    grid.append(raw_input())

  if h == 1:
      for x in xrange(2):
          print(grid[0])
      return
  
  new_grid = []
  for i in xrange((h-1)*2):
      row = ['' for _ in xrange(w)] 
      pos = (i+1)/2
      for j in xrange(w):
          row[j] = grid[pos][j]
      if pos == 0:
          new_grid.append(''.join(row))
      new_grid.append(''.join(row))
  new_grid.append(new_grid[-1])
  
  for row in new_grid:
      print(''.join(row))


main()


Measured memory_bytes: 2692
from collections import Counter

def main():
    H, W = map(int, input().split())
    all_c = Counter([])
    for _ in range(H):
        line = list(input())
        line_c = Counter(line)
        all_c += line_c
    
    if H % 2 == 0 and W % 2 == 0:
        if all(val%4 == 0 for val in all_c.values()):
            print("Yes")
        else:
            print("No")

    elif H % 2 ^ W % 2:
        flag = all(val%2 == 0 for val in all_c.values())
        two_count = sum(val%4 == 2 for val in all_c.values())

        if H % 2 == 0:
            threshould = H//2
        else:
            threshould = W//2

        if flag and two_count <= threshould:
            print("Yes")
        else:
            print("No")

    elif H % 2 == 1 and W % 2 == 1:
        one_count = sum(val%2 == 1 for val in all_c.values())
        
        three_count = sum(val%4 == 3 for val in all_c.values())
        two_count = sum(val%4 == 2 for val in all_c.values())

        threshould = H//2 + W//2
        if one_count == 1 and three_count + two_count <= threshould:
            print("Yes")
        else:
            print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9456
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {

int x,y,z;cin>>x>>y>>z;
	swap(x,y);
	swap(x,z);

	cout<<x<<" "<<y<<" "<<z<<endl;












    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
typedef pair<ll,ll> P;
int main(){
  ll k,a,b;
  cin>>k>>a>>b;
  if(a+1>=b){
    cout<<k+1;
    return 0;
  }
  if(k<=a){
    cout<<k+1;
    return 0;
  }
  ll c=0;
  k-=a-1;
  c+=b;
  k-=2;
  c+=k/2*(b-a);
  if(k%2==1) c++;
  cout<<c;
}

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

int main() {
    string N;
    cin >> N;
    if (N[0] == N[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

int bi(int n,int k){//2進展開
if(k==1 && n%2==0){return 0;}
else if(k==1 && n%2==1){return 1;}
else{return  bi(n/2,k-1);}
}


int power(int n){//べき乗
if(n==0){return 1;}
else{return 2*power(n-1);}
}



int main() {
int D;
int G;
cin >>D>>G;

int p[11];
int c[11];

for(int i=1; i<=D; i++){
cin >>p[i] >>c[i];
}

int mondai;//解いた問題の数
int score;//スコア

int ans=1000;


for(int i=0; i<power(D); i++){

mondai=0;
score=0;

for(int j=1; j<=D; j++){//全問解くセットを解く

if(bi(i,j)==1){
mondai=mondai+p[j];
score=score+100*j*p[j]+c[j];}

}


int hai=D;
while(score<G){//全問解かないセットを解いていく

if(hai==0){mondai=1000;break;}

if(bi(i,hai)==0 && score+100*hai*(p[hai]-1)<G){
mondai=mondai+p[hai]-1;
score=score+100*hai*(p[hai]-1);}

else if(bi(i,hai)==0 && score+100*hai*(p[hai]-1)>=G){
while(score<G){
mondai=mondai+1; 
score=score+100*hai;}
}
hai=hai-1;


}

if(ans>mondai){ans=mondai;}
}

cout <<ans;


}



Measured memory_bytes: 256
#include <stdio.h>
#define mx(a,b) (a<b?b:a)
int main() {long long i,j,k,n,f;while (scanf("%lld",&n)!=EOF && n) {j=i=0,f=-5000000007;while (n--) {scanf("%lld",&k);f=mx(f,k);j+=k;i=mx(i,j);j=mx(j,0);} if (f<=0 && !i) i=f;printf("%lld\n",i);} return 0;}

Measured memory_bytes: 1028
a,b,c=gets.split(" ").map(&:to_i)
m1 = [a,b,c].max
m3 = [a,b,c].min
m2 = a + b + c - m1 - m3
count=0
while m2<m1
  m2+=1
  m3+=1
  count+=1
end
if (m2-m3) % 2 == 1
  m1+=1
  m2+=1
  count+=1
end
t = (m2-m3)/2
t.times do
  m3+=2
  count+=1
end
puts count


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const ll inf = 1LL << 59;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

////////////////////////////////////////////////////////////////////////

ll N, A, B, C, D;

void solve() {
	cin >> N >> A >> B >> C >> D;
	N--;
	for(ll i = N; i >= 0; i--) {
		ll j = i - N;
		if(A + D * i + C * j >= B && B >= A + D * j + C * i) {
			cout << "YES\n";
			return;
		}
	}
	cout << "NO\n";
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
import java.io.*;
 
public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1, line.length()));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26280
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

#define pii pair<int,int>
int main() {
  int a,b;
  map<int,int> m;
  map<int,int> f;
  string s;
  while(getline(cin,s)) {
    if(sscanf(s.c_str(),"%d,%d\n", &a,&b) != 2) break;
    m[a]++;
    f[a]=1;
  }
  while(scanf("%d,%d\n", &a,&b) == 2) {
    m[a]++;
    if(f[a]) f[a]=2;
  }
  vector<pii> v;
  FOR(i,m) {
    if (f[(*i).first]==2) {
      v.push_back(pii(*i));
    }
  }
  sort(ALL(v));
  FOR(i,v)
    cout << (*i).first << " " <<(*i).second << endl;
}

Measured memory_bytes: 0
class Integer
  def inverse(m = nil)
    return Rational(1, self) if m.nil?

    # extended Euclidean algorithm
    a, b, u, v = self, m, 1, 0
    until b.zero?
      a, (t, b) = b, a.divmod(b)
      u, v = v, u - t * v
    end

    # u is an inverse iff self.gcd(m) == 1
    if a.abs != 1
      raise ArgumentError,
            "modulus is not coprime to the receiver" 
    end

    u = -u if a < 0
    u % m   # 0 <= u < m || m < u <= 0
  end
end

n, k, *a = $stdin.read.split.map(&:to_i)
M = 10**9 + 7

CMB = Array.new
CMB << (x = 1)
(n - k).times do |i|
  CMB << (x = x * (i + k) * (i + 1).inverse(M) % M)
end
CMB.reverse!

a.sort!
fsum = CMB.lazy.zip(a, a.reverse_each).inject(0) { |sum, (cmb, min, max)| (sum + cmb * (max - min)) % M }

puts fsum


Measured memory_bytes: 13300
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    while(cin>>A>>B)
    {
        int cnt=0;
        if(A>=B)
        {
            cnt+=A;
            A--;
        }
        else
        {
            cnt+=B;
            B--;
        }
        if(A>=B)
        {
            cnt+=A;
            A--;
        }
        else
        {
            cnt+=B;
            B--;
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[10001];
    double sum=0;
    for(int i=0;i<n;i++){
      cin>>a[i];
      sum+=a[i];
    }
    double ave=sum/(double)n;
    int ans=0;
    for(int i=0;i<n;i++) if(a[i]<=ave) ans++;
  	cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector> 
using namespace std;

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

string map[20];
int W, H;

int dfs(int y, int x){
  
  int count = 1;
  int i;
  for(i = 0;i < 4;i++){
    int next_x = x + dx[i] ,next_y = y + dy[i];
    if(0 <= next_x && next_x < W && 0 <= next_y && next_y < H && map[next_y][next_x] == '.'){
      map[next_y][next_x] = 'a';
      count += dfs(next_y, next_x);
    }
  }
  return count;
}


int main(){
  int i, j, x, y;
  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0) break;
    bool start = false;
    for(i = 0;i < H;i++){
      cin >> map[i];
      
    }

    for(i = 0;i < H;i++){
      for(j = 0;j < W;j++){
        if(map[i][j] == '@'){
          x = j;
          y = i;
          start = true;
          break;
        }
      }
      if(start) break;
    }

    cout << dfs(y, x) << endl;

    
  }

  return 0;
}

Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int num;
		for(;;){
			String wo = sc.next();
			if(wo.equals("-"))break;
			String[] woArray = wo.split("");
			String[] ans = new String[woArray.length];
			String[] sans = new String[woArray.length];
			int m = sc.nextInt();
			for(int i=0; i<m; i++){
				int h = sc.nextInt();
				for(int j=0; j<woArray.length; j++){
					int add = j + h;
					if(add>=woArray.length){
						num = add - woArray.length;
					}else{
						num = add;
					}
					ans[j]=woArray[num];
				}
				for(int j=0; j<woArray.length; j++){
					woArray[j]=ans[j];
				}
			}
			for(int j=0; j<ans.length; j++){
				System.out.print(ans[j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26320
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    diff_c = 0
    tmp = {}
    for x in [A[i], B[i], C[i]]:
        if x in tmp.keys():
            tmp[x] += 1
        else:
            tmp[x] = 1
    common = max(tmp, key=tmp.get)
    if A[i] != common:
        diff_c += 1
    if B[i] != common:
        diff_c += 1
    if C[i] != common:
        diff_c += 1
    ans += diff_c
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS pow(10, -9)

int main() {
	int n, m;
	while (cin >> n >> m) {
		if (n == 0 && m == 0) {
			break;
		}
		vector< vector<double> > hyou(n, vector<double>(n));
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cin >> hyou[i][j];
			}
		}
		vector< vector<double> > nae(m, vector<double>(n, 1.0));
		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				nae[i][j] = nae[i-1][0]*hyou[0][j];
				for (int k = 1; k < n; k++) {
					nae[i][j] = max(nae[i][j], nae[i-1][k]*hyou[k][j]);
				}
			}
		}
		double MAX = 0.0;
		for (int i = 0; i < n; i++) {
			MAX = max(MAX, nae[m-1][i]);
		}
		MAX += EPS;
		printf("%.2f\n", MAX);
	}
	return 0;
}

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

using namespace std;


#define MAXN 100010
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, a[MAXN] = {};
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += abs(a[i]-a[i-1]);
  }
  sum += abs(a[n]-0);
  for (int i = 1; i <= n; ++i) {
    int diff = abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i+1]-a[i]);
    cout << sum+diff << "\n";
  }
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s;
	cin >> s;
	int cnt[26];
	for(int i=0; i<26; i++) cnt[i] = 0;

	for(int i=0; i<s.length(); i++){
		cnt[s.at(i)-'a']++;
	}

	for(int i=0; i<26; i++){
		if(cnt[i]>1){
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" <<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(a >= 13)cout << b;
    else if(a >= 6)cout << b/2;
    else cout << 0;
}


Measured memory_bytes: 256
//
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <numeric>
#include <functional>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<complex>

using namespace std;

#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()

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

const ll inf = INT_MAX;
const double eps = 1e-10;
const double pi = acos(-1.0);
const int di[][2] = {{1,0},{0,1},{-1,0},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};

int main(){

	int a,b,h;
	cin >> a >> b >>h;
	cout << (a+b) * h /2 << endl;
	return 0;
}


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

const ll INF = 1LL << 60;


int main() {
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);

    ll target = min(N, B - 1);
    // cout << target << endl;
    cout << floor(A * target / B) - A * floor(target / B) << endl;
    // if (B > N) {
    //     cout << N << endl;
    // } else {
    //     cout << N << endl;
    // }
}


Measured memory_bytes: 3848
import copy
D = int( input() )
c = list( map( int, input().split() ) )
s = []
for _ in range( D ):
    s_i = list( map( int, input().split() ) )
    s.append( s_i )

def next_satisfy( d, c, s, next_t, last,  pre_satisfy ):
    ans = pre_satisfy + s[ d ][ next_t ]
    last_d = copy.deepcopy( last[ -1 ] )
    last_d[ next_t ] = d
    last.append( last_d )
    for i in range( 26 ):
        ans -= c[ i ] * ( d - last[ d ][ i ] )
    return ans

t = []
last = [ [ -1 for _ in range( 26 ) ] ]
last_i = [ -1 for _ in range( 26 ) ]
for d in range( D ):
    max_satisfy = - 10 ** 10
    next_t = -1
    for i in range( 26 ):
        satisfy_i = next_satisfy( d, c, s, i, last, 0 )
        if max_satisfy < satisfy_i:
            max_satisfy = satisfy_i
            next_t = i
    last_i[ next_t ] = d
    last.append( copy.deepcopy( last_i ) )
    t.append( next_t + 1 )

for t_i in t:
    print( t_i )
    

Measured memory_bytes: 12904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    string s;
    ll n;
    cin >> s >> n;

    string ans = "";
    for (int i = 0; i < s.size(); i+=n)
    {
        ans += s[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n, m, x = map(int, input().split())

L = [0]*n
C = [0]*n
for i in range(n):
    temp = list(map(int, input().split()))
    L[i] = temp[1:]
    C[i] = temp[0]

import itertools
ans = 10**18
for i in range(1, n+1):
    for p in itertools.combinations(range(n),i):
        #print(p)
        temp = [0]*m
        cost = 0
        for j in range(len(p)):
            A = L[p[j]]
            cost += C[p[j]]
            for k in range(m):
                temp[k] += A[k]
        flag = True
        for l in range(m):
            if temp[l] < x:
                flag = False
        if flag:
            ans = min(ans, cost)
if ans == 10**18:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 73580