akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  string s; cin >> s;
  int num[26]; CLR(num);
  FOR(i,0,s.length()) num[s[i]-'a']++;
  FOR(i,0,26) {
    if(num[i] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int a[3] ;

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

	for (int i = 0 ; i < 3 ; i ++) {
		cin >> a[i] ;
		if (!(a[i] & 1)) return cout << "0\n" , 0 ;
	}

	sort(a , a + 3) ;

	cout << 1ll * a[0] * a[1] << '\n' ;
}


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

int main() {
  int N, sum = 0, prev_eat = 0;
  vector<int> A;
  vector<int> B;
  vector<int> C;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    A.push_back(x);
  }
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    B.push_back(x);
  }
  for (int i = 0; i < N - 1; ++i) {
    int x;
    cin >> x;
    C.push_back(x);
  }
  for (int i = 0; i < N; ++i) {
    sum += B[A[i] - 1];
    if (prev_eat + 1 == A[i]) {
      sum += C[prev_eat - 1];
    }
    prev_eat = A[i];
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll H, W;
ll N;
queue<ll> A;

int main() {
	cin >> H >> W;
	cin >> N;
	for (ll n = 1; n <= N; n++) {
		ll a;
		cin >> a;
		A.push(a);
	}
	vector<vector<ll>> ans(H, vector<ll>(W, 0));
	ll n = 1;
	for (ll y = 0; y < H; y++) {
		for (ll x = 0; x < W; x++) {
			ans[y][x] = n;
			A.front()--;
			if (A.front() == 0) {
				A.pop();
				n++;
			}
		}
	}
	for (ll y = 0; y < H; y++) {
		if (y & 1) {
			for (ll x = W - 1; x >= 0; x--)cout << ans[y][x] << " ";
		}
		else {
			for (ll x = 0; x < W; x++)cout << ans[y][x] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

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

    double l;
    cin >> l;

    double a=l/3.0;
    cout << fixed << setprecision(7) << a*a*a;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();
      	boolean ok = d <= s * t;
		System.out.println(ok? "Yes" : "No");
	}
}

Measured memory_bytes: 35836
#include <iostream>

using namespace std;

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

    int aa = A + A - 1;
    int ab = A + B;
    int bb = B + B - 1;
    
    if (aa > ab) {
        cout << max(aa, bb);
    } else {
        cout << max(ab, bb);
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n;
    cin>>n;
    bool answer=true;
    while(n--){
        int tmp;
        cin>>tmp;
        if(tmp%2==0 && tmp%3!=0 && tmp%5!=0) answer=false;
    }
    if(answer) cout<<"APPROVED";
    else cout<<"DENIED";

    return 0;
}


Measured memory_bytes: 256
import math

def distance(D, X, Y):
    ans = 0.0
    for i in range(D):
        ans += (X[i]-Y[i])*(X[i]-Y[i])
    return math.sqrt(ans)

def isInteger(n):
    return (n // 1) == n

N, D = map(int,input().split())
X = []
cnt = 0
for i in range(N):
    X.append(list(map(int,input().split())))
for i in range(N):
    for j in range(i+1, N):
        temp = distance(D, X[i], X[j])
        if isInteger(temp):
            cnt += 1
print(str(cnt))

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

class Main{
	static int N;
	static int[] a;

	static long[][][] memo;
	static boolean[][][] flag;

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

		a = new int[N];
		memo = new long[2][N][N];
		flag = new boolean[2][N][N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			Arrays.fill(flag[0][i], false);
			Arrays.fill(flag[1][i], false);
		}

		System.out.println(dp(0, 0, 0));
		sc.close();
	}

	static long dp(int i, int x, int y) {
		if(x + y == N) {
			return 0;
		}
		if(flag[i][x][y]) {
			return memo[i][x][y];
		}
		flag[i][x][y] = true;

		long r;
		if(i == 0) {
			memo[i][x][y] = dp(1, x + 1, y) + a[x];
			r = dp(1, x, y + 1) + a[N - y - 1];
			if(memo[i][x][y] < r)
				memo[i][x][y] = r;
		}
		else {
			memo[i][x][y] = dp(0, x + 1, y) - a[x];
			r = dp(0, x, y + 1) - a[N - y - 1];
			if(memo[i][x][y] > r)
				memo[i][x][y] = r;
		}

		return memo[i][x][y];
	}
}

Measured memory_bytes: 250324
data = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())

for nc in range(n):
    (b,f,r,v) = [int(i) for i in input().split()]
    data[b - 1][f - 1][r - 1] += v



for b in range(4):
    for f in range(3):
        for r in range(10):
            print('',data[b][f][r], end='')
        print()
    print('#' * 20) if b < 4 - 1 else print(end='')

Measured memory_bytes: 6724
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int max = 0;

		for (int i = 0; i <= s.length() - t.length(); i++) {
			int match = 0;
			for (int j = 0; j < t.length(); j++) {
				if (t.charAt(j) == s.charAt(i + j)) {
					match++;
				}
			}
			if (max < match) {
				max = match;
			}
		}
		System.out.println(t.length() - max);
	}
}

