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

using namespace std;


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

    string s;
    cin >> s;

    if (n % 2 == 1) {
        cout << "No" << endl;
    }
    else {
        string sub1 = s.substr(0, n / 2);
        string sub2 = s.substr(n / 2);

        if (sub1 == sub2) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }


    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int w[100];
int v[100];
long long dp[100][100001];

const long long infinity = 1e18;

int main()
{
    int n,W;
    cin>>n>>W;
    for(int i = 0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }
    dp[0][0] = 0;
    dp[0][w[0]]=v[0];
    for(int id = 1;id<n;id++)
    {
        dp[id][0] = 0;
        for(int j = 1;j<=W;j++)
        {
            dp[id][j] = dp[id-1][j];
            if(j>=w[id])
            {
            dp[id][j] = max(dp[id][j],v[id]+dp[id-1][j-w[id]]);
            }
        }
    }
    long long answer = -infinity;
    for(int j = 0;j<=W;j++)
    {
        answer = max(answer,dp[n-1][j]);
    }
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 80912
_,S=input(),input()
numc,numw,numcmin=0,0,0
for s in S:
    if s == '#':
        numc = numc + 1
    else:
        numw = numw + 1
        numc = numc - 1
        if numc < numcmin:
            numcmin = numc
print(numcmin + numw)

Measured memory_bytes: 3500
#include<stdio.h>
#define maxn 100010

int a[maxn];
int main()
{
	int n; scanf("%d",&n);
	
	int x;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		a[x]=i;
	}
	for(int i=1;i<=n;i++)
	{
		printf("%d ",a[i]);
	}
	return 0;
} 

Measured memory_bytes: 1152
#include<iostream> 
#include<climits> 
#include <bitset>
#include<string>
#include<math.h>
#include <cstdlib>
using namespace std ;
 
void swap(int* a, int* b) 
{ 
    int t = *a; 
    *a = *b; 
    *b = t; 
} 
  

int partition (int arr[], int low, int high) 
{ 
    int pivot = arr[high];   
    int i = (low - 1);   
  
    for (int j = low; j <= high- 1; j++) 
    { 

        if (arr[j] <= pivot) 
        { 
            i++;    
            swap(&arr[i], &arr[j]); 
        } 
    } 
    swap(&arr[i + 1], &arr[high]); 
    return (i + 1); 
} 
  

void quickSort(int arr[], int low, int high) 
{ 
    if (low < high) 
    { 
        
        int pivot = partition(arr, low, high); 
  
        
        quickSort(arr, low, pivot - 1); 
        quickSort(arr, pivot + 1, high); 
    } 
} 
  
  
int main() 
{ 
    int n , m ;
    long int  sum ;
    cin >> n >>  m ;
    int *arr = (int * )malloc(sizeof(int)*n) ; 
    for (int i = 0; i < n; i++)
    {
       cin >>  arr[i] ;
    }
    
    quickSort(arr, 0, n-1); 
    for (int i = 0; i < n; i++)
    {
        sum += arr[i] ;
    }
    int vc = sum/(4*m) ;
    /*for (int i = 0; i < n; i++)
    {
        cout << arr[i] << endl ;
    }*/
    //cout << vc << " ....."<< endl ;
    int count = 0 ;
    for (int i = n - 1 ; i >= 0 ; i--)
    {
        if(arr[i] >= ((float)sum)/(4.0*m))count++ ;
    }
    //cout << count <<"............" <<endl ;
    if (count >= m)
    {
        cout << "Yes" ;
    }
    else
    {
        cout << "No" ;
    }
    return 0; 
}

Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var a, b, k int

func main() {
	sc.Split(bufio.ScanWords)
	a, b, k = nextInt(), nextInt(), nextInt()

	fmt.Printf("%d %d\n", maxInt(0, a-k), maxInt(0, minInt(b, b+a-k)))
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static int n;
        static int[] lining;
        static int mod = (int)Math.Pow(10, 9) + 7;

        static void Main(string[] args)
        {
            //[summary]C - Lining Up
            n = int.Parse(Console.ReadLine());
            var a = ReadLine();
            lining = new int[n];

            foreach(var ai in a)
            {
                lining[ai]++;
            }

            Console.WriteLine(CountPermutations());
        }

        static long CountPermutations()
        {
            long count = 1;

            for(int i = 0; i < n; i++)
            {
                if (n % 2 == 0)
                {
                    if (i % 2 == 0 && lining[i] == 0)
                    {
                        //何もしない   
                    }
                    else if (i % 2 == 1 && lining[i] == 2)
                    {
                        count *= 2;
                    }
                    else
                    {
                        return 0;
                    }
                }
                else
                {
                    if (i == 0 && lining[0] == 1)
                    {
                        //何もしない
                    }
                    else if (i % 2 == 0 && lining[i] == 2)
                    {
                        count *= 2;
                    }
                    else if (i % 2 == 1 && lining[i] == 0)
                    {
                        //何もしない
                    }
                    else
                    {
                        return 0;
                    }
                }

                count %= mod;
            }

            return count;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 19552
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;
#define INF 1e18LL

const ll MAX = 1000000000000000000; //1e18

int main(){
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }
    int LL = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            int ans = 0;
            for(int k = 0; k < d; k++){
                ans += pow(x[i][k] - x[j][k], 2);
            }
            for(int k = 1; k*k <= ans; k++){
                if(k*k == ans) LL++;
            }
        }
    }
    cout << LL << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
	int n;
	cin >> n;
	cout << n*(n+1)/2 << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if ((a+b)%2) cout<<"IMPOSSIBLE"<<endl;
  else cout<<(a+b)/2<<endl;
  return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

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

  cout << n * 800 - ((n / 15) * 200) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue> 
