akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 
int n ;
int main(){
    fastio
    cin >> n ;
    vector<int> v(n) ; 
    cin >> v[1] ; 
    int ans = v[1] ;
    for(int i=1;i<n;i++){
    	cin >> v[i] ; 
    	ans ^= v[i] ; 
    }
    if ( ans == 0 ){
    	cout << "Yes" << endl;
    }
    else cout << "No" << endl;
    return 0 ;
}


Measured memory_bytes: 640
//建最大堆
#include<iostream>
#include<algorithm> 
using namespace std;
#define maxx 2000000
int H,A[maxx+1];
void maxHeapify(int i)
{
	int l,r,largest;
	l=i*2;
	r=i*2+1;
	if(H>=l&&A[l]>A[i])
		largest=l;
	else largest=i;
	if(r<=H&&A[r]>A[largest])
		largest=r;
	if(largest!=i)
	{
		int tt=A[i];
		A[i]=A[largest];
		A[largest]=tt;
		//swap(A[i],A[largest]);
		maxHeapify(largest);
	}
}
int main()
{
	cin>>H;
	for(int i=1;i<=H;i++)
	{
		cin>>A[i];
	}
	for(int i=H/2;i>=1;i--)
	{
		maxHeapify(i);
	}
	for(int i=1;i<=H;i++)
	{
		cout<<" "<<A[i];
	}
	cout<<endl;
	return 0;
} 


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int n;
    Scd(n);

    int p[103] = {};

    int cnt = 0;
    int tmp;
    for( int i = 2; i <= n; i++ ){
        tmp = i;
        for( int j = 2; j <= i; j++ ){
            if( tmp%j == 0 )do{
                p[j]++;
                tmp/=j;
            }while( tmp%j == 0 );
        }
    }

    int cnt15 = 0;
    int cnt5 = 0;
    int cnt25 = 0;
    int cnt3 = 0;
    Rep(i,n+1){
        p[i]++;
        if( p[i] >= 75 ){
            cnt += cnt3 + cnt5 + cnt15 + cnt25;
            cnt25 += cnt5;
            cnt15 += cnt5 + cnt3;
            cnt++;
            cnt25++;
            cnt15++;
            cnt5++;
            cnt3++;
        }
        else if( p[i] >= 25 ){
            cnt += cnt3 + cnt5 + cnt15 + cnt25;
            cnt25 += cnt5;
            cnt15 += cnt5 + cnt3;
            cnt25++;
            cnt15++;
            cnt5++;
            cnt3++;
        }
        else if( p[i] >= 15 ){
            cnt += cnt5 + cnt15 + cnt25;
            cnt25 += cnt5;
            cnt15 += cnt5 + cnt3;
            cnt15++;
            cnt5++;
            cnt3++;
        }
        else if( p[i] >= 5 ){
            cnt += cnt15 + cnt25;
            cnt25 += cnt5;
            cnt15 += cnt5 + cnt3;
            cnt5++;
            cnt3++;
        }
        else if( p[i] >= 3 ){
            cnt +=  cnt25;
            cnt15 += cnt5;
            cnt3++;
        }
    }

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

    return 0;
}



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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define MN 500005
int n;
pii a[MN];
int main(){
	int N,M;read(N);read(M);read(n);
	for(int i=1;i<=n;++i){
		read(a[i].ft);read(a[i].sd);
	}
	sort(a+1,a+n+1);
	int mx=0;
	for(int i=1;i<=n;++i){
		if(a[i].ft-a[i].sd>mx)return printf("%d",a[i].ft-1),0;
		if(a[i].ft-a[i].sd==mx)++mx;
	}
	cout<<N;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    string mark="SHCD";
    map<string,ll> mp;
    mp["S"]=0;
    mp["H"]=1;
    mp["C"]=2;
    mp["D"]=3;
    ll n;cin>>n;
    vector< vector<bool> > ok(4,vector<bool>(13));
    rep(i,n){
        string m;cin>>m;
        ll x;cin>>x;
        ok[mp[m]][x-1]=true;
    }
    rep(i,4){
        rep(j,13){
            if(!ok[i][j]){
                cout<<mark[i]<<" "<<j+1<<endl;
            }
        }
    }
}

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



Measured memory_bytes: 3212
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String S = sc.next();
		String T = sc.next();
		
		char[] map = new char[26];
		for (int i = 'a'; i <= 'z'; i++) {
			map[i-'a'] = '0';
		}
		
		for (int i = 0; i < S.length(); i++) {
			if (map[S.charAt(i)-'a'] == '0' || map[S.charAt(i)-'a'] == T.charAt(i)) {
				map[S.charAt(i)-'a'] = T.charAt(i);
			} else {
				System.out.println("No");
				return;
			}
		}
		
		for (int i = 'a'; i <= 'z'; i++) {
			int count = 0;;
			for(char c: map) {
				if(c == i) {
					count++;
				}
			}
			
			if (count > 1) {
				System.out.println("No");
				return;
			}
		}
		
		System.out.println("Yes");
	}
}


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