Measured memory_bytes: 35656
#include<bits/stdc++.h>
using namespace std;
const int N=205;
int n,m,f[2][N][N][N],a[N][N];
bool check(int j,int k,int l,int r){
	int x=(k-j+1)*(r-l+1),y=a[k][r]-a[j-1][r]-a[k][l-1]+a[j-1][l-1];
	return (!y || x==y);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){
		char c; scanf(" %c",&c);
		a[i][j]=(c=='#')+a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	}
	for(int x=0;x<2;x++) for(int j=1;j<=n+1;j++)
		for(int l=1;l<=m;l++) f[x][j][j-1][l]=N;
	for(int j=1;j<=n;j++) for(int k=j;k<=n;k++){
		for(int l=m;l;l--){
			if(l==m) f[0][j][k][l]=m;
			else f[0][j][k][l]=f[0][j][k][l+1];
			while(!check(j,k,l,f[0][j][k][l])) f[0][j][k][l]--;
			//cout<<j<<" "<<k<<" "<<l<<" "<<f[0][j][k][l]<<endl;
		}
	}
	//return 0;
	for(int i=1;;i++){
		int x=(i&1);
		if(f[!x][1][n][1]==m){
			cout<<i-1<<endl; return 0;
		}
		for(int j=1;j<=n;j++) for(int k=j;k<=n;k++)
			for(int l=1;l<=m;l++) f[x][j][k][l]=f[!x][j][k][f[!x][j][k][l]+1];
		for(int j=1;j<=n;j++) for(int l=1;l<=m;l++){
			for(int k=j,p=j;k<=n;k++){
				while(p<k && min(f[!x][j][p][l],f[!x][p+1][k][l])<=min(f[!x][j][p+1][l],f[!x][p+2][k][l])) p++;
				f[x][j][k][l]=max(f[x][j][k][l],min(f[!x][j][p][l],f[!x][p+1][k][l]));
			}
		}
	}
	return 0;
}


Measured memory_bytes: 65408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    reverse(a,a+n);
    vector<int> dp(n+1,inf);
    rep(i,n){
        int idx = upper_bound(dp.begin(),dp.end(),a[i])-dp.begin();
        dp[idx]=a[i];
    }
    for(int i = n; i>=0; --i){
        if(dp[i]!=inf){
            cout<<i+1<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1024
f=input
n,s,q=int(f()),list(f()),int(f())
d={chr(97+i):[] for i in range(26)}
for i in range(n):
  d[s[i]]+=[i]
from bisect import *
for i in range(q):
  a,b,c=f().split()
  b=int(b)-1
  if a=='1':
    if s[b]==c: continue
    d[s[b]].pop(bisect(d[s[b]],b)-1)
    s[b]=c
    insort(d[c],b)
  else:
    t=0
    for l in d.values():
      m=bisect(l,b-1)
      if m<len(l) and l[m]<int(c): t+=1
    print(t)

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

signed main()
{
	ll n,k;
	cin >> n >> k;
	ll ans = 0;
	
		if(1)
		{
			ans += (n/k)*(n/k)*(n/k);
		}
		if(k%2==0)
		{
			ans += (n/k+(n%k<k/2?0:1))*(n/k+(n%k<k/2?0:1))*(n/k+(n%k<k/2?0:1));
		}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque

n,m = map(int,input().split())
edge = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
    
v = [-1 for i in range(n)]
v[0]=0
q = deque()
q.append(0)
while len(q) > 0:
    x = q.popleft()
    for y in edge[x]:
        if v[y]!=-1:
            continue
        q.append(y)
        v[y] = x

print("Yes")
for i in range(1,n):
    print(v[i]+1)
        

Measured memory_bytes: 33996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

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

        string aStr = a.ToString();
        string bStr = b.ToString();

        string ast = string.Empty;
        string bst = string.Empty;
        for (int i = 0; i < a; ++i)
        {
            bst += bStr;
        }
        for (int i = 0; i < b; ++i)
        {
            ast += aStr;
        }

        int aint = int.Parse(ast);
        int bint = int.Parse(bst);

        WriteLine(a<b?ast:bst);
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 100000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int cnt=0;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=(n/i + 1);j++)
       {
           if((n-(i*j))>=1)cnt++;
       }
   }
   cout<<cnt<<endl;
}