using namespace std;

int dp[3005][3005][2];

int main()
{
	int n,t;
	cin >> n >> t;
	vector<int> a(n),b(n);
	for(int i=0;i<n;i++)
		cin >> a[i] >> b[i];

	dp[0][a[0]][0]=b[0];
	dp[0][0][1]=b[0];
	for(int i=1;i<n;i++)
		for(int j=0;j<t;j++)
		{
			dp[i][j][0]=dp[i-1][j][0];
			dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j][0]+b[i]);
			if(j-a[i]>=0)
			{
				dp[i][j][0]=max(dp[i][j][0],dp[i-1][j-a[i]][0]+b[i]);
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-a[i]][1]+b[i]);
			}
			dp[i][j][1]=max(dp[i][j][1],dp[i][j][0]);
		}
	int ans=0;
	for(int i=0;i<=t;i++)
		if(dp[n-1][i][1]>ans)
			ans=dp[n-1][i][1];
	cout << ans << endl;



}


Measured memory_bytes: 70656
#include <stdio.h>

int main(void)
{
	int s[100000], t[50000];
	int c = 0;
	int n, q;
	int i;

	int binary_search(int s[], int s_min, int s_max, int target);

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &s[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &t[i]);
	}
	
	for (i = 0; i < q; i++) {
		if (binary_search(s, 0, n, t[i])) {
			c++;
		}
	}

	printf("%d\n", c);

	return 0;
}

int binary_search(int s[], int s_min, int s_max, int target) {
	int s_med;

	while (s_min < s_max) {
		s_med = (s_max + s_min) / 2;
		if (target == s[s_med]) {
			return 1;
		}
		if (target > s[s_med]) {
			s_min = s_med + 1;
		}
		else if (target < s[s_med]) {
			s_max = s_med;
		}
	}
	return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

ll solve(int x)
{
    ll n=1;
    while(n*(n+1)/2<x) ++n;
    return n;
}

int main()
{
    int x;
    cin >>x;
    cout << solve(x) << endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    bool flag = false;
    for(int i = 0; i < n; i++) {
        char s; cin >> s;
        if(s == 'Y') flag = true;
    }
    if(flag) cout << "Four" << endl;
    else cout << "Three" << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
for k in range(n):
 b=a[k];b[3],b[4]=b[4],b[3]
t=0
for i in range(n-1):
 if t==1:break
 d=a[i]
 for j in range(i+1,n):
  if t==1:break
  e=a[j]
  for p in('012345','152043','215304','302541','410352','514320'):
   if t==1:break
   f=[d[int(k)]for k in p]
   if f[0]==e[0]and f[5]==e[5]:
    f=f[1:5]*2
    for k in range(4):
     if f[k:k+4]==e[1:5]:t=1;break
print(('Yes','No')[t])


Measured memory_bytes: 5616
#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(20)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//Dijkstra法
struct edge {
	ll to;
	ll cost;
};
typedef pair<ll, ll> P;

void Dijkstra(int s, vector<vector<edge>>& g, vector<ll>& d) {
	priority_queue<P, vector<P>, greater<P>> q;
	d = vector<ll>(g.size(), INF_LL);
	d[s] = 0;
	q.push(P{ 0,s });

	while (!q.empty()) {
		P p = q.top(); q.pop();
		ll v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				q.push(P{ d[e.to] , e.to });
			}
		}
	}
}

