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

using namespace std;

int n;
double a, b, c, d, e, f;
double x[3], y[3];
double r;
double px, py;

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];

		a = x[0] - x[1];
		b = y[0] - y[1];
		c = (x[1]*x[1] - x[0]*x[0] + y[1]*y[1] - y[0]*y[0]) / 2;
		d = x[2] - x[0];
		e = y[2] - y[0];
		f = (x[0]*x[0] - x[2]*x[2] + y[0]*y[0] - y[2]*y[2]) / 2;

		px = -(c * e - f * b) / (a * e - d * b);
		py = -(c * d - f * a) / (b * d - e * a);
		r = sqrt((x[0] - px) * (x[0] - px) + (y[0] - py) * (y[0] - py));

		printf("%.3f %.3f %.3f\n", px, py, r);
	}

	return 0;
}

/*@@@@@@@@@@@@@@@@@@@@@@@@@*/
/*@                       @*/
/*@ debug output erased ? @*/
/*@                       @*/
/*@@@@@@@@@@@@@@@@@@@@@@@@@*/

Measured memory_bytes: 1244
n = int(input())
a = list(map(int, input().split())) + [0]

money = 1000
stock = 0

for i in range(n):
    if a[i] == a[i+1]:
        continue
    elif a[i] < a[i+1]:
        stock += money // a[i]
        money -= a[i] * (money // a[i])
    elif a[i] > a[i+1]:
        money += a[i] * stock
        stock = 0

print(money)

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

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

using namespace std;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int N, K;
vector<int> g[2048];
bool visited[2048];
int cnt[2048][2048];

void dfs(int s, int v, int d) {
  visited[v] = true;
  ++cnt[s][d];
  for (int i: g[v]) {
    if (visited[i]) continue;
    dfs(s, i, d + 1);
  }
}

int main() {
  cout << setprecision(12) << fixed << boolalpha;
  cin >> N >> K;
  REP(i,N-1) {
    int a, b;
    cin >> a >> b;
    g[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
  }
  REP(i,N) {
    memset(visited, 0, sizeof(visited));
    dfs(i, i, 0);
  }
  REP(i,N) REP(j,N) cnt[i][j+1] += cnt[i][j];
  if (K % 2 == 0) {
    int res = 0;
    REP(i,N) chmax(res, cnt[i][K/2]);
    cout << N - res << endl;
  }
  else {
    int res = 0;
    REP(i,N) for (int j: g[i]) {
      int sign = 1, sum = 0;
      for (int k = K / 2; k >= 0; --k, sign *= -1) {
        sum += sign * (cnt[i][k] + cnt[j][k]);
      }
      chmax(res, sum);
    }
    cout << N - res << endl;
  }
  return 0;
}


Measured memory_bytes: 16384
#include <stdio.h>
#include <string.h>

int main(){
	char a[11], b[11], c[11];
	scanf("%s",a);
	scanf("%s",b);
	scanf("%s",c);
	int la, lb, lc;
	la=strlen(a);
	lb=strlen(b);
	//lc=strlen(c);
	if(a[la-1]==b[0] && b[lb-1]==c[0])
	printf("YES\n");
	else
	printf("NO\n");
}
	


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
	int H,W,i,j;
	while(cin>>H>>W)
	{
		if(H==0&&W==0)
			break;
		else
		{
			for(i=1;i<=H;i++)
			{
				for(j=1;j<=W;j++)
				{
					if(i==1||i==H)
						cout<<"#";
					else
					{
						if(j==1||j==W)
							cout<<"#";
						else
							cout<<".";
					}
				}
				cout<<"\n";
			}
			cout<<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 3060
N = int(input())
S = []
for i in range(N):
    s = sorted(input())
    S.append(''.join(s))

S.sort()
ans = 0
count = 0
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        ans += count + 1
        count += 1
    else:
        count = 0
print(ans)

Measured memory_bytes: 59352
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    lint a,b; cin>>a>>b;
    lint ans;
    if(a<b) swap(a,b);
    REP(i,a){
        if(i==0) ans = b;
        else ans = ans*10+b;
    }
    print(ans);
    return 0;
}

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

long long int n,s,order,n2,s2;

int main(){

    cin>>n;

    s=0;

    order=(int)log10(n);

     n2=n;

for(int i=order;i>=0;i--){
        s2=n2/pow(10,i);
        s+=s2;
        n2-=s2*pow(10,i);
    }

if(n%s==0){
    cout<<"Yes"<<endl;
}
else{
    cout<<"No"<<endl;
}

return 0;

}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for _ in range(N)]
A_s = sorted(A)[::-1]

for i in A:
    if (A_s[0] == i) & (A_s[1] == i):
        print(A_s[0])
    elif (A_s[0] == i) & (A_s[0] != A_s[1]):
        print(A_s[1])
    else:
        print(A_s[0])


Measured memory_bytes: 14160
from collections import defaultdict
from sys import stdin
def gen_bound(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return lb,ub+1
def solve():
	count = defaultdict(int)
	ans = [0]*10
	L = map(lambda x:map(int,x.split()),stdin.readlines())
	H,W,N = L[0]
	ans[0] = (H-2)*(W-2)
	for i in xrange(1,N+1):
		xlb,xub = gen_bound(L[i][0],H)
		ylb,yub = gen_bound(L[i][1],W)
		for x in xrange(xlb,xub):
			for y in xrange(ylb,yub):
				count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] -= sum(ans[1:])
	for c in ans: print c
solve()

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().trim().split("\\s+");
        int n = Integer.parseInt(s[0]);
        int w = Integer.parseInt(s[1]);
        int[][] arr = new int[n][2];
        for(int i = 0 ; i<n ; i++) {
            s = br.readLine().trim().split("\\s+");
            arr[i][0] = Integer.parseInt(s[0]);
            arr[i][1] = Integer.parseInt(s[1]);
        }

        long[][] dp = new long[n+1][w+1];

        for(int i=0 ; i<=n ; i++)
            dp[i][0] = 0;

        for(int i=0 ; i<=w ; i++)
            dp[0][i] = 0;

        for(int i=1 ; i<=n ; i++)
        {
            for(int j=1 ; j<=w ; j++)
            {
                dp[i][j] = dp[i-1][j];
                if(arr[i-1][0] <= j)
                    dp[i][j] = Math.max(dp[i][j], arr[i-1][1] + dp[i-1][j-arr[i-1][0]]);
            }
        }

        System.out.println(dp[n][w]);
    }
}

