akhauriyash/Code-Regression huggingface dataset:
import scala.annotation.tailrec
import scala.io.StdIn._



object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val n = readInt()
    if (n == 0) return
    val Array(a, b, c, d) = readLine.trim.split(' ').map(_.toInt)
    val square = Square(Point(a, b), Point(c, d))
    var minCount = 0
    val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
    var current = Point(x, y)
    for (i ← 1 to n){
      val Array(x, y) = readLine.trim.split(' ').map(_.toInt)
      val next = Point(x, y)
      minCount += Math.min(current.distanceTo(square) + next.distanceFrom(square), current.distanceTo(next))
      current = next
    }
    println(minCount)
    solve()
  }
  case class Point(x: Int, y: Int) {
    def distanceTo(point: Point): Int = Math.abs(x - point.x) + Math.abs(y - point.y)
    def distanceFrom(square: Square): Int = {
      val xDiff = if ((square.left to square.right).contains(x)) 0 else Math.min(Math.abs(x - square.left), Math.abs(x - square.right))
      val yDiff = if ((square.top to square.bottom).contains(y)) 0 else Math.min(Math.abs(y - square.top), Math.abs(y - square.bottom))
      xDiff + yDiff
    }
    def distanceTo(square: Square): Int = Math.max(distanceFrom(square) - 1, 0)
  }
  case class Square(leftTop: Point, rightBottom: Point) {
    def left: Int = leftTop.x
    def top: Int = leftTop.y
    def right: Int = rightBottom.x
    def bottom: Int = rightBottom.y
  }
}


Measured memory_bytes: 47924
cnt = 0
def merge(L,R):
    global cnt
    n = len(L)+len(R)
    lenL = len(L)
    A = []
    i = j = 0
    L.append(-1)
    R.append(-1)
    for _ in range(n):
        if L[i] > R[j]:
            A.append(L[i])
            i += 1
        else:
            A.append(R[j])
            j += 1
            cnt += lenL-i
    return A

def mergeSort(A):
    if len(A)==1: return A
    m = len(A)//2
    return merge(mergeSort(A[:m]),mergeSort(A[m:])) 

if __name__=='__main__':
    n = int(input()) 
    A = list(map(int,input().split()))
    mergeSort(A[::-1])
    print(cnt)

Measured memory_bytes: 30356
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll n=in();
    string s;cin>>s;
    ll ans=0;
    char foo='X';
    for(auto c:s){
        if(c!=foo){
            foo=c;
            ++ans;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <string>
#include <queue>
using namespace std;

queue<string> que;
map<string, int> used;

int pos[] = {-1,1,4,-4};

void bfs() {
  que.push("01234567");
  while( !que.empty() ) {
    string str = que.front(); que.pop();
    int zero;
    for ( int i = 0; i < str.size(); i++ ) if ( str[i] == '0' ) zero = i;
    
    for ( int i = 0; i < 4; i++ ) {
      string str2 = str;
      int next;
      next = zero + pos[i];
      if ( next >= 0 && next <= 7 &&
	   !( ( zero == 3 && next == 4 ) || ( zero == 4 && next == 3 ) ) ){
	swap ( str2[zero], str2[next] );
	if ( !used[str2] ) {
	used[str2] = used[str] + 1;
	que.push(str2);
	}
      }
    }
  }
}

int main() {
  char ch;
  string num;
  bfs();
  while ( cin >> ch ) {
    num.clear();
    num += ch;
    for ( int i = 0; i < 7; i++ ) {
      cin >> ch;
      num += ch;
    }
    //cout << num << endl;
    if ( num == "01234567" ) cout << 0 << endl;
    else cout << used[num] << endl;
  }

  return 0;
}

Measured memory_bytes: 3440
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long

int main(void){
  int n;
  string s;
  cin>>n>>s;
  int nums[10][10][10];
  rep(i,10)rep(j,10)rep(k,10){
    nums[i][j][k]=0;
  }
  nums[s[n-3]-'0'][s[n-2]-'0'][s[n-1]-'0']=1;
  vii nums2=vii(10,vi(10,0));
  nums2[s[n-3]-'0'][s[n-2]-'0']=1;
  nums2[s[n-2]-'0'][s[n-1]-'0']=1;
  
  nums2[s[n-3]-'0'][s[n-1]-'0']=1;
  for(int now=n-1-3;now>=0;now--){
    int tmp=s[now]-'0';
    //cout<<tmp<<endl;
    vii num22=nums2;
    rep(i,10)rep(j,10){
      if(num22[i][j]==1){
        //cout<<i <<" "<<j<<endl;
        nums[tmp][i][j]=1;
        nums2[tmp][i]=1;
        nums2[tmp][j]=1;
      }
    }
  }
  int ans=0;
  rep(i,10)rep(j,10)rep(k,10){
    ans+=nums[i][j][k];
  }
  cout<<ans;
  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    
    pll p[100001];
    ll n, m; cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }
    
    sort(p, p + n);
    
    ll total = 0;
    for (int i = 0; i < n; i++) {
        if (m >= p[i].second) {
            total += p[i].first * p[i].second;
            m -= p[i].second;
        } else {
            total += p[i].first * m;
            break;
        }
    }
    
    cout << total << '\n';
    
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2007, MOD = 924844033;
int mod(int n) {
    n %= MOD;
    if (n < 0) return n + MOD;
    else return n;
}   
int n, k, f[N], dp[N];
int addf[N][N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    f[0] = 1;
    for (int i = 1; i < N; ++i)
        f[i] = mod(f[i - 1] * i);
    cin >> n >> k;
 
    addf[0][0] = 1;
    for (int i = 1; i < N; ++i) {
        addf[i][0] = 1;
        for (int j = 1; j < N; ++j) {
            addf[i][j] = addf[i - 1][j];
            if (i >= 2) addf[i][j] = mod(addf[i][j] + addf[i - 2][j - 1]);
        }   
    }   
    #ifdef HOME
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cout << addf[i][j] << ' ';
        }   
        cout << '\n';
    }
    #endif
    dp[0] = 1;
    for (int md = 0; md < k; ++md) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i)
            cnt += i % k == md;
        for (int t = 0; t < 2; ++t) 
            for (int i = n; i >= 0; --i) 
                for (int add = 1; add <= cnt; ++add) 
                    dp[i + add] = mod(dp[i + add] + dp[i] * addf[cnt][add]);
    }   
    #ifdef HOME
    for (int i = 0; i <= n; ++i)
        cout << dp[i] << ' ';   
    cout << '\n';
    #endif
    int ans = 0;
    for (int i = 0; i <= n; i += 2)
        ans = mod(ans + dp[i] * f[n - i]);
    for (int i = 1; i <= n; i += 2)
        ans = mod(ans - dp[i] * f[n - i]);
    cout << ans << '\n';
}