int main() {
	int H, W;
	cin >> H >> W;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<string> m(H);
	for (int i = 0; i < H; i++)cin >> m[i];
	//auto itopos = [&](int idx) {return pair{ idx / W,idx % W }; };
	auto postoi = [&](int y, int x) {return y * W + x; };
	int neighbor[4][2] = { {1,0},{-1,0},{0,1},{0,-1} };
	vector<vector<edge>> g(H * W * 2);
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		if (m[i][j] == '#')continue;
		for (int k = -2; k <= 2; k++)for (int s = -2; s <= 2; s++) {
			if (0 <= i + k && i + k < H && 0 <= j + s && j + s < W && m[i + k][j + s] == '.') {
				int p = postoi(i + k, j + s), q = postoi(i, j);
				g[q].push_back({ p,1 });
			}
		}
		for (int k = 0; k < 4; k++) {
			if (0 <= i + neighbor[k][0] && i + neighbor[k][0] < H && 0 <= j + neighbor[k][1] && j + neighbor[k][1] < W && m[i + neighbor[k][0]][j + neighbor[k][1]] == '.') {
				int p = postoi(i + neighbor[k][0], j + neighbor[k][1]), q = postoi(i, j);
				g[q].push_back({ p,0 });
			}
		}
	}
	vector<ll> dist;
	Dijkstra(postoi(ch, cw), g, dist);
	cout << (dist[postoi(dh,dw)] == INF_LL ? -1 : dist[postoi(dh,dw)]) << endl;
}

Measured memory_bytes: 238168
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  int taro = 0, hanako = 0;
  rep(i, 0, n) {
    string s, t;
    cin >> s >> t;
    if (s < t)
      hanako += 3;
    else if (s > t)
      taro += 3;
    else {
      taro += 1;
      hanako += 1;
    }
  }
  cout << taro << " " << hanako << endl;
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    int K, N, x;
    vector<int> A;
    
    cin >> K >> N;
    for(int i=0; i<N; ++i)
    {
    	cin >> x;
    	A.push_back(x);
	}
	
	sort(A.begin(), A.end());
	int d= 0;
	for(int i=0; i<N-1; ++i)
	{
		d = max( d, A[i+1]-A[i] );
	}
	d = max(d, A[0]+K-A[N-1]);
	cout << K-d << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int main() {
    int N;

    cin >> N;

    if (N == 1){
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A;
        cin >> B;

        cout << (A + B) << endl;
    }

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int position[30000];
    for(int i = 1; i <= n; i++){
        int in;
        cin >> in;
        position[in] = i;
    }
    for(int i = 1; i < n; i++){
        cout << 30000 * i + position[i] << " ";
    }
    cout << 30000 * n + position[n] << endl;
    for(int i = 1; i < n; i++){
        cout << 30000 * (n + 1 - i) << " ";
    }
    cout << 30000<< endl;

    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

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

  int l = s.size();

  bool a = false, b = false;
  ll aCount = 0;
  ll result = 0;
  for (int i = 0; i < l; i++) {
    if (s[i] == 'A') {
      if (a && !b) aCount++;
      else aCount = 1;
      a = true;
      b = false;
    } else if (s[i] == 'B' && a && !b) {
      b = true;
    } else if (s[i] == 'C' && a && b) {
      result += aCount;
      a = true;
      b = false;
    } else {
      aCount = 0;
      a = false;
      b = false;
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 3752
// 线段树区间修改，区间查询

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int N = 200010, mod = 998244353;

struct SegmentTree
{
    LL sum, lz;
}tr[N << 2];

LL s[N], ten[N];
int n, q;

void pushup(int p, int l, int r)
{
    int mid = l + r >> 1;
    tr[p].sum = (tr[p << 1].sum * ten[r - mid] % mod + tr[p << 1 | 1].sum) % mod;
}

void build(int p, int l, int r)
{
    if (l == r)
    {
        tr[p].sum = 1;
        return;
    }   

    int mid = l + r >> 1;
    build(p << 1, l, mid);
    build(p << 1 | 1, mid + 1, r);

    pushup(p, l, r);
}

void pushdown(int p, int l, int r)
{
    if (tr[p].lz)
    {
        int mid = l + r >> 1;
        tr[p << 1].sum = s[mid - l + 1] * tr[p].lz % mod;
        tr[p << 1 | 1].sum = s[r - mid] * tr[p].lz % mod;
        tr[p << 1].lz = tr[p].lz;
        tr[p << 1 | 1].lz = tr[p].lz;
        tr[p].lz = 0;
    }
}

void update(int p, int l, int r, int L, int R, int d)
{
    if (L <= l && R >= r)
    {
        tr[p].sum = s[r - l + 1] * d % mod;
        tr[p].lz = d;
        return;
    }

    int mid = l + r >> 1;
    pushdown(p, l, r);

    if (L <= mid) update(p << 1, l, mid, L, R, d);
    if (R > mid) update(p << 1 | 1, mid + 1, r, L, R, d);

    pushup(p, l, r);
}

int main()
{
    scanf("%d%d", &n, &q);

    s[1] = ten[0] = 1, ten[1] = 10;
    for (int i = 2; i <= n; i ++ )
    {
        s[i] = (s[i - 1] + ten[i - 1]) % mod;
        ten[i] = ten[i - 1] * 10 % mod;
    }

    build(1, 1, n);

    while (q --)
    {
        int l, r, d;
        scanf("%d%d%d", &l, &r, &d);
        update(1, 1, n, l, r, d);

        printf("%lld\n", tr[1].sum);
    }

    return 0;
}


Measured memory_bytes: 15120
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
auto comp = [&] (const int& x, const int& y) {
  return a[x] > a[y];
};
struct Value {
  vector<int> idx;
  Value () {}
  void merge (const Value& v) {
    idx.insert(idx.begin(), v.idx.begin(), v.idx.end());
    sort(idx.begin(), idx.end());
    idx.erase(unique(idx.begin(), idx.end()), idx.end());
    sort(idx.begin(), idx.end(), comp);
    if ((int) idx.size() > 2) idx.resize(2);
  }
  int get () {
    int res = 0;
    for (int i : idx) res += a[i];
    return res;
  }
};
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  a.resize(1 << n);
  for (int i = 0; i < (1 << n); i++) {
    cin >> a[i];
  }
  vector<Value> dp(1 << n);
  for (int i = 0; i < (1 << n); i++) dp[i].idx.push_back(i);
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      if (mask & (1 << i)) dp[mask].merge(dp[mask ^ (1 << i)]);
    }
  }
  int ans = dp[0].get();
  for (int i = 1; i < (1 << n); i++) {
    ans = max(ans, dp[i].get());
    cout << ans << '\n';
  }
  return 0;
}

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