Measured memory_bytes: 126420
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000
#define DIVISOR 1000000007

static int64_t factorial[NUM_MAX+1];
static int64_t inv_factorial[NUM_MAX+1];

struct pair {
    int x;
    int y;
};

struct pair gcdext(int a, int b) {
    if(a==0) { return (struct pair){0, 1}; }
    struct pair p = gcdext(b%a, a);
    return (struct pair){p.y-(b/a)*p.x, p.x};
}
void init_combi(int ulimit) {
    factorial[0] = factorial[1] = 1;
    inv_factorial[0] = inv_factorial[1] = 1;
    int i;
    for(i = 2; i <= ulimit; i++) {
        factorial[i] = (factorial[i-1] * i) % DIVISOR;
        struct pair p = gcdext(i, DIVISOR);
        int inv = (p.x + DIVISOR)%DIVISOR;
        inv_factorial[i] = (inv_factorial[i-1] * inv) % DIVISOR;
    }
    return;
}

int64_t calc_combi(int n, int k) {
    if(k > n) return 0;
    int64_t ans = 1;
    ans = (ans * factorial[n])%DIVISOR;
    ans = (ans * inv_factorial[k])%DIVISOR;
    ans = (ans * inv_factorial[n-k])%DIVISOR;
    return ans;
}