Measured memory_bytes: 31744
#include<stdio.h>

int main(void){

  int x,y;
  int i,j;

  while(1){

    scanf("%d %d",&y,&x);

    if(x == 0 && y == 0){
      break;
    }
    
    for(j = 0; j < y;j++){
        for(i = 0;i < x;i++){
            putchar('#');
        }
        putchar('\n');
    }
    putchar('\n');

  }

  return(0);
}



Measured memory_bytes: 2032
#include "stdio.h"

long long int bagger(int L,long long int X,long long int*P,long long int*H){
  if (L==0) {return 1;}
  if (X==1) {return 0;}
  if (X==H[L]) {return P[L];}
  if (X==(H[L]+1)/2) {return P[L-1]+1;}
  if (X>(H[L]+1)/2) {
    return bagger(L-1,X-(H[L]+1)/2,P,H)+P[L-1]+1;
  }
  if (X<(H[L]+1)/2) {
    return bagger(L-1,X-1,P,H);
  }
  return 0;
}

int main(int argc, char const *argv[]) {
  int N,i;
  long long int X;
  scanf("%d%lld",&N,&X);
  long long int P[N+1];
  long long int H[N+1];
  P[0]=1;H[0]=1;
  for (i = 1; i <=N; i++) {
    P[i]=2*P[i-1]+1;
    H[i]=2*H[i-1]+3;
  }
  printf("%lld",bagger(N,X,P,H));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fr(i,a,b) for(register int i = a;i <= b;++i)
#define int long long
#define N 100010
using namespace std;

priority_queue<int>q;

inline int read(){
	int x = 0,f = 1;char c = getchar();
	while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}
	while(isdigit(c)){x = x * 10 + c - '0';c = getchar();}
	return f * x;
}

signed main(){
	int n = read(),m = read();
	fr(i,1,n){
		int x = read();
		q.push(x);
	}
	while(m--){
		int x = q.top();q.pop();
		q.push(x / 2);
	}
	int ans = 0;
	while(q.size()){ans += q.top();q.pop();}
	printf("%lld",ans);
	return 0;
}

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

#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))

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

int main(){
ll N,K; cin>>N>>K;
vi A(N,1);
REP(i,K){
    int d=0;
    cin>>d;
    for(int j=0;j<d;j++){
        int tmp=0;
        cin>>tmp;
        A.at(tmp-1)=0;
  
    }
}
int ans=0;
REP(i,N){
    ans+=A.at(i);
}
cout<<ans<<endl;
}