dist = [abs(a[i + 1] - a[i]) for i in range(len(a) - 1)]
total = sum(dist)

for i in range(1, n + 1):
    ans = total - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i - 1] - a[i + 1])
    print(ans)


Measured memory_bytes: 14048
#include <iostream>

using namespace std;

int main()
{
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0){
        cout<<1;
    }
    if(x2==0){
        cout<<2;
    }
    if(x3==0){
        cout<<3;
    }
    if(x4==0){
        cout<<4;
    }
    if(x5==0){
        cout<<5;
    }

    return 0;
}

Measured memory_bytes: 3532
# -*- coding: utf-8 -*-
N = int(input())
S = [i for i in input()] + [-1, -1]
ans = 0
for i in range(N):
    if S[i] == "A":
        if S[i+1] == "B":
            if S[i+2] == "C":
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,n,l;
    cin>>n>>l;
    vector<string> vs;
    string a,ans;
    for(i=1;i<=n;i++){
        cin>>a;
        vs.push_back(a);
    }
    sort(vs.begin(),vs.end());

    for(i=0;i<n;i++) ans+=vs[i];

    cout<<ans<<endl;
}


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

int main(){
  int x;
  cin >> x;
  double ans = 0;
  for(int i=1; i<32; i++){
    for(int j=2; j<10; j++){
      if(pow(i,j) > x) continue;
      ans = max(ans,pow(i,j));
    }
  }
  cout << ans << endl;      
}



Measured memory_bytes: 256
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
a=lnii()+[0]

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

print(money)

Measured memory_bytes: 9156
def splitstr(str,num):
    l =[]
    l = [str[i::num] for i in range(num)]
    l=["".join(i) for i in zip(*l)]
    rem = len(str) % num
    if rem: l.append(str[-rem:])
    return l
 
a = [[0 for i in range(5)] for j in range(6)]
q=97
for i in range(5):
    for j in range(5):
        a[i][j] = chr(q)
        q+=1
for i,j in enumerate('z.?! '): a[5][i] = j
 
while True:
    try:
        me = raw_input()
        if '0' in me: print "NA" ; continue
        me = splitstr(me,2)
        ans = ""
        for i in me:
            ans+=a[int(i[0])-1][int(i[1])-1]
        print ans
    except IndexError: print "NA" ; continue
    except EOFError: break
    except ValueError: print "NA" ; continue

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define N 100010

int n,k,a[N];
ll sum1[N],sum2[N],ans=0;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin >> n >> k;
    for(int i = 1  ; i <= n ; ++i){
        cin >> a[i];
        sum2[i]=sum2[i-1]+a[i];
        sum1[i]=sum1[i-1];
        if(a[i]>0) sum1[i]+=a[i];
    }
    for(int i = 1 ; i+k-1 <= n ; ++i){
        ll res = sum1[n]-(sum1[i+k-1]-sum1[i-1]);
        if(sum2[i+k-1]-sum2[i-1]>0) res+=sum2[i+k-1]-sum2[i-1];
        ans=max(ans,res);
    }
    cout << ans;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