Measured memory_bytes: 3668
#include<iostream>
#include<cstdio>
#include<cmath>
#include<stdio.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        
        if(n == 0) break;
        
        int P[n];
        double sum = 0;
        double sum2 = 0;
        double m;
        
        for(int i = 0; i < n; i++){
            P[i] = 0;
        }
        
        for(int j = 0; j < n; j++){
            int p;
            cin >> p;
            P[j] = p;
            sum += p;
        }
        
        m = sum /n;
        
        for(int k = 0; k < n; k++){
            sum2 += pow(P[k] - m, 2);
        }
        
        double a = sqrt(sum2 / n);
        printf("%.8f\n", a);
    }
    
    return 0;
}



Measured memory_bytes: 3152
# -*- coding: utf-8 -*-
def main():
    S = list(input())
    #print(S)
    SS = set(S)
    #print(SS)
    #print(len(SS))
    if len(SS)==2:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
template <typename T>
using Vector = vector<vector<T>>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

const lli mod = 1E9 + 7;

void solve() {
	int n, t;
	cin >> n >> t;

	vector<pii> dish(n + 1, {0, 0});
	for (int i = 1; i <= n; ++i) {
		cin >> dish[i].X >> dish[i].Y;
	}

	sort(ALL(dish));

	int dp[n + 1][t + 1], maxAns = 0;
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i < n; ++i) {
		for (int j = 1; j < t; ++j) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (j >= dish[i].X) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - dish[i].X] + dish[i].Y);
			}
			// printf("dp[%d][%d]: %d\n", i, j, dp[i][j]);
		}
		dp[i][t] = dish[i + 1].Y + dp[i][t - 1];
		// printf("dp[%d][%d]: %d\n", i, t, dp[i][t]);
		maxAns = max(maxAns, dp[i][t]);
	}

	cout << maxAns << "\n";
}

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

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int n,k,a[N],p[N];
struct Treap{
	int v,Min,ran;
	Treap *lc,*rc;
	Treap(int val){Min=v=val;lc=rc=0;ran=rand();}
	void update(){
		Min=v;
		if (lc) Min=min(Min,lc->Min);
		if (rc) Min=min(Min,rc->Min);
	}
}*T;
Treap *merge(Treap *x,Treap *y){
	if (!x) return y;
	if (!y) return x;
	if (x->ran>y->ran){
		x->rc=merge(x->rc,y);
		x->update();
		return x;
	}
	else{
		y->lc=merge(x,y->lc);
		y->update();
		return y;
	}
}
void split(Treap *x,Treap *&lt,Treap *&rt,int key){
	if (!x) return void(lt=rt=0);
	if (x->rc&&x->rc->Min<key){
		split(x->rc,lt,rt,key);
		x->rc=lt;
		(lt=x)->update();
	}
	else if (x->v<key){
		rt=x->rc;
		x->rc=0;
		(lt=x)->update();
	}
	else{
		split(x->lc,lt,rt,key);
		x->lc=rt;
		(rt=x)->update();
	}
}
void visit(Treap *x){
	static int cnt=0;
	if (!x) return;
	visit(x->lc);
	p[++cnt]=x->v;
	visit(x->rc);
}
int main()
{
	srand((unsigned)time(0));
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),p[a[i]]=i;
	for (int i=1;i<=n;i++){
		Treap *lt,*rt;
		split(T,lt,rt,p[i]+k);
		T=merge(merge(lt,new Treap(p[i])),rt);
	}
	visit(T);
	for (int i=1;i<=n;i++) a[p[i]]=i;
	for (int i=1;i<=n;i++) printf("%d\n",a[i]);
	return 0;
}

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

int n, c;
int d[30][39];
int t[3][30];

int main()
{
  cin >> n >> c;
  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      cin >> d[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      ++t[(i + j)%3][x -1];
    }
  }

  int res = 1 << 30;

  for (int i = 0; i < c; i++) {
    for (int j = 0; j < c; j++) {
      if (i == j) {
        continue;
      }
      for (int k = 0; k < c; k++) {
        if (i == k || j == k) {
          continue;
        }
        int tt = 0;
        for (int l = 0; l < c; l++) {
          tt += d[l][i] * t[0][l];
        }
        for (int l = 0; l < c; l++) {
          tt += d[l][j] * t[1][l];
        }
        for (int l = 0; l < c; l++) {
          tt += d[l][k] * t[2][l];
        }
        if (tt < res) {
          res = tt;
        }
      }
    }
  }

  cout << res << endl;
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) ((n)*(n))

using namespace std;
using ll = long long;
const int INF = 1e9 + 5;