int main(){
int a,b,c,k;
cin >> a >> b >> c >>k;
int ans = a;

if(k<=a){
  ans = k;
}

if(k>a&&k-a-b>0){
  ans = a - (k-a-b);
}

if(k>a&&k-a-b<=0){
  ans = a;
}


cout << ans << endl;

}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

int main() {
	int i, temp, answer, first_array_size, second_array_size;
	scanf("%d", &first_array_size);

	int* first_array = (int*)malloc(sizeof(int) * first_array_size);
	for (i = 0; i != first_array_size; i++) {
		scanf("%d", &first_array[i]);
	}

	answer = 0;
	scanf("%d", &second_array_size);
	while (second_array_size--) {
		scanf("%d", &temp);
		for (i = 0; i != first_array_size; i++) {
			if (first_array[i] == temp) {
				answer++;
				break;
			}
		}
	}

	printf("%d\n", answer);
		
	free(first_array);
}


Measured memory_bytes: 2096
h,w,k=map(int,input().split())
ls=[[0 for t in range(w)] for s in range(h)]
p=1
for i in range(h):
  row=list(input())
  if "#" in row:
    ch=0
    for j in range(w):
      if row[j]=="#":
        if ch==0:
          ls[i][j]=p
          ch+=1
        else:
          p+=1
          ls[i][j]=p
          
          ch+=1
      else:
        ls[i][j]=p
    p+=1
  else:
    if i==0:
      pass
    else:
      for j in range(w):
        ls[i][j]=ls[i-1][j]
  

if sum(ls[0])==0:
  c=1
  while True:
    if sum(ls[c])==0:
      c+=1
    else:
      break
  for j in range(0,c):
    for i in range(w):
      ls[j][i]=ls[c][i]

for i in ls:
  print(" ".join(map(str,i)))

Measured memory_bytes: 7156
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    
modKey  = (`mod` 1000003)

yakusuBetween :: Int -> Int -> Int -> Int
yakusuBetween l h n = h `div` n - ((l - 1) `div` n )

solve :: [(Int, Int)] -> String
solve ablst = let
    sorted = sortOn snd ablst
    (_, totalTimeList) = mapAccumL (\total (time, deadLine) -> (total+time, (total+time <= deadLine))) 0 sorted
    in
        if and totalTimeList then "Yes" else "No"

main = do
    n <- readInt
    ablst <- replicateM n readTuple2
    putStrLn $ solve ablst





Measured memory_bytes: 113020
// fuck rating
// experience matters

#include <bits/stdc++.h>

#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);

#define ll long long
#define ld long double
#define pb push_back
#define mkpr make_pair
#define fi(i,a,b) for (int i=a;i<b;i++)
#define vll vector<ll>
#define vch vector<char>
#define vst vector<string>
#define vpll vector<pll>
#define vii vector<int>
#define vvl vector<vector<ll>>
#define rev(v) reverse(v.begin(),v.end())
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define mxe(v) *max_element(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define mll map<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b)
#define nl "\n"
#define sp " "
#define sz(x)  (int)x.size()

using namespace std;

double PI = (acos(-1));
ll md = 1000000007;
//ll md = 998244353;
ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;}
ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;}
ll modinv(ll n){return pwmd(n, md - 2);}
ll nc2(ll n){return (1ll * n * (n - 1)) / 2;}
ll nsum(ll n){return (1ll * n * (n + 1)) / 2;}
bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;}


#define MAX_SIZE 1005
void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){
            for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}}
    for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);}
        


vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};



//---------VIPUL SHARMA----------\\


void solve(){
    ll n;
    cin>>n;
    cout<<(n+1)%2<<nl;
}



int main(){
    //vector<int> primes;
    //Sieve(primes);

    fast
    ll tests=1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    
    return 0;
}










Measured memory_bytes: 3672
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
  int n,k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<Pi> b(n);
  rep(i,n){
    b[i].first = a[i];
    if(a[i] < 0){
      b[i].first = -a[i];
      b[i].second = 1;
    }
  }
  sort(b.rbegin(),b.rend());
  int cnt = 0;
  ll ans = 1;
  int now = -1;
  int now2 = -1;
  rep(i,k){
    ans *= b[i].first;
    ans %= MOD;
    if(b[i].second == 1){
      now = i;
      cnt++;
    }
    else now2 = i;
  }
  if(cnt % 2 == 0){
    cout << ans << endl;
    return 0;
  }
  bool ok = false;
  rep(i,n){
    if(a[i] >= 0) ok = true;
  }
  if(!ok){
    sort(a.rbegin(),a.rend());
    ll ans = 1;
    rep(i,k){
      ans *= a[i];
      ans %= MOD;
      if(ans < 0) ans += MOD;
    }
    cout << ans << endl;
    return 0;
  }
  ll ans2 = 1;
  ll c,d,e,f;
  rep(i,k){
    if(i == now){
      c = b[i].first;
      continue;
    }
    ans2 *= b[i].first;
    ans2 %= MOD;
  }
  bool ok2 = false;
  repr(j,k,n){
    if(b[j].second == 0){
      ok2 = true;
      d = b[j].first;
      ans2 *= b[j].first;
      ans2 %= MOD;
      break;
    }
  }
  ll ans3 = 1;
  if(now2 == -1){
    cout << ans2 << endl;
    return 0;
  }
  rep(i,k){
    if(i == now2){
      e = b[i].first;
      continue;
    }
    ans3 *= b[i].first;
    ans3 %= MOD;
  }
  bool ok3 = false;
  repr(j,k,n){
    if(b[j].second == 1){
      ok3 = true;
      f = b[j].first;
      ans3 *= b[j].first;
      ans3 %= MOD;
      break;
    }
  }
  if(!ok2 && !ok3){
    ll ans4 = 1;
    sort(b.begin(),b.end());
    rep(i,k){
      ans4 *= b[i].first;
      ans4 %= MOD;
    }
    ans4 = -ans4;
    ans4 += MOD;
    cout << ans4 << endl;
  }
  else if(!ok3){
    cout << ans2 << endl;
  }
  else if(!ok2){
    cout << ans3 << endl;
  }

  else if(d*e < c*f){
    cout << ans3 << endl;
  }
  else cout << ans2 << endl;

}