template <class T> class MultiArray2
{
    public:
        T* _a;
        int _w;
        int _h;
        MultiArray2(int w, int h, bool clr = false)
        {
            _w = w; _h = h;
            _a = new T[_w * _h];
            if(clr) memzero();
        }

        void memzero()
        {
            memset(_a, 0, _w * _h * sizeof(T));
        }

        ~MultiArray2()
        {
            delete _a;
        }

        T* operator[](int i)
        {
            return _a + (i * _h);
        }
};

inline bool isbit(int n, int bit)
{
    return n & (1 << bit);
}

bool check(int *t, int h, int k, int n)
{
    int pre = 0;
    rep(j, h)
    {
        pre += t[j];
        if( pre > k ) return true;
        if( isbit(n, j) ) pre = 0;
    }
    return false;
}

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    MultiArray2<int> s(w, h);
    rep(j, h)
    {
        string str;
        cin >> str;
        rep(i, w) s[i][j] = (str[i] == '0' ? 0 : 1);
    }

    int tmp[10];

    int best = w + h;

    //縦方向の分割を全種類試す
    rep(n, 1 << (h - 1))
    {
        int num = 0;
        rep(j, h - 1) 
        {
            if( isbit(n, j) ) num++;
        }

        bool errorflag = false;

        rep(u, h) tmp[u] = 0;
        // 左から順に最大ｋ個になるようにわっていく
        rep(i, w)
        {
            if( check(s[i], h, k, n) )
            {
                errorflag = true;
                break;
            }
            rep(j, h) tmp[j] += s[i][j];
            if( check(tmp, h, k, n) )
            {
                num++;
                rep(j, h) tmp[j] = s[i][j];
            }
        }
        if( errorflag ) continue;
        best = min(best, num);
    }

    cout << best;

    return 0;    
}

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

const int N = 5e5 + 5;
string s, t, T, P;
int f[N], cl, cs;
vector<int> g[N];

void getFail() {
    int m = P.length();
    f[0] = 0; f[1] = 0;
    for(int i = 1; i < m; i++){
        int j = f[i];
        while(j && P[i]!=P[j]) j = f[j];
        f[i+1] = P[i] == P[j]? j+1 : 0;
    }
}

void find() {
    int n = T.length(), m = P.length();
    getFail();
    int j = 0;
    for(int i = 0; i < n; i++) {
        while(j && P[j]!=T[i]) j = f[j];
        if(P[j] == T[i]) j++;
        if(j == m) g[(i-m+1)%cs].push_back((i+1)%cs);
    }
}

int c[N], d[N] = {0}, ans = 0;
bool dfs(int u) {
	c[u] = -1;
	for(int i = 0; i < g[u].size(); i++) {
        int v = g[u][i];
		if(c[v] < 0) return false;
		else if(!c[v]&&!dfs(v)) return false;
		d[u] = max(d[u], d[v]);
	}
	d[u]++;
	ans = max(ans, d[u]);
	c[u] = 1;
	return true;
}

bool toposort(){
	memset(c, 0, sizeof(c));
	for(int u = 0; u < N; u++) if(!c[u])
        if(!dfs(u)) return false;
	return true;
}

int main() {
    cin >> s >> t;
    cl = s.length() + t.length(), cs = s.length();
    while(s.length() < cl) s += s;
    T = s, P = t;
    find();
    if(toposort()) cout << ans - 1;
    else cout << -1;
}

Measured memory_bytes: 59848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
#define MAXN 100000
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
int n, A[MAXN+5], Sum;
int main()
{
	n = read(); for(rint i = 1; i <= n; A[i] = read(), Sum += abs(A[i]-A[i-1]), i++); Sum += abs(A[n]);
	for(rint i = 1; i <= n; printf("%d\n",Sum-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1])), i++); return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main(){
    double n,t,a,h;
    cin>>n;
    cin>>t>>a;
    double ans_temp=114514191.0;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>h;
       if(abs(t-h*0.006-a)<ans_temp){
           ans_temp=abs(t-h*0.006-a);
           ans=i;
       }
    }
    cout<<ans<<endl;
}


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

int s[MAX];
int top;

int isEmpty(){
	if(top==0) return 1;
	return 0;
}

int isFull(){
	if(top >= MAX - 1) return 1;
	return 0;
}

void push(int x){
	if(isFull()){
		fprintf(stderr,"Stack is full.\n");
		exit(1);
	}else{
		top++;
		s[top]=x;
	}
}

int pop(){
	if(isEmpty()){
		fprintf(stderr,"Stack is empty.\n");
		exit(1);
	}
	top--;
	return s[top+1];
}



