akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

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

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

void trace(int A[], int N) {
    for (int i = 0; i < N; ++i) {
        if (i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

using ll = long long;
using P = pair<int, int>;

const unsigned long long INF = 1LL << 60;

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

int a, b, c;

int main() {
    cin >> a >> b >> c;
    int num = 0;

    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            num++;
        }
    }

    cout << num << endl;
}



Measured memory_bytes: 3100
N, x = map(int, input().split())
A = list(map(int, input().split()))
A += A
INF = 10 ** 18
ans = INF
B = [INF] * N
for cnt in range(N):
    for i in range(N):
        B[i] = min(B[i], A[N + i - cnt])
    ans = min(ans, cnt * x + sum(B))

print(ans)

Measured memory_bytes: 3316
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n-2):
    if (p[i]<p[i+1] and p[i+1]<p[i+2]) or (p[i+1]<p[i] and p[i+2]<p[i+1]):
        c+=1
print(c)


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

using namespace std;
long long a[1000005],dp[100005]={};
long long used[100005]={};
#define MOD 1000000007
int main(){
	long long n,m;
	cin>>n>>m;
	memset(used,0,sizeof(used));
	memset(dp,0,sizeof(dp));
	for(int i=0;i<m;i++)cin>>a[i],used[a[i]]=-1;
	if(used[0]!=-1)dp[0]=1;
	if(used[1]!=-1){
		if(used[0]!=1)dp[1]=1;
	}
	for(int i=2;i<=n;i++){
		if(used[i]!=-1){
			if(used[i-1]!=-1)dp[i]+=dp[i-1]%MOD;
			if(used[i-2]!=-1)dp[i]+=dp[i-2]%MOD;
		}
	}
//	for(int i=0;i<=n;i++)cout<<dp[i]<<" ";
	cout<<dp[n]%MOD;	
	return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define int long long int
#define all(v) v.begin(),v.end()
#define ov(v) for(int i=0;i<(v).size();i++)cout<<v[i]<<" ";cout<<endl;
#define N 1001
using namespace std;
int visited[N][N];
int n,m,sex,sey,dex,dey;
string grid[N];
queue<pair<int,pair<int,int> > >q;
int found = 0;
bool check(int x,int y)
{
	if(x>=0 && y>=0 && x<n && y<m && grid[x][y]=='.' && !visited[x][y])return 1;
	return 0;
}
void dfs(int x,int y,int dis)
{
	// cout<<x<<" "<<y<<endl;
	if(x==dex && y == dey)
	{
		found = 1;
		return;
	}
	if(visited[x][y])return;
	visited[x][y] = 1;
	int dx[] = {0,0,-1,1};
	int dy[] = {-1,1,0,0};
	for(int i = 0;i<4;i++)
	{
		int xx = x+dx[i];
		int yy = y+dy[i];
		if(check(xx,yy))dfs(xx,yy,dis);		
	}

	for(int i = -2;i<=2;i++)
	{
		for(int j = -2;j<=2;j++)
		{
			int xx = x+i;
			int yy = y+j;
			if(check(xx,yy))
				q.push({dis+1,{xx,yy}});
		}
	}

}
void solve()
{
	cin>>n>>m>>sex>>sey>>dex>>dey;
	for(int i = 0;i<n;i++)cin>>grid[i];
	sex--;sey--;dex--;dey--;
	q.push({0,{sex,sey}});
	while(!q.empty())
	{
		int x = q.front().second.first;
		int y = q.front().second.second;
		int dis = q.front().first;
		q.pop();

		if(visited[x][y])continue;
		dfs(x,y,dis);
		if(found == 1)
		{
			cout<<dis<<endl;
			return;
		}
	}
	cout<<-1<<endl;

}
signed main() 
{
	// int t;
	// cin>>t;
	// while(t--)
	solve();
	return 0; 
}

Measured memory_bytes: 14016
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const int MOD = 1000000007;
const int INF = 1000000;

    int N,ans=0,buff,temp;
    bool A[100010];
    int count=0;


int main(){
    REP(i,100010)A[i]=false;
    scanf("%d",&N);
    REP(i,N){
        scanf("%d",&temp);
        if(!A[temp]){
            A[temp]=true;
            ans++;
        }
    }
    if(ans%2==0)ans--;
    printf("%d",ans);
}


Measured memory_bytes: 892
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)

using namespace std;

const int N = (int)2e5 + 1;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

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

