akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] h = new int[N];
        int[] dp = new int[N];

        for(int i = 0; i < N ;i++){
            h[i] = Integer.parseInt(sc.next());
        }
        int j = 0;
        dp[0] = 0;
        dp[1] = Math.abs(h[1] - h[0]);
        for(j = 2; j < N  ;j++){
            int dp1 = Math.abs(h[j] - h[j -1]) +dp[j-1] ;
            int dp2 = Math.abs(h[j] - h[j -2]) + dp[j-2];;
            if(dp1 <= dp2){
                dp[j] = dp1 ;
            }else{
                dp[j] = dp2 ;
            }
        }
        System.out.println(dp[j-1]);       
    }

}

Measured memory_bytes: 49252
for i in range(9999999):
    a = list(map(int, input().split()))

    
    if a[0] == 0 and a[1] == 0:
        break

    if a[0] > a[1]:
        i = a[0]
        a[0] = a[1]
        a[1] = i
    print(a[0], a[1])



Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[310][310];
int x[100010], y[100010];
int d[100010];
int main()
{
	int H, W, D;
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A[i][j];
			x[A[i][j]] = j + 1;
			y[A[i][j]] = i + 1;
		}
	}
	for (int i = 1 + D; i <= H * W; i++) {
		d[i] = d[i - D] + abs(x[i] - x[i - D]) + abs(y[i] - y[i - D]);
	}
	int Q;
	cin >> Q;
	while (Q--) {
		int L, R;
		cin >> L >> R;
		cout << d[R] - d[L] << endl;
	}
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)){x=x*10ll+ch-'0';ch=getchar();}
	return x*f;
}
bitset<4000001> f;
int n,a[2010],_;
signed main(){
	n=read();
	f[0]=1;
	for (int i=1,x;i<=n;i++) x=read(),f|=(f<<x),_+=x;
	for (int i=_/2+(_%2?1:0);i<=_;i++){
		if (f[i]){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


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

#define INF 1234567890
#define ll long long
#define MOD 1000000007
#define inv2 500000004

int N, M, cnt = 0;
vector<int> g[200201];
bool vis[200201];

void DFS(int n)
{
	vis[n] = true; cnt++;
	for(int next : g[n])
	{
		if (vis[next]) continue;
		DFS(next);
	}
}

int main()
{
	scanf("%d %d", &N, &M);
	for(int i=0; i<M; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int res = 0;
	for(int i=1; i<=N; i++)
	{
		if (vis[i]) continue;
		cnt = 0;
		DFS(i);
		res = max(res, cnt);
	}
	printf("%d", res);
	return 0;
}

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

mt19937 rnd;
uniform_real_distribution<> dist01(0.0, 1.0);
double rnd01(){ return dist01(rnd);}

const double TIME_LIMIT = 1950;
double elapsed;
chrono::system_clock::time_point t_start;
void update_time(){
    auto t_now = chrono::system_clock::now();
    elapsed = chrono::duration_cast<chrono::milliseconds>(t_now - t_start).count();
}
bool timeover(){ return (elapsed > TIME_LIMIT);}

const int D = 365, T = 26;
int C[T], S[D][T];
int CS[D+2][T];

vector<int> st[T];

int ans[D];
int opt = -1e9;

int calc_score(){
    int last[T];
    for(int i=0; i<T; i++) last[i] = -1;
    int res = 0;
    for(int i=0; i<D; i++){
        res += S[i][ans[i]];
        last[ans[i]] = i;
        for(int j=0; j<T; j++) res -= C[j] * (i-last[j]);
    }
    return res;
}

int calc_diff(int t, int bef, int aft){
    int res = opt + S[t][aft] - S[t][bef];
    {
        auto it = lower_bound(st[bef].begin(), st[bef].end(), t);
        int d1 = *next(it) - t, d2 = t - *prev(it);
        res -= CS[d1+d2][bef] - CS[d1][bef] - CS[d2][bef];
    }
    {
        auto it = lower_bound(st[aft].begin(), st[aft].end(), t);
        int d1 = *it - t, d2 = t - *prev(it);
        res += CS[d1+d2][aft] - CS[d1][aft] - CS[d2][aft];
    }
    return res;
}

void try_update(){
    // pick random & update
    int t = rnd() % D;
    int bef = ans[t], aft = rnd() % T;
    if(bef == aft) return;

    // calculate
    int score = calc_diff(t, bef, aft);
    const int T = 4000;
    double temp = T * (1 - elapsed/TIME_LIMIT);
    double prob = exp((score - opt) / temp);
    if(rnd01() < prob){
        opt = score;
        ans[t] = aft;
        st[aft].insert(lower_bound(st[aft].begin(), st[aft].end(), t), t);
        st[bef].erase(lower_bound(st[bef].begin(), st[bef].end(), t));
    }else{
        // rollback
    }
}

int main(){
    t_start = chrono::system_clock::now();
    // get input & initialize
    int _; cin >> _;
    for(int j=0; j<T; j++) cin >> C[j];
    for(int i=0; i<D; i++) for(int j=0; j<T; j++) cin >> S[i][j];
    for(int i=0; i<=D+1; i++) for(int j=0; j<T; j++) CS[i][j] = i*(i-1)/2*C[j];

    for(int i=0; i<D; i++) for(int j=0; j<T; j++) if(S[i][ans[i]] < S[i][j]) ans[i] = j;
    opt = calc_score();
    cerr << "before score: " << opt << endl;

    for(int j=0; j<T; j++) st[j].push_back(-1);
    for(int i=0; i<D; i++) st[ans[i]].push_back(i);
    for(int j=0; j<T; j++) st[j].push_back(D);

    // iterate
    int iter = 0;
    while(!timeover()){
        iter++;
        try_update();
        if(iter % 1000 == 0) update_time();
    }

    // output result
    for(int i=0; i<D; i++) cout << ans[i]+1 << endl;


    // output debug
    cerr << "score: " << opt << endl;
    cerr << "iter: " << iter << endl;
    update_time();
    cerr << "elapsed: " << elapsed << endl;
    return 0;
}


Measured memory_bytes: 4420
X = int(input())
if X <= 599:
    print(8)
elif X <= 799:
    print(7)
elif X <= 999:
    print(6)
elif X <= 1199:
    print(5)
elif X <= 1399:
    print(4)
elif X <= 1599:
    print(3)
elif X <= 1799:
    print(2)
else:
    print(1)

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B, W;
	cin >> W >> A >> B;

	if (max(B + W - A, A + W - B) > 2 * W)
	{
		cout << min(abs(A - (B + W)), abs(B - (A + W))) << endl;
	}
	else
	{
		cout << 0 << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    vector<int> v;
    int ans = 0;
    for(size_t i = 1; i <= max(a,b); i++)
    {
        if(a%i == 0 && b%i == 0){
            v.push_back(i);
        }
    }
    reverse(v.begin(), v.end());
    cout << v[k-1] << endl;
    
    return 0;
}

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

int main() {
    int N;
    int A[2][100];

    int num_max, num_tmp = 0;

    cin >> N;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
            if (i == 0 && j == 0 || i == 1) num_tmp += A[i][j];
        }
    }

    num_max = num_tmp;

    for (int j = 1; j < N; j++) {
        num_tmp += A[0][j];
        num_tmp -= A[1][j - 1];
        if (num_tmp > num_max) num_max = num_tmp;
    }

    cout << num_max << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,arr[200005],f[1000005],has,cek;
int main()
{
	cin>>n;
	if(n==1)
	{
		cout<<"1"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++) 
	{
		cin>>arr[i];
		f[arr[i]]++;
		if(arr[i]==1) cek++;
	}
	if(cek==1) 
	{
		cout<<"1"<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		int now=arr[i];
		int p=1;
		for(int j=1;j*j<=now;j++)
		{
			if(now%j==0)
			{
				if(j==1) 
				{
					if(f[j]||f[now/j]>1)
					{
						p=0;
						break;
					}
				}
				else if(f[j]||f[now/j])
				{
					p=0;
					break;
				}
			}
		}
		if(p) has++;
	}
	cout<<has<<endl;
}

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

using namespace std;

string N;

int main(void)
{
    cin >> N;

    int count = 0;
    int max = 0;
    for (int i = 0; i < N.length(); i++)
    {
        if (N[i] == 'R')
        {
            count++;
            if (max < count)
            {
                max = count;
            }
        }
        else
        {
            count = 0;
        }
    }

    cout << max;
}


Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int n;
int num[101];
long long int mem[21][101]={0};
long long int tyosa(int x,int y);
int main(){
  cin >> n;
  for(int i=0;i<n;i++){ 
    cin >> num[i];
  }
  cout<<tyosa(num[0],0)<<endl;
  return 0;
}
long long int tyosa(int x,int y){


  if(x<0||x>20){
    return 0;
  }
  if(y==n-2&&x==num[n-1]){
    return 1;
  }
  if(y==n-2&&x!=num[n-1]){
    return 0;
  }
  if(mem[x][y]!=0){ 
    return mem[x][y];
  }
  return mem[x][y]=tyosa(x+num[y+1],y+1)+tyosa(x-num[y+1],y+1);
}

Measured memory_bytes: 1172
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    int n;
    cin >> n;
    int ans = 1e9;
    vi a(n);
    forn(i, n) cin >> a[i];
    for2(x, -100, 100){
        int sum = 0;
        forn(i, n) sum += (x - a[i]) * (x - a[i]);
        ans = min(ans, sum);
    }
    cout << ans << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define MOD 1000000007
typedef long long ll;
using namespace std;

struct UnionFind{
  vector<int> par;

  UnionFind(int N) : par(N){
    for(int i=0;i<N;i++) par[i] = i;
  }

  void init(int N){
    for(int i=0;i<N;i++) par[i] = i;
  }

  int root(int x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry; 
  }

  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int N,M; cin >> N >> M;
  vector<pair<int,int>> v(M); 
  for(int i=0;i<M;i++){
    int a,b; cin >> a >> b;
    a--; b--;
    v[i].first = a;
    v[i].second = b;
  }
  
  UnionFind graph(N);
  int ans = 0;
  for(int i=0;i<M;i++){
    graph.init(N);
    for(int j=0;j<M;j++){
      if(i == j) continue;
      graph.unite(v[j].first, v[j].second);
    }
    set<int> st;
    for(int i=0;i<N;i++) st.insert(graph.root(i));
    if(st.size() > 1) ans++;
  }

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

Measured memory_bytes: 256
#include <stdio.h>
char map[101][101];
int H, W;


void visit(int i, int j){
  char temp;
  temp=map[i][j];
  if(temp=='.'){
    printf("%d %d\n", j, i);
    return;
  }
  if(temp=='@'){
    printf("LOOP\n");
    return;
  }
  map[i][j]='@';
  if(temp=='>'){
    visit(i,j+1);
  }
  else if(temp=='<'){
    visit(i,j-1);
  }
  else if(temp=='^'){
    visit(i-1,j);
  }
  else if(temp=='v'){
    visit(i+1,j);
  }
}

int main(){
  char x;
  int i,j;

  while(1){
    
    scanf("%d %d", &H, &W);
    if(H==0 && W==0) break;
    for(i=0;i<H;i++){
      getchar();
      for(j=0;j<W;j++){
        scanf("%c", &x);
	map[i][j]=x;
      }
    }

    visit(0,0);
     
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
	int n;
	cin>>n;
	vi v(n), od, ev;
	for(int i = 0; i < n; i++){
		cin>>v[i];
		if(i%2)ev.pb(v[i]);
		else od.pb(v[i]);
	}	
	if(n%2){
		reverse(all(od));
		for(auto i:od)cout<<i<<" ";
		for(auto i:ev)cout<<i<<" ";
	}
	else{
		reverse(all(ev));
		for(auto i:ev)cout<<i<<" ";
		for(auto i:od)cout<<i<<" ";
	}
}
signed main(){
	speed;
	int t=1;
	//cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 6672
S=str(input())
N=len(S)
l,r=0,0
ans=0
while r<N:
	if S[r]=='A' or S[r]=='T' or S[r]=='C' or S[r]=='G':
		r=r+1
		ans=max(ans,r-l)
	else:
		l=r+1
		r=r+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long A[N], B[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> A[i];

    for (int i = 0; i < n; ++i)
        cin >> B[i];

    return true;
}

void solve() {
    set< pair<long long, int> > Q;
    auto check = [] (int i, set< pair<long long, int> >& Q) {
        (i += n) %= n;
        auto a = B[(n + i - 1) % n];
        auto b = B[i];
        auto c = B[(i + 1) % n];

        if (b > a + c)
            Q.insert(make_pair(b, i));
    };

    for (int i = 0; i < n; ++i)
        check(i, Q);

    auto ans = 0ll;

    while (!Q.empty()) {
        auto i = Q.rbegin()->second;
        Q.erase(--Q.end());
        auto d = B[(n + i - 1) % n] + B[(i + 1) % n];
        auto k = (B[i] - A[i]) / d;
        B[i] -= k * d;
        ans += k;
        check(i - 1, Q);
        check(i + 1, Q);
    }

    for (int i = 0; i < n; ++i)
        if (A[i] != B[i]) {
            cout << -1 << endl;
            return ;
        }

    cout << ans << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();
 
    return 0;
}
 


Measured memory_bytes: 12160
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;


int main(){
  int n;
  cin >> n;
  pair<int,int> a[n];
  for(int i=0;i<n;i++){
    a[i].second = i;
    cin >> a[i].first;
  }
  sort(a,a+n);
  for(int i=0;i<n;i++){
    cout << a[i].second + 1 << ' ';
  }
  cout << endl;
  return 0;
}


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

int main (){
  string S ;
  cin >> S ;
  int ans=0 ;
  for(int i=0;i<4;i++){
    if(S[i] == '+')
      ans ++;
    else
      ans --;
  }
  cout << ans << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>
#define np number_of_weapons
#define ta total_attacks
#define td total_damage

int main()
{
    int health, np, ta, i, td;

    scanf("%d%d", &health, &np);
    int damage[np];

    td = 0;
    for (i = 0; i < np; i++)
    {
        scanf("%d", &damage[i]);
        td += damage[i];
    }

    if (td >= health)
        printf("Yes");
    else
        printf("No");
}

Measured memory_bytes: 512
import java.io.*;
// import java.math.*;
import java.util.*;
// import java.util.Map.*;
// import java.util.stream.*;

public class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        String S = reader.readLine();
        System.out.println (
            7 - Arrays.asList ("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
                    .indexOf (S));
        return;
    }
}


Measured memory_bytes: 32612
const main = (input: void) => {
  const A: number = input.split('\n')[0];
  const B: number = input.split('\n')[1];
  const C: number = input.split('\n')[2];
  const X: number = input.split('\n')[3];
  let ptn: number = 0;
  let total: number;

  for (let a=0; a <= A; a++) {
    for (let b=0; b <= B; b++) {
      for (let c=0; c <= C; c++) {
        total = 500*a +100*b + 50*c;
        if (X == total) {
          ptn++;
        }
      }
    }
  }
  console.log(ptn);
}

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

Measured memory_bytes: 9420
# Your code here!
n,s=gets.split
n=n.to_i
s=s.to_i

array=gets.split.map(&:to_i)

answer=0
i=0

(n-1).times{
    if array[i]+array[i+1]>s  &&  array[i]<=s
        jj=array[i]+array[i+1]-s
        answer+=jj
        array[i+1]-=jj
    elsif  array[i]+array[i+1]>s
      answer+=array[i+1]+array[i]-s
       array[i+1]=0
       array[i]=s
    
    end
    
    
    i+=1
    
    
    
}




p answer

Measured memory_bytes: 8620
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        d: usize,
        x: [[i64; d]; n],
    }
    let mut count = 0;
    for j in 0..n {
        for i in 0..j {
            let mut d2 = 0;
            for k in 0..d {
                d2 += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for k in 0.. {
                if k * k > d2 {
                    break;
                }
                if k * k == d2 {
                    count += 1;
                    break;
                }
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2156
/*
 * AOJ 1105 Unable Count
 * n, a, b <= 1,000,000
 */

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAX_N 1000001

int n, a, b;
bool pos[MAX_N];
void init() {
    memset(pos, 0, sizeof(pos));
    for (int i = 0; i <= n; i+=a) {
        for (int j = i; j <= n; j+=b) {
            if (pos[j]) break;
            pos[j] = true;
        }
    }
}

int main() {
    while (cin >> n >> a >> b) {
        if (n == 0 && a == 0 && b == 0) break;
        init();
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            if (!pos[i]) {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <cstring>
#include <omp.h>

using std::cout;
using std::cin;
using std::endl;
using std::string;

bool isStable(string *in, string *out, size_t n){
  for(int i=0;i<n;i++)
    if(in[i]!=out[i]) return false;
  return true;
}

void bubbleSort(string *a, size_t n){
  for(int i=0;i<n;i++){
    for(int j=n;j>i;j--){
      if(a[j].substr(1,1) < a[j-1].substr(1,1))	a[j].swap(a[j-1]);
    }
  }
}

void selectionSort(string *a, size_t n){
  int minj;
  for(int i=0;i<n;i++){
    minj=i;
    for(int j=i;j<n;j++)
      if( a[j].substr(1,1) < a[minj].substr(1,1) ) minj=j;
    a[i].swap(a[minj]);
  }
}

int main(){
  int n;
  cin >> n;
  string tmp;
  string selCards[]={"AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ"};
  string bubCards[]={"AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ","AZ"};
  for(size_t i=0;i<n;i++){
    cin >> tmp;
    selCards[i]=tmp;
    bubCards[i]=tmp;
  }
  //part -> bubbleSort
  bubbleSort(bubCards, n);
  for(size_t i=0;i<n;i++){
    if(i) cout << " ";
    cout << bubCards[i];
  }
  cout << endl << "Stable" << endl;
  
  //part -> selectionSort
  selectionSort(selCards, n);
  for(size_t i=0;i<n;i++){
    if(i) cout << " ";
    cout << selCards[i];
  }
  cout << endl;
  if(isStable(bubCards, selCards, n)) cout << "Stable" << endl;
  else cout << "Not stable" << endl;
  return 0;
}
  



Measured memory_bytes: 3236
n = int(input())
p = list(map(int, input().split(' ')))
cnt = 0
for i in range(1, n-1):
  tri = [p[i-1], p[i], p[i+1]]
  pi = tri[1]
  if max(tri) != pi and min(tri) != pi:
    cnt += 1
print(cnt)

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

int main(){
    char s[1006];
    scanf("%s", s);
    if(s[strlen(s) - 1] == 's'){
        strcat(s, "es\0");
    }else{
        strcat(s, "s\0");
    }
    printf("%s\n", s);

    return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;

bool isPrime(ll x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2LL==0)return false;
    
    rep(i,3,sqrt(x)+1)if(x%i==0)return false;
    return true;
}

int main(){
    
    
    ll x;
    cin>>x;
    if(isPrime(x)){
        string s=to_string(x);
        cout<<s.size()<<endl;
    }else {
        int ans=INF;
        rep(i,1,sqrt(x)+1){
            if(x%i==0){
                string s=to_string(i);
                string ss=to_string(x/i);
                ans=min(ans,(int)max(s.size(),ss.size()));
            }
        }
        cout<<ans<<endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 256
sp = list(input())
t = list(input())
n = len(sp)
s = []
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s.append('')
        ss = sp
        ss[n - i:n - i + len(t)] = t
        for j in range(n):
            if ss[j] == '?':
                s[-1] += 'a'
            else:
                s[-1] += ss[j]
if s == []:
    print('UNRESTORABLE')
else:
    s.sort()
    print(s[0])


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

const ll mod = (ll)1e9 + 7;
const int MAXN = (int)2e5;
int n, k;
ll fact[MAXN + 5], inv[MAXN + 5];

ll power(ll x, ll y){
	ll ret = 1;
	while(y){
		if(y & 1){
			ret = (ret * x) % mod;
		}
		x = (x * x) % mod;
		y >>= 1;
	}
	return ret;
}

void init_stuff(){
	fact[0] = 1;
	for(int i = 1 ; i <= MAXN ; ++i){
		fact[i] = (fact[i - 1] * (ll)i) % mod;
	}
	inv[0] = 1;
	for(int i = 1 ; i <= MAXN ; ++i){
		inv[i] = power(fact[i], mod - 2);
	}
}

ll povrh(ll x, ll y){
	ll ret = fact[x];
	ret = (ret * inv[x - y]) % mod;
	ret = (ret * inv[y]) % mod;
	return ret;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
init_stuff();
cin >> n >> k;
ll sol = 0;
for(int i = n ; i >= max(n - k, 1) ; --i){
	ll sad = (povrh(n, i) * povrh(n - 1, i - 1)) % mod;
	sol = (sol + sad) % mod;
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,a[N];
char s[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int solve(int n)
{
	if(n==1)return 1;
	return 1+2*solve(n/2);
}
signed main()
{
	n=read();
	cout<<solve(n);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m==0)break;
			int[] masu = new int[n];
			int[] d = new int[m];
			for(int i=0;i<n;i++){
				masu[i] = sc.nextInt();
			}
			for(int i=0;i<m;i++){
				d[i] = sc.nextInt();
			}
			
			int now = 0;
			for(int i=0;i<m;i++){
				if(now+d[i]>=n-1){
					System.out.println(i+1);
					break;
				}
				now = now + d[i] + masu[now+d[i]];
				if(now<0)now=0;
				if(now>=n-1){
					System.out.println(i+1);
					break;
				}
			}

		}
	}
}

Measured memory_bytes: 27700
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{


        ll k, i, j, x, yy, p=0, s=0, h, f=0;
        long double n, m, y;
        cin>>n>>m;
        y=n*m+0.0001;
        yy = y;

        cout<<yy<<endl;

    return 0;
}



Measured memory_bytes: 3740
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<int,int>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;
int solution(vector<int> A, int k) 
{ 
 
    int N = A.size(); 
 
    vector<int> v1(N, 0); 
    vector<int> v2(N, 0); 
    vector<int> v3(100, 0); 
  

    v2[N - 1] = 1; 
    v3[A[N - 1] - 1] = 1; 
  

    for (int i = N - 2; i >= 0; i--) { 
  
        v2[i] = v2[i + 1]; 
  
        if (v3[A[i] - 1] == 0) { 
            v2[i]++; 
            v3[A[i] - 1] = 1; 
        } 
    } 
  
    for (int j = 1; j < k; j++) { 
  
     
        fill(v3.begin(), v3.end(), 0); 
  
        v1[N - 1] = 0; 
  
        for (int i = N - 2; i >= 0; i--) { 
  
            v1[i] = v1[i + 1]; 
  
           
            v1[i] = v1[i] + v2[i + 1]; 
  
            v1[i] = v1[i] - v3[A[i] - 1]; 
  
            v3[A[i] - 1] = v2[i + 1]; 
        } 
  
        v2 = v1; 
    } 
    return v1[0]; 
}  
signed main()
{
    fast;
   
    int n,i;
    cin>>n;
    string s;
    cin>>s;
    vector<int> v;
    for(i=0;i<n;i++)
    {
    	v.pb(s[i] - '0' + 1);

    }
    cout<<solution(v,3);
}

Measured memory_bytes: 1440
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL N,K;
	cin >> N >> K;
	LL ans = 0;
	if( K==0 ){
		cout << N*N << endl;
		return;
	}
	for(int i=K+1;i<=N;++i){//割る数	
		ans += (N/i)*(i-K);
		if( (N%i) >= K ){
			ans += (N%i)-K+1;
		}
	}
	cout << ans << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
import sys
from collections import Counter

if __name__ == "__main__":
	N, M = map(int,input().split())
	A = [int(i) for i in input().split()]

	s = sum(A)

	A_sort = sorted(A, reverse=True)
	A_select = A_sort[:M]

	if len(A_select) != M:
		print("No")
		sys.exit()

	for a in A_select:
		if a < (s*(1 / (4*M))):
			print("No")
			sys.exit()

	print("Yes")

Measured memory_bytes: 3444
# Generated by AtcoderGreedy on 2018-10-31
# ABC111 B
# Your code here
n_1,n_2,n_3 = gets.strip.split('').map(&:to_i)

if n_1 < n_2
  n_1 += 1
elsif n_1 == n_2
  if n_2 < n_3
    n_1 += 1
  end
end
puts 100 * n_1 + 10 * n_1 + n_1


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main(){
	IOS;
	int r;
	cin>>r;
	cout<<fixed<<setprecision(12)<<2*3.141592653589793238*r;
	
	
	
	}

Measured memory_bytes: 3752
import math
import itertools

N = int(input())

ans1 = sum(range(1, N+1))

ans2 = 0
for x in itertools.combinations(range(1, N+1), 3):
  ans2 = ans2 + math.gcd(math.gcd(x[0],x[1]),x[2]);


ans2 = ans2 * 6

ans3 = 0
for x in itertools.combinations(range(1, N+1), 2):
  ans3 = ans3 + math.gcd(math.gcd(x[0],x[0]),x[1]);


ans3 = ans3 * 6

print(ans1 + ans2 + ans3)

Measured memory_bytes: 9212
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      cin>>n;

      ll ara[n+3];


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


          if(ara[i]<0)cnt++;

          ara[i]=abs(ara[i]);

          sum+=ara[i];
      }

      sort(ara,ara+n);



      if(cnt&1)sum-=(2*ara[0]);

      cout<<sum<<endl;













}



Measured memory_bytes: 4320
#include<bits/stdc++.h>
#define MAX (int)(2e6+5)
#define PB push_back
#define MP make_pair
#define ll long long
#define pii pair<long long,long long>
#define sz(a) (int)a.size()
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld%lld",&a,&b)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d%d",&a,&b)
#define p1(a) cout<<"Check "<<a<<endl;
#define p2(a,b) cout<<"Check "<<a<<' '<<b<<endl;
#define p3(a,b,c) cout<<"Check "<<a<<' '<<b<<' '<<c<<endl;
#define forn(i,n) for(int i=0;i<int(n);i++)
#define fore(i,l,n) for(int i=int(l);i<int(n);i++)
#define clr(a) memset(a,0,sizeof(a))
#define MOD (int)(1e7+7)
#define INF (long long)(1e18)

using namespace std;

int main()
{
    //freopen("tt.txt","r",stdin);
    int test=1,i=0,n,m;
    //si(test);
    while(test--){
        int n,k,d;
        sii(n,k);
        int vis[n+5];
        clr(vis);
        while(k--){
            si(d);
            int x;
            while(d--){
                si(x);
                vis[x]++;
            }
        }
        int cnt=0;
        fore(i,1,n+1) if(vis[i]==0) cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}


Measured memory_bytes: 3760
a,b,c,x,y = map(int,input().split())
min_total = a*x + b*y
for ci in range(max(x,y)*2+1):
  ai = max(0,x - ci//2)
  bi = max(0,y - ci//2)
  
  total = ai*a + bi*b + ci*c
  if min_total > total:# and (ai+ci//2 >= x) and (bi+ci//2 >= y):                 
    min_total = total    
print(min_total)      

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
    
    int n;
    int k;
    int a[2999];
    long long ans=0;
    long long kaijo=0;
    long long kaijom=0;
    
    scanf("%d %d", &n, &k);
    
    for(int i=0; i<n; i++){
        
        scanf("%d", &a[i]);
        
    }
    
    for(int j=1; j<k; j++){
        
        kaijom += j;
        
    }
    
    kaijom %= 1000000007;
    
    kaijo = kaijom + k;
    kaijo %= 1000000007;
    
    for(int p=0; p<n; p++){
        
        for(int q=0; q<n; q++){
            
            if(a[p]>a[q]){
                
                if(p<q){
                    
                    ans += kaijo;
                    ans %= 1000000007;
                    
                } else if(p>q){
                    
                    ans += kaijom;
                    ans %= 1000000007;
                    
                }
                
            }
            
        }
        
    }
    
    printf("%d", ans);
    
    return 0;
    
}

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

bool is_Right_Triangle(int a, int b, int c){
  if(a > b) swap(a, b);
  if(a > c) swap(a, c);
  if(b > c) swap(b, c);
  if(a*a + b*b == c*c) return true;
  return false;
}

int main(){
  int n;
  cin >> n;
  int a, b, c;
  while(n--){
    cin >> a >> b >> c;
    printf("%s\n", is_Right_Triangle(a, b, c) ? "YES" : "NO");
  }
  return 0;
}

Measured memory_bytes: 1120
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

static const int MOD = 1e9 + 7;

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

int main() {

    int N;
    cin >> N;
    vector<int>x(N+1), y(N+1);
    for (int i = 1; i <= N; i++)cin >> x[i] >> y[i];

    double sum = 0;
    for (int i = 1; i < N; i++) {
        for (int j = i + 1; j <=N ; j++) {
            sum += dis(x[i], y[i], x[j], y[j]);
        }
    }

    cout << fixed << setprecision(10) << sum*2/N;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(0, N)]

ans = 0
A = {}

for i in range(0, N):
    S[i] = sorted(S[i])
    S[i] = ''.join(S[i]) 
    if S[i] in A.keys():
        ans += A[S[i]]
        A[S[i]] += 1
    else:
        A[S[i]] = 1
    
print(ans)

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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int ans = 0,n,k,temp1,temp2,rev = 0;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		n = Integer.parseInt(s[0]);
		k = Integer.parseInt(s[1]);
		str = bf.readLine();
		temp1 = str.charAt(0);
		for(int i = 1;i < n;++i) {
			temp2 = str.charAt(i);
			if(temp1 != temp2) {
				rev++;
			}
			temp1 = temp2;
		}
		rev -= k*2;
		if(rev < 0) {
			rev = 0;
		}
		ans = n - rev - 1;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, P = mapint()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from collections import Counter
primes = prime_factorize(P)
c = Counter(primes)
ans = 1
for v, cnt in c.most_common():
    if cnt<N:
        break
    ans *= v**(cnt//N)
print(ans)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
int A[MAX_N];
int B[MAX_N];

void naive(int N) {
  ll ans = 0;
  REP(i, N) REP(j, N) ans ^= (A[i] + B[j]);
  cout << ans << endl;
}

int main2() {
  int N = nextInt();
  REP(i, N) A[i] = nextInt();
  REP(i, N) B[i] = nextInt();
  // naive(N); return 0;
  int ans = 0;
  vector<int> a(N), b(N);
  REP(keta, 29) {
    const int T = 1 << keta;
    REP(i, N) a[i] = A[i] % (2*T);
    REP(i, N) b[i] = B[i] % (2*T);
    sort(ALL(a));
    sort(ALL(b));
    int curr = 0;

    for (auto x : a) {
      int index1 = lower_bound(ALL(b), T - x) - b.begin();
      int index2 = lower_bound(ALL(b), 2*T-x) - b.begin();
      curr += index2 - index1;

      int index3 = lower_bound(ALL(b), 3*T-x) - b.begin();
      int index4 = lower_bound(ALL(b), 4*T-x) - b.begin();
      curr += index4 - index3;
    }
    ans |= T * (curr&1);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e2+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll dp[MAXn][64];
ll add(ll x,ll y){
    ll ret = x+y;
    if (ret >= MOD) ret -= MOD;
    return ret;
}
string cal(ll x){
    string ret = "";
    while (x) {
        if (x%4 == 0) ret += 'A';
        else if (x%4 == 1) ret += 'G';
        else if (x%4 == 2) ret += 'C';
        else ret += 'T';
        x /= 4;
    }
    while (SZ(ret) < 3) ret += 'A';
    reverse(ALL(ret));
    return ret;
}
int main(){
    IOS();
    ll n;
    cin >> n;
    REP (I,64) {
        if (I == 18 || I == 6 || I == 9) continue;
        dp[3][I] = 1;
    }

    for (ll i=4;i<=n;i++) {
        REP (I,64) {
            if (I == 18 || I == 6 || I == 9) continue;
            ll tmp = I/4;
            REP (J,4) {
                if (J == 0 && I%16 == 6) continue;
                if (J == 0 && I/16 == 1 && I%4 == 2) continue;
                dp[i][I] = add(dp[i][I],dp[i-1][J*16+tmp]);
            }
        }
    }
    ll ans = 0;
    REP (I,64) ans = add(ans,dp[n][I]);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
    //freopen("frog.inp","r",stdin);
    //freopen("frog.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin>>n>>k;
    long long res[n], h[n];
    for (int i=1;i<=n;i++)
    {
        cin>>h[i];
    }
    res[1]=0;
    res[2]=abs(h[1]-h[2]);
    for (int i=3;i<=n;i++)
    {
        res[i]=res[i-1]+abs(h[i]-h[i-1]);
        for (int j=1;j<=k;j++)
        {
            if (i-j>=1)
            {
                res[i]=min(res[i],abs(h[i]-h[i-j])+res[i-j]);
            }
        }
    }
    cout<<res[n];
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = n%10;
        int b = n/10%10;
        int c = n/100%10;
        if(a==7 || b==7||c==7) {
            p("Yes");
        }else {
            p("No");
        }
    }

    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pp(T message) {
        System.out.print(message);
    }
}

Measured memory_bytes: 35760
n=int(input())
a=list(input().split())
b=[]
if len(a)%2==0:
  for i in range(n-1,0,-2):
    b.append(a[i])
  for i in range(0,n-1,2):
    b.append(a[i])
else:
  for i in range(n-1,-1,-2):
    b.append(a[i])
  for i in range(1,n-1,2):
    b.append(a[i])
print(' '.join(b))

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

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	int c = (a * 100 + 8 - 1) / 8;
	int d;
	if((a + 1) * 100 % 8 == 0) {
		d = ((a + 1) * 100 / 8) - 1;
	}else {
		d = (a + 1) * 100 / 8 ;
	}

	int ans = 0;
	for(int i = c; i <= d; i++) {
		if(i / 10 == b) {
			ans = i;
			break;
		}
	}
	if(ans == 0) {
		printf("%d\n", -1);
	}else {
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 256
local mod = 1000000007
local function badd(x, y) return (x + y) % mod end
local function bmul(x, y) return (x * y) % mod end
local n, m = io.read("*n", "*n")
local xsum = 0
local xprev = io.read("*n")
for i = 1, n - 1 do
  local xnxt = io.read("*n")
  local len = (xnxt - xprev) % mod
  local mul = bmul(i, n - i)
  xsum = badd(xsum, bmul(mul, len))
  xprev = xnxt
end
local ysum = 0
local yprev = io.read("*n")
for i = 1, m - 1 do
  local ynxt = io.read("*n")
  local len = (ynxt - yprev) % mod
  local mul = bmul(i, m - i)
  ysum = badd(ysum, bmul(mul, len))
  yprev = ynxt
end
print(bmul(xsum, ysum))


Measured memory_bytes: 256