int main(void){
	int x,a,b;
	char c[8];
	top=0;
	while(scanf("%s",c)>0){
		if(c[0]=='+'&&c[1]=='\0'){
			b=pop();
			a=pop();
			push(a+b);
		}
		else if(c[0]=='-'&&c[1]=='\0'){
			b=pop();
			a=pop();
			push(a-b);
		}
		else if(c[0]=='*'&&c[1]=='\0'){
			b=pop();
			a=pop();
			push(a*b);
		}else{
			push(atoi(c));
		}
	}
	x=pop();
	if(isEmpty()) printf("%d\n",x);
	else fprintf(stderr,"Stack isn't empty. x=%d\n",x);
	return 0;
}

Measured memory_bytes: 1764
#!/usr/bin/env python3
import sys


def solve(a: int, b: int):
    ab = str(a)*b
    ba = str(b)*a
    if ab > ba:
        print(ba)
    else:
        print(ab)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> N(3);
  for(int i=0;i<3;i++) {
    cin>>N.at(i);
  }
  sort(N.begin(),N.end());
  cout<<N.at(0)+N.at(1)<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[][] stock = new int[N][3];
		for (int i = 0; i < N; i++) {
			stock[i][0] = scan.nextInt();
			stock[i][1] = scan.nextInt();
			stock[i][2] = scan.nextInt();
			scan.hasNextLine();
		}
		int prev = -1;
		int flag = -1;
		int t = 0;
	
		int[][] aux = new int[N][3];
		aux[0][0] = stock[0][0];
		aux[0][1] = stock[0][1];
		aux[0][2] = stock[0][2];
		for(int k =1;k<N;k++) {
		    aux[k][0]=Math.max(aux[k-1][1],aux[k-1][2]) + stock[k][0] ;
		    aux[k][1]=Math.max(aux[k-1][0],aux[k-1][2]) + stock[k][1] ;
		    aux[k][2]=Math.max(aux[k-1][0],aux[k-1][1]) + stock[k][2] ;
		}
		
		t = Math.max(Math.max(aux[N-1][0], aux[N-1][1]), aux[N-1][2]);
		
		
		System.out.println(t);
		scan.close();
	}

}


Measured memory_bytes: 162840
package main

import (
	"fmt"
	"go/constant"
	"go/token"
	"go/types"
)

func main() {
	var a, op, b string
	fmt.Scan(&a, &op, &b)

	s := a + op + b

	tv, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, s)
	val, _ := constant.Int64Val(tv.Value)

	fmt.Println(val)
}


Measured memory_bytes: 640
#include <stdio.h>
#define N 100
void insertionSort(int*,int);
int main(){
  int i,j,n,tmp;
  int A[N];

  scanf("%d",&n);
  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);

  for(i = 0; i<n; i++) {
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");

  insertionSort(A,n);
 
  return 0;
}

void insertionSort(int A[], int n)
{
  int i,j,v;

  for(i=1; i<n; i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
  
    for(j = 0; j<n; j++) {
      if(j>0) printf(" ");
      printf("%d",A[j]);
    }
    printf("\n");
  }
}