int a[5];
int main (){
  forn (i, 1, 3){
    scanf ("%d", a + i);
  }
  sort (a + 1, a + 3 + 1);
  int sum = 0;
  forn (i, 2, 3){
    sum += (a[i] - a[i - 1]);
  }
  printf ("%d\n", sum);
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
#define N 1200

int main() {
	char str[N];
	int i;
	fgets(str, N, stdin);

	for (i = 0; str[i] != '\n'; i++)
		if ('A' <= str[i] && str[i] <= 'Z') str[i] += 'a' - 'A';
		else if ('a' <= str[i] && str[i] <= 'z') str[i] -= 'a' - 'A';
		printf("%s", str);
	return 0;
}

Measured memory_bytes: 524
#include<stdio.h>


int main(){
	int n;
	int arr[100];
	int i;
	int a;
	int j, k;
	int count = 0;
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &arr[i]);
	}
	
	
	for(j=n-1; j>=0; j--){
		for(k=n-1; k>=0; k--){
			if(arr[k-1]>arr[k]){
				a = arr[k-1];
				arr[k-1] = arr[k];
				arr[k] = a;
				count++;
			}
		}
	}
	
	for(i=0; i<n; i++){
		if(i!=0 && i!=n){
			printf(" ");
		}
		printf("%d",arr[i]);
	}
	printf("\n");
	printf("%d\n",count);
	
	
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

//#define EVEL 1

#ifndef EVEL00
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

vector<int> A;
int ins;
int dis[2];
bool a, b;
int ans;

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

	for(int i = 0; i < 3; i++){
		cin >> ins;
		A.push_back(ins);
	}
	sort(A.begin(), A.end());
	//for(int i = 0; i < 3; i++) cout << A[i] << "\n";
	dis[0] = A[2]-A[0];dis[1] = A[2]-A[1];
	a = ( (dis[0]%2) == 0 );
	b = ( (dis[1]%2) == 0 );

	if(a){
		if(b){
			ans = (dis[0]+dis[1])/2;
		}else{
			ans = (dis[0]+dis[1]+1)/2 + 1;
		}
	}else{
		if(b){
			ans = (dis[0]+dis[1]+1)/2 + 1;
		}else{
			ans = (dis[0]+dis[1]-2)/2 + 1;
		}
	}

	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
/*
A - Frog 1

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100points

--------------------

Problem Statement

There are Nstones, numbered 1,2,…,N. 
For each i (1≤i≤N), the height of Stone i is hi.

There is a frog who is initially on Stone 1. 
He will repeat the following action some number of times to reach Stone N:
·If the frog is currently on Stone i, jump to Stone i+1 or Stone i+2.
  Here, a cost of |hi-hj| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

------------------

Constraints
All values in input are integers.
2≤N≤10^5
1≤hi≤10^4

Input

Input is given from Standard Input in the following format:

N
h1 h2 …hN


Output

Print the minimum possible total cost incurred.

----------------

Sample Input 1

4
10 30 40 20

Sample Output 1

30

If we follow the path 1→ 2 → 4, the total cost incurred would be |10-30|+|30-20|=30.

-----------------

Sample Input 2
2
10 10

Sample Output 2
0

If we follow the path 1→ 2, the total cost incurred would be |10-10|=0.

------------------

Sample Input 3
6
30 10 60 10 60 50

Sample Output 3
40

If we follow the path 1→ 3 → 5 → 6, 
the total cost incurred would be |30-60|+|60-60|+|60-50|=40.
*/

#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int n,k,h[100002];
long long s[100002];

int main(){
	for(int i=0;i<100002;i++) s[i]=inf;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&h[i]);
	s[0]=0;
	s[1]=0;
	s[2]=abs(h[1]-h[2]);
	for(int i=3;i<=n;i++){
		for(int j=1;((i-j>0)&&(j<=k));j++){
			s[i]=min(s[i],s[i-j]+abs(h[i-j]-h[i]));
		}
	}
	printf("%lld",s[n]);
	return 0;
}

/*

Required
Username
This username is available.
You can use only English letters and numbers. The length must be between 3 and 16, inclusive.
Email Address
Password
The password must contain at least 6 characters and must contain both English letters and numbers at least once respectively.
Confirm Password
Country/Region 

*/

Measured memory_bytes: 1280
sx, sy, tx, ty = map(int, input().split())


def inverse(line :str):
    ret = ""
    for c in line:
        if c == "U":
            ret += "D"
        elif c == "D":
            ret += "U"
        elif c == "R":
            ret += "L"
        else:
            ret += "R"
    
    return ret

# 1st loop
str1out = ""
for dx in range(tx - sx):
    str1out += "R"

for sy in range(ty - sy):
    str1out += "U"

str1in = inverse(str1out)

# 2nd loop
str2out = "DR" + str1out + "UL"
str2in = "UL" + str1in + "DR"
print(str1out + str1in + str2out + str2in)


Measured memory_bytes: 3064
#![allow(unused_parens)]

static mut H :u32 = 0;
static mut W :u32 = 0;