Measured memory_bytes: 3624
//Never stop chasing!-MdSourav.
#include <bits/stdc++.h>

#define yes            cout<<"YES"<<endl
#define no             cout<<"NO"<<endl
#define sz(x)          x.size()
#define ll                    long long int
#define ls             long int
#define start          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test           int t;cin>>t;while(t--)
#define f(i, a, n)     for(int i=a; i<n;i++)
#define gcd(a,b)7           __gcd(a,b)
#define lcd(a,b)       (a*b)/gcd(a,b)
#define pb             push_back
#define mp(x,y)        make_pair(x,y)
#define rsrt(v)        sort(v.begin(),v.end(),greater<int>())
#define srt(v)         sort(v.begin(),v.end())
#define basrt(a,n)     sort(a,a+n,greater<int>())
#define asrt(a,n)      sort(a,a+n)
#define fact(n)        ll x=1;for(ll i=1;i<=n;i++){x=(x*i);}
#define F              first
#define S              second
#define deb(x)         cout << #x << ": " << x << endl;
#define enter(v,n)     for(ll i=0;i<n;i++){ll x;cin>>x;v.pb(x);}
#define INF 	       1000000007
#define unique(v)      v.erase(unique(v.begin(),v.end()),v.end())
using namespace std;

double pi=3.14159265358979323846;
typedef vector<ll> vll ;
typedef vector<int> vii ;

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
void solve()
{
      int n;cin>>n;
      int x=n%10;
      //deb(x);
      if(x==2 ||x==4 || x==5 ||  x==7 || x==9)
	  {
	  	cout << "hon" << endl;
	  }
	  else if(x==0 || x==1 || x==6 || x==8)
	  {
	  	cout << "pon" << endl;
	  }
	  else if(x==3)
	  {
	  	cout << "bon";
	  }

}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    ll test_case=1;
    //cin>>test_case ;
    while(test_case--)
	{
		 solve();
	}

	return 0;
}


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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
void solve() {
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> rest;
	for (int i = 1; i <= n; i++) {
		string city;
		int lol; cin >> city >> lol;
		rest.push_back(make_pair(make_pair(city, -lol), i));
	}
	sort(rest.begin(), rest.end());
	for (auto i: rest)
		cout << i.second << endl;
}

Measured memory_bytes: 384
x = int(input())
def isPrime(n):
  if n < 2:
    # 2未満は素数でない
    return False
  if n == 2:
    # 2は素数
    return True
  for p in range(2, n):
      if n % p == 0:
        # nまでの数で割り切れたら素数ではない
        return False
  # nまでの数で割り切れなかったら素数
  return True

while True:
    if isPrime(x) == False:
        x = x+1
    else:
        break
print(x)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const string YES = "Yes";
const string NO = "No";
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

bool isP(string s){
    int n = s.length();

    REP(i,n/2){
        if (s[i] != s[n- 1 -i]){
            return false;
        }
    }

    REP(i,n/4){
        if (s[i] != s[n/2 - 1 - i]){
            return false;
        }
    }
    return true;
}

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

    string s;
    cin >> s;
    cout << (isP(s) ? YES : NO) << "\n";
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n;
long long a[200010];
long long rSum[200010];

const long long MOD = 1000000007;

int main()
{
	scanf("%d", &n);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%lld", &(a[i]));
	
	rSum[n] = 0;
	for (int j = n - 1 ; j >= 0 ; j--) {
		rSum[j] = (rSum[j + 1] + a[j]) % MOD;
	}
	
	long long sum = 0;
	for (int i = 0 ; i < n ; i++) {
		long long prod;
		prod = (a[i] * rSum[i + 1]) % MOD;
		sum = (sum + prod) % MOD;
	}
	
	printf("%lld\n", sum);

	return 0;
}




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

int main()
{
    int N, M, x, y;
    bool z = false;
    cin >> N >> M;

    int list[]{-1, -1, -1};

    for (int i = 0; i < M; i++)
    {
        cin >> x >> y;
        //上書きを弾く
        if (list[x - 1] != -1 && list[x - 1] != y)
        {
            z = true;
            break;
        }
        else
        {
            //先頭0を弾く(ただし1桁はセーフ)
            if (x == 1 && y == 0 && N != 1)
            {
                z = true;
                break;
            }
            else
            {
                list[x - 1] = y;
            }
        }       
    }

    if(z)
    {
        cout << -1;
    }     
    else
    {
        for (int i = 0; i < N; i++ )
        {
            if (list[i] == -1)
            {
                if (i == 0 && N != 1)
                    cout << 1;
                else
                    cout << 0;
            }
            else
                cout << list[i];
        }
    }
}

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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 1e9+7;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    string S;
    cin >> S;
    int idx = -1, end = -1;
    const int sz = S.size();
    Fr(i, 1, sz) if (S[i] == S[i-1]) {
        idx = i;
        end = i+1;
        break;
    } else if (i != 1 && S[i] == S[i-2]) {
        idx = i-1;
        end = i+1;
        break;
    }
    cout << idx _ end << endl;

}