Measured memory_bytes: 604
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-7
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e9+9
#define Vector Point
const int Mod=1e9+7;
const long long Maxx=2e18;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
char s[201],t[201];
char st[201];
void solve(){
	cin>>s>>t;
	int ans=0;
	if(strcmp(s,t)==0)  ans=1;
	int l=strlen(s);
	For(i,1,l-1){
		For(j,0,l-1) {
			st[j]=s[(j+i)%l];
		}
		st[l]='\0';
		if(strcmp(st,t)==0) ans=1;
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main(){
//  fre("in.txt","r",stdin);
    int t=0;
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

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

	void run() {
		Scanner sc = new Scanner(System.in);

		String[] A=sc.next().split("");
		String[] B=sc.next().split("");
		String[] C=sc.next().split("");

		Deque<String> handA=new ArrayDeque<String>();
		Deque<String> handB=new ArrayDeque<String>();
		Deque<String> handC=new ArrayDeque<String>();


		for (int i = 0; i < A.length; i++) {
			handA.add(A[i]);
		}

		for (int i = 0; i < B.length; i++) {
			handB.add(B[i]);
		}

		for (int i = 0; i < C.length; i++) {
			handC.add(C[i]);
		}

		String top=handA.poll();

		while(true) {

			if(top.equals("a")) {
				if(!handA.isEmpty()) {
					top=handA.poll();
				}else {
					pln("A");
					return;
				}
			}else if(top.equals("b")) {
				if(!handB.isEmpty()) {
					top=handB.poll();
				}else {
					pln("B");
					return;
				}

			}else {
				if(!handC.isEmpty()) {
					top=handC.poll();
				}else {
					pln("C");
					return;
				}
			}

		}

	}

	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

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

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007

#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;

typedef long long ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
    cin>>a[i];
    ll pos=1;
    ll tm=a[n-1];
    for(i=n-2;i>=0;i--)
    {
        if(tm<a[i]-1)
        pos=0;
        tm=min(tm,a[i]);
    }
    if(pos==1)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}

Measured memory_bytes: 1024
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断

    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, M, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(M)]
CD = [tuple(map(int, input().split())) for _ in range(K)]

uf = UnionFind(N+1)

friends = [0]*(N+1)
for A, B in AB:
    friends[A] += 1
    friends[B] += 1
    uf.Unite(A, B)

ans = [0]*(N+1)
for i in range(1, N+1):
    ans[i] = uf.Count(i)-1-friends[i]

for C, D in CD:
    if uf.isSameGroup(C, D):
        ans[C] -= 1
        ans[D] -= 1

print(*ans[1:])


Measured memory_bytes: 38744
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
#define mkp(a,b) make_pair(a,b)
#define all(v) v.begin(),v.end()
using namespace std;
bool compare(pair<int,int>& p1,pair<int,int>& p2)
{
    return p1.second<p2.second;
}
int main()
{
    fastio
    char c;
    cin>>c;
    if(c-96>0)
        cout<<"a\n";
    else
        cout<<"A\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int, int>
#define f first
#define s second 
using namespace std;
const LL INF = (LL) 1e9 + 5;
const LL MOD = (LL) 1e9 + 7;
const int LIM = 400005;
//const int MAXN = 200005;

LL qpow(LL a, LL pw) {
	LL res = 1;
	a %= MOD;
	while (pw) {
		if (pw & 1) res = res * a % MOD;
		a = a * a % MOD;
		pw >>= 1;
	}
	return res;
}

LL fac[LIM], finv[LIM];

void init() {
	fac[0] = finv[0] = 1;
	for (int i = 1; i < LIM; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		finv[i] = qpow(fac[i], MOD - 2);
	}
}

LL C(LL n, LL k) {
	return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}

LL H(LL n, LL k) {
	// n boxes, k items.
	return C(n + k - 1, k);
}

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

	LL n, k;
	cin >> n >> k;
	
	if (n == 2) {
		cout << "1\n";
		return 0;
	}
	
	LL emp = min(k, n - 1), ans = 0;
	init();
	for (LL i = n - emp; i <= n; i++) {
//		cout << "at " << i << " " << C(n, i) << ' ' << '\n';
		ans = (ans + C(n, i) * H(i, n - i)) % MOD;
	}
	
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 6528
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, K: int, A: "List[int]"):
    ## 一つの場合の転倒数を数えていく
    tentousuu = dict()
    all_tentousuu = dict()
    for a in range(0,2001):
        tentousuu[a] = 0
        all_tentousuu[a] = 0 

    for i in range(0,N):
        for j in range(0,N):
            if j<i and A[j]>A[i]:
                tentousuu[A[i]]+=1
            
            if A[i]<A[j]:
                all_tentousuu[A[i]] += 1
    
    one_to_k_sum = (K)*(K-1)//2
    answer = 0
    for a in range(0,2001):
        answer += tentousuu[a]*K+all_tentousuu[a]*one_to_k_sum
    
    print(answer%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N - 1 - 0 + 1)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3584
#include<stdio.h>
int main(){
  int n,i;
  scanf("%d",&n);
  double a[n+1],count=0;
  for(i=0;i<n;i++){
    scanf("%lf",&a[i]);
    a[i]=1/a[i];
    count+=a[i];
  }
  printf("%lf\n",1/count);
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;

	int K, N;
	cin >> K >> N;
	vector<int> A(N);
	int res = K;
	forn(i, N)
	{
		cin >> A[i];
		if (i)
		{
			int tmp = K - (A[i] - A[i - 1]);
			res = min(res, tmp);
		}
	}
	res = min(res, K - (K + A[0] - A[N-1]));
	cout << res << endl;
	return 0;
}


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

int main(){
  int H,W,M;
  cin >> H >> W >> M;
  vector<int> Ch(H,0),Cw(W,0);
  vector<vector<int>> V(H,vector<int>(0));
  int maxCh = 0;
  for(int i=0;i<M;i++){
    int h,w;
    cin >> h >> w;
    h--;w--;
    Ch[h]++;
    Cw[w]++;
    V[h].push_back(w);
    maxCh = max(maxCh,Ch[h]);
  }
  
  int count = 0;
  vector<int> V2(W,0);
  for(int i=0;i<H;i++){
    if(Ch[i]!=maxCh) continue;
    count++;
    for(int j=0;j<V[i].size();j++){
      V2[V[i][j]]++;
    }
  }
  
  for(int i=0;i<W;i++){
    if(V2[i]==count) Cw[i]--;
  }
  sort(Cw.begin(),Cw.end());
  
  cout << maxCh + Cw[W-1] << endl;
  return 0;
}


Measured memory_bytes: 23300
/*
    Author : DemonStar
*/

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")

#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;
#define ordered_set tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pl pair<long long, long long>
#define pld pair<long double, long double>
#define endl '\n'
#define loop(i, n) for (ll i = 0; i < n; i++)
#define rep(i, begin, end) for (__typeof(begin) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) x.begin(), x.end()
#define vl vector<ll>
#define vi vector<int>
#define ml map<ll, ll>
#define vpl vector<pair<ll, ll>>
const ll mod = 1e9 + 7;

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t)
{
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t)
{
    for (auto &i : t)
        os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v)
{
    for (T &t : v)
        is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v)
{
    for (pair<T1, T2> &t : v)
        is >> t.first >> t.second;
    return is;
}