Measured memory_bytes: 5632
#include <stdio.h>

int main()
{
  int N,i,j,tmp,swap_times=0;

  scanf("%d",&N);

  int a[N];

  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<N;i++){
    for(j=(N-1);j>i;j--){
      if(a[j]<a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
	swap_times++;
      }
    }
  }

  for(i=0;i<N;i++){
    printf("%d",a[i]);
    if(i!=N-1) printf(" ");
  }

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

  return 0;
}


Measured memory_bytes: 2128
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}

template< typename T > inline void Max (T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min (T &a, T b) {if(b<a) a=b;}
template< typename T > inline void Swap(T &a, T &b) {T c=a;a=b;b=c;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double   pi = acos(-1.0) ;
const int     MOD = (int)998244353 ;
const int     INF = (int)0x3f3f3f3f ;
const LL     LINF = (LL)INF<<32|INF ;
const int    SINF = (uint)(-1)>>1 ;
const LL    SLINF = (ULL)(-1)>>1 ;
const double DINF = 1e50 ;
const double  eps = 1e-8 ;
const int    maxn = (int) 1e5+20 ;
const int    maxm = (int) 1000+20 ;
const int    maxk = (int) 1000+20 ;

inline int sig(double x) {return x<-eps?-1:x>eps;}
inline LL fp(LL a,LL n,LL p) {LL res=1; for(;n;n>>=1,a=a*a%p) if(n&1) res=res*a%p; return res;}
template<typename T>inline T gcd(T a,T b) {for(T c;b;c=a%b,a=b,b=c); return a;}

//--------------------start--------------------

int n ;
void work()
{
    cin >>n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        int x; read(x);
        ans += x;
    }
    cout <<ans - n <<endl;
}

//---------------------end---------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXN 500000
#define INF 1000000000
using namespace std;
struct edge
{
	int u,v,w;
	edge(){};
	edge(int _u,int _v,int _w):u(_u),v(_v),w(_w){};
};
struct state
{
	int u,dist;
	state(){};
	state(int _u,int _dist):u(_u),dist(_dist){};
};
bool operator < (edge a,edge b){return a.w<b.w;}
bool operator < (state a,state b){return a.dist>b.dist;}
priority_queue<state> que;
vector<edge> edges;
vector<int> G[MAXN+5];
vector<int> need;
int setfa[MAXN+5],imcnt,img[MAXN+5],dist[MAXN+5];
bool vis[MAXN+5];
void Init1()
{
	for(int i=0;i<=MAXN;i++)
		setfa[i]=i;
}
void Init(int N)
{
	if(imcnt==0)
		for(int i=0;i<=MAXN;i++)
			dist[i]=INF,G[i].clear();
	else
		for(int i=0;i<=imcnt;i++)
			dist[i]=INF,G[i].clear();
	edges.clear();
	imcnt=N;
}
inline int Findfa(int x)
{
	if(x==setfa[x])
		return x;
	return setfa[x]=Findfa(setfa[x]);
}
inline void Union(int x,int y)
{
	int fx=Findfa(x),fy=Findfa(y);
	if(fx==fy)
		return;
	setfa[fx]=fy;
}
inline void Set(int x)
{
	if(vis[x]==true)
		return;
	vis[x]=true;
	img[x]=++imcnt;
}
int Dijkstra(int ed)
{
	while(que.empty()==false)	que.pop();
	que.push(state(1,0));
	dist[1]=0;
	while(que.empty()==false)
	{
		int u=que.top().u;
		int dn=que.top().dist;
		que.pop();
		if(dist[u]!=dn)
			continue;
		for(int i=0;i<(int)G[u].size();i++)
		{
			int v=G[u][i];
			if(dist[v]>dn+1)
			{
				dist[v]=dn+1;
				que.push(state(v,dist[v]));
			}
		}
	}
	if(dist[ed]==INF)
		return -2;
	return dist[ed];
}
int main()
{
	int N,M;
	Init1();
	scanf("%d %d",&N,&M);
		Init(N);
		int a,b,c;
		for(int i=1;i<=M;i++)
		{
			scanf("%d %d %d",&a,&b,&c);
			edges.push_back(edge(a,b,c));
		}
		sort(edges.begin(),edges.end());
		for(int i=0;i<=(int)edges.size();i++)
		{
			if(i==(int)edges.size()||(i!=0&&edges[i].w!=edges[i-1].w))
			{
				for(int j=0;j<(int)need.size();j++)
				{
					Set(Findfa(need[j]));
					img[need[j]]=img[Findfa(need[j])];
					G[need[j]].push_back(img[need[j]]);
					G[img[need[j]]].push_back(need[j]);
				}
				for(int j=0;j<(int)need.size();j++)
					vis[need[j]]=false,setfa[need[j]]=need[j];
				need.clear();
			}
			if(i<(int)edges.size())
			{
				need.push_back(edges[i].u);
				need.push_back(edges[i].v);
				Union(edges[i].u,edges[i].v);
			}
		}
		int ans=Dijkstra(N);
		printf("%d\n",ans/2);
//	}
	return 0;
}

Measured memory_bytes: 32240
N = int(input())
n = input()
cnt = 0
for i in range(1000):
    i = str(i).zfill(3)
    first = n.find(i[0])
    if first > -1:
        second = n[first+1 :].find(i[1]) + first + 1
        if n[first+1 :].find(i[1]) > -1:
            if len(n) >= second + 1:
                third = n[second+1 :].find(i[2]) + second + 1
                if n[second + 1 :].find(i[2]) > -1:
                    cnt += 1
    first, second, third = 0,0,0
print(cnt)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().execute();
	}

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int T = sc.nextInt();
		final int A = sc.nextInt();

		double min_dif = Double.MAX_VALUE;
		int ans = -1;

		for (int i = 0; i < N; i++) {
			int hi = sc.nextInt();
			double temp = T - hi * 0.006;
			double diff = Math.abs(A - temp);
			if (diff < min_dif) {
				min_dif = diff;
				ans = i + 1;
			}
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

int gcd(int a,int b,int c)
{
  int a2,b2;
  while(a%b != 0)
  {
   a2=a;
   a=b;
   b=a2%b;
  }
  while(b%c != 0)
  {
    b2=b;
    b=c;
    c=b2%c;
  }
  return c;
}

 int main()
 {
    int k,a,b,c;
    long sum=0;
    cin >> k;
    for(a=1;a<=k;a++){
     for(b=1;b<=k;b++){
      for(c=1;c<=k;c++){
       sum=sum+gcd(a,b,c);
      }
     }
    }
   cout << sum << endl;
   return 0;     
 }


Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;

int A[1010][12][22];
int main(){
	int a=1, b=1, c=0, t=0;
	while(a<1000){
		++c;
		if (a%3!=0){
			if (b%2==1){
				if(c>20) c=1, ++b;
			}
			else
				if(c>19) c=1, ++b;
		}			
		else
			if (c>20) 	 c=1, ++b;
		
		if (b==11) ++a, b=1;
		++t;
		A[a][b][c] = t;
	}
	int N;
	scanf("%d", &N);
	while(N--){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		printf("%d\n", 196471-A[a][b][c]);		
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <string>
#include <utility>

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

// grid-repainting.cpp --- Grit Repainting
// author: Seong Yong-ju <sei40kr@gmail.com>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  assert(2 <= h && h <= 50);
  assert(2 <= w && w <= 50);

  bool grid[h][w];
  int dp[h][w];
  fill_n((int *)dp, h * w, INT_MAX);
  int ws = 0;

  REP(i, h) {
    string s;
    cin >> s;

    REP(j, w) {
      if (s[j] == '#') {
        grid[i][j] = true;
      } else {
        ++ws;
        grid[i][j] = false;
      }
    }
  };

  priority_queue<tuple<int, int, int>> q;
  q.push(make_tuple(0, 0, 1));

  while (!q.empty()) {
    int i, j, cost;
    tie(i, j, cost) = q.top();
    q.pop();

    if (i < 0 || h <= i || j < 0 || w <= j) {
      continue;
    }
    assert(0 <= i && i < h);
    assert(0 <= j && j < w);

    if (grid[i][j])  {
      continue;
    }
    assert(!grid[i][j]);

    if (dp[i][j] <= cost) {
      continue;
    }
    assert(cost < dp[i][j]);

    dp[i][j] = cost;

    ++cost;
    q.push(make_tuple(i - 1, j, cost));
    q.push(make_tuple(i + 1, j, cost));
    q.push(make_tuple(i, j - 1, cost));
    q.push(make_tuple(i, j + 1, cost));
  }

  int dist = dp[h - 1][w - 1];
  int ans = -1;
  if (dist != INT_MAX) {
    ans = ws - dist;
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:input()

"""========main code==============="""
t=1
#t=ii()
for _ in range(t):
    a=ip()
    b=ip()
    n=len(a)
    m=len(b)
    mn=1e18
    for i in range(n-m+1):
        cnt=0
        for j in range(m):
            if(a[i+j]!=b[j]):
                cnt+=1
        mn=min(mn,cnt)
    print(mn)    

Measured memory_bytes: 68164
A, B, K = list(map(int, input().split()))

if A > K:
  Ta = A - K
  Ao = B
  
elif B > K - A:
  Ta = 0
  Ao = B - (K - A)
  
else:
  Ta = 0
  Ao = 0
  
print(Ta, Ao)
  

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
int i=0;
int j=0;
int x=0;
int in=0;
int in2=0;
int d[]=new int[a];
Arrays.fill(d, 200000000);
do {
	if(j==0) {
	in=scan.nextInt();
	j=1;
	}
	else if(j==1) {
		in2=scan.nextInt();
		if(in2<=b) {
			d[x]=in;
			x++;
		}
		i++;
		j=0;
	}
	if(i==a) {break;}

}while(true);
Arrays.sort(d);
int c=0;
x=0;
	if(d[0]==200000000) {System.out.println("TLE");}
	else {System.out.println(d[0]);}
	x++;


	}

}


Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int x, y;
    cin >> x >> y;
    cout << x+y+1-__gcd(x, y) << "\n";
    return 0;
}


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

int main () {
  int x,s1,s2,s3,ans;
  cin >> x;
  s1 = x / 100;
  s2 = ( x - s1 *100) / 10;
  s3 = x- s1 * 100 - s2 * 10;
  ans = s1+ s2 + s3;
  cout << ans << endl;
}


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

void solve(){
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(m == 1){
        cout << 0 << endl;
        exit(0);
    }

    if(2*n > m){
        ans += m/2;    
    }
    else{
        m -= 2*n;
        ans += n;
        ans += m/4;
    }

    cout << ans << endl;

}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cstdio>
#include <algorithm>
#define llint long long
#define mod 1000000007
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint a[5005];
bool dp[5005][5005];

bool check(llint x)
{
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= k; j++){
      dp[i][j] = false;
    }
  }
  dp[0][0] = true;

  for(int i = 0; i < n; i++){
    for(int j = 0; j <= k; j++){
      if(!dp[i][j]) continue;
      dp[i+1][j] = true;
      if(i+1 != x && j+a[i+1] <= k) dp[i+1][j+a[i+1]] = true;
    }
  }

  for(int j = max(0LL, k-a[x]); j < k; j++){
    if(dp[n][j]) return true;
  }
  return false;
}

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

  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> a[i];
  sort(a+1, a+n+1);

  llint ub = n+1, lb = 0, mid;
  while(ub-lb>1){
    mid = (ub+lb)/2;
    if(check(mid)) ub = mid;
    else lb = mid;
  }
  cout << ub-1 << endl;

  return 0;
}