int main() {
    FAST;

    int n, k, i, j;
    cin >> n >> k;

    vector<int> h(n), dp(n, INF);
    for (i = 0; i < n; ++i) cin >> h[i];
    dp[0] = 0;

    for (i = 0; i < n; ++i) {
        for (j = i+1; j <= i+k; ++j) {
            if (j >= n) break;
            dp[j] = min(dp[j], dp[i]+abs(h[j]-h[i]));
        }
    }

    cout << dp[n-1] << "\n";

    return 0;
}


Measured memory_bytes: 1024
n=int(input())
s=int((n)**(1/2))+1
#print(s)

for i in range(s+1,0,-1):
    if n%i==0:
        l=i
        break
#print(l)
r=n//l
l=str(l)
r=str(r)
print(max(len(l),len(r)))

Measured memory_bytes: 3060
#include<stdio.h>
#include<string>
#include<iostream>

void max_heapify(int* A, int i, int H)
{
    int l = 2 * i, r = 2 * i + 1;
    if(l > H && r > H) return;
    int maxid = i;
    if(l <= H){ if(A[l] > A[maxid]) maxid = l; }
    if(r <= H){ if(A[r] > A[maxid]) maxid = r; }
    if(maxid == i) return;
    std::swap(A[maxid], A[i]);
    max_heapify(A, maxid, H);
}

int main()
{
    int A[2000001];
    int i, H, key;
    char cmd[8];
    scanf("%d", &H);
    for(i = 1; i <= H; i++) scanf("%d", &A[i]);
    H = 0;

    while(1){
        scanf("%s", cmd);  
        if(cmd[2] == 'd') break;  // end.
        if(cmd[0] == 'e'){  // extract.
            if(H == 0) continue;
            printf("%d\n", A[1]);
            A[1] = A[H]; H--;
            if(H > 0) max_heapify(A, 1, H);
        }else{
            scanf("%d", &key); // H++;   // insert key.
            i = ++H;
            while(i > 1){
                if(A[i / 2] > key) break;
                A[i] = A[i / 2];
                i /= 2;
            };
            A[i] = key;
        }
    };
    return 0;
}

Measured memory_bytes: 6936
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll h,w,n;
  cin >> h >> w >> n;
  P a[n];
  set<P> s;
  rep(i,n) {
    cin >> a[i].F >> a[i].S;
    a[i].F--;
    a[i].S--;
    s.insert(a[i]);
  }
  ll z=(h-2)*(w-2);
  set<P> d[10];
  rep(i,n) {
    rep(ii,3) {
      rep(jj,3) {
        int xx=a[i].F-ii,yy=a[i].S-jj,cnt=0;
        if(!check(h,w,xx,yy)) continue;
        bool f=1;
        rep(j,3) {
          rep(k,3) {
            int x=xx+j,y=yy+k;
            if(check(h,w,x,y)) cnt+=s.count(P(x,y));
            else f=0;
          }
        }
        if(f) d[cnt].in(P(xx,yy));
      }
    }
  }
  rep(i,10) z-=d[i].size();
  pr(z);
  REP(i,1,10) pr(d[i].size());
}

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


Measured memory_bytes: 47872
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
x = b[0]-a[0]
y = c[0]-a[0]
if ((b[1]-a[1])==x)and((b[2]-a[2])==x)and((c[1]-a[1])==y)and((c[2]-a[2])==y):
    print("Yes")
else:print("No")

Measured memory_bytes: 3064
/*
	与えられた3辺の数値から、直角三角形かどうかを判別するプログラム
*/

#include<stdio.h>
	
int main(void){
	int n;
	int i;
	int x,y,z;
	
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d %d %d",&x ,&y ,&z);
		if( (x*x+y*y==z*z) || (y*y+z*z==x*x) || (z*z+x*x==y*y) ){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 580
package main

import "fmt"

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func two_entries_unless_zero(m map[int]int) bool {
	for k, v := range m {
		if k != 0 && v != 2 {
			return false
		}
	}
	return true
}

func same_parity(m map[int]int) bool {
	parity := make([]int, 0)
	for k := range m {
		parity = append(parity, k%2)
	}
	for i := 0; i < len(parity)-1; i++ {
		if parity[i] != parity[i+1] {
			return false
		}
	}
	return true
}

func pow(a, b int) int {
	if b == 0 {
		return 1
	}
	return pow(a, b-1) * a % 1000000007
}

func solve(m map[int]int) int {
	l := len(m)
	if m[0] > 0 {
		return pow(2, l-1)
	}
	return pow(2, l)
}

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}

	counter := make(map[int]int)
	for _, a := range as {
		counter[a]++
	}

	if counter[0] > 1 || !two_entries_unless_zero(counter) || !same_parity(counter) {
		fmt.Println(0)
	} else {
		fmt.Println(solve(counter))
	}
}