Measured memory_bytes: 512
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby

# 入力 =stdin.readline().rstrip()
# 分割 = stdin.readline().rstrip().split()

'''
条件に合うものを絞り込む
data = [1, 2, 3]
s = [x for x in data if x % 3 == 0]
'''

'''
文字配列を数値に
l_si = ['-10', '0', '100']

l_si_i = [int(s) for s in l_si]
'''

'''
a = [2, 4, 6, 8]
b = [3, 6, 9]

print(list(set(a) | set(b)))  # 和集合
print(list(set(a) & set(b)))  # 積集合
'''

'''
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
while len([x for x in A if x % 2 == 0]) == N:
    A = list(map(lambda y: y / 2, A))
    count += 1
print(count)
'''

'''
.append(要素)
.insert(場所,要素)
-1で末尾で末尾から一つ前
'''


num = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()
lis = [''] * num
res = ''
count = 1
for el in data:
    lis[int(el)-1] = str(count)
    count += 1
print(' '.join(lis))


Measured memory_bytes: 17844
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
        int n;
        cin >> n;
        vi a(n);
        int sum = 0;
        rep(i, n) {
                cin >> a[i];
                sum += a[i];
        }
        int ave = sum / n;

        int ans = INF;
        int res;
        for (int j = -5; j <= 5; j++) {
                res = 0;
                rep(i, n) {
                        res += ((ave + j) - a[i]) * ((ave + j) - a[i]);
                }
                amin(ans, res);
        }
       
        D(ans);

        return 0;
}



Measured memory_bytes: 256
S = list(str(input()))
if (S[0]==S[1]) and (S[0]==S[2]) and (S[0]==S[3]):
    print('No')
elif (S[0]==S[1]) and (S[2]==S[3]):
    print('Yes')
elif (S[0]==S[2]) and (S[1]==S[3]):
    print('Yes')
elif (S[0]==S[3]) and (S[1]==S[2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef double ff;
#define ari for( int i = 1 ; i <= n ; i++ ) cin >> p[i];
int n;
ff p[3002], dp[3002];

int main(){
	cin >> n;
	ari;
	dp[0] = 1.000;
	for( int i = 1 ; i <= n ; i++ ){
		for( int j = i ; j > 0 ; j-- )
			dp[j] = dp[j] * ( 1 - p[i]) + dp[ j - 1 ] * p[i];
		dp[0] *= ( 1 - p[i]);
	}
	for( int i = n/2 + 1 ; i <= n ; i++ )
		dp[ n + 1 ] += dp[i];
	cout << setprecision(11) << dp[ n + 1 ] << endl;
	return(0);
}

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

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;
typedef long double LD;
const int INF = 0x3f3f3f3f;

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
		if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}
typedef pair<LL, LL> pii;

int cost[330][330];
int dp[330][330];
char mp[330][330];
int main() {
	int H, W;
	cin >> H >> W;
	for(int i = 1; i <= H; i ++) scanf("%s", mp[i] + 1);
	int ans = 0;
	for(int id = 1; id < W; id ++) {
		for(int i = H - 1; i >= 0; i --)
			for(int j = H - 1; j >= 0; j --) 
				cost[i][j] = cost[i + 1][j + 1] + (mp[H - i][id] 
					== mp[H - j][id + 1]);	

		for(int i = 0; i <= H; i ++)
			for(int j = 0; j <= H; j ++) {
				if(i == 0 && j == 0) { dp[i][j] = 0; continue; }
				dp[i][j] = 0x3f3f3f3f;
				if(i)
					dp[i][j] = min(dp[i][j], dp[i - 1][j] + cost[i - 1][j]);
				if(j)
					dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost[i][j - 1]);
			}
		ans += dp[H][H];
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define int long long int
#define MOD 1000000007
#define mkp make_pair
#define maxN 100005
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,a,b) for(int i=a;i<b;i++)
#define pi pair<int,int>
#define pii pair<int,pi>
#define mp map<int,int>
#define ump unordered_map<int,int>
#define  vi vector<int>
#define st set<int>
#define mst multiset<int>
#define pq priority_queue
#define mpq priority_queue<int,vector<int>,greater<int> >
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define in cin>>
#define out cout<<
using namespace std;
void printArray(int arr[],int n)
{
   for(int i=0;i<n;i++)cout<<arr[i]<<' ';
cout<<endl;
}
 set<pair<int,int>> primeset;
void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
        for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          primeset.insert(mkp(p,1));
}
ll modExp(ll base, ll power) {
    if (power == 0) {
        return 1;
    } else {
        ll cur = modExp(base, power / 2); cur = cur * cur; cur = cur % MOD;
        if (power % 2 == 1) cur = cur * base;
        cur = cur % MOD;
        return cur;
    }
}
int32_t main()
{
fastio;
int n;in n;
int arr[n+1];
rep(i,n) in arr[i+1];
int dp[n+1];
int a=INT_MAX;
rep(i,n+1) dp[i]=a;
dp[1]=0;
dp[2]=abs(arr[1]-arr[2]);
//printArray(dp,n+1);
for(int i=2;i<=n;i++){
    //printArray(dp,n+1);
    dp[i]=min(dp[i],min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2])));
}
cout<<dp[n];

    return 0;
}