int main(void) {
    int num = get_int();
    static int arr[NUM_MAX+1];
    fget_array(arr, num+1);

    static int idx_map[NUM_MAX+1];
    memset(idx_map, 0xFF, sizeof(int)*(NUM_MAX+1));
    int i;
    int first = 0;
    int second = 0;
    for(i = 0; i < num+1; i++) {
        int cur = arr[i];
        if(idx_map[cur] == -1) {
            idx_map[cur] = i;
        } else {
            first = idx_map[cur];
            second = i;
            break;
        }
    }

    init_combi(num+1);

    int k;
#ifdef DEBUG
    printf("1st: %d 2nd: %d\n", first, second);
#endif
    static int ans[NUM_MAX+2];
    for(k = 1; k <= num+1; k++) {
        if(k==1) {
            ans[k] = num;
            continue;
        }
        // k>=2
        int64_t res = calc_combi(num+1, k);
#ifdef DEBUG
        printf("%lld - %d\n", res, num-second+first);
#endif
        res = (res + DIVISOR - calc_combi(num+1-1-second+first, k-1))%DIVISOR;
        ans[k] = res;
    }

    for(k = 1; k <= num+1; k++) {
        printf("%d\n", ans[k]);
    }
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
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 = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    n /= 2;
    rep(i, n){
        if(s[i] != s[n+i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
n,m,d=map(int,input().split())
#すべての組み合わせの和の平均 = すべての組み合わせからランダムに1つ選んだ時の期待値
#「期待値の線形性」とは「和の期待値は期待値の和に等しい」こと
#E[X+Y]=E[X]+E[Y]
if d==0:
    pro=1/n
else:
    pro=(2*(n-d))/n**2

ans=pro*(m-1)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
 
int main(){
	ll a;
    string b;
  cin >> a >> b;
    ll b_100 = (b[0] - '0')*100 + (b[2] - '0')*10 + (b[3] - '0');
  //b[1] is decimal separater
    ll c = (a * b_100)/100;
  
  cout << c << endl;
  
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector< pair< string, P > > v;
    for( int i = 0; i < n; ++i ) {
        string s;
        int a;
        cin >> s >> a;
        v.pb( MP( s, MP( a, i + 1  ) ) );

    }
    sort( v.begin(), v.end() );
    for( int i = 0; i < v.size(); ++i ) {
        int pos = i;
        ++pos;
        while( pos < v.size() && v[pos - 1].F == v[pos].F ) pos++;
        int tmp = i;
        i = pos - 1;
        --pos;

        while( pos >= tmp ) { cout << v[pos].S.S << endl; --pos; }

    }
    return 0;
}


Measured memory_bytes: 256
mNM = map(int, input().split())
lNM = list(mNM)

mWay = [map(int, input().split()) for i in range(lNM[1])]
lWay = [list(mWay[i]) for i in range(lNM[1])]

maps = [-1 for i in range(lNM[0])]
deep = [-1 for i in range(lNM[0])]
ways = [[] for i in range(lNM[0])]

for i in range(lNM[1]):
    ways[lWay[i][0] - 1].append(lWay[i][1])
    ways[lWay[i][1] - 1].append(lWay[i][0])

maps[0] = 0
deep[0] = 0
nexts = [0]

for i in range(lNM[0]):
    try:
        index = nexts     
        nexts = []
        
        for x in index:
            for w in ways[x]:
                if(deep[w - 1] == -1):
                    deep[w - 1] = i + 1
                    maps[w - 1] = x + 1
                    nexts.append(w - 1)
        
    except:
        pass
    
if(-1 in maps):
    print('No')
else:
    print('Yes')
    for i in maps[1:]:
        print(i)

Measured memory_bytes: 110852
n = input()
l = input()
ans = True
#print(n[0])
#print(n[])
for i in range(len(n)):
    if i ==0:
        if n[0] == l[-1]:
            continue
        else :
            ans = False
            break
        
    elif n[i] == l[-i-1]:
        continue
    else :
        ans = False
        break
if ans:
    print("YES")
else:
    print("NO")


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

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int x;
    cin>>x;
    if(x == 0){
        cout<<"1";
    }
    else{
        cout<<"0";
    }
    return 0;
}

Measured memory_bytes: 3648
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		ArrayList<Integer> array = new ArrayList<Integer>();
		for(int i = 0;i<4;i++){
			array.add(Integer.parseInt(a.substring(i,i+1)));
		}
		String[] param = a.split("");
		if(array.get(0) + array.get(1) + array.get(2) + array.get(3) == 7){ //+++

			System.out.println(array.get(0) + "+" + array.get(1) + "+" + array.get(2) + "+" + array.get(3) +"=7" );

		}else if(array.get(0) + array.get(1) + array.get(2) - array.get(3) == 7){ //++-

			System.out.println(array.get(0) + "+" + array.get(1) + "+" + array.get(2) + "-" + array.get(3) +"=7" );

		}else if(array.get(0) + array.get(1) - array.get(2) - array.get(3) == 7){ //+--

			System.out.println(array.get(0) + "+" + array.get(1) + "-" + array.get(2) + "-" + array.get(3) +"=7" );

		}else if(array.get(0) + array.get(1) - array.get(2) + array.get(3) == 7){ //+-+

			System.out.println(array.get(0) + "+" + array.get(1) + "-" + array.get(2) + "+" + array.get(3) +"=7" );

		}else if(array.get(0) - array.get(1) + array.get(2) + array.get(3) == 7){ //-++

			System.out.println(array.get(0) + "-" + array.get(1) + "+" + array.get(2) + "+" + array.get(3) +"=7" );

		}else if(array.get(0) - array.get(1) - array.get(2) + array.get(3) == 7){ //--+

			System.out.println(array.get(0) + "-" + array.get(1) + "-" + array.get(2) + "+" + array.get(3) +"=7" );

		}else if(array.get(0) - array.get(1) - array.get(2) - array.get(3) == 7){ //---

			System.out.println(array.get(0) + "-" + array.get(1) + "-" + array.get(2) + "-" + array.get(3) +"=7" );

		}else if(array.get(0) - array.get(1) + array.get(2) - array.get(3) == 7){ //-+-

			System.out.println(array.get(0) + "-" + array.get(1) + "+" + array.get(2) + "-" + array.get(3) +"=7" );
		}
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e5+5;

int a[M];
map<int,int> p;
int main(){
	for(int i=0;i<M;i++) a[i]=1;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		int j=i;
		if(s[i]=='R'){
			while(s[i+1]=='R') a[i]=0,i++;
			int m=i-j;
			a[i]+=m/2;
			a[i+1]+=m/2+m%2;
		}
		else if(s[i]=='L'){
			while(s[i+1]=='L') a[i+1]=0,i++;
			int m=i-j;
			a[j]+=m/2;
			a[j-1]+=m/2+m%2;
		}
	}
	cout<<a[0];
	for(int i=1;i<s.length();i++)
		cout<<" "<<a[i];
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
tmp = 1
lipos = [1]
while tmp<10**9:
  tmp *= 4
  lipos.append(lipos[-1]+tmp)
#print(lipos)
tmp = -2
lineg = [-2]
while tmp > - 10**9:
  tmp *= 4
  lineg.append(lineg[-1]+tmp)
#print(lineg)
if n == 0:
  print("0")
elif n == 1:
  print("1")
elif n == -1:
  print("10")
elif n > 0:
  flag = True
  i = 0
  while flag:
    if lipos[i] < n <= lipos[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = lipos[k]-n
  print(bin(lipos[k]^diff)[2:])
else:
  flag = True
  i = 0
  while flag:
    if lineg[i] > n > lineg[i+1]:
      k = i+1
      flag = False
    i += 1
  diff = n-lineg[k]
  print(bin((-lineg[k])^diff)[2:])


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int N; cin >> N;
    cout << N << ": ";
    for (int i = 2; i * i <= N; i++) {
        while (N % i == 0) {
            cout << i;
            N /= i;
            if (N != 1) cout << " ";
        }
    }
    if (N != 1) cout << N;
    cout << endl;
    return 0;
}

Measured memory_bytes: 1164
A,V = map(int,input().split(" "))
B,W = map(int,input().split(" "))
T, = map(int,input().split(" "))
kyori = abs(A-B)
dif = V-W
if dif>0:
  if kyori/dif<=T:
    print("YES")
  else:
    print("NO")
else:
  print("NO")

Measured memory_bytes: 9128
#include <iostream>
using namespace std;
void insertionSort(int A[], int N){
    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for(int k = 0; k < N; k++){
            if(k == N - 1){
                cout << A[k] << endl;
            } else {
                cout << A[k] << " ";
            }
        }
    }
}

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(i == N - 1){
            cout << A[i] << endl;
        } else {
            cout << A[i] << " ";
        }
    }
    insertionSort(A, N);

    return 0;
}


