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

int main() {
    
    string a,b;
    cin >> a;
    cin >> b;
    int i;
    for(i = 0 ; i < a.size() ; i++) {
        if (a[i] != b[i]) {
            cout << "No"; return 0;
        }
    }
    
    if (i < b.size()) {
        cout << "Yes"; return 0;
    }
    
    cout << "No";
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <iostream>

using namespace std;
int main() {
	while (true)
	{
		double D,E;
		cin >> D >> E;
		if (D == 0 && E == 0) { break; }
		double x, y;
		double min = 1000000;
		for (x = 0; x <= D / 2; ++x) {
			y = D - x;
			double dis = abs(sqrt(x*x+y*y)-E);
			if (dis < min) { min = dis; }

		}
		cout<<min<<endl;
	}
}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

bool func(int n, int a, int b){
  int now = 0;
  while(n){
    now += n%10;
    n /= 10;
  }
  if(a <= now && now <= b) return true;
  return false;
}

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

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int ans = 1, now = a[0];
  for(int i = 1; i < n; i++){
    if(now == a[i]) continue;
    now = a[i];
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
00:42 - 01:17
 */

#include<iostream>
#include<algorithm>
#include<climits>
#include<cstdio>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 31
using namespace std;

int H,W;
bool used[MAX][MAX];
char G[MAX][MAX];
int sp,mincost;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

inline bool isValid(int x,int y){ return ( 0 <= x && x < W && 0 <= y && y < H); }

void dfs(int cur,int cost,int pdir){

  if(cost >= 10)return;
  if(mincost <= cost)return;
  int x = cur % W, y = cur / W;

  if(G[y][x] == '>'){
    mincost = min(mincost,cost);
    return;
  }

  if(used[y][x])return;

  rep(i,4){
    //if(i == pdir)continue;

    int rnx = x + dx[(i+2)%4], rny = y + dy[(i+2)%4];//次に進む方向の逆
    if( G[rny][rnx] == '#' ){

      used[y][x] = true;
      int nx = x + dx[i], ny = y + dy[i];
      while( G[ny][nx] == '_' ){ 
	if( G[ny+dy[i]][nx+dx[i]] == '^' )break;
	if( G[ny+dy[i]][nx+dx[i]] == '_'){
	  G[ny+dy[i]][nx+dx[i]] = '#';
	  dfs(nx+ny*W,cost+1,(i+2)%4);
	  G[ny+dy[i]][nx+dx[i]] = '_';
	}
	  nx += dx[i], ny += dy[i];
      }
      if( G[ny][nx] == '>' )dfs(nx+ny*W,cost,(i+2)%4);
      if( G[ny][nx] == '#'){
	nx -= dx[i], ny -= dy[i];
	dfs(nx+ny*W,cost,(i+2)%4);
      }
      used[y][x] = false;
    } else if( rnx+rny*W != sp && G[rny][rnx] == '_' ) {
      G[rny][rnx] = '#';
      dfs(cur,cost+1,pdir);
      G[rny][rnx] = '_';
    }
  }
}

int main(){
  int T;
  scanf("%d",&T);
  while(T--){
    scanf("%d %d",&H,&W);
    rep(y,H)rep(x,W){
      cin >> G[y][x];
      if(G[y][x] == 'A')sp = x + y * W, G[y][x] = '_';
      used[y][x] = false;
    }
    
    mincost = IINF;
    dfs(sp,0,IINF);
    if(mincost == IINF)puts("10");
    else               printf("%d\n",mincost);

  }
  return 0;
}

Measured memory_bytes: 1228
#include <iostream>
using namespace std;
int main(){
 int m,f,r;
 while(1){
  	cin >> m >> f >> r;
  	if(m==-1 && f==-1 && r==-1){
       break;
  	}
  	if(m==-1 || f==-1){
  		cout << "F" << endl;
  	}
  	else if(m+f>=80){
  		cout << "A" << endl;
  	}
  	else if(m+f<80 && m+f>=65){
  		cout << "B" << endl;
  	}
  	else if(m+f<65 && m+f>=50){
  		cout << "C" << endl;
  	}
  	else if(m+f<50 && m+f>=30){
  		if(r>=50){
  			cout << "C" << endl;
  		}
  		else if(r<50){
  			cout << "D" << endl;
  		}
  	}
  	else if(m+f<30){
  		cout << "F" << endl;
  	}
  }
return 0;
}


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

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

bool dp[200100];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  rep(i, k) rep(j, n) if (!dp[i]) dp[i + a[j]] = true;

  cout << (dp[k] ? "First" : "Second") << endl;
  return 0;
}

Measured memory_bytes: 3768
#!/usr/bin/env python3

def main():
    X,N = map(int, input().split())
    p = list(map(int, input().split()))
    
    if X not in p:
        ans=X
    else:
        for i in range(100):
            if X-i not in p:
                ans=X-i
                break
            elif X+i not in p:
                ans=X+i
                break
        
    print(ans)
    
if __name__ == "__main__":
    main()


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

struct P
{
    int x,y;

    bool operator<(const P &a)const{
        if(x!=a.x) return x>a.x;
        return y<a.y;
    }
};


vector<int> v[1];
vector<int> v1;
//bitset<4001000> b;
int i,n,m,k,a,d,b,c;
int e;
int o[2];
int l[1];
int j[31];

int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
int px[10]={-1,1,1,-1,1,1,-1,-1},py[10]={1,1,-1,-1,1,-1,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<int> se[33],s1;

//priority_queue<P> q[2];
queue<P> q;
//string r,r1;

char r1[110],r[331];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
map<int,int> p;
//v.resize(unique(v.begin(),v.end())-v.begin());

bool as(P a,P b)
{
    //if(a.x!=b.x)
    return a.x<b.x;

}


//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();



int main()
{
    scanf("%d",&a);
    printf("%d",(a-2)*180);
}




Measured memory_bytes: 256
import java.util.*;
//文字操作
class Main {
	Scanner sc = new Scanner(System.in);

	public void lmap(int i,int j){
		map[i][j]='0';
		if(i-1>=0 && map[i-1][j]=='1'){
			lmap(i-1,j);
		}
		if(i+1<12 &&map[i+1][j]=='1'){
			lmap(i+1,j);
		}
		if(j>=1 && map[i][j-1]=='1'){
			lmap(i-1,j-1);
		}
		if(j+1<12 && map[i][j+1]=='1'){
			lmap(i,j+1);
		}
	}
	char[][] map;
	public void run() {
		while(sc.hasNext()){
			map=new char[12][12];
			for(int i=0;i<12;i++){
				map[i]=sc.next().toCharArray();
			}
			int count=0;
			for(int i=0;i<12;i++)
				for(int j=0;j<12;j++){
					if(map[i][j]=='1'){
						count++;
						lmap(i, j);
					}
				}
			ln(count);
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

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

ll N;

const ll MAXN = 2 * 100000;
ll A[MAXN];
ll S[MAXN + 1];

#if 0
ll solve(ll lhs, ll rhs)
{
    const ll s = lhs;
    const ll t = rhs;

    while (lhs + 1 < rhs) // for (ll i=0;i<1024&&lhs+1<rhs;++i)
    {
        const ll mid = (lhs + rhs) >> 1;

        const ll a = S[mid + 1] - S[s];
        const ll b = S[t] - S[mid + 1];

        if (a < b) { lhs = mid; } else { rhs = mid; }
    }

    return rhs;
}
#endif

ll calc(ll ai, ll bi, ll ci, ll di)
{
    if (ai < 0 || ai >= bi || bi >= ci || ci >= di) { return S[N]; }

    const ll a = S[ai + 1] - S[0];
    const ll b = S[bi + 1] - S[ai + 1];

    const ll c = S[ci + 1] - S[bi + 1];
    const ll d = S[di + 1] - S[ci + 1];

    const ll lhs = min(a, min(b, min(c, d)));
    const ll rhs = max(a, max(b, max(c, d)));

    return rhs - lhs;
}

int main()
{
    cin >> N;

    rep (i, N) { cin >> A[i]; }
    rep (i, N) { S[i + 1] = S[i] + A[i]; }

    ll ans = S[N];

    ll ai = 0;
    ll ci = 0;

    for (ll bi=1;bi<N-2;++bi)
    {
        if (ci <= bi) { ci = bi + 1; }

        while (ai + 1 < bi)
        {
            const ll a = S[ai + 2];
            const ll b = S[bi + 1] - S[ai + 2];

            if (a <= b) { ++ai; } else { break; }
        }

        while (ci + 1 < N - 1)
        {
            const ll c = S[ci + 2] - S[bi + 1];
            const ll d = S[N] - S[ci + 2];

            if (c <= d) { ++ci; } else { break; }
        }

        for (ll i=0;i<=1;++i)
        for (ll j=0;j<=1;++j)
        {
            const ll res = calc(ai + i, bi, ci + j, N - 1);
            ans = min(ans, res);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
from collections import deque
def bfs(N,start,dp):
  visited=[0]*N
  visited[start]=1
  que=deque([start])
  while que:
    a=que.popleft()
    for i in dp[a]:
      if not visited[i]:
        visited[i]=a+1
        que.append(i)
  return visited
N,M=map(int,input().split())
dp=[[] for i in range(N)]
for _ in range(M):
  A,B=map(int,input().split())
  dp[A-1].append(B-1)
  dp[B-1].append(A-1)
visited=bfs(N,0,dp)[1:]
if all(visited):
  print('Yes')
  for i in visited:
    print(i)
else:
  print('No')

Measured memory_bytes: 37400
N, P=map(int,input().split())
S = list(map(int,list(input())))

def ma25():
  ret = 0
  for i in range(N):
    if S[i]%P == 0:
      ret+=(i+1)
  print(ret)

def ma():
  dp = [0]*P
  dp[0] = 1
  r = 0
  for i in range(N-1,-1,-1):
    r = ((S[i]*pow(10,N-1-i,P))+r)%P
    dp[r] += 1
  ret = 0
  for m in dp:
    ret += m*(m-1)//2
  print(ret)

if P == 2 or P == 5:
  ma25()
else:
  ma()


Measured memory_bytes: 6560
#include <atcoder/maxflow>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using ll = long long;

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

int main(){
  int n,m; cin >> n >> m;
  vector<string> grid(n);
  rep(i,n){
    cin >> grid[i];
  }
  mf_graph<int> mf(n * m + 2);
  ll s = n * m, t = n * m + 1;
  rep(i, n){
    rep(j,m){
      if(grid[i][j] == '#') continue;
      int v = i * m + j; 
      if((i+j) % 2 == 0){
        mf.add_edge(s,v,1);
      }else{
        mf.add_edge(v,t,1);
      }
    }
  }
  rep(i, n){
    rep(j,m){
      if(grid[i][j] == '#' || (i+j)%2 == 1) continue;
      int u = i * m + j; 
      vector<int> dx = {0,1,0,-1};
      vector<int> dy = {1,0,-1,0};
      rep(k,4){
        int nx = i + dx[k];
        int ny = j + dy[k];
        int v = nx * m + ny;
        if(nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if(grid[nx][ny] == '#') continue;
        mf.add_edge(u,v,1);
      }
    }
  }
  
  cout << mf.flow(s,t) << endl;
  auto edges = mf.edges();
  for(auto &e : edges){
    if(e.flow == 0 || e.from == s || e.to == t) continue;
    int i0 = e.from/m;
    int j0 = e.from % m;
    int i1 = e.to/m;
    int j1 = e.to%m;
    if(i0 == i1){
      if(j0 > j1) swap(j0,j1);
      grid[i0][j0] = '>';
      grid[i1][j1] = '<';
    }else{
      if(i0 > i1) swap(i0,i1);
      grid[i0][j0] = 'v';
      grid[i1][j1] = '^';
    }
  }
  rep(i,n){
    cout << grid[i] << endl;
  }
}


Measured memory_bytes: 5584
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		int M = 1000000007;
		BigInteger a = BigInteger.valueOf(1);
		for (int x = 1; x <= n; x++) {
			a = a.multiply(BigInteger.valueOf(x)).mod(BigInteger.valueOf(M));
		}
		System.out.println(a);
	}

}


Measured memory_bytes: 41112
#define rep(i,N) for(int i=0;i<(int)N;i++)
#include <bits/stdc++.h>
using namespace std;
int main()
{
  bool thru;
  int N,M,count=0,loop=1;
  cin>>N>>M;
  vector<int> a(M),b(M),A;
  rep(i,N){A.push_back(i+1);}//初期順列
  vector<vector<bool>> get(N,vector<bool>(N,false));//検索表と初期化。
  rep(i,M){cin>>a.at(i)>>b.at(i);}
  rep(i,M)
  {
    get.at(a.at(i)-1).at(b.at(i)-1)=true;
    get.at(b.at(i)-1).at(a.at(i)-1)=true;
  }//辺が繋がっているかどうかの表。
  rep(i,N-1){loop*=(i+1);}//一桁目は1で固定する為、(N-1)!通りで良い。
  rep(i,loop)
  {
    thru=true;
    rep(j,N-1)
    {
      if(!(get.at(A.at(j)-1).at(A.at(j+1)-1)))thru=false;
    }
    if(thru){count++;}//全ての頂点が繋がっていた時。
    next_permutation(A.begin()+1,A.end());//一桁目は1で固定し次の順列へ。
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<int>> vec(h, vector<int>(w));
    int count{};
    for (int i = 0; i < h; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < w; j++)
        {
            if (s[j] == '#')
            {
                vec[i][j] = ++count;
            }
            else
            {
                vec[i][j] = 0;
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            if (vec[i][j] > 0)
            {
                int l, r;
                for (int x = j + 1; x < w; x++)
                {
                    if (vec[i][x] != 0)
                    {
                        r = x - 1;
                        break;
                    }
                    vec[i][x] = vec[i][j];
                }
                for (int x = j - 1; x >= 0; x--)
                {
                    if (vec[i][x] != 0)
                    {
                        l = x + 1;
                        break;
                    }
                    vec[i][x] = vec[i][j];
                }
            }
        }
    }
    for (int i = 0; i < h; i++)
    {
        int t;
        if (vec[i][0] > 0)
        {
            t = i;
            while (t + 1 < h && vec[t + 1][0] == 0)
            {
                t++;
                for (int j = 0; j < w; j++)
                {
                    vec[t][j] = vec[i][j];
                }
            }

            t = i;
            while (t - 1 >= 0 && vec[t - 1][0] == 0)
            {
                t--;
                for (int j = 0; j < w; j++)
                {
                    vec[t][j] = vec[i][j];
                }
            }
        }
    }

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << vec[i][j] << ' ';
        }
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    string N_str;
    cin >> N_str;
    int n = N_str.length();

    vector<int> N(n + 1, 0);
    rep(i,n) N[i] = N_str[n - 1 - i] - '0';

    vector<vector<int>> dp(n + 1, vector<int>(2, INF));
    dp[0][0] = 0;

    rep(i,n) rep(j,2) {
        N[i] += j;
        rep(A,10) {
            int p = i + 1, q = 0;
            int B = A - N[i];
            if (B < 0) {
                q = 1;
                B += 10;
            }
            dp[p][q] = min(dp[p][q], dp[i][j] + A + B);
        }
        N[i] -= j;
    }

    cout << min(dp[n][0], dp[n][1] + 1) << endl;
    
    return 0;
}

Measured memory_bytes: 59780
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
	int i, n;
	int x[100], y[100];
	double D1 = 0.0, D2 = 0.0, D3 = 0.0, Dinf = 0.0;

	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> x[i];
	}

	for (i = 0; i < n; i++) {
		cin >> y[i];
	}

	for (i = 0; i < n; i++) {
		D1 += abs(x[i] - y[i]);
		D2 += pow(abs(x[i] - y[i]), 2);
		D3 += pow(abs(x[i] - y[i]), 3);
		if (abs(x[i] - y[i]) > Dinf) Dinf = abs(x[i] - y[i]);
	}

	D2 = sqrt(D2);
	D3 = pow(D3, 1.0 / 3.0);
	
	cout << fixed << setprecision(6);

	cout << D1 << endl << D2 << endl << D3 << endl << Dinf << endl;


	return 0;
}



Measured memory_bytes: 3436
package main

/*
	予め片方の一端を引いたぶんでかんがえればいいね
	(X-Z) // ((Y+Z)
*/

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	x, y, z := nextInt(), nextInt(), nextInt()
	fmt.Fprint(out, (x-z)/(y+z))
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
// Author: πα

#include <bits/stdc++.h>
using namespace std;
#define long int64_t
#define minn(x, y) (abs(x) < abs(y) ? x : y)

int main()
{
    int n, l, mn = INT_MAX, sum = 0;
    cin >> n >> l;
    for(int i = 0; i < n; ++i)
        mn = minn(mn, i+l), sum += i+l;
    cout << sum - mn;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int i = s.find('A');
    int j = s.find_last_of('Z');
    int ans = j - i + 1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
public class Main {

	/**
	 * 
	 * ????????????????????¨?????????????????°??????
	 */
	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		for(int i = 1;i <= 9; i++) {
			for(int j = 1;j <= 9; j++) {
				int answer = i * j;
				System.out.println(i+"x"+j+"="+answer);
			}
				
		}
	}

}

Measured memory_bytes: 16852
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,k;
int a[100001];
vector<int> G[100005];
vector<int> rG[100005];
int dist[100005];

int main(void){
	scanf("%d%d",&n,&k);
	queue<int> que;
	memset(dist,-1,sizeof(dist));
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]>0){
			G[a[i]-1].push_back(i);
			rG[i].push_back(a[i]-1);
		}
	}
	for(int i=0;i<n;i++){
		if(G[i].size()==0){
			que.push(i);
			dist[i]=0;
		}
	}
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<rG[v].size();i++){
			if(dist[rG[v][i]]==-1){
				dist[rG[v][i]]=dist[v]+1;
				que.push(rG[v][i]);
			}
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		if(dist[i]<k || rG[i].size()==0)res++;
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 14988
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

const int N=200010;
int n,a[N];
ll ans1,ans2;

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int l=0,r=n+1,x=n/2+1;
	rep(i,2,n) if (i&1) ans1+=a[--r]-a[x],x=r; else ans1+=a[x]-a[++l],x=l;
	l=0,r=n+1,x=(n+1)/2;
	rep(i,2,n) if (i&1) ans2+=a[x]-a[++l],x=l; else ans2+=a[--r]-a[x],x=r;
	printf("%lld\n",max(ans1,ans2));
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main()
{
	for (;;)
	{
		int m, f, r;
		cin >> m >> f >> r;

		string s;
		if (m == -1 && f == -1 && r == -1)
		{
			break;
		}
		else if (m == -1 || f == -1)
		{
			s = "F";
		}
		else if (m + f >= 80)
		{
			s = "A";
		}
		else if (m + f >= 65)
		{
			s = "B";
		}
		else if (m + f >= 50)
		{
			s = "C";
		}
		else if (m + f >= 30)
		{
			if (r >= 50)
			{
				s = "C";
			}
			else
			{
				s = "D";
			}
		}
		else
		{
			s = "F";
		}

		cout << s << endl;
	}
}


Measured memory_bytes: 3140
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    cin >> N;
    llong A;
    if(N%1000==0){
        cout << 0 << endl;
        exit(0);
    }
    A = N%1000;
    cout << 1000-A << endl;
    return 0;
}





Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

// drken1215 method
ll dp[201000][5];

int main(){
  string s;
  cin >> s;
  int ssize = (int)s.size();
  dp[0][0]=1;
  rep(i,ssize){
    rep(j,4){
      // カウント進めない
      if(s[i]!='?'){
        dp[i+1][j] += dp[i][j]; dp[i+1][j] %= mod;
      }
      else{
        dp[i+1][j] += dp[i][j]*3; dp[i+1][j]%=mod;
      }
    }
    //カウント
    if(s[i]=='A' || s[i] == '?'){
      dp[i+1][1] += dp[i][0]; dp[i+1][1] %= mod;
    }
    if(s[i]=='B' || s[i] == '?'){
      dp[i+1][2] += dp[i][1]; dp[i+1][2] %= mod;
    }
    if(s[i]=='C' || s[i] == '?'){
      dp[i+1][3] += dp[i][2]; dp[i+1][3] %= mod;
    }
  }

  cout << dp[ssize][3] << endl;

  return 0;
}


Measured memory_bytes: 4608
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = 0;
    long b = 0;
    long min = n;

    for(int i=1 ; i<=Math.sqrt(n) ; i++){
      if(n%i==0){
        a = i-1;
        b = n/i-1;
      }
      min = Math.min(min,a+b);
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 23764
L, R = map(int, input().split())

if R - L >= 2019:
    print(0)
    quit()

mod = 2019
ans = 2019
for l in range(L, R):
    for r in range(l+1, R+1):
        tmp = l * r % mod
        ans = min(ans, tmp)

print(ans)

Measured memory_bytes: 3060
N, K = map(int, input().strip().split())
V = [int(i) for i in input().strip().split()]

R = min(N, K)

MAX_VALUE = 0

for a in range(R + 1):
  for b in range(R - a + 1):
    tmp = V[0:a]
    if b > 0:
      tmp.extend(V[-b:])

    tmp.sort()
    start = 0
    for i in range(min(len(tmp), K - a - b)):
      if tmp[i] >= 0:
        break
      start = i + 1
    MAX_VALUE = max(MAX_VALUE, sum(tmp[start:]))

print(MAX_VALUE)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#define MAX 1000000

int main(){
    int m,n;
    
    while(cin >> m,m){
        cin >> n;
    
        int cnt = 0;
        for(int i = m ; i <= n ; i++){
            int tmp = i;
            while(!(tmp%2)||!(tmp%3)||!(tmp%5)){
                if(!(tmp%2)) tmp /= 2;
                else if(!(tmp%3)) tmp /= 3;
                else if(!(tmp%5)) tmp /= 5;
            }
            if(tmp == 1) cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "D"
const ll base=1000000007;
int n, m;
ll x[100001];
ll y[100001];
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(m);
    FOR(i, 1, n) read(x[i]);
    FOR(i, 1, m) read(y[i]);
    x[0]=x[1];
    FOR(i, 1, n) x[0]=min(x[0], x[i]);
    FOR(i, 1, n) x[i]-=x[0];
    y[0]=y[1];
    FOR(i, 1, m) y[0]=min(y[0], y[i]);
    FOR(i, 1, m) y[i]-=y[0];
    sort(x+1, x+n+1);
    sort(y+1, y+m+1);
    ll ansx=0;
    FOR(i, 1, n) ansx=(ansx+x[i]*((i-1)-(n-i)))%base;
    ansx+=base;
    ll ansy=0;
    FOR(i, 1, m) ansy=(ansy+y[i]*((i-1)-(m-i)))%base;
    ansy+=base;
    writeln((ansx*ansy)%base);
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(num,init,name) vector<int> name((num),(init));


int main(){
    int n;
    cin>>n;
    vec(100001,INT_MAX,dp);
    dp[0]=0;
    repf(i,0,100000){
        rep(j,10){
            if((i+pow(6,j))<=100000){
                dp[i+pow(6,j)]=min(dp[i]+1,dp[i+pow(6,j)]);
            }else break;
        }
        rep(j,10){
            if((i+pow(9,j))<=100000){
                dp[i+pow(9,j)]=min(dp[i]+1,dp[i+pow(9,j)]);
            }else break;
        }
        dp[i+1]=min(dp[i+1],dp[i]+1);
    }
    cout<<dp[n]<<endl;
    
    
    return 0;


}



Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<utility>
#include<cmath>
#define pb push_back
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int> a,b,c;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		b.pb(x);
	}
	for(int i=0;i<n-1;i++){
		int x;
		cin>>x;
		c.pb(x);
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		ans += b[ a[i]-1 ];
		if( i<n-1 && a[i]+1 == a[i+1]) ans += c[a[i]-1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF (1 << 30)

int N, M, C[1001], D[1001], dp[1010][1010];

int main()
{
  fill((int*)dp, (int*)dp + 1010 * 1010, INF);
  cin >> N >> M;
  for(int i = 0; i < N; i++)
    cin >> D[i];
  for(int i = 0; i < M; i++)
    cin >> C[i];
  for(int i = 0; i <= M; i++)
    dp[i][0] = 0;
  for(int i = 0; i < M; i++)
    for(int j = 0; j < N; j++)
      dp[i + 1][j + 1] = min(dp[i][j] + C[i] * D[j], dp[i][j + 1]);
  int ans = INF;
  for(int i = 0; i <= M; i++)
    ans = min(dp[i][N], ans);
  cout << ans << endl;
}

Measured memory_bytes: 5152
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N,an=0;
	cin >> N;
	vector<ll> a(N);
	rep(i, N) {
		cin >> a.at(i);
		if (i % 2 == 0 && a.at(i) % 2 != 0)an++;
	}
	cout << an << endl;
	
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
    int64_t v;
    Mint() { v = 0; }
    Mint(int64_t x) { v = x % MOD; if(v < 0)  v += MOD; }

    Mint operator-() { return Mint{-v}; };
    Mint operator+(Mint x) { return Mint(v + x.v); };
    Mint operator-(Mint x) { return Mint(v - x.v); };
    Mint operator*(Mint x) { return Mint(v * x.v); };
    Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

    Mint& operator+=(Mint x) { return *this = (*this + x); };
    Mint& operator-=(Mint x) { return *this = (*this - x); };
    Mint& operator*=(Mint x) { return *this = (*this * x); };
    Mint& operator/=(Mint x) { return *this = (*this / x); };

    static Mint pow(Mint base, int64_t exp) {
        if(exp == 0)  return Mint(1);
        return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
    }

    friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<998244353>;

template<class T> struct Counting {
    Counting(int64_t n) {
        _fact.assign(n+1, 1);
        for(int64_t i = 1; i <= n; i++)  _fact[i] = T(i) * _fact[i-1];
    }

    T fact(int64_t n) {
        assert(0 <= n && n < (int)_fact.size());
        return _fact[n];
    }

    T perm(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / fact(n-k);
    }

    T comb(int64_t n, int64_t k) {
        if(n < k)  return 0;
        return fact(n) / (fact(k) * fact(n-k));
    }

    private:
        vector<T> _fact;
};

int main() {
    lint N, M, K;
    cin >> N >> M >> K;

    Counting<mint> cnt(212345);
    mint ans = 0;
    for(lint i=0; i<=K; i++) {
        ans += cnt.comb(N-1, i) * mint::pow(M-1, N-1-i);
    }
    cout << ans*mint(M) << endl;
}

Measured memory_bytes: 4844
from collections import defaultdict
a = defaultdict(int)
n = int(input())
for i in range(1, n + 1):
    s = str(i)
    a[(s[0], s[-1])] += 1
rslt = 0
for i in range(1, 10):
    for j in range(1, 10):
        rslt += a[(str(i), str(j))] * a[(str(j), str(i))]
print(rslt)



Measured memory_bytes: 3316
// ABC045B - 3人でカードゲームイージー

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

typedef unsigned long long int ull;
typedef long long int ll;

int main() {
	string Sa, Sb, Sc;
	cin >> Sa >> Sb >> Sc;

	int A = 0, B = 0, C = 0;

	char next = 'a';

	while (1) {
//		cout << next << ' ';
		if (next == 'a') {
			if (A == Sa.size()) {
				cout << 'A' << endl;
				return 0;
			}
			next = Sa[A];
			++A;
		} else if (next == 'b') {
			if (B == Sb.size()) {
				cout << 'B' << endl;
				return 0;
			}
			next = Sb[B];
			++B;
		} else if (next == 'c') {
			if (C == Sc.size()) {
				cout << 'C' << endl;
				return 0;
			}
			next = Sc[C];
			++C;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		FastReader reader = new FastReader();
		PrintWriter writer = new PrintWriter(System.out);

		int a = reader.nextInt();
		int b = reader.nextInt();

		if (a<=8 && b<=8)
			writer.println ("Yay!");
		else
			writer.println (":(");

		writer.close();
	}

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt()
		{
			return Integer.parseInt(next());
		}

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 23124
//#include <bits/stdc++.h>
#include <unordered_set>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>

using namespace std;

/* macros */
#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

/*typedefs*/
typedef long long ll;

/*functions*/
bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str) {
    int num;
    istringstream iss(str); //put string in input stream
    iss>>num; return num; //read from stream as integer
}

template <class T> string toStr(T par) {
    ostringstream oss;  //output stream string
    oss<<par;    //write par to the stream
    return oss.str(); //return string of output
}

const int MAXN = 50;
bool arr[MAXN][MAXN] = {0};
bool img[MAXN][MAXN] = {0};

int main() {
    IOS();
    int n, m ;
    cin>>n>>m;
    for(int i = 0 ; i < n ; ++i)
    {
        for(int j =0 ; j <n ; ++j)
        {
            char c;
            cin>>c;
            arr[i][j] = (c == '#');
        }
    }

    for(int i = 0 ; i < m ; ++i)
    {
        for(int j =0 ; j <m ; ++j)
        {
            char c;
            cin>>c;
            img[i][j] = (c == '#');
        }
    }
    if(n == m)
    {
        int cnt = 0;
        for(int i = 0 ; i < n ;i++)
        {
            for(int j=0; j <n ; j++)
            {
                if(arr[i][j] == img[i][j])
                {
                    cnt++;
                }
            }
        }
        if(cnt == n*n)
        {
            cout<<"Yes\n";
            return 0;
        }
        cout<<"No\n";
        return 0;
    }
    //brute force ??
    for(int i = 0 ; i < (n-m) ;++i)
    {
        for(int j = 0 ; j < (n-m) ;++j)
        {
            int cnt =0;
            //use array with next if not same ??
            for(int k = 0; k < m ;++k)
            {
                for(int z = 0 ; z < m; ++z)
                {
                    if(arr[i+k][j+z] == img[k][z])
                    {
                        cnt++;
                    }
                }
            }
            if(cnt == m*m)
            {
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    cout<<"No\n";
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e5+10;


const ll inf = 1e18;

int n;
ll a[maxn][3];
ll dp[maxn][3];

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

    cin>>n;
    for (int i=0; i<n; i++) {
	for (int j=0; j<3; j++) {
	    cin>>a[i][j];
	}
    }

  
    for (int j=0; j<3; j++) {
	dp[0][j]=a[0][j];
    }


    for (int i=1; i<n; i++) {
	for (int j=0; j<3; j++) {
	    for (int k=0; k<3; k++) {
		if (j==k) continue;
		dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
	    }
	}
    }


    ll ans=max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    out(ans);

    
  

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cmath>
#include <utility>

using ll = long long;

int main()
{
    using namespace std;

    map<int, int> length2Count;

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int in;
        cin >> in;
        length2Count[in]++;
    }

    vector<ll> usable;
    for (auto l2c : length2Count)
    {
        auto c = l2c.second;
        if (c >= 4)
            usable.push_back(l2c.first);
        if (c >= 2)
            usable.push_back(l2c.first);
    }

    sort(usable.rbegin(), usable.rend());

    if (usable.size() < 2)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << usable[0] * usable[1] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 4992
class RMQ:
    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N + 1)
    def max(self, i):
        s = 0
        while i > 0:
            if s < self.tree[i]:
                s = self.tree[i]
            i -= i & -i
        return s
    def __setitem__(self, i, x):
        while i <= self.size:
            if self.tree[i] < x:
                self.tree[i] = x
            i += i & -i


N, *HA = map(int, open(0).read().split())
H, A = HA[:N], HA[N:]

dp = RMQ(N)
for h, a in zip(H, A):
    dp[h] = a + dp.max(h)

print(dp.max(N))

Measured memory_bytes: 49284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_W 10000
#define MAX_H 10000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int field[MAX_H][MAX_W], W, H, N, Y, X;
int dy[] = {0,-1,0,1,-1,1}, dx[] = {-1,0,1,0,-1,1};

int shortestPath(int sy, int sx, int ey, int ex){
  /*  queue<pii>q;
  map<pi, int>m;
  q.push(MP(0, MP(sy, sx)));
  m[MP(sy, sx)] = 1;

  while(!q.empty()){
    pii now = q.front(); q.pop();
    //    printf("%d %d %d\n", now.F, now.S.F, now.S.S);
    if(now.S.F == ey && now.S.S == ex){
      return now.F;
    }
    rep(d, 6){
      int ny = now.S.F + dy[d], nx = now.S.S + dx[d];
      if(ny < 0 || ny >= H || nx < 0 || nx >= W || m.count(MP(ny, nx))) continue;
      q.push(MP(now.F + 1, MP(ny, nx)));
      m[MP(ny, nx)] = 1;
    }
  } 
  return 0;*/
  if((sy <= ey && sx <= ex) || (sy >= ey && sx >= ex)) return max(abs(sy-ey), abs(sx-ex));
  return abs(sy-ey)+abs(sx-ex);
}

int main(){
  scanf("%d%d%d", &W, &H, &N);
  int sy, sx, ey, ex;
  int res = 0;
  scanf("%d%d", &sx, &sy); sy--; sx--;
  rep(i, N-1){
    scanf("%d%d", &ex, &ey); ey--; ex--;
    res += shortestPath(sy, sx, ey, ex);
    sy = ey, sx = ex;
  }
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 1188
K = int(open(0).read())

def f(n):
    n += 1
    d = 1
    c = sum(map(int, str(n)))
    p = n; q = c
    while d < n:
        b = (n // d) % 10
        n += (9 - b) * d
        c += 9 - b
        if p*c > n*q:
            p = n
            q = c
        d *= 10
    return p

ans = []
n = 0
for i in range(K):
    n = f(n)
    ans.append("%d\n" % n)
open(1, 'w').writelines(ans)

Measured memory_bytes: 3188
open System
stdin.ReadLine ()
let rec mergelists s t =
    match s with
    | [] -> t
    | s0 :: s_ ->
        match t with
        | [] -> s
        | t0 :: t_ -> s0 :: t0 :: mergelists s_ t_
let [|s; t|] = (stdin.ReadLine ()).Split(' ')
mergelists (List.ofSeq s) (List.ofSeq t)
    |> List.toArray |> stdout.Write

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

int main(){
  int N,K;
  cin>>N>>K;
  int64_t count=0;
  vector<int64_t> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  sort(H.begin(),H.end());

  for(int i=0;i<N-K;i++){
    count+=H[i];
  }
  cout<<count<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define         sz         100010
using namespace std;

long long arr[sz];

int main(){


    int n,flag=0;

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    arr[n] = 1111111111;

    for(int i=1;i<n;i++){
        if(arr[i]<arr[i-1]) arr[i]++;
    }


    for(int i=0;i<n;i++){
        if(arr[i]>arr[i+1]) flag = 1;
    }


    if(flag==1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }




    return 0;
}


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

int main() {
    int N, ans = 0;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (i % 2 == 0 && a % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  map<ll, int> mp;
  int idx = 0;
  vector<ll> path;
  do {
    mp[x] = idx++;
    path.emplace_back(x);
    x = x * x % m;
  } while (!mp.count(x));
  int start = mp[x];
  int len = idx - start;
  ll sum = 0;
  for (int i = start; i < idx; ++i)
    sum += path[i];
  ll ans = 0;
  if (n < start) {
    for (int i = 0; i < n; ++i)
      ans += path[i];
  } else {
    for (int i = 0; i < start; ++i)
      ans += path[i];
    ll loop = (n - start) / len;
    ans += loop * sum;
    ll rem = (n - start) % len;
    for (int i = 0; i < rem; ++i)
      ans += path[start + i];
  }
  cout << ans;
}

Measured memory_bytes: 6612
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String nc = sc.next();
    switch (nc) {
    case "A":
      System.out.println("T");
      break;
    case "C":
      System.out.println("G");
      break;
    case "G":
      System.out.println("C");
      break;
    case "T":
      System.out.println("A");
      break;
    default:
      break;
    }
  }
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

inline bool inside(ll y, ll x, ll H, ll W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vvll a(2, vll(n));
  rep(i,2){
    rep(j,n) cin>>a[i][j];
  }
  vvll dist(2,vll(n,-1));
  dist[0][0]=a[0][0];
  queue<pll> q;
  q.emplace(0,0);
  while(!q.empty()){
    ll y=q.front().first, x=q.front().second; q.pop();
    rep(i,2){
      ll ny=dy[i]+y, nx=dx[i]+x;
      if(inside(ny,nx,2,n)){
        if(dist[ny][nx]==-1){
          dist[ny][nx]=dist[y][x]+a[ny][nx];
          q.emplace(ny,nx);
        }else{
          chmax(dist[ny][nx],dist[y][x]+a[ny][nx]);
        }
      }
    }
  }
  cout<<dist[1][n-1]<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n;
	
	cin>>n;
	
	ll ans = 0;
	map<string,int> c;
	for(int i=0;i<n;++i){
		string s;
		cin>>s;
		sort(ALL(s));
		ans+=c[s];
		c[s]++;
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <iomanip>
#define NMAX 3000

using namespace std;

int n;
double v[NMAX+10], dp[NMAX+10][NMAX+10], sol;

int main()
{
    cin >> n;
    for(int i=1; i<=n; i++) cin >> v[i];
    dp[0][0] = 1;
    for(int i=1; i<=n; i++)
        {   dp[i][0] = dp[i-1][0] * (1 - v[i]);
            for(int j=1; j<=n; j++)
                dp[i][j] = v[i] * dp[i-1][j-1] + (1 - v[i]) * dp[i-1][j];
        }
    for(int i=n/2+1; i<=n; i++) sol = sol + dp[n][i];
    cout << setprecision(9) << fixed << sol << '\n';
    return 0;
}


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

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

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

int n, m;
int main (){
  scanf ("%d %d", &n, &m);
  printf ("%d\n", (1900 * m + 100 * (n - m)) * (1 << m));
  return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    long long int n;
    cin >> n;

    priority_queue<float> q;
    for(int i=0; i<n; i++){
        float temp;
        cin >> temp;
        q.push(-temp);
    }

    float temp;
    while(--n){
        float a = -q.top(); q.pop();
        float b = -q.top(); q.pop();
        temp = (a+b)/2;
        q.push(-temp);
    }

    cout << temp << "\n";

    return 0;
}


Measured memory_bytes: 256