fn read_vec<T>() -> Vec<T>
where T: std::str::FromStr,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(
        |e| e.parse().ok().unwrap()
    ).collect()
}
fn read_code() -> Vec<u8>
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().chars().map(
        |c| if c=='#' {1} else {0}
    ).collect()
}

// = 黒点を広げる関数
fn black_add(black :Vec<usize>, vsmap :&mut Vec<Vec<u8>>) -> Vec<Vec<usize>>
{
    let h = black[0];
    let w = black[1];
    let mut rets = Vec::new();
    //println!("black_add < ({},{})", h, w);
    if vsmap[h][w-1] == 0 {
        vsmap[h][w-1] = 1;
        rets.push(vec![h, w-1]);
    }
    if vsmap[h][w+1] == 0 {
        vsmap[h][w+1] = 1;
        rets.push(vec![h, w+1]);
    }
    if vsmap[h-1][w] == 0 {
        vsmap[h-1][w] = 1;
        rets.push(vec![h-1, w]);
    }
    if vsmap[h+1][w] == 0 {
        vsmap[h+1][w] = 1;
        rets.push(vec![h+1, w]);
    }
    //println!("{:?}", &rets);
    rets
}

// = main
fn main()
{
    let inputs: Vec<u32> = read_vec();
    let hh;
    let ww;
    unsafe {
        H = inputs[0]; hh = H;
        W = inputs[1]; ww = W;
    }
    // マップの読み込み
    let mut vsmap :Vec<Vec<u8>> = Vec::new();
    vsmap.push(vec![1; (ww+2) as usize]);
    for _h in 0..hh {
        let mut ips :Vec<u8> = read_code();
        ips.insert(0,1);
        ips.push(1);
        vsmap.push(ips);
    }
    vsmap.push(vec![1; (ww+2) as usize]);
    //for h in 0..(hh+2) {
    //    println!("{:?}", vsmap[h as usize]);
    //}
    // マップの探索
    // - 黒い点の位置を記憶する
    let mut blks = Vec::new(); // （うまく書けん）usizeのベクトルの配列
    for y in 1..(hh+1) {
        let h = y as usize;
        for x in 1..(ww+1) {
            let w = x as usize;
            if (vsmap[h][w]==1) {
                blks.push(vec![h,w]);
            }
        }
    }
    // - 黒い点を広げていく
    let mut count = 0;
    loop {
        let mut blks2 :Vec<Vec<usize>> = Vec::new();
        for black in blks.iter() {
            let mut bs = black_add(black.to_vec(), &mut vsmap);
            blks2.append(&mut bs);
        }
        blks = blks2;
        if blks.len() > 0 {
            count = count + 1;
        } else {
            break;
        }
        //println!("c = {}", count);
    }

    println!("{}", count);
}


Measured memory_bytes: 49424
#include <iostream>
#include <vector>
#include <string>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <utility>
#include <boost/foreach.hpp>
#include <cmath>

long long int N;
long long int A[2 * 100000 + 1];
bool f[1000000 + 1];

long long int ans;