Measured memory_bytes: 9216
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x: u16,
        y: u16,
    }

    for i in 0..x + 1 {
        if 2 * i + 4 * (x - i) == y {
            println!("Yes");
            return;
        }
    }
    println!("No");
}


Measured memory_bytes: 2088
import math
h, w = [int(item) for item in input().split()]
a = (math.ceil(h/3) - int(h/3)) * w
b = (math.ceil(w/3) - int(w/3)) * h
c1 = sorted([int(w/3)*h, int(h/2)*(w-int(w/3)), math.ceil(h/2)*(w-int(w/3))])
c2 = sorted([math.ceil(w/3)*h, int(h/2)*(w-math.ceil(w/3)), math.ceil(h/2)*(w-math.ceil(w/3))])
d1 = sorted([int(h/3)*w, int(w/2)*(h-int(h/3)), math.ceil(w/2)*(h-int(h/3))])
d2 = sorted([math.ceil(h/3)*w, int(w/2)*(h-math.ceil(h/3)), math.ceil(w/2)*(h-math.ceil(h/3))])
c = min(c1[-1] - c1[0], c2[-1] - c2[0])
d = min(d1[-1] - d1[0], d2[-1] - d2[0])
print(min(a, b, c, d))

Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))

count4=0
count2=0
for i in range(n):
    if a[i]%4==0: count4+=1
    elif a[i]%2==0: count2+=1

count=count4+count2//2
must=n//2

if count>=must: print("Yes")
else: print("No")

Measured memory_bytes: 15020
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    long long int h;
    cin >> h;
    
    long long int cnt = 1;
    long long int numofmoster = 1;
    h = h / 2;
    numofmoster *= 2;
    //cout << h << "," << cnt << "," << numofmoster << endl;
    while(h>0){
        h = h / 2;
        cnt += numofmoster;
        numofmoster *= 2;
        //cout << h << "," << cnt << "," << numofmoster << endl;
    }
    cout << cnt << endl;
    return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int r, d,x; cin >> r >> d >> x;
    vi ans;
    for(int i = 0; i < 10; i++) {
        int p = r*x - d;
        ans.emplace_back(p);
        x = p;
    }
    for(auto i : ans) cout << i << '\n';

    // printf("ExcutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int n,k,x,y; cin >> n >> k >> x >> y;
	int result = (n > k) ? k * x + (n-k) * y : n * x;
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A;
  cin >> N >> A;
  
  // 1 <= N <= 10000   
  // 0 <= A <= 1000    ¥1
 
  int n = N/500;
  int r = N%500;
  
  if (r <= A){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }
  return 0;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;


int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<p> lr(m);
  for (int i = 0; i < m; i++) {
    cin >> lr[i].first >> lr[i].second;
    // lr[i].first--;
    // lr[i].second--;
  }
  vector<p> query(q);
  for (int i = 0; i < q; i++) {
    cin >> query[i].first >> query[i].second;
    // query[i].first--;
    // query[i].second--;
  }
  vector<vector<int>> area(n+1, vector<int>(n+1, 0));
  for (int i = 0; i < m; i++) {
    int start = lr[i].first;
    int goal = lr[i].second;
    area[start][goal]++;
  }
  // print(area);

  for (int i = 0; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      area[i][j] += area[i][j-1];
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      area[j][i] += area[j-1][i];
    }
  }

  // print(area);
  for(auto a : query){
    int minv = min(a.first, a.second);
    int maxv = max(a.first, a.second);
    int res = area[maxv][maxv] + area[minv-1][minv-1];
    // cout << res << endl;
    res -= (area[maxv][minv-1] + area[minv-1][maxv]);
    cout << res << endl;
    // cout << "====" << endl;
  }
}


Measured memory_bytes: 4224
import java.util.*;
class Main {

	
	
		public static void main(String[] args) {
			Scanner Cf=new Scanner(System.in);
				
				int[] A=new int[3];
				 A[0]=Cf.nextInt();
				 A[1]=Cf.nextInt();
				 A[2]=Cf.nextInt();
				
				
				
				Solver(A);
				Cf.close();
			}
		
		
		public static void Solver(int[] A) {
		
			Arrays.sort(A);
			int diff=0;
			for(int i=1;i<A.length;i++) {
				diff=Math.abs(A[i]-A[i-1])+diff;
			}
			System.out.println(diff);
		}
	

	}


Measured memory_bytes: 22868
import Data.Functor((<$>))
import Text.Printf(printf)
 
main :: IO ()
main = do
        q  <- read.last.words <$> getLine
        xs <- map ((\[n, t] -> (n, read t)).words).lines <$> getContents
        solve xs [] q 0
 