Measured memory_bytes: 24704
#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>
#include<iterator>
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)

lint gcd(lint a, lint b) {
	//aとbの最大公約数を返す
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	return a / gcd(a, b) * b;
}

int main() {
	lint A, B;
	while (cin >> A >> B) {
		cout << gcd(A, B) << ' ' << lcm(A, B) << endl;
	}

}


Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> b(n);
  rep(i,n){
    b[a[i]-1]=i+1;
  }
  rep(i,n) cout << b[i] << endl;
  return 0;
}

Measured memory_bytes: 1664
using System;

namespace Dice
{
    class Program
    {
        private static bool Eql(string[] x, string[] y)
        {
            var g = true;
            for (int o = 0; o < x.Length; o++)
              if (x[o] != y[o]) g = false;
            return g;
        }

        private static bool Check(string[] x, string[] y)
        {
            if (Eql(x, y)) return true;
            for (int p = 0; p < 2; p++)
            {
                for(int q = 0; q < 4; q++)
                {
                    var a = x[0]; var b = x[1]; var c = x[2];
                    var d = x[3]; var e = x[4]; var f = x[5];
                    x = p == 0 ? new string[] { e, a, c, d, f, b } :
                                 new string[] { d, b, a, f, e, c };
                    if (Eql(x, y)) return true;
                    var h = x;
                    for(int r = 0; r < 4; r++)
                    {
                        var i = h[0]; var j = h[1]; var k = h[2];
                        var l = h[3]; var m = h[4]; var n = h[5];
                        h = new string[] { i, k, m, j, l, n };
                        if (Eql(h, y)) return true;
                    }
                }
            }
            return false;
        }