int rec(vi &dp, vector<vi> &v, int i)
{
    int &ans = dp[i];
    if (ans != -1)
        return ans;
    ans = 0;
    for (auto x : v[i])
    {
        ans = max(ans, 1 + rec(dp, v, x));
    }
    return ans;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vi> v(n, vi());
    while (m--)
    {
        int a, b;
        cin >> a >> b;
        v[b - 1].push_back(a - 1);
    }
    vi dp(n, -1);
    for (int i = 0; i < n; i++)
        rec(dp, v, i);
    cout << *max_element(all(dp)) << endl;

#ifdef LOCAL
    cerr
        << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif

    return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
#define ll long long

using namespace std;

inline long long read(){
   long long w=1,s=0;
   char ch=getchar();
   while(ch<'0'||ch>'9') {if (ch=='-') w=-1;ch=getchar();} 
   while(ch>='0'&&ch<='9')  s=s*10+ch-'0',ch=getchar();
   return s*w;
}

int main(){
    int a=read(),b=read();
    for(int i=1;i<=3;i++)
    if ((a*b*i)%2==1) {
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
} 

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

int main(){
	int N, M;
	cin >> N >> M;
	pair <ll,ll> p[N];
	rep(i,N) {
		int a, b;
		cin >> a >>b;
		p[i] = make_pair(a,b);
	}

	sort(p,p+N);
	ll ans = 0;
	ll tot = 0;
	rep(i,N) {
		ans += p[i].first*min(p[i].second, M-tot);
		tot += min(p[i].second, M-tot);
		if (tot == M) break;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_10_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] readLine = Console.ReadLine().Split(' ');
            double a = double.Parse(readLine[0]);
            double b = double.Parse(readLine[1]);
            double C = double.Parse(readLine[2]);
            var sinC = Math.Sin(C * (Math.PI / 180));
            var cosC = Math.Cos(C * (Math.PI / 180));
            double S = (a * b * sinC) / 2;
            double L = a + b + Math.Sqrt(a * a + b * b - 2 * a * b * cosC);
            double h = b * sinC;
            Console.WriteLine(S);
            Console.WriteLine(L);
            Console.WriteLine(h);
        }
    }
}



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


char Search(int n,char s,char *code1,char *code2){

	int i;

	for(i=0;i<n;i++){

		if(code1[i] == s)
			return code2[i];

	}

	return s;

}

int main(void){

	int n,m;
	char *code[2];
	char s;
	int i;

	while(1){

		scanf("%d",&n);
		if(n==0)
			break;

		code[0] = (char*)malloc(sizeof(char)*n);
		code[1] = (char*)malloc(sizeof(char)*n);

		for(i=0;i<n;i++)
			scanf(" %c %c",&code[0][i],&code[1][i]);

		scanf("%d",&m);

		for(i=0;i<m;i++){
			scanf(" %c",&s);

			printf("%c",Search(n,s,code[0],code[1]));
		}

		puts("");

		free(code[0]),free(code[1]);


	}

	return 0;

}

Measured memory_bytes: 588
#include<bits/stdc++.h>
using namespace std;
typedef int Int;
#define int long long
#define INF 0x3f3f3f3f
#define maxn 105
int a[maxn];
Int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    cout<<*max_element(a+1,a+n+1)-*min_element(a+1,a+n+1)<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int base=0;
    for(int i = 0; i < n; i++) {
        base^=a[i];
    }
    for(int i = 0; i < n; i++) {
        cout << int(base^a[i]) << " ";
    }
    cout << "\n";

    return 0;
}

Measured memory_bytes: 3988