Measured memory_bytes: 3032
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

typedef long double ld;
typedef long long ll;
  
int main(){
    ld M,Rd,Rr,Cd,Cr;
  
    cin >> M >> Rd >> Rr >> Cd >> Cr;
  
    ld D,R;
  
    D = ceil(Cd*100/Rd); R = ceil(Cr*100/Rr);
  
    if(M - (D + R) >= 0) printf("%lld\n" ,(ll)(M-(D+R)));
    else cout << "-1" << endl;
  
    return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);

  
int A,B;cin>>A>>B;
  cout<<max({A+B,A-B,A*B})<<endl;
}


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

int main() {
    int x, y;
    cin >> x;
    bool finished =false;
    y=x;
    while(true) {
        for(int i=2; i<x+1; i++) {
            if(y==2) {
                finished = true;
                break;
            }

            if(i ==  x) {
                finished = true;
                break;
            }

            if(y%i == 0) {
                break;
            } 
        }
        if(finished == true) {
            break;
        }
        y++;
    }
    cout << y << endl;
}

Measured memory_bytes: 256
from itertools import product
def prime_factors(N): #素因数 1を含まないことに注意
    ret = []
    middle = int( N**(1/2))
    tmp = N
    for i in range(2, middle+1):
        if tmp%i == 0:
            t = 1
            while tmp%i == 0:
                tmp //= i
                t *= i
            ret.append(t)
    if tmp != 1:
        ret.append(tmp)
    return ret

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def main():
    N = int( input())
    # print("start")
    P = prime_factors(2*N)
    M = len(P)
    ans = 2*N-1
    # print(M)
    for p in product( range(2), repeat=M):
        x = 1
        for i, t in enumerate(p):
            if t == 1:
                x *= P[i]
        y = N*2//x
        if x == 1:
            if y-1 < ans:
                ans = y-1
            continue
        if y == 1:
            if x-1 < ans:
                ans = x-1
            continue
        _, a, b = xgcd(x,y)
        now = -a*x
        # print(x, y, a, b)
        if a < 0:
            pass
        else:
            now = -b*y
        if now < ans:
            ans = now
    print(ans)
        
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 68632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll best = a * c;
    if (a <= 0 && 0 <= b) {
        best = max(best, 0ll);
    }
    if (c <= 0 && 0 <= d) {
        best = max(best, 0ll);
    }
    best = max(best, b * d);
    best = max(best, a * d);
    best = max(best, b * c);

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

Measured memory_bytes: 3620
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
     
public class Main{
    
    static InputReader ir;
    static PrintWriter out;

    static void solve(){
	int n=ir.nextInt();
	int[][] a=new int[n][n];
	for(int i=0;i<n;i++){
	    int u=ir.nextInt()-1;
	    int k=ir.nextInt();
	    int[] v=ir.nextIntArray(k);
	    for(int j=0;j<k;j++){
		a[u][--v[j]]^=1;
	    }
	}
	for(int i=0;i<n;i++){
	    for(int j=0;j<n;j++){
		if(j==n-1)
		    out.println(a[i][j]);
		else
		    out.print(a[i][j]+" ");
	    }
	}
    }

    public static void main(String[] args) throws Exception {
	ir = new InputReader(System.in);
     	out = new PrintWriter(System.out);
	solve();
	out.flush();
     }
 
    static class InputReader {
	private InputStream in;
	private byte[] buffer=new byte[1024];
	private int curbuf;
	private int lenbuf;

	public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
   