solve                        :: [(String, Int)] -> [(String, Int)] -> Int -> Int -> IO ()
solve []            []  _ _  = return ()
solve []            ys q cnt = solve (reverse ys) [] q cnt 
solve ((n, t) : xs) ys q cnt = let t'   = t - q
                                   cnt' = cnt + q
                                   m    = cnt' + t'
                               in if t' > 0 then solve xs ((n, t') : ys) q cnt'
                                            else printf "%s %d\n" n m >> solve xs ys q m

Measured memory_bytes: 13416
#include<bits/stdc++.h>
using namespace std;
int g(int a,int b){
  if(a>b)
    return g(b,a);
  if(a==0)
    return b;
  return g(b%a,a);
}
int main(){
  int a,b,k;
  cin>>a>>b>>k;
  int c=0;
  for(int i=g(a,b);c<k;i--){
    if(g(a,b)%i==0)
      c++;
    if(c==k)
      cout<<i<<endl;
  }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = [0, 2, 5, 5, 4, 5 ,6, 3, 7, 6]
dp = ["" for i in range(N+30)]
for i in range(N):
    if i!=0 and dp[i]=="":
        continue
    for a in A:
        tmpscore = dp[i]+str(a)
        if len(dp[i+num[a]]) < len(tmpscore):
            dp[i+num[a]] = tmpscore
        elif len(dp[i+num[a]]) > len(tmpscore):
            continue
        else:
            dp[i+num[a]] = max(dp[i+num[a]], tmpscore)
print(dp[N])

Measured memory_bytes: 30196
package main

import (
	"fmt"
)

func main() {
	var N int
	var T int
	var now int
	var total int = 0
	var during int = 0

	fmt.Scan(&N)
	fmt.Scan(&T)

	for i := 0; i < N; i++ {
		fmt.Scan(&now)
		if during <= now {
			total += T
			during = now + T
		} else {
			total += T - (during - now)
			during = now + T
		}
	}

	fmt.Println(total)
}


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

int main() {
    long n, capacity, capacity_min = 0;
    cin >> n;
    for (int i=0; i<5; i++) {
        cin >> capacity; 
        capacity_min = (capacity_min != 0 ? min(capacity_min, capacity): capacity);
    }
    long result = n%capacity_min == 0 ? n/capacity_min+4 : n/capacity_min+5;
    cout << result << endl;
}

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

int cost(int i,int j,int x,int y){return abs(i-x)+abs(j-y);}

int main(void){
	int H,W,D,Q,i,j;
	scanf("%d%d%d",&H,&W,&D);
	int xy[90001][2]={0},d[90001]={0};
	for(i=1;i<=H;i++){
		for(j=1;j<=W;j++){
			int a;
			scanf("%d",&a);
			xy[a][0] = i;
			xy[a][1] = j;
		}
	}
	for(i=D+1;i<=H*W;i++){
		d[i] = d[i-D] + cost(xy[i][0],xy[i][1],xy[i-D][0],xy[i-D][1]);
	}
	scanf("%d",&Q);
	while(Q--){
		int L,R;
		scanf("%d%d",&L,&R);
		printf("%d\n",d[R]-d[L]);
	}
	
	return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
	int K,A,B,i;
	char str[1000];
 
	fgets(str, sizeof(str), stdin);
	
	if(strncmp(str,"ABC",3) ==0){
		printf("ARC\n");
	}else{
		printf("ABC\n");
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  for(int i=0; i<N; i++){
    cin >> v.at(i);
  }

  sort(v.begin(), v.end());
  stack<double> bord;
  for(int i=N-1; i>=0; i--){
    bord.push(v.at(i));
  }

  while(bord.size() > 1){
    double first = bord.top();
    bord.pop();
    double second = bord.top();
    bord.pop();
    double alchemy = (first + second) / 2;
    bord.push(alchemy);
  }

  double ans = bord.top();

  cout << fixed << setprecision(7);
  cout << ans << endl;
}

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

int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for (int i = 0; i <= a;) {
        for (int j = 0; j <= b;) {
            for (int k = 0; k <= c;) {
                if (500*i+100*j+50*k == x) {
                    count++;
                    k = c+1;
                }
                else k++;
            }
            j++;
        }
        i++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }




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

	long double psum = 0;
	rep(i, n) {
		int s = i + 1;
		int c = 0;
		while (s < k) {
			c++;
			s *= 2;
		}
		psum += pow(0.5, c);
	}

	cout << setprecision(20) << psum / n << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n; cin >> n;
    bitset<20> mask;
    int k; cin >> k;
    for(int i=0; i<k; ++i){
        int b; cin >> b;
        mask|=(1<<b);
    }
    for(int i=0; i<(1<<n); ++i){
        
        bitset<20> bit(i);
        vector<int> S;
        for(int j=0; j<n; ++j){
            if(i & (1<<j) && ((bit&mask)==mask)){
                S.push_back(j);
            }
        }
        if(S.size()==0&&mask.any()) continue;
        cout << i << ":";
        for(int j=0; j<S.size(); ++j){
            cout << " " << S[j];
        }
        cout << endl;
    }
	return 0;
}


Measured memory_bytes: 3220
N = int(input())
A = list(map(int, input().split()))
num = 0
flag = False
while True:
    for a in A:
        if a%2==1:
            flag = True
    
    if flag == True:
        break

    for i in range(len(A)):
        A[i] /= 2
    num+=1

print(num)

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

int main(void) {
    int H, W;
    cin >> H >> W;
    bool s[110][110];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c;
            cin >> c;
            s[i][j] = (c == '.');
        }
    }
    int d[100][100];
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = 0;
        }
    }
    d[0][0] = s[0][0] ? 0 : 1;
    for (int i = 1; i < W; i++) {
        d[0][i] = d[0][i - 1];
        if (!s[0][i] && s[0][i - 1]) {
            ++d[0][i];
        }
    }
    for (int i = 1; i < H; i++) {
        d[i][0] = d[i - 1][0];
        if (!s[i][0] && s[i - 1][0]) {
            ++d[i][0];
        }
    }
    for (int i = 1; i < H; i++) {
        for (int j = 1; j < W; j++) {
            d[i][j] = min(d[i - 1][j], d[i][j - 1]);
            int cand_r = d[i - 1][j], cand_c = d[i][j - 1];
            if (!s[i][j]) {
                if (s[i - 1][j]) {
                    ++cand_r;
                }
                if (s[i][j - 1]) {
                    ++cand_c;
                }
            }
            d[i][j] = min(cand_r, cand_c);
        }
    }
    printf("%d\n", d[H - 1][W - 1]);
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<cstdio>
#define LL long long
#define Re register int
using namespace std;
const int N=303,P=1e9+7;
int n,m,cnt1,cnt2,ok[N<<1],vis[N<<1],A[N<<1],B[N<<1],dp[N<<1][N][N];
inline void in(Re &x){
    int f=0;x=0;char c=getchar();
    while(c<'0'||c>'9')f|=c=='-',c=getchar();
    while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
    x=f?-x:x;
}
int main(){
//	freopen("123.txt","r",stdin);
	in(n);
	for(Re i=1;i<=(n<<1);++i)in(A[i]);
	for(Re i=1;i<=(n<<1);i+=2)
		if(A[i]==-1&&A[i+1]==-1)++cnt1;
		else if(A[i]>0&&A[i+1]>0)vis[A[i]]=vis[A[i+1]]=1;
		else ++cnt2,ok[A[i]>0?A[i]:A[i+1]]=1;
	for(Re i=(n<<1);i>=1;--i)if(!vis[i])B[++m]=i;
	dp[0][0][0]=1;
	for(Re i=1;i<=m;++i)
		for(Re j=0;j<=cnt1+cnt2;++j)
			for(Re k=0;k<=cnt2;++k)if(dp[i-1][j][k]){
				if(ok[B[i]]){
					(dp[i][j][k+1]+=dp[i-1][j][k])%=P;
					if(j)(dp[i][j-1][k]+=dp[i-1][j][k])%=P;
				}
				else{
					(dp[i][j+1][k]+=dp[i-1][j][k])%=P;
					if(j)(dp[i][j-1][k]+=dp[i-1][j][k])%=P;
					if(k)(dp[i][j][k-1]+=(LL)k*dp[i-1][j][k]%P)%=P;
				}
			}
	Re ans=dp[m][0][0];
	for(Re i=1;i<=cnt1;++i)ans=(LL)ans*i%P;
	printf("%d\n",ans);
}

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