Measured memory_bytes: 1792
S = int(input())
if 0 <= S and S <= 86400 :
    h = (S - (S % 3600)) // 3600
    m = (((S % 3600) - ((S % 3600) % 60)) // 60)
    s = ((S % 3600) % 60)
    print(str(h) + ":" + str(m) + ":" + str(s))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl
#define MAXE(a,b) a=max(a,b)
#define MINE(a,b) a=min(a,b)

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    SCIN(s);
    Yes(s.substr(0,4) == "YAKI");
    return 0;
}


Measured memory_bytes: 256
// This  Program is made by Jan(Codezebra)
#include<bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f
using namespace std;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;;i++){
		if(i*111>=n){
			cout<<i*111;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <string.h>
#include <iostream>

using namespace std;

const int M = 1000003;
const int L = 12;

char dict[M][L];


int h1(long key) {
    return key % M;
} 

int h2(long key) {
    return 1 + key % (M - 1);
}

int h(long key, int i) {
    return (h1(key) + i * h2(key)) % M;
}

long strToKey(char str[]) {
    long result = 0;

    int length = strlen(str);
    for (int i = 0; i < length; i++) {
        // Because there is only 4 kind of letters
        result *= 5;
        switch(str[i]) {
            case 'A':
                result += 1;
                break;
            case 'C':
                result += 2;
                break;
            case 'G':
                result += 3;
                break;
            case 'T':
                result += 4;
                break;
        }
    }
    
    return result;
}

int insert(char str[]) {
    long key = strToKey(str);

    int i = 0;
    int index = h(key, i);
    while (dict[index][0] != '\0') {
        i += 1;
        index = h(key, i);
    }
    strcpy(dict[index], str);
    return 0;
}

int find(char str[]) {
    long key = strToKey(str);

    int i = 0;
    int index = h(key, i);
    while (dict[index][0] != '\0') {
        if(strcmp(dict[index], str) == 0) {
            return index;
        } else {
            i += 1;
            index = h(key, i);
        }
    }
    return -1;
}


int main() {
    for (int i = 0; i < M; i++) {
        dict[M][0] = '\0';
    } 
    
    int n;
    cin >> n;
    char cmd[6];
    char str[L];
    for (int i = 0; i < n; i++) {
        cin >> cmd >> str;
        switch(cmd[0]) {
            case 'i':
                insert(str);
                break;
            case 'f':
                if(find(str) >= 0) {
                    cout << "yes\n";
                } else {
                    cout << "no\n";
                }
                break;
        }
    }
}


Measured memory_bytes: 14784
#include <stdio.h>

using namespace std;

int linearSearch(int target, int A[], int n) {
    for(int i = 0; i < n; i++) {
        if(target == A[i])
            return target;
    }
    return -1;
}

int main()
{
    int S[10001], T[5001], n, q;
    int result = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }

    scanf("%d",&q);
    for(int i = 0; i < q; i++) {
        scanf("%d", &T[i]);
        if(linearSearch(T[i], S, n) != -1)
            result++;
    }
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

int main(){
    int N;cin >> N;
    vector<int> p(N);
    int cou = 0;
    string S;
    rep(i,N){
        cin >> p[i];
    }
    vector<int> q(N);
    q = p;
    sort(all(p));
    if(p == q){
        cout << "YES" << endl;
    }
    else{
        p = q;
        S = "NO";
        int tmp;
        vector<int> n(N);
        vector<int> m(N);
        n = p;
        m = p;
        sort(all(m));
        rep(i,N){
            for(int j = i+1;j < N;j++){
                tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
                if(p == m){
                    S = "YES";
                    break;
                }
                p = n;                          
            }
             if(p == m){
                break;
            } 
        }   
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	char s[102];
	int a=0,b=0;
	cin>>s;
	for(int i=0;i<strlen(s);i++)
	{
		if(s[i]=='C')
		{
			a=1;
		}
		if(s[i]=='F'&&a==1)
		{
			b=1;
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(b==0)
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((c>=a)&&(c>=b))
    {
        if(a>=b)
        {
            printf("%d %d %d",b,a,c);
        }
        else
        {
            printf("%d %d %d",a,b,c);
        }
    }
    if((a>=b)&&(a>=c))
    {
        if(b>=c)
        {
            printf("%d %d %d",c,b,a);
        }
        else
        {
            printf("%d %d %d",b,c,a);
        }
    }
    if((b>=a)&&(b>=c))
    {
        if(a>=c)
        {
            printf("%d %d %d",c,a,b);
        }
        else
        {
            printf("%d %d %d",a,c,b);
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2100
use proconio::input;
use proconio::marker::Chars;
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::collections::HashMap;
#[allow(unused)]
const ALPHA_SMALL: [char; 26] = [
    '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',
];
#[allow(unused)]
const ALPHA: [char; 26] = [
    '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',
];
macro_rules! maxs {
    ($x:expr, $($y:expr), *) => {{
        let mut ret = $x;
        $(
            ret = max(ret, $y);
        )*
        ret
    }};
}

fn main() {
    input!(N: usize, X: usize, M: usize);
    let mut set = HashMap::new();
    let mut sum = vec![0; M + 1];
    let mut now = X;
    let mut L = (0, 0);
    sum[0] = X;
    if X == 0 {
        println!("0");
        return;
    }
    for i in 1..=M + 10 {
        let next = now * now % M;
        sum[i] = sum[i - 1] + next;
        if let Some(&h) = set.get(&(now, next)) {
            L = (h + 1, i);
            break;
        }
        set.insert((now, next), i);
        now = next;
    }
    let (h, i) = L;
    let l = i - h + 1;
    let sumL = sum[i] - sum[h - 1];
    let ans = sumL * ((N - h) / l) + sum[(N - h) % l + h - 1];
    println!("{}", ans);
}


Measured memory_bytes: 4704
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int K = tmp[0];
            int X = tmp[1];
            WriteLine(K * 500 >= X ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define ll long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
int main(){
    int n, k;
    cin >> n >> k;
    if(n%k == 0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

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

using namespace std;

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

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 18) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 1<<18;

int main()
{
	
	int a = inp();
	int b = inp();
	if (b >= a)
		printf("%d\n", a);
	else
		printf("%d\n", a-1);
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
//classic bitmask dp problem . in anyd p problem when we have to take a subset fo values along the way
//we use bitmask dp . and a mask to represent the set of thangs . 
#define ll long long
#define MOD 1000000007
vector<vector<int> > arr(31,vector<int> (31));

ll int dp[31][(1<<21)] ;

ll int solve(int n ,int i,ll int mask){
    //out asn is dp[1][allmask] . //number of ways to make n pairs from 1-N men with all the women available. 
    if(i==n+1 && mask==0){
         if(mask==0){
             return 1 ; 
         }else{
             return 0 ; 
         }
    }
    if(dp[i][mask]!=-1){
        return dp[i][mask] ; 
    }
    ll int ans = 0 ; 
    for(int women = 0 ; women<n;  women++){
        bool available  = (((1<<women)&(mask))==0)?0:1 ; 
        if(available && arr[i][women+1]){
            ans+= (solve(n,i+1,mask^(1<<women)))%MOD; 
        }
    }
    return dp[i][mask]=ans%MOD ; 
}
int main(){
    int n ; cin>>n ;   
    for(int i = 1 ; i<=n ; i++){
        for(int j = 1; j<=n ; j++){
            cin>>arr[i][j] ;
        }
    }
   memset(dp,-1,sizeof(dp))  ;  //dp[i][X] = number of ways to pair (i,N) men wiht the set fo woman X . 
   ll int allmask = ((1<<(n))-1) ; //2^n-1 .
   cout<<solve(n,1,allmask) ; 
   return 0 ; 
}

Measured memory_bytes: 508288
N, X = [int(x) for x in input().split()]
xn = sorted(list(set([abs(int(x) - X) for x in input().split()])))
def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)

if N == 1:
  print(xn[0])
else:
  n = (gcd(xn[0], xn[1]))
  for x in xn[2:]:
    n = gcd(x, n)
  else:
    print(n)

Measured memory_bytes: 14224
N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

As[0], Bs[0], ans = max(As[0]-Bs[0], 0), max(Bs[0]-As[0], 0), min(As[0], Bs[0])

for i in range(1,N):
  As[i], Bs[i-1], ans = max(As[i]-Bs[i-1], 0), max(Bs[i-1]-As[i], 0), ans + min(As[i], Bs[i-1])
  if As[i] > 0:
    As[i], Bs[i], ans = max(As[i]-Bs[i], 0), max(Bs[i]-As[i], 0), ans + min(As[i], Bs[i])

if As[-1] > 0 and Bs[-1] > 0:
  ans += min(As[-1], Bs[-1])
    
print(ans)

Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> void Max(T &m, const T q) { if (m < q) m = q; }
template<typename T> void Min(T &m, const T q) { if (m > q) m = q; }
template<typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> &l, pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

double R1, R2;

int main()
{
    cin >> R1 >> R2;
    cout << (R1 * R2) / (R1 + R2) << endl;
}


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

int main() {
  int N, M, H, A, B;
  cin >> N >> M;
  vector<vector<int>> data(N+1);
  int cnt = 0;
  for (int i = 1; i <= N; i++){
    cin >> H;
    data[i].push_back(H);
  }
  for (int i = 0; i < M; i++){
    cin >> A >> B;
    data[A].push_back(data[B][0]);
    data[B].push_back(data[A][0]);
    }
  for (int i = 1; i < data.size(); i++){
     if (data[i].size() == 1) {
         cnt++;
         continue;
       }
      bool judge = true;
    for (int j = 1; j < data[i].size(); j++){
       if(data[i][0] <= data[i].at(j)){
       judge = false;
       break;
       }
    }
    if (judge) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 9304
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		int total = 0;
		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			arr[i] = x;
			total += x;
		}
		int min = Integer.MAX_VALUE;
		int minIdx = 0;
		for (int i = 0; i < n; i++) {
			int x = Math.abs(arr[i] * n - total);
			if (min > x) {
				min = x;
				minIdx = i;
			}
		}
		System.out.println(minIdx);
	}
}

Measured memory_bytes: 22996
#include<iostream>

using namespace std;

int gcd( int x, int y )
{
	if( 0 == y ) {
		return x;
	} else {
		return gcd( y, x%y );
	}
}


int main()
{

    int a,b;
      
   cin>>a>>b;
   	
    cout<<gcd( max( a, b ), min( a, b ) )<<endl;
	
    return 0;
}

Measured memory_bytes: 1164
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	M = 1000000007
)

var (
	fac  []int
	ifac []int
)

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func mpow(x int, n int) int {
	ans := 1
	for n != 0 {
		if n&1 == 1 {
			ans = ans * x % M
		}
		x = x * x % M
		n = n >> 1
	}
	return ans
}

func comb(a int, b int) int {
	if a == 0 && b == 0 {
		return 1
	}
	if a < b || a < 0 {
		return 0
	}
	tmp := ifac[a-b] * ifac[b] % M
	return tmp * fac[a] % M
}

func main() {
	X := readInt()
	Y := readInt()

	if (2*Y-X)%3 != 0 || (2*X-Y)%3 != 0 {
		fmt.Println(0)
		return
	}

	fac = make([]int, 3000001)
	ifac = make([]int, 3000001)

	a := (2*Y - X) / 3
	b := (2*X - Y) / 3

	if a < 0 || b < 0 {
		fmt.Println(0)
		return
	}

	fac[0] = 1
	ifac[0] = 1
	for i := 0; i < 2000000; i++ {
		fac[i+1] = fac[i] * (i + 1) % M
		ifac[i+1] = ifac[i] * mpow(i+1, M-2) % M
	}

	fmt.Println(comb(a+b, min(a, b)) % M)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 35200
let () = Scanf.scanf "%d %d\n" @@ fun w h ->
  let ps = Array.init w (fun _ -> Scanf.scanf "%d\n" (fun p -> (p, `P))) in
  let qs = Array.init h (fun _ -> Scanf.scanf "%d\n" (fun q -> (q, `Q))) in
  List.sort compare (Array.to_list qs @ Array.to_list ps)
  |> List.fold_left (fun (cost, (w, h)) -> function
    | (p, `P) ->
        (* p_i は，∀j. (i, j)と(i + 1, j)を結ぶコスト *)
        (cost + p * h, (w - 1, h))
    | (q, `Q) ->
        (* q_j は，∀i. (i, j)と(i, j + 1)を結ぶコスト *)
        (cost + q * w, (w, h - 1))) (0, (w + 1, h + 1))
  |> fst
  |> Printf.printf "%d\n"

Measured memory_bytes: 27264
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lines = br.readLine().split(" ");
      int  n = Integer.parseInt(lines[0]);
      long z = Long.parseLong(lines[1]);

      long[] ax = new long[n];
      lines = br.readLine().split(" ");
      int k=0;
      for (String s : lines) {
        ax[k++] = Math.abs( Long.parseLong(s) - z );
      }

      long d = ax[0];
      if(n>1) {
        d = gcd(ax[0],ax[1]);
        for(int i=2; i<n; i++)
          d = gcd(d,ax[i]);
      }
      
      System.out.println(d);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
  
  public long gcd(long x, long y) {
    if( x<y ) {
      long tmp = x; x = y; y = tmp;
    }
    if( (x%y) == 0 ) return y;
    else return gcd(y,x%y);
  }
}

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

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

    int ans=0;
    for (int i=A; i<=B; i++) {
        int a=i/10000;
        int b=i/1000%10;
        int c=i%100/10;
        int d=i%10;
        if (a==d && b==c) {
            ans++;
        }
    }
    cout << ans << endl;
}
    
    

     


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

using namespace std;
#define int long long
#define all(v) v.begin(), v.end()
#define pii pair <int , int>
#define F first
#define S second

int check(int n, int x) {
    while (n % x == 0) n/=x;
    return (n % x == 1);
}
int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, y, z; cin >> x >> y >> z;
    cout << z << " " << x << " " << y << "\n";
}


Measured memory_bytes: 256
/********************************
*								*
*	ants book					*
*	1-6							*
*		coin					*
*								*
*								*
********************************/

/*宣言*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define N_MAX 50000
#define M_MAX 20

int dp[N_MAX + 1];
int c[M_MAX];
int main()
{
	int N, M;

	cin >> N >> M;
	memset(dp, 0x7f, sizeof(dp));
	rep(i, M) {
		cin >> c[i];
		dp[c[i]] = 1;
	}

	sort(c, c + M);

	dp[0] = 0;

	rep(i, N) {
		rep(j, M) {
			if (i + c[j] > N)break;
			dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 3372
n,X=map(int, input().split())
x=list(map(int, input().split()))

# x間の最小公倍数が答え
from functools import reduce
import fractions

x=sorted(x)
x_bet=[0]*(n-1)

for i in range(n-1):
    x_bet[i]=x[i+1]-x[i]
x_bet=[abs(X-x[0])]+x_bet
print(reduce(fractions.gcd, x_bet))

Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

string S;
int D[2001], P[2001], n[2001], press[2001];
vector<int> E[2001];
void dfs(int A) {
	if (D[A] == 0) {
		D[A] = 1;
		int ret1 = 0;
		int ret2 = 0;
		int ret3 = 0;
		int saidai = 0;
		for (int i : E[A]) {
			dfs(i);
			ret1 += P[i] + n[i];
			ret2 += n[i];
			saidai = max(saidai, 2 * (P[i] + n[i]) - 2 * press[i]);
		}
		if (saidai - ret1 < 0) ret3 = ret1 / 2;
		else ret3 = ret1 - saidai / 2;
		if (S[A - 1] == '1') ret2++;
		
		P[A] = ret1;
		n[A] = ret2;
		press[A] = ret3;
	}
}

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


	int N;
	cin >> N;
	cin >> S;

	rep(i, N - 1) {
		int a, b;
		cin >> a >> b;
		E[a].pb(b);
		E[b].pb(a);
	}

	bool OK = 0;
	int saishou = 1e9;
	rep1(i, N) {
		rep1(j, N) {
			D[j] = 0;
			P[j] = 0;
			n[j] = 0;
			press[j] = 0;
		}
		dfs(i);

		if (P[i] == press[i] * 2) {
			OK = 1;
			saishou = min(saishou, press[i]);
		}
	}

	if (OK) co(saishou);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 512
N, = [int(x) for x in input().strip().split(" ")]
T, A = [int(x) for x in input().strip().split(" ")]
Hs = [int(x) for x in input().strip().split(" ")]

rs = []
for h in Hs:
    hh = T - (h * 0.006)
    rs .append(abs(A - hh))

rr = None
for i, r in enumerate(rs):
    if rr == None:
        rrr = i
        rr = r
        continue
    if r < rr:
        rrr = i
        rr = r
print(rrr + 1)


Measured memory_bytes: 38256