	public boolean hasNextByte() {
	    if(curbuf>=lenbuf){
		curbuf= 0;
		try{
		    lenbuf=in.read(buffer);
		}catch(IOException e) {
		    throw new InputMismatchException();
		}
		if(lenbuf<=0) return false;
	    }
	    return true;
	}
  
	private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
	private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
  
	private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
	public boolean hasNext(){skip(); return hasNextByte();}
  
	public String next(){
	    if(!hasNext()) throw new NoSuchElementException();
	    StringBuilder sb=new StringBuilder();
	    int b=readByte();
	    while(!isSpaceChar(b)){
		sb.appendCodePoint(b);
		b=readByte();
	    }
	    return sb.toString();
	}
  
	public int nextInt() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    int res=0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public long nextLong() {
	    if(!hasNext()) throw new NoSuchElementException();
	    int c=readByte();
	    while (isSpaceChar(c)) c=readByte();
	    boolean minus=false;
	    if (c=='-') {
		minus=true;
		c=readByte();
	    }
	    long res = 0;
	    do{
		if(c<'0'||c>'9') throw new InputMismatchException();
		res=res*10+c-'0';
		c=readByte();
	    }while(!isSpaceChar(c));
	    return (minus)?-res:res;
	}
  
	public double nextDouble(){return Double.parseDouble(next());}
  
	public int[] nextIntArray(int n){
	    int[] a=new int[n];
	    for(int i=0;i<n;i++)
		a[i]=nextInt();
	    return a;
	}
  
	public char[][] nextCharMap(int n,int m){
	    char[][] map=new char[n][m];
	    for(int i=0;i<n;i++)
		map[i]=next().toCharArray();
	    return map;
	}
    }
}



Measured memory_bytes: 26872
import java.util.*;

public class Main {
    public static void main(String[] args){
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int Y = sc.nextInt();
        
        boolean flag = false;
        
        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= (N-i); j++){
                int c = N - i - j;
                
                int sum = 0;
                int count = 0;
                 
                sum = (10000 * i) + (5000 * j) + (1000 * c);
                count = i + j + c;
                if(sum == Y && count == N){
                    System.out.println(i + " " + j + " " + c);
                    flag = true; 
                    break;
                }
            }
            
            if(flag){
                break;
            }
        }
        
        if(flag == false){
            System.out.println("-1 -1 -1");
        }
        
    }
    
}


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

int main() {

	int n;
	scanf("%d", &n);
	vector<int> d(n);
	int ans = 0;
	for(int i = 0; i < n; i++) {
		scanf("%d", &d[i]);
	}
	sort(d.begin(), d.end());
	ans = d[n / 2] - d[n / 2 - 1];
	if(ans > 0) {
		printf("%d\n", ans);
	} else {
		printf("%d\n", 0);
	}
}

Measured memory_bytes: 640
# https://atcoder.jp/contests/agc028/tasks/agc028_a

import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]
# Greatest Common Divisor(Euclidean algorithm)


def gcd(x: int, y: int) -> int:
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x, y = y, r
    return x


# Least Common Multiple
def lcm(x: int, y: int) -> int:
    _gcd = gcd(x, y)
    return (x * y) // _gcd


def main():
    n, m = input_int_list()
    _gcd = gcd(m, n)
    size = lcm(m, n)
    S = input()
    T = input()
    if S[::n // _gcd] == T[::m // _gcd]:
        print(size)
    else:
        print(-1)


if __name__ == "__main__":
    main()


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

// ITP1_9_A:   Finding a Word
int main(){
  string word;
  cin >> word;
  int wordLen = word.length();

  int num = 0;
  while (true) {
    string s;
    cin >> s;

    if (s == "END_OF_TEXT") {
      break;
    }

    std::transform(s.begin(), s.end(), s.begin(), [](char c) -> char{ if ('A' <= c && c <= 'Z') { return c - 'A' + 'a'; } else { return c; } });

    int len = s.length();
    std::string::size_type pos = s.find(word);
    while (pos != std::string::npos) {
      if (pos > 0) {
        char check = s[pos - 1];
        if ('a' <= check && check <= 'z') {
          pos = s.find(word, pos + wordLen);
          continue;
        }
      }
      if (pos + wordLen < len) {
        char check = s[pos + wordLen];
        if ('a' <= check && check <= 'z') {
          pos = s.find(word, pos + wordLen);
          continue;
        }
      }
      ++num;
      pos = s.find(word, pos + wordLen);
    }
  }
  cout << num << endl;

  return 0;
}



Measured memory_bytes: 3128
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    S = int(input())
    x1 = math.ceil(S ** 0.5)
    x2 = x1 ** 2 - S
    print(0, 0, x1, 1, x2, x1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9304
i = gets.chomp.split(' ').map(&:to_i)
if i[0]>=i[3] then
    puts i[3]
else
    if i[0]+i[1]>=i[3] then
        puts i[0]
    else
        puts i[0]-(i[3]-(i[0]+i[1]))
    end
end

Measured memory_bytes: 14312
def resolve():

    n, y = map(int, input().split())

    for i in range(n + 1):
        for j in range(n - i + 1):
            k = n - i - j

            if i * 10000 + j * 5000 + k * 1000 == y:
                print('{} {} {}'.format(i, j, k))
                return
    print('-1 -1 -1')
    
resolve()

Measured memory_bytes: 38768
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll N,K;
  cin>>N>>K;
  cout<<N-K+1<<endl;
  
  return 0;
}


Measured memory_bytes: 888
"use strict"

const Main = (inpuut)=>{
const Array= inpuut.split(/\n/)
const N = Array[0]-0
const D = Array[1].split(" ").map((ele)=>{return ele-0})[0]
const X =Array[1].split(" ").map((ele)=>{return ele-0})[1]

let sum = 0

// iが人
//jがAにかかる係数

for (let i=1; i<=N; i+=1){
  const A = Array[i+1]-0

  for(let j=0;A*j+1<=D;j++){
   sum+=1
  }
 
}

console.log(sum+X)
}


Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

int main(){
    int n;
    cin >> n;
    ve<int> ans(n+10,0);
    for (int x = 1; x < 105; x++) {
        for(int y = 1; y < 105; y++){
            for(int z = 1; z < 105; z++){
                int now = x*x + y*y + z*z;
                now += x*y + y*z + z*x;
                if(now<n+10){
                    ans[now]++;
                }
            }
        }
    }
    rep(i,n) cout << ans[i+1] << endl;
    return 0;
}


Measured memory_bytes: 3592
from collections import Counter
def main():
    N = int(input())
    S = list(input() for _ in range(N))
    counter = Counter(S)
    most_count = []
    max_count = 0
    for i, (word, cnt) in enumerate(counter.most_common()):
        if max_count>cnt:
            break
        max_count = cnt
        most_count.append(word)
    most_count.sort()
    for m in most_count:
        print(m)



if __name__=='__main__':
    main()


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n-k;i++){
        cout << (a[i] < a[i+k] ? "Yes" : "No") << endl;
    }
    return 0;
}

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