int main() {
	int n, m;
	int a;
	cin >> n;
	vector<int> p(2*n);
	for (int i = 0; i < 2*n; i++) {
		p[i] = i+1;
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> a;
		if (a == 0) {
			vector<int> r;
			for (int j = 0; j < n; j++) {
				r.push_back(p[j]);
				r.push_back(p[j+n]);
			}
			p = r;
		} else {
			vector<int> q;
			for (int j = a; j < 2*n; j++) {
				q.push_back(p[j]);
			}
			for (int j = 0; j < a; j++) {
				q.push_back(p[j]);
			}
			p = q;
		}
	}
	for (int i = 0; i < 2*n; i++) {
		cout << p[i] << endl;
	}
	return 0;
}

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

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

    long int count,reg;
    count = N/(A+B);
    reg = N%(A+B);

    if(reg<=A)
    {
        count = count*A + reg;
    }
    else
    {
        count = (count+1)*A;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <limits>
 
using namespace std;
 
int main() {
    unsigned long long a;
    unsigned long long N;
    unsigned long long count = numeric_limits<unsigned long long>::max();
 
    cin >> N;
 
    for (unsigned long i = 1; i <= sqrt(N); i++) {
        if (N % i == 0) {
            a = (unsigned long long)(i + N / i - 2);
            if (count > a) {
                count = a;
            }
 
        }
    }
 
    cout << count;
 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int main() {
	int n, a[100],ans;
	float sum = 0,min=101.0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	for (int i = 0; i < n; i++) {
		if (fabs(a[i] - sum) == min)continue;
		if (fabs(a[i] - sum) < min){
          	min = fabs(a[i] - sum);
			ans = i;

        }
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.*;

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

  private void run() {
    while(sc.hasNext()) {
      final int n = sc.nextInt();

      if(n == 0) break;

      int[][] table = new int[n + 1][n + 1];

      for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
          table[i][j] = sc.nextInt();
        }
      }

      for(int i = 0; i < n; i++) {
        table[i][n] = 0;
        for(int j = 0; j < n; j++) {
          table[i][n] += table[i][j];
        }
      }

      for(int i = 0; i <= n; i++) {
        table[n][i] = 0;
        for(int j = 0; j < n; j++) {
          table[n][i] += table[j][i];
        }
      }

      for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= n; j++) {
          System.out.printf("%5d", table[i][j]);
        }
        System.out.println();
      }
    }
  }

  private final Scanner sc = new Scanner(System.in);
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int K, A, B; cin >> K >> A >> B;

    FOR(i,A,B+1){
        if(i%K==0){
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
void read(int &n){
    int x=0,f=1;
	char ch=getchar();
    while (!isdigit(ch)){
    	if(ch=='-')f=-1;
		ch=getchar();
	}
    while (isdigit(ch)){
    	x=x*10+ch-'0';
		ch=getchar();
	}
    n=x*f;
}
void read(long long &n){
    long long x=0,f=1;
	char ch=getchar();
    while (!isdigit(ch)){
    	if(ch=='-')f=-1;
		ch=getchar();
	}
    while (isdigit(ch)){
    	x=x*10+ch-'0';
		ch=getchar();
	}
    n=x*f;
}
void read(char &n){
    do{
    	n=getchar();
	}while(n==' ');
}
int main(){
	int a,b,c;
	read(a);
	read(b);
	read(c);
	if(a-b==b-c)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm> 
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define skip continue
#define NAME "code"

using namespace std;

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

void faster(){
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
	cout.tie(NULL);
}

const int MAXN = 5e1 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

ll A, B, C, k;

int main(){
	faster();

	cin >> A >> B >> C >> k;
	if(k & 1) cout << B - A;
	else cout << A - B;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long int64;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

vector<P> cut(P cake, int s){
    int w = cake.first, d = cake.second;
    if(s > 2*w+2*d){
        return cut(cake, s-(2*w+2*d));
    }else if(s > w+d){
        return cut(cake, s-(w+d));
    }

    vector<P> res(2);
    if(s > w){
        s-=w;
        res[0] = mp(w, min(d-s, s));
        res[1] = mp(w, max(d-s, s));
    }else{
        res[0] = mp(min(w-s, s), d);
        res[1] = mp(max(w-s, s), d);
    }

    return res;
}


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

    int n, w, d;
    cin >> n >> w >> d;
    while(!(n==0 && w==0 && d==0)){
        
        vector<P> c;
        c.pb(mp(w, d));
        REP(i, n){
            int p, s;
            cin >> p >> s;
            p--;
            
            P cake = c[p];
            c.erase(c.begin() + p);
            vector<P> res = cut(cake, s);
            c.pb(res[0]); c.pb(res[1]);
        }
        multiset<int> area;
        REP(i, n+1){
            area.insert(c[i].first*c[i].second);
        }
        auto a = area.begin();
        REP(i, n+1){
            cout << *(a++) << (i==n ? "\n":" ");
        }
        cin >> n >> w >> d;
    }
    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>

int main(void) {
	int a, b, i;
	char s[11];
	
	scanf("%d %d",&a,&b);
	scanf("%s",s);
	
	for(i=0;i<a;i++){
		if(s[i]>=48&&s[i]<58);
		else {
			printf("No"); return 0;
		}
	}
	
	if(s[a] != '-'){
		printf("No");
		return 0;
	}
	
	for(i=0;i<b;i++){
		if(s[i+a+1]>=48&&s[i+a+1]<58);
		else {
			printf("No"); return 0;
		}
	}
	
	printf("Yes");
	
	return 0;
}


Measured memory_bytes: 128