int main() {
  std::cin >> N;
  for (long long int i = 1; i <= N; i++) {
    std::cin >> A[i];
  }

  std::sort(A + 1, A + N + 1);

  for (int i = 1; i <= N; i++) {
    if (f[A[i]] == true) {
      continue;
    }
    if (i != N) {
      if (A[i + 1] != A[i]) {
        ans++;
      }
    }
    else {
      ans++;
    }

    for (int j = A[i]; j <= 1000000; j += A[i]) {
        f[j] = true;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 6128
#include<iostream>
#include<set>
using namespace std;
string s;
int i,k;
int main(){
	cin>>s>>k;
	set<string>m;
	for(;i<s.size();i++)for(int j=1;j<=k;j++)m.insert(s.substr(i,min(j,(int)s.size()-i)));
	auto itr=m.begin();while(--k)itr++;
	cout<<*itr<<endl;
	return 0;
}

Measured memory_bytes: 1664
# AOJ 1100: Area of Polygons
# Python3 2018.7.14 bal4u

from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def calc_area(pp):
	n = len(pp)
	if n < 3: return 0
	s = 0
	for i in range(n):
		s += (pp[i].real-pp[(i+1)%n].real)*(pp[i].imag+pp[(i+1)%n].imag)
	return abs(s)/2

cno = 0
while True:
	n = input()
	if n == '': n = input()
	n = int(n);
	if n == 0: break
	pp = []
	for i in range(n):
		x, y = map(int, input().split())
		pp.append(complex(x, y))
	cno += 1
	print(cno, Decimal(str(calc_area(pp))).quantize(Decimal('0.1'), rounding=ROUND_HALF_UP))



Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

long long X;

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> X;
  long long rem = X%11, p = X/11;
  long long res = p*2;
  if(p%2 == 0){
    res += (rem <= 6) ? 1 : 2;
  }
  else{
    res += (rem <= 5) ? 1 : 2;
  }
  if(rem == 0) 
    --res;
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,m,a[110];
int main(){
	cin>>m>>n;
	int x;
	for(int i=1;i<=n;++i){
		cin>>x;
		a[x]=1;
	}
	int mn=1000000007,mnid=0;
	for(int i=0;i<=101;++i)if(a[i]==0){
		if(abs(m-i)<mn){
			mn=abs(m-i);
			mnid=i;
		}
	}
	cout<<mnid<<endl;
	return 0;
}




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

typedef long long ll;

int main(void){
	ll n;
	cin>>n;
	ll ave = 0;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		ave += x;
	}
	cout<<ave/n<<endl;

	return 0;
}

Measured memory_bytes: 0
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int a, b, c, d, e, n, m, k;
  string s;
  cin >> s;
  if(s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if(s == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto K = RD;

	double ans = cast(double)(max(0, N - K + 1)) / N;
	debug writeln(ans);
	foreach (i; 1..N+1-max(0,N-K+1))
	{
		auto x = i;
		double p = 1.0;
		while (x < K)
		{
			p /= 2.0;
			x *= 2;
		}
		ans += p / N;
		debug writeln(i, " ", ans);
	}

	writefln(FMT_F, ans);
	stdout.flush();
	debug readln();
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = a; i <= b; ++i) {
        if (i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
}

Measured memory_bytes: 3524
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  int ans=0;
  REP(i,N+1){
    int k=0;
    REP(j,5){
      k+=(i/int(pow(10,j)))%10;
    }
    // cout<<i<<" "<<k<<endl;
    if(k>=A and k<=B){
      ans+=i;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String b =sc.next();
		if(b.equals("A")){
			System.out.println("T");
		}else if(b.equals("T")){
			System.out.println("A");
		}else if(b.equals("G")){
			System.out.println("C");
		}else if(b.equals("C")){
			System.out.println("G");
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl



int main(){
    ll h, w;
    cin >> h >> w;

    vector<vector<ll>> a(h, vector<ll>(w,0));
    vector<vector<ll>> b(h, vector<ll>(w,0));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> b[i][j];
        }
    }

    ll MAXSIZE = (h+w)*80+5;
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(MAXSIZE,false)));
    dp[0][0][abs(a[0][0]-b[0][0])] = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i == 0 && j == 0){continue;}
            ll diff = abs(a[i][j]-b[i][j]);
            for(int k = 0; k < MAXSIZE; k++){
                if(i-1>=0){
                    if(dp[i-1][j][k]){
                        if(0 <= abs(k+diff) && abs(k+diff) < MAXSIZE){dp[i][j][abs(k+diff)] = true;}
                        if(0 <= abs(k-diff) && abs(k-diff) < MAXSIZE){dp[i][j][abs(k-diff)] = true;}
                    }
                }
                if(j-1>=0){
                    if(dp[i][j-1][k]){
                        if(0 <= abs(k+diff) && abs(k+diff) < MAXSIZE){dp[i][j][abs(k+diff)] = true;}
                        if(0 <= abs(k-diff) && abs(k-diff) < MAXSIZE){dp[i][j][abs(k-diff)] = true;}
                    }
                }
            }
        }
    }
    ll ans = -1;
    for(int i = 0; i < MAXSIZE; i++){
        if(dp[h-1][w-1][i]){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 10880
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (ll)(1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll dp[101][8];
int main() {
	int h, w, s; cin >> h >> w >> s; s--;
	dp[0][0] = 1;
	rep(i, h) {
		rep(j, (1 << (w - 1))) {
			vector<int> v;
			rep(k, w - 1) {
				if (j&(1 << k)) {
					v.push_back(k);
				}
			}
			bool valid = true;
			rep(k, (int)v.size() - 1) {
				if (v[k + 1] - v[k] == 1)valid = false;
			}
			if (!valid)continue;
			rep(k, 8) {
				if (count(v.begin(), v.end(), k - 1)) {
					(dp[i + 1][k - 1] += dp[i][k])%=mod;
				}
				else if (count(v.begin(), v.end(), k)) {
					(dp[i + 1][k + 1] += dp[i][k]) %= mod;
				}
				else {
					(dp[i + 1][k] += dp[i][k]) %= mod;
				}
			}
		}
	}
	cout << dp[h][s] << endl;
	return 0;
}

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

int main() {
  int N, Alice, Bob;
  
  
  cin >> N;
  vector<int> card(N);
  
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  int i = 0, turn = 0;
  int max = 0, max_index = 0;
  while (true) {
    for (int j = 0; j < N; j++) {
      if (card.at(j) > max) {
        max = card.at(j);
        max_index = j;
      }
    }
    if (turn % 2 == 0) {
      // Alice
      Alice += max;
      card.at(max_index) = 0;
    }
    else {
      // Bob
      Bob += max;
      card.at(max_index) = 0;
    }
    turn++;
    if (turn == N) {
      break;
    }
    max = 0;
    max_index = 0;
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int main() {
  string A, B, C;
  cin >> A >> B >> C;
  if (A.back() == *B.begin() && B.back() == *C.begin()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long power = 1;
        for(int i = 1; i <= n; i++){
            power *= i;
            power = power % (int)(Math.pow(10,9) + 7);
        }

        System.out.println(power);
    }
}



Measured memory_bytes: 21204
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,t,c;
	string s;
	
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k;
    cin>>n>>k;
    vector<ll>H(n);
    for(int i = 0; i < n ; i++){
        cin>>H[i];
    }
    sort(H.rbegin(),H.rend());

    
    ll ans = 0;
    for(int i = k ; i < n ; i++){
        ans+=H[i];
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1792
n = int(input())
ab =[list(map(int,input().split())) for _ in range(n)]

ab.sort()
a = []
b =[]
for x in ab:
  a.append(x[0])
  b.append(x[1])
a.sort()
b.sort()

ca,cb =0,0
if n % 2 == 0:
  ca = (a[n//2-1] + a[n//2])/2
  cb = (b[n//2-1] + b[n//2])/2
  ans = int((cb-ca)//0.5+1)
else:
  ca = a[(n+1)//2-1]
  cb = b[(n+1)//2-1]
  ans = (cb-ca) +1

print(int(ans))

Measured memory_bytes: 50264
#include <iostream>
using namespace std;
int main(void){
    int t, n, S, A, B, C; // t…チケットの種類　n…枚数
    S=6000;
    A=4000;
    B=3000;
    C=2000;
    
    for(int i=1; i<=4; i++){
        cin >> t >> n;
        if(t == 1){
            cout << S * n << endl;
        }
        else if(t == 2){
            cout  << A * n << endl;
        }
        else if(t == 3){
            cout << B * n << endl;
        }
        else if(t== 4){
            cout << C * n << endl;
        }
    }
    return 0;
}

/*
　値段は直書きでもＯＫ。
　for分で４回処理を回しましょう。
*/


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll D[5010];

int main() {
	ll K, Q;
	cin >> K >> Q;
	for (int i = 0;i < K;i++) {
		cin >> D[i];
	}
	ll N, X, M, S, C;
	vector<ll> V, VS, VT, fa(Q);
	for (int i = 0;i < Q;i++) {
		cin >> N >> X >> M;

		S = 0;
		N--;
		for (int j = 0;j < K;j++) {
			if (j == N % K)VT = V;
			if (D[j] % M)V.push_back(D[j] % M);
			S += D[j] % M;
		}

		S *= (N / K);
		S += X % M;
		C = (ll)V.size() * (N / K) + (ll)VT.size();

		for (ll j : VT) {
			S += j;
		}
		C -= S / M;
		fa[i] = C;

		V = VS;
		VT = VS;
	}
	
	for (ll A : fa) {
		cout << A << endl;
	}
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    var (H,W) = readLine()!!.split(" ").map(String::toInt)
    repeat(W+2){print("#")}
    print("\n")
    for(i in 1..H){
        var s = readLine()!!.toString()
        println("#"+s+"#")
    }
    repeat(W+2){print("#")}
    print("\n")
}


Measured memory_bytes: 37872
/**
    BISMILLAH
    @Author : Arham
*/
#include <bits/stdc++.h>
using namespace std;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[false] << b[true] << c[true * 2] << endl;

    return;
}

int main() {
    int t = true;
//    cin >> t;
    while(t--)
        solve();

    return 0;
}


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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		//		new Main().solveB();
		//		new Main().solveC();
		new Main().solveC2();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			if (numN % 2 == 0) {
				System.out.println(numN);
			} else {
				System.out.println(numN * 2);
			}

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] wk = new int[numN];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
			}
			Arrays.sort(wk);

			System.out.println(wk[wk.length - 1] - wk[0]);

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private int getCry(int b, int currentI, int maxI, int[] wk) {
		if (currentI == maxI) {
			return 0;
		}

		return getCry(b, currentI + 1, maxI, wk) + Math.abs(wk[currentI] - (b + currentI + 1));
	}

	private void solveC2() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - (i + 1);
		}
		sc.close();
		Arrays.sort(A);
		int med = N % 2 == 0 ? N / 2 - 1 : N / 2;
		int b = A[med];
		long ans = 0;
		for (int a : A) {
			ans += Math.abs(a - b);
		}

		System.out.println(ans);
	}

	/**
	 * ⅰ)abs(xi-a)の総和(aとの距離の総和)を最小にするのは中央値で、
	 * ⅱ)(xi-a)^2の総和を最小にするのは平均値
	 */
	private void solveC() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			int[] wk = new int[numN];

			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt() - (i + 1);
			}

			//			int[] wkWk = new int[numN];
			//			for (int i = 0; i < numN; i++) {
			//				wkWk[i] = wk[i] - (i + 1);
			//			}
			//			Arrays.sort(wkWk);
			Arrays.sort(wk);

			int b = 0;
			//			if (numN % 2 == 0) {
			//				b = wkWk[numN / 2 - 1];
			//			} else {
			//				b = wkWk[numN / 2];
			//			}
			if (numN % 2 == 0) {
				b = wk[numN / 2 - 1];
			} else {
				b = wk[numN / 2];
			}
			int res = 0;

			//			for (int a : wkWk) {
			//				res += Math.abs(a - b);
			//			}
			for (int a : wk) {
				res += Math.abs(a - b);
			}
			System.out.println(res);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 90404
#include<stdio.h>

int solve(int,int);

int A[2000],n;

int main(){

  int i,j,q,m[2000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&m[j]);
  }
  for(j=0;j<q;j++){
    if(solve(0,m[j])==1)
      printf("yes\n");
    else printf("no\n");
  }

  return 0;
}


int solve(int i,int m){
  int res;
  if(m==0)
    return 1;
  if(i>=n || m<0)
    return 0;
  if(solve(i+1,m) || solve(i+1,m-A[i]))
  return 1;
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
#define lp(k,a) for(int k=1;k<=a;k++)
#define lp0(k,a) for(int k=0;k<a;k++)
#define lpn(k,n,a) for(int k=n;k<=a;k++)
#define lpd(k,n,a) for(int k=n;k>=a;k--)
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d %d",&a,&b)
#define ll long long
#define MAX 100000

using namespace std;


int a[10000];

int main()
{
   // freopen("in.txt","r",stdin);
    int m ,d;
    cin>>m>>d;
    int ans = 0;
    for (int i=1;i<=m;i++) {
        for (int j=1;j<=d;j++) {
            if(j%10>=2 && j/10>=2 && ((j%10)*(j/10))==i) {
                //cout<<i<<" "<<j<<endl;
                ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int i_tmp, count, max_count=0, retval=1;
  
  for (int i=1;i<=N;i++){
    i_tmp = i;
    count = 0;
    while (i_tmp%2==0){
      i_tmp /= 2;
      count++;
    }
    if (count>max_count) {
        max_count = count;
        retval = i;
    }
  }

  cout << retval << endl;
}
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  else if (A + B > C + D) {
    cout << "Left" << endl;
  }

  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,res,res2;
	int count{0},count2{0};
	while(cin>>s){
        count=0;
		count2=0;
		int len=s.size();
		for(int i=0; i<len; i++){
			if(s[i]=='J'&&s[i+1]=='O'&&s[i+2]=='I'){
				res+=s[i];
				res+=s[i+1];
				res+=s[i+2];
				count++;
			}
		}
		cout << count << endl;
		for(int j=0; j<len; j++){
			if(s[j]=='I'&&s[j+1]=='O'&&s[j+2]=='I'){
				res2+=s[j];
				res2+=s[j+1];
				res2+=s[j+2];
				count2++;
			}
		}
		cout << count2 << endl;
	}
	return 0;
}

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

int main() {
	int n; cin >> n;
	long long a[n];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		if(i > 0) a[i] += a[i-1];
	}
	sort(a, a + n);
	long long res = 0;
	int id = 0;
	while (id < n)
	{
		long long cnt = upper_bound(a, a + n, a[id]) - a - id;
		if(a[id] == 0) res += cnt;
		res += cnt * (cnt - 1) / 2;
		id += cnt;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 5216
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);


int N, C;
int tab[11][11];
int tmp[11][11];
bool flag[11][11];
int di[] = {-1,-1,0,0,1,1};
int dj[] = {-1,0,-1,1,0,1};
bool isin(int i, int j){
  return (0 <= i && i < N && 0 <= j && j <= i);
}

void dfs(int i, int j, int c){
  if(!isin(i,j) || tmp[i][j] != c || flag[i][j]) return;
  flag[i][j] = true;
  REP(d,6)
	dfs(i+di[d],j+dj[d],c);
}

int calc(){
  fill((bool*)flag, (bool*)flag+11*11, false);
  REP(i,N) REP(j,i+1){
	if(tmp[i][j] == 0){
	  REP(d,6){
		int i_ = i+di[d], j_ = j+dj[d];
		if(isin(i_,j_))
		  dfs(i_,j_,tmp[i_][j_]);
	  }
	}
  }

  int res = 0;
  REP(i,N) REP(j,i+1)
	if(!flag[i][j] && tmp[i][j] != 0)
	  res += (tmp[i][j] == C? -1: 1);

  return res;
}

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

  while(cin>>N>>C,N){
	REP(i,N) REP(j,i+1)
	  cin >> tab[i][j];

	int ans = -1e9;
	REP(i,N) REP(j,i+1){
	  if(tab[i][j] == 0){
		REP(i1,N) REP(j1,i1+1) tmp[i1][j1] = tab[i1][j1];
		tmp[i][j] = C;
		ans = max(ans, calc());
	  }
	}

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

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

int main() {
  int N, a, b, c, d;
  cin >> N;

  a = N % 10;
  b = (N / 10) % 10;
  c = (N / 100) % 10;
  d = N / 1000;
  
  if(b == c){
    if((a == b) || (c == d))
      cout << "Yes" << endl;
    else
      cout << "No" <<endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   int n, d;
   cin >> n >> d;
   double x[n][d];
   rep(i, n)rep(j,d)cin >> x[i][j];

   int count = 0;
   for(int i = 0; i < n; i++){
       for(int j = i+1; j < n; j++){
           double s = 0;
           for(int k = 0; k < d; k++)s+=pow((x[i][k] - x[j][k]), 2);
           double t = sqrt(s);
           //cout << "t:" << t << endl;
           //cout << "int:" << double(int(t)) << endl;
           if(t - double(int(t)) == 0)count++;
       }
   }
   cout << count << endl;

}

Measured memory_bytes: 256
/**
*   Bismillahir Rahmanir Rahim.
*   Imtiaz_rafi
*   PCIU, CHITTAGONG
**/
#include<bits/stdc++.h>
using namespace std;
#define speed ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,a) for(ll i=0;i<a;i++)
#define all(v)   v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
// bitshift (1LL<<(3)) *2^3
typedef long long int ll;
int main()
{
    speed;
    ll a,b,c,d,e=0,f=0,g=0;
    cin>>a>>b>>c>>d;
    e=(min(d,a));
    d=d-e;
    f=min(d,b);
    d=d-f;
    f=0;
    g=min(d,c);
    d=d-g;
    g=g*(-1);
    cout<<e+f+g<<endl;
}



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    
    int N,M,Ans;
    int h[1500],w[1500];
    int H[1500],W[1500];
    const int MEM = 1500100;
    //const int MEM = 1500;
    int d[MEM];
    while(1){
        cin >> N >> M;
        if(N==0 && M==0){
            return 0;
        }
        Ans=0;
        memset(d,0,sizeof(d));
        H[0]=0;
        REP(i,N){
            cin >> h[i];
            H[i+1]=H[i]+h[i];
        }
        REP(i,M){
            cin >> w[i];
            W[i+1]=W[i]+w[i];
        }
        
        
        REP(j,N){
            REP(i,j+1){
                d[(H[j+1]-H[i])]++;
            }
        }
        REP(j,M){
            REP(i,j+1){
                Ans+=d[(W[j+1]-W[i])];
            }
        }
        cout << Ans << endl;
        
    }
    return 0;
}




Measured memory_bytes: 14860
n,d = map(int, input().split())
ans = 0
for i in range(n):
  x, y = map(int, input().split()) 
  if x*x + y*y <= d*d: # since they have given atmost distance d
    ans+= 1
print(ans)
'''
using distance formula check whether the the distance 
from origin is less than x sq and y sq
'''

Measured memory_bytes: 9088
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>
#include <climits>

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

#define MOD 1000000007

using namespace std;

int N;
int s[110];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> N;
    int sum = 0;
    rep(i,N) {
        cin >> s[i];
        sum += s[i];
    }

    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }

    sort(s, s + N);

    rep(i,N) {
        if (s[i] % 10 != 0) {
            cout << sum - s[i] << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






typedef long long ll;
vector<ll> build(ll K) {
    vector<ll> ans;

    ll d = K % 50;
    rep(i, 0, 50 - d) ans.push_back(49 - d);
    rep(i, 0, d) ans.push_back(50);

    ll a = K / 50;
    rep(i, 0, 50) ans[i] += a;

    return ans;
}

ll naive(vector<ll> A) {
    ll ans = 0;
    int n = A.size();
    while (1) {
        int ok = 1;
        rep(i, 0, n) if (n <= A[i]) ok = 0;
        if (ok) return ans;

        ans++;
        ll big = 0; int bigid = -1;
        rep(i, 0, n) if (big < A[i]) big = A[i], bigid = i;
        rep(i, 0, n) {
            if (i == bigid) A[i] -= n;
            else A[i]++;
        }
    }

    return ans;
}
#define INF 1LL<<60
ll count(vector<ll> A) {
    int n = A.size();
    ll ans = 0;
    while (1) {
        ll mi = INF, ma = 0;
        rep(i, 0, n) {
            mi = min(mi, A[i]);
            ma = max(ma, A[i]);
        }

        if (ma < n) return ans;

        if (n <= mi) {
            ll d = mi - n + 1;
            ans += 1LL * d * n;
            rep(i, 0, n) A[i] -= d;
        } else {
            ll d = ma / n;
            ans += d;
            int id = -1;
            rep(i, 0, n) if (A[i] == ma) id = i;
            rep(i, 0, n) {
                if (i == id) A[i] -= d * n;
                else A[i] += d;
            }
        }
    }
}
//---------------------------------------------------------------------------------------------------
void _main() {
    int N;

    while (cin >> N) {
        vector<ll> A;
        rep(i, 0, N) {
            ll x; cin >> x; A.push_back(x);
        }

        ll ans = count(A);
        cout << ans << endl;
        continue;

        ans = naive(A);
        cout << ans << endl;
    }
}

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

int main() {
  int smax = 0, tm;
  string s, t;
  cin >> s >> t;
  int sl = s.size(), tl = t.size();
  for(int i = 0; i <= sl-tl; i++){
    tm = 0;
    for(int j = 0; j<tl; j++){
      if(s[i+j] == t[j]) tm++;
    }
    if(tm > smax) smax = tm;
  }
  cout << tl - smax << endl;
  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M; cin >> N >> M;
	vector<int>a(N), b(N), c(M), d(M);
	rep(i, 0, N)cin >> a[i] >> b[i];
	rep(i, 0, M)cin >> c[i] >> d[i];

	rep(i, 0, N) {
		int dist(INF);
		int index;
		rep(j, 0, M) {
			if (dist > abs(a[i] - c[j]) + abs(b[i] - d[j]))
				dist = abs(a[i] - c[j]) + abs(b[i] - d[j]), index = j;
		}
		cout << index + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  vector<int> v(3);
  rep(i,3){
    cin >> v[i];
  }
  sort(all(v));
  cout << v[0]+v[1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    int t=b,s=1;
    while(t>=1){
        t/=10;
        s*=10;
    }
    long long ans=(a*s)+b;
    //cout<<ans<<endl;
    for(int i=2;i*i<=ans;i++){
        if(i*i==ans){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;  cin >> s;
    if (s[0] == '9' || s[1] == '9') {
      cout << "Yes" << '\n';
    } else {
      cout << "No" << '\n';
    }

    return 0;
}


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

using namespace std;

#define endl '\n'
typedef long long ll;
using namespace std;

int main()
{

	int N, W;
	cin >> N;
	cin >> W;
	vector<vector<ll>> A(N, vector<ll>(2));
	for (int i = 0; i < N; ++i)
	{
		for (int j = 0; j < 2; ++j)
		{
			cin >> A[i][j];
		}
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));

	for (int i = 1; i <= N; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			if ( j - A[i - 1][0] >= 0)
			{
				dp[i][j] = max(dp[i-1][j], (A[i - 1][1] + dp[i - 1][j - A[i - 1][0]]));
			}
			else
			{
				dp[i][j] = dp[i - 1][j];
			}
		}
	}

	/*for (int i = 0; i < N + 1; ++i)
	{
		for (int j = 0; j < W + 1; ++j)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	cout << dp[N][W] << endl;
}

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

int main() {
    int n, a, b;
    while (cin >> n, n) {
        int pa = 0, pb = 0;
        for (int i=0; i<n; ++i) {
            cin >> a >> b;
            if (a > b) {
                pa += a + b;
            } else if (a < b) {
                pb += a + b;
            } else {
                pa += a;
                pb += b;
            }
        }
        cout << pa << " " << pb << endl;
    }
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    cout << fixed << setprecision(8);
    int n;
    cin >> n;
    int A[n + 1];
    for(int i = 0; i < n; i++) cin >> A[i];
    sort(A, A + n);
    double ans = -1;
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int last = n - 1;
            while(last == i || last == j) last--;
            int a = A[last];
            last--;
            while(last == i || last == j) last--;
            int b = A[last];
            double x = (a + b) / (double)(A[j] - A[i]);
            ans = max(x, ans);
        }
    }
    cout << ans << endl;
	return 0;
}




Measured memory_bytes: 3316
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), A = sc.nextInt();
		boolean ok = false;
		while (true) {
			if (N<0) break;
			if (N<=A) ok=true;
			N-=500;
		}
		System.out.println(ok ? "Yes" : "No");
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

Measured memory_bytes: 35816