        static void Main()
        {
            int s = int.Parse(Console.ReadLine());
            var t = new string[s][];
            for(int u = 0; u < s; u++)
                t[u] = Console.ReadLine().Split(' ');
            for (int v = 0; v < s; v++)
                for (int w = v + 1; w < s; w++)
                    if (Check(t[v], t[w]))
                    {
                        Console.WriteLine("No");
                        return;
                    }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 9332
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

signed main()
{
  int x;
  cin>>x;
  int ans=1;
  for(int b=2;b*b<=x;b++)
    for(int t=b*b;t<=x;t*=b)
      ans=max(ans,t);
  cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int max(int a, int b){
	return a >= b ? a : b;
}

int next(int R, int *es, int *emaxs){
	int i;
	for(i = 0; i < R; i++){
		if(es[i] < emaxs[i]){
			es[i]++;
			return 1;
		}
		else{
			es[i] = 0;
		}
	}
	return 0;
}

int is_covered(int R, int *m_facts, int *es){
	int i;
	for(i = 0; i < R; i++){
		if(m_facts[i] > es[i]){
			return 0;
		}
	}
	return 1;
}

int main(){
	int N, K, R, Q, i, j, now, ans = 0;
	scanf("%d", &Q);
	int *m = (int *)malloc(sizeof(int) * Q);
	int *x = (int *)malloc(sizeof(int) * Q);
	for(i = 0, N = 0; i < Q; i++){
		scanf("%d%d", &m[i], &x[i]);
		N = max(N, m[i]);
	}
	int *prime_num = (int *)malloc(sizeof(int) * (N + 1));
	for(i = 0; i <= N; i++){
		prime_num[i] = 0;
	}
	prime_num[0] = -1;
	prime_num[1] = -1;
	for(i = 2, K = 0; i <= N; i++){
		if(prime_num[i] == 0){
			prime_num[i] = K;
			K++;
			for(j = 2; i * j <= N; j++){
				prime_num[i * j] = -1;
			}
		}
	}
//	printf("N = %d\n", N);
/*	for(i = 0; i <= N; i++){
		printf("prime_num[%d] = %d\n", i, prime_num[i]);
	}
	printf("\n");
*/	int *primes = (int *)malloc(sizeof(int) * K);
	int *emaxs = (int *)malloc(sizeof(int) * K);
	for(i = 0; i <= N; i++){
		if(prime_num[i] >= 0){
			primes[prime_num[i]] = i;
		}
	}
	for(i = 0; i < K; i++){
		for(emaxs[i] = -1, now = 1; now <= N; emaxs[i]++, now *= primes[i]){}
	}
//	printf("K = %d\n", K);
/*	for(i = 0; i < K; i++){
		printf("primes[%d] = %d\n", i, primes[i]);
	}
	printf("\n");
	for(i = 0; i < K; i++){
		printf("emaxs[%d] = %d\n", i, emaxs[i]);
	}
	printf("\n");
*/	for(R = 0; emaxs[R] > 1; R++){}
//	printf("R = %d\n", R);

	int **m_facts = (int **)malloc(sizeof(int *) * Q);
	int *max_fact = (int *)malloc(sizeof(int) * Q);
	for(i = 0; i < Q; i++){
		m_facts[i] = (int *)malloc(sizeof(int) * K);
		for(j = 0; j < K; j++){
			m_facts[i][j] = 0;
		}
		for(j = 0; m[i] > 1; j++){
			if(m[i] % primes[j] == 0){
				m_facts[i][j]++;
				m[i] /= primes[j];
				max_fact[i] = j;
				j--;
			}
		}
//		printf("i = %d\n", i);
/*		for(j = 0; j < K; j++){
			printf("%d ", m_facts[i][j]);
		}
		printf("\n");
		printf("max_fact[%d] = %d\n\n", i, max_fact[i]);
*/	}

	int *es = (int *)malloc(sizeof(int) * R);
	for(i = 0; i < R; i++){
		es[i] = 0;
	}
	int *A = (int *)malloc(sizeof(int) * K);
	do{
/*		printf("es:");
		for(i = 0; i < R; i++){
			printf("%d ", es[i]);
		}
		printf("\n");
*/		now = 0;
		for(i = R; i < K; i++){
			A[i] = 0;
		}
		for(i = 0; i < Q; i++){
			if(is_covered(R, m_facts[i], es) == 1){
				if(max_fact[i] < R){
					now += x[i];
				}
				else{
					A[max_fact[i]] += x[i];
				}
			}
		}
		for(i = R; i < K; i++){
			now += max(0, A[i]);
		}
		ans = max(ans, now);
	}while(next(R, es, emaxs) == 1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        static void Main(){
            long[] nkq = ILongs();

            long[][] a = ILongLongs(nkq[2]);

            long[] p = new long[nkq[0]];
            for(int i=0;i<p.Length;i++){
                p[i] = nkq[1] - nkq[2];
            }
            for(int i=0;i<nkq[2];i++){
                p[a[i][0]-1] ++;
            }
            for(int i=0;i<nkq[0];i++){
                WriteLine((p[i]>0)?"Yes":"No");
            }
        }

        static readonly long MOD = 1000000007;

        ///<summary>a_1, a_2, a_3, ...みたいなの</summary>
        static long[] ILongs(){
            string[] s = ReadLine().Split();
            long[] re = new long[s.Length];
            for(long i=0;i<s.Length;i++){
                re[i] = long.Parse(s[i]);
            }
            return re;
        }

        ///<summary>xooxoxoxxoxo...みたいなの</summary>
        static char[] IChars(){
            return ReadLine().ToCharArray();
        }

        ///<summary>n m とかをちょっとはやくかくだけ</summary>
        static string[] IStrings(){
            return ReadLine().Split();
        }

        ///<summary>n行の入力を取ったり</summary>
        static long[][] ILongLongs(long n){
            long[][] re = new long[n][];
            for(long i=0;i<n;i++){
                string[] s = ReadLine().Split();
                re[i] = new long[s.Length];
                for(long j=0;j<s.Length;j++){
                    re[i][j] = long.Parse(s[j]);
                }
            }
            return re;
        }

        ///<summary>n行の文字列を取ったり</summary>
        static char[][] ICharsChars(long n){
            char[][] re = new char[n][];
            for(long i=0;i<n;i++){
                re[i] = ReadLine().ToCharArray();
            }
            return re;
        }
    }
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long int n;
  cin>>n;
  vector<string>v(n);
  for(long int i=0;i<n;i++)
    cin>>v[i];
  sort(v.begin(),v.end());
  long int c=1;
  for(long int i=0;i<n-1;i++)
  {
    if(v[i].compare(v[i+1]))
      c+=1;
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 9540
#include <bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  int i=1;
for(;i<=n;i++){
  int x=i;
  if(x%3==0){cout<<" "<<i;
    continue;
  }
  while(x){
    if(x%10==3){
      cout<<" "<<i;
      break;;
    }
    x/=10;
  }
}
cout<<endl;
return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans;
  string s;
  cin >> s;
  
  if(s[0]=='1') ans++;
  if(s[1]=='1') ans++;
  if(s[2]=='1') ans++;
  cout << ans << endl;
  }
     
     
     

Measured memory_bytes: 256
/*
<問題文>
JOI 王国には広大な森林がある．森林は長方形の形をしており，南北に H マス，
東西に W マスのマス目状に分けられている．北から i マス目，西から j マス目(1≦i≦H,1≦j≦W)の領域には 
Ai,j 本の木が生えている．ただし，北西の端の領域には木材加工工場があり，木が生えていない．
すなわち，A1,1=0 である．
木が生えていない領域には人が立ち入ることが出来る．
また人は東西南北に隣接する領域に，その領域に木が生えていなければ，
移動することができる．森林の外に出ることはできない．JOI 君は JOI 王国の公共事業として，
木を伐採し，北西の端の領域と南東の端の領域を，相互に行き来可能にしたい．
木の伐採は以下のようにして行う．はじめ，JOI 君は木材加工工場のある北西の端の領域にいる．
JOI 君は，現在いる領域と東西南北に隣接する木の生えていない領域に 1 分で移動することができる．
また，東西南北に隣接する木の生えている領域から，1 分で木を 1 本伐採することができる．
ただし，木を 1 本伐採したら，そのたびに北西の端の領域にある木材加工工場まで
伐採した木を運ばなければならない．
木を運んでいる間も，JOI 君の移動速度は変わらない．木を運んでいる間は，他の木を伐採することはできない．
条件を満たすように木を伐採するのにかかる時間の最小値を求めよ．
ただし，伐採にかかる時間とは，最後に伐採した木を，木材加工工場に運ぶまでの時間とする．
<制約>
1≤H≤30
1≤W≤30
(H,W)≠(1,1)
0≤Ai,j≤10000 (1≤i≤H,1≤j≤W)
A1,1=0
<入力・出力>
入力
入力は以下の形式で標準入力から与えられる．
H W
A1,1 … A1,W
:
AH,1 … AH,W

出力
条件を満たすように木を伐採するのにかかる時間の最小値を 1 行で出力せよ．
<入出力例>
入力例1
2 3
0 1 2
3 4 5
出力例1
32
北から i マス目，西から j マス目の領域を (i,j) で表す．
まず (1,2) の木を伐採する．これには 1 分かかる．
次に (1,3) の木をすべて伐採する．1 本伐採するのに，(1,1) から東に 1 マス進み，(1,3) の木を
伐採し，西に 1 マス進んで (1,1) に戻ればいいので，3 分かかる．よってこれには 2×3=6 分かかる．
次に (2,3) の木をすべて伐採する．1 本伐採するのに，(1,1) から東に 2 マス進み，(2,3) の木を伐採し，西に 2 マス進んで (1,1) に戻ればいいので， 5 分かかる．よってこれには 5×5=25 分かかる．
全部で 1+6+25=32 分かかる．これより少ない時間で，条件を満たすように木を伐採することはできないので，32 を出力する．
*/
#include<algorithm>
#include<iostream>
#include <bits/stdc++.h>
#include<cstdio>
#include<cmath>
//#include<iostream>
using namespace std;
const int INF=1e9;
int h,w,A[30][30];
int main(void){
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>A[i][j];
		}
	}
	static int D[30][30][1000];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int k=0;k<h*w;k++){
				D[i][j][k]=INF;
			}
		}
	}
	D[0][0][0]=0;
	int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
	for(int k=0;k<h*w-1;k++){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int v=0;v<4;v++){
					int x=i+dx[v],y=j+dy[v];
					if(0<=x&&x<h&&0<=y&&y<w){
						D[x][y][k+1]=min(D[x][y][k+1],D[i][j][k]+(2*k+1)*A[x][y]);
					}
				}
			}
		}
	}
	int ans=INF;
	for(int k=0;k<h*w;k++){
		ans=min(ans,D[h-1][w-1][k]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6620
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,x,m[100],mn,cnt,x1,i,sum;
	scanf("%d %d",&n,&x);
	mn=9999;
	sum=0;
	for(i=0;i<n;i++)	{
		scanf("%d",&m[i]);
		sum+=m[i];
		if(mn>m[i])	mn=m[i];
	}
	x=x-sum;
	x1=x/mn;
	x1+=n;
	printf("%d\n",x1);
	return 0;
}

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

int n, m;
map<int, vector<int> > cave;
map<int,int> room;


int check(int i) {
    cout << "check: " << i << endl;
    int res = 1;
    queue<int> q;
    for (int j = 0; j < cave[i].size(); j++) {
        if (cave[i][j] == room[i]) continue;
        if (room[cave[i][j]] == 0) {
            cout << "\troom: " << cave[i][j] << " " << i << endl;
            room[cave[i][j]] = i;
            q.push(cave[i][j]);
        }
    }
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        check(p);
    }
    // cout << "\tres: " << res << endl;
    return res;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        cave[a].push_back(b);
        cave[b].push_back(a);
    }
    // map<int, int> room;
    queue<int> q;
    q.push(1);
    while (!q.empty()) {
        int p = q.front();
        q.pop();
        for (int i = 0; i < cave[p].size(); i++) {
            if (room[cave[p][i]] == 0) {
                // cout << "room: " << cave[p][i] << " " << p << endl;
                room[cave[p][i]] = p;
                q.push(cave[p][i]);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << room[i] << endl;
    }
    // if (check(1) == 0) {
    //     cout << "No" << endl;
    // } else {
    //     cout << "Yes" << endl;
    //     for (int i = 2; i <= n; i++) {
    //         cout << room[i] << endl;
    //     }
    // }

    return 0;
}


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

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

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int g = a[0];
    int mx = 0;
    //N個の要素すべてに対するGCDを求め、また、最大の要素を見つける
    rep(i, N){
        g = GCD(g, a[i]);
        mx = max(mx, a[i]);
    }

    if(K <= mx && K % g == 0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <algorithm>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
#include <stdio.h>

#define rep(i,m,n) for(unsigned long long int i=(m);i<(n);++i)
#define rem(i,m,n) for(int i=(m);i>(n);--i)
#define MOD 1000000007

using namespace std;

using ll =long long int;
using std::swap;

vector<long long int> v;
vector<long long int> w;

int main() {
	double N,ans;
	cin >> N;
	ans = (N - (int)(N / 2)) / N;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 3003
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n;
double a[oo],f[oo][oo];
void ReadInPut()
{
    n=read();
    F(i,1,n)cin>>a[i];
}
void Solve()
{
    double ans=0;
    F(i,1,n)
    {
        F(j,0,n/2)
        {
            f[0][0]=1;
            if(j==0){
                f[i][j]=f[i-1][j]*a[i];
                if(i==n)ans+=f[i][j];
                continue;
            }
            if(j<=i)f[i][j]=f[i-1][j]*a[i]+f[i-1][j-1]*(1-a[i]);
            else f[i][j]=f[i-1][j];
            if(i==n)ans+=f[i][j];
        }
    }
    cout<<fixed<<setprecision(10)<<ans;
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}


Measured memory_bytes: 69760
// 2015/03/25 Tazoe

#include <iostream>
#include <string>
using namespace std;

void DFS(int J, int Y, int a, int b, string s)
{
	if(a==J && b==Y){
		cout << s << endl;
		return;
	}

	if(a>J || b>Y)
		return;

	if(b<5 || (b==5 && a==4)){
		DFS(J, Y, a+1, b, s+"A");
	}

	if(a<5 || (a==5 && b==4)){
		DFS(J, Y, a, b+1, s+"B");
	}
}

int main()
{
	int j, y;
	cin >> j >> y;

	DFS(j, y, 0, 0, "");

	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 1e12

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i) { return i % 2; }

#define all(v) v.begin(), v.end()
#define size(x) int(x.size())

int gcd(int a, int b) { return __gcd(a, b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f) {
  if (f)
    printf("Yes\n");
  else
    printf("No\n");
}
void YES_NO(bool f) {
  if (f)
    printf("YES\n");
  else
    printf("NO\n");
}

template <typename T>
void deb1(T x) {
  cout << x << "\n";
}

template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
//-------------------ここから回答する-----------------------

void solve(void) {
  string s;
  cin >> s;
  ll ans = 0;
  rep(i, size(s)) ans += s[i] - '0';
  ans %= 9;
  Yes_No(ans == 0);
}
int main(void) { solve(); }

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

int next_combination(int bit) {
  int x = bit & -bit, y = bit + x;
  return (((bit & ~y) / x) >> 1) | y;
}

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

  int N, K;
  std::cin >> N >> K;

  uint64_t C[16]{0};
  uint64_t S[16]{0};

  uint64_t max = 0;
  int mi = 0;
  for (int i = 0; i < N; i++) {
    std::cin >> C[i];
    if (C[i] > max) {
      mi = i;
      max = C[i];
    }
  }

  int k = (1 << K) - 1;
  uint64_t out = UINT64_MAX;
  for (int bit = k; bit < (1 << N); bit = next_combination(bit)) {
    uint64_t last = 0;
    uint64_t cost = 0;
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        uint64_t diff = 0;
        if (mi < i && last < max) {
          last = max;
        }
        if (C[i] <= last) {
          cost += (diff = last - C[i] + 1);
        }

        last = (C[i] + diff);
      }
    }

    out = std::min(out, cost);
  }

  std::cout << out << std::endl;
}


Measured memory_bytes: 256