int main(){
  int N,A,B,x,y;
  cin>>N>>A>>B;
  
  x=N*A;
  y=B;
  
  if(x<y){
    cout<<x<<endl;
  }
  else if(x>y){
    cout<<y<<endl;
  }
  else
    cout<<x<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int l[10];
int p[500]={};
int q[500]={};
int x[3];

int main(){
	int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c);
	REP(i, n) scanf("%d", l+i);
	REP(i, 1<<n){
		REP(j, n) if(i&(1<<j)) p[i]+=l[j], q[i]++;
	}
	int ans=INT_MAX;
	FOR(i, 1, 1<<n){
		FOR(j, 1, 1<<n){
			if(i&j) continue;
			FOR(k, 1, 1<<n){
				if(i&k) continue;
				if(j&k) continue;
				x[0]=p[i];
				x[1]=p[j];
				x[2]=p[k];
				sort(x, x+3);
				SML(ans, abs(x[2]-a)+abs(x[1]-b)+abs(x[0]-c)+(q[i]+q[j]+q[k]-3)*10);
			}
		}
	}
	printf("%d\n", ans);
}


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

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

  char A, B, C, D;
  cin >> A >> B >> C >> D;
  for(int i = 0; i < (1 << 3); i++) {
    string ans_s = "";
    ans_s = ans_s + A;
    int ans_i = A - '0';
    if((i >> 0) & 1) {
      ans_i += B - '0';
      ans_s = ans_s + "+" + B;
    }
    else {
      ans_i -= B - '0';
      ans_s = ans_s + "-" + B;
    }
    if((i >> 1) & 1) {
      ans_i += C - '0';
      ans_s = ans_s + "+" + C;
    }
    else {
      ans_i -= C - '0';
      ans_s = ans_s + "-" + C;
    }
    if((i >> 2) & 1) {
      ans_i += D - '0';
      ans_s = ans_s + "+" + D;
    }
    else {
      ans_i -= D - '0';
      ans_s = ans_s + "-" + D;
    }
    if(ans_i == 7) {
      ans_s = ans_s + "=7";
      cout << ans_s << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    ll ans=0;
    for(ll i=1;i<N;i++){
        ans+=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()

flag = [0, 0, 0]

s1 = s
if s1.replace('A', '') == 'KIHBR':
	flag[0] = 1

s2 = s
if 'AA' not in s2:
	flag[1] = 1

s3 = s
if 'KAI' not in s3 and 'IAH' not in s3:
	flag[2] = 1

if flag == [1, 1, 1]:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;

const int n_max=100000;

int main() {

    int n;
    int a[n_max];
    scanf("%d",&n);
    rep(i,n)    scanf("%d",&a[i]);
    int ans[n_max];

    rep(i,n) {
        ans[(a[i]-1)]=i+1;
    }
    rep(i,n) {
        printf("%d\n",ans[i]);
    }
  
 return 0;
}

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

int main(){
    string s,t;
    cin >> s;
    cin >> t;
    int n = t.size();
    int ma = 0;
    rep(i,s.size()){
        if(i+n-1>=s.size()) break;
        int tmp=0;
        rep(j,n){
            if(s[i+j]==t[j]) tmp++;
        }
        ma = max(ma, tmp);
    }
    cout << n-ma << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
	int i, j, H, W;
	scanf("%d %d", &H, &W);
	while((H!=0)||(W!=0)){
		for(i=0; i<H ;i++){
			if((i==0)||(i==(H-1))){
				for(j=0; j<W; j++){
					printf("#");
					if(j == (W-1))
						printf("\n");
				}
			}
			else{
				printf("#");
				for(j=1; j<(W-1); j++)
					printf(".");
				printf("#\n");				
			}
		}
		printf("\n");
		scanf("%d %d", &H, &W);
	}
	return 0;
}

Measured memory_bytes: 588
import java.util.*;

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

	public Main() {
		AOJ2253 obj = new AOJ2253();
		while(true){
			int t = in.nextInt(),n = in.nextInt();
			if(n+t==0)break;
			obj.doIt(t,n);
		}
	}
	class AOJ2253{
		void doIt(int t,int n){
			int[][] map = new int[121][121];
			for(int i=0;i<121;i++)Arrays.fill(map[i],-1);
			boolean syougai[][] = new boolean[121][121];
			for(int i=0;i<n;i++){
				int gx = in.nextInt()+60;
				int gy = in.nextInt()+60;
				syougai[gy][gx] = true;
			}
			int sx = in.nextInt()+60,sy = in.nextInt()+60;
			LinkedList<State> q = new LinkedList<State>();
			int ax[] = {1,0,1,-1,0,-1};
			int ay[] = {0,1,1,0,-1,-1};
			q.add(new State(sx, sy, 0));
			while(q.size()>0){
				State now = q.remove();
//				System.out.println(now);
				if(map[now.y][now.x]>0)continue;
				map[now.y][now.x] = now.step;
				if(now.step == t)continue;
				for(int i=0;i<6;i++){
					int nx = ax[i]+now.x;
					int ny = ay[i]+now.y;
					if(nx<0||nx>=121||ny<0||ny>=121){
//						System.out.println("*");
						continue;
					}
					if(syougai[ny][nx])continue;
					q.add(new State(nx, ny, now.step+1));
				}
			}
			int cnt = 0;
			for(int i=0;i<121;i++)for(int s=0;s<121;s++)if(map[i][s]>=0)cnt++;
			System.out.println(cnt);
		}
		class State{
			int x,y,step;
			public State(int x,int y,int step) {
				this.x = x;
				this.y = y;
				this.step = step;
			}
		}
	}
}

Measured memory_bytes: 70772
a,b,c,d=map(int,input().split())
mod=998244353
dp=[[0]*(d+1) for i in range(c+1)]
for i in range(1,c+1):
  for j in range(1,d+1):
    if i>=a and j>=b:
      if i==a and j==b:
        dp[i][j]=1
      else:
        dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1))%mod
print(dp[i][j])

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
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++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll N; cin >> N;
    ll h, n, w;
    rep1(i, 3500){
        rep1(j, 3500){
            ll u = N*i*j;
            ll d = 4*i*j - i*N - j*N;
            if(d <= 0) continue;
            if(u%d == 0){
                h = u/d;
                n = i;
                w = j;
            }
        }
    }

    cout << h << " " << n << " " << w << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main() {
  int a,b,c;
  int tmp;
  bool chk = false;
  
  cin >> a >> b >> c;
  
  for(int i = 1; i <= a*b; i++){
    if(a*i % b == c){
      chk = true;
      break;
    }
  }
  
  if(chk == true) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a.sort()
if n==2:
    print((a[0]+a[1])/2)
else:
    ans = []
    ans.append((a[0]+a[1])/2)
    for i in range(2,n):
        g = (ans[i-2]+a[i])/2
        ans.append(g)
    print(ans[-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 31
using namespace std;
#define double long double
const double EPS = 1e-4;
double x[N],y[N],z[N];
double A,B,C;

double dis(double x1,double y1,double z1,double x2,double y2,double z2){
  x1-=x2;
  y1-=y2;
  z1-=z2;
  return sqrt(x1*x1+y1*y1+z1*z1);
}


bool eq(double a,double b){
  return abs(a-b)< EPS;
}

int check(int i,int j,int k){
  double a = dis(x[i],y[i],z[i],x[j],y[j],z[j]);
  double b = dis(x[j],y[j],z[j],x[k],y[k],z[k]);
  double c = dis(x[k],y[k],z[k],x[i],y[i],z[i]);
  /*
  if(i == 0 && j==1 && k == 3){
    cout<<A/B<<" "<<B/C<<" "<<C/A<<endl;
    cout<<a/b<<" "<<b/c<<" "<<c/a<<endl;
  }
  */
  if(!eq(A/C,a/c))return 0;
  if(!eq(B/C,b/c))return 0;
  if(!eq(C/C,c/c))return 0;
  
  return 1;
}

signed main(){
  int q;
  cin>>q;
  
  while(q--){
    int n;
    cin>>A>>B>>C;
    cin>>n;


    for(int i=0;i<n;i++) cin>>x[i]>>y[i]>>z[i];

    int ans[3] = {};
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	for(int k=0;k<n;k++){
	  if(i==j || j==k || i==k)continue;
	  if(check(i,j,k)){
	    ans[0] = i+1;
	    ans[1] = j+1;
	    ans[2] = k+1;
	    //cout<<i<<":"<<j<<":"<<k<<endl;
	    break;
	  }
	}
    cout<<ans[2]<<" "<<ans[0]<<" "<<ans[1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3216
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

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

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, X, Y := sc.nextInt(), sc.nextInt()-1, sc.nextInt()-1
	G := make([][]int, N)
	for i := 0; i < N-1; i++ {
		G[i] = append(G[i], i+1)
		G[i+1] = append(G[i+1], i)
	}
	G[X] = append(G[X], Y)
	G[Y] = append(G[Y], X)
	q := &Queue{}
	bfs := func(cur int, D []int) {
		for i := 0; i < len(G[cur]); i++ {
			next := G[cur][i]
			if D[next] == -1 {
				D[next] = D[cur] + 1
				q.push(Node{next})
			}
		}
	}
	set := make(map[int]int)
	for i := 0; i < N; i++ {
		D := make([]int, N)
		for i := 0; i < N; i++ {
			D[i] = -1
		}
		D[i] = 0
		q.push(Node{i})
		for !q.isEmpty() {
			bfs(q.pop().id, D)
		}
		for i := 0; i < N; i++ {
			set[D[i]]++
		}
	}
	for i := 1; i < N; i++ {
		fmt.Fprintln(wtr, set[i]/2)
	}
}

type Node struct {
	id int
}

type Queue struct {
	arr []Node
}

func (q *Queue) push(v Node) {
	q.arr = append(q.arr, v)
}

func (q *Queue) pop() Node {
	res := q.arr[0]
	q.arr = q.arr[1:]
	return res
}

func (q *Queue) isEmpty() bool {
	return len(q.arr) == 0
}


Measured memory_bytes: 7552
n=int(input())
a=[0]*n
for  i in range(n):
    a[i]=int(input())
a.sort(reverse=True)
ans=0
aupper=a[:n//2]
adowner=a[n//2:]
if len(a)==2:print(a[0]-a[1])
elif len(a)==3:
    print(max(sum(a[:n-1])-a[n-1]*2,a[0]*2-sum(a[1:])))
elif n%2==1:
    ans1=0;ans2=0
    for i in range(n//2):
        ans1+=aupper[i]*2-(adowner[i]+adowner[i+1])
    ans1+=(adowner[1]-adowner[-1])
    a=a[::-1]
    adowner=a[:n//2]
    aupper=a[n//2:]
    for i in range(n//2):
        ans2+=aupper[i]+aupper[i+1]-adowner[i]*2
    ans2+=aupper[-1]-aupper[1]
    print(max(ans1,ans2))
else:
    ans=0
    for i in range(n//2):
        if i!=n//2-1:
            ans+=aupper[i]*2-(adowner[i]+adowner[i+1])
        else:
            ans+=aupper[i]-adowner[i]
    print(ans)

Measured memory_bytes: 8488
#include<stdio.h>
#include<ctype.h>
#include<string.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  int f=0;
  int g=0;
  char A[201];
  char A2;
  while(1){
    scanf("%s",&A);
    if(A[0]=='-')break;
    scanf("%d",&a);
    for(b=0;b<a;b++){
      scanf("%d",&c);
      f=c-1;
      g=c-2;
      for(d=c;d>0;d--){
	for(e=strlen(A)-c;e>0;e--){
	  A2=A[f];
	  A[f]=A[f+1];
	  A[f+1]=A2;
	  f=f+1;
	}
	f=g;
	g=g-1;
      }
      f=0;
    }
    printf("%s\n",A);
  }
  return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int n[4];
	cin >> n[0] >> n[1] >> n[2] >> n[3];
	sort(n, n + 4);
	
	if (n[0] = 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))[::-1]
dp = [b[0] for _ in range(n)]
for i in range(1,n):
    dp[i] = dp[i-1]+b[i]
dp = dp[::-1]
c = 0
dp2 = [0 for _ in range(n)]
for i in range(n):
    c += a[i]
    dp2[i] = c +dp[i]
print(max(dp2))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int Rmin=1000000,Lmax=0,buff;
		for(int i=0;i<m;i++) {
			buff=sc.nextInt();
			if(buff>Lmax) {
				Lmax=buff;
			}
			buff=sc.nextInt();
			if(buff<Rmin) {
				Rmin=buff;
			}
		}
		System.out.println(Math.max(0, Rmin-Lmax+1));

	}
}




Measured memory_bytes: 65676
/**
 * Author: PraveenKumarRana
**/

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

void solve(){
    int n,k; cin>>n>>k; 
    vector<int> h(n);
    for(int&x :h) cin>>x;
    vector<int> dp(n,1e9+5);
    dp[0]=0; 
    for(int i=0; i<n; i++){
        for(int j=i+1; j<i+k+1; j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}



Measured memory_bytes: 1024