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

int main(void) {
    int N;
    int a,x,y;
    int cnt ,maxcnt = 0;
    bool result;
    cin >> N;

    vector<vector<int>> A(N,vector<int>(N,-1));

    for(int i=0;i<N;i++) {
        cin >> a;
        for(int j=0;j<a;j++) {
            cin >> x >> y;
            --x;
            A[i][x] = y;
        }
    }

    // iに現在の正直者の数が入っている
    for(int i=0;i<(1 << N);i++) {
        result = true;
        for(int j=0;j<N;j++) {
            if(i >> j & 1) {
                for(int k=0;k<N;k++) {
                    if(A[j][k] == -1) continue;
                    if(A[j][k] != ((i >> k) & 1)) {
//                        printf("A[%d][%d] = %d, %d >> %d & 1 = %d\n", j,k,A[j][k],i,k,((i>>k)&1));
                        result = false;
                        break; 
                    }
                }
            }
            if(!result) break;
        }

        if(result) {
            cnt = __builtin_popcount(i);
            if(maxcnt < cnt) {
                maxcnt = cnt;
            }
        }
    }
    cout << maxcnt << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;                     
using namespace __gnu_pbds;
// assert(a[i]<n ) // if we want to check for special cond , used for debug
// make less_equal in order to make a multiset pbds
const ll Mod = (int)1e9 + 7;
ll CaseN=1;



ll tst()
{
	ll ans=0;
	
	
return ans;	
}

void solve()
{
	ll n;
	cin>>n;
	ll a[n+3];
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
	cin>>a[i];	
	}
	sort(a+1,a+n+1);
	
	//smaller of left right
	ans=a[n];
	ll i=0;
	ll p = n-1;
	ll f=0;
	while(i<n-2)
	{
		ans+=a[p];
		f++;
		if(f==2)
		{
		p--;	
          f=0;
		}
		i++;
		//if(i<=0)
		//{
		//break;	
		//}
	}
	
	
	cout<<ans<<endl;
	//cerr<<"Case #"<<CaseN<<": ";
    CaseN++;

  return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	
	solve();	
	}
}




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

int main(){
    int total, number;
    char mark;
    int card[4][13] = {{}};
    
    cin >> total;
    for(int i = 0; i < total; i++){
    cin >> mark >> number;
    switch(mark){
        case 'S' :
        card[0][number-1] = 1;
        break;
        case 'H' :
        card[1][number-1] = 1;
        break;
        case 'C' :
        card[2][number-1] = 1;
        break;
        case 'D' :
        card[3][number-1] = 1;
        break;
        }
    }
    
    for(int i = 0; i < 52; i++){
        switch(i/13){
            case 0 :
        if(card[0][i%13] == 0) cout << 'S' << " " << i%13+1 << endl;
        break;
        case 1 :
        if(card[1][i%13] == 0) cout << 'H' << " " << i%13+1 << endl;
        break;
        case 2 :
        if(card[2][i%13] == 0) cout << 'C' << " " << i%13+1 << endl;
        break;
        case 3 :
        if(card[3][i%13] == 0) cout << 'D' << " " << i%13+1 << endl;
        break;
        }
        
    }
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int t1 = h1 * 60 + m1;
    int t2 = h2 * 60 + m2;

    cout << t2 - t1 - k << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <vector>
#include <string>

using namespace std;
using ll = long long ;



int main() {
    int h,w,k ;
    cin >> h >> w >> k ;
    string s[h],cp[h] ;
    int ans = 0 ;
    
    for (int i = 0; i < h; i++) cin >> s[i] ;
    
    for (int bit = 0; bit < (1 << h); ++bit) {
        for (int bit2 = 0; bit2 < (1 << w); ++bit2) {

        for (int i = 0; i < h; i++) cp[i] = s[i] ;


        for (int i = 0; i < h ; ++i) {

             if (bit & (1 << i)){
                 for(int m = 0; m < w; m++) cp[i][m] = 'r' ;
             }
        }


            for (int j = 0; j < w ; j++)
            {
                if (bit2 & (1 << j)){
                   for(int m = 0; m < h; m++) cp[m][j] = 'r' ;
                }
            }    

    int cnt = 0 ;
    for (int m = 0; m < h; m++)
    {
       for (int l = 0; l < w; l++)
       {
           if(cp[m][l]=='#') cnt++ ;
       }
    }
    if(cnt==k) ans++ ;
    }



        }
 

    cout << ans << endl ;

}

Measured memory_bytes: 3568
def main():
    N, M = map( int, input().split())
    ANS = []
    if N%2 == 1:
        n = N//2
        for i in range(M):
            ANS.append([n-i, n+1+i])
    else:
        n = N//2
        t = 0
        for i in range(M):
            if i%2 == 0:
                ANS.append([n-i//2, n+1+i//2])
            else:
                ANS.append([(i+1)//2, N-(i+1)//2])

    print( "\n".join( [" ".join( map( str,ans)) for ans in ANS]))
if __name__ == '__main__':
    main()


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

int main(){
  int length, sum, i, left = 0,
    right = 0, currentSmallest = 1000000;
  scanf(" %d %d", &length, &sum);
  int *array = (int *) malloc(sizeof(int[length]));
  for ( i = 0; i < length; i++ )
    scanf(" %d", array+i);
  int currentSum = array[0];
  // iterate right until the sum is greater, then iterate left
  while ( 1 ){
    if ( currentSmallest == 1 ){ // can't find a smaller piece than 1
      printf("%d\n", 1);
      return 0;
    }
    int subLength = right-left+1;
    if ( subLength >= currentSmallest ) {
      // subtract the left from currentSum then iterate left
      currentSum -= array[left++];
      continue;
    }
    // reached the goal of exceeding sum
    if ( currentSum >= sum ){ 
      currentSmallest = subLength;
      currentSum -= array[left++];
      continue;
    } else if ( right == length-1 ){
      // reached the case in which the sum does not exist in array
      if ( left == 0 ){
	printf("%d\n", 0);
	return 0;
      }
      printf("%d\n", currentSmallest);
      return 0;
    }
    // iterate right then add right to currentSum
    currentSum += array[++right];
  }
  return 0;
}



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

namespace CodeFest2016
{
	class Program
	{
		static char[] alpgabet;
		const int alphLength = 26;

		static int GetCost(char a)
		{
			return (int) a - (int) 'a';
		}

		static int GetStepsCountToLowestCost(char a)
		{
			return alphLength - GetCost(a);
		}

		static char GetCharByCostToLowestCost(int toLowestCost)
		{
			if (toLowestCost == 0) return alpgabet[0];
			return alpgabet[alphLength-toLowestCost];
		}

		static void Main(string[] args)
		{
			var debug = false;

			alpgabet =  "abcdefghijklmnopqrstuvwxyz".ToCharArray();

			var s = (debug ? "codefesdfsdgsdfhghjtgjgj" : Console.ReadLine()).Select(GetStepsCountToLowestCost).ToArray();

			var n = debug ? 10000000 : int.Parse(Console.ReadLine());

			for (var i = 0; i < s.Length; i++)
			{
				if (s[i] <= n && s[i]!=alphLength)
				{
					n -= s[i];
					s[i] = alphLength;
				}
				else
				{
					continue;
				}
			}

			var ended = n-(n/alphLength)*26;

			s[s.Length - 1] -= ended;

			for (int i = 0; i < s.Length-1; i++)
			{
				Console.Write(GetCharByCostToLowestCost(s[i]));
			}
			Console.WriteLine(GetCharByCostToLowestCost(s[s.Length-1]));
		}
	}
}


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

int main()
{
    int N;
    int i,k;
    int seki;
    if(scanf("%d", &N) == 1);

    for (i = 1; i < 10; i++) {
        for (k = 1; k < 10; k++) {
            seki = i * k;
            if (seki == N) {
                printf("Yes");
                return(0);
            }
        }
    }
    printf("No");
    return(0);
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;


struct Book {
    ll price;
    vector<ll> points;
};


int main() {
    ll n, m, x;
    cin >> n >> m >> x;

    vector<Book> books(n);
    rep(i, n) {
        cin >> books[i].price;
        books[i].points = vector<ll>(m);
        rep(j, m) cin >> books[i].points[j];
    }

    ll ans = INF;
    rep(i, 1 << n) {
        vector<ll> points(m);
        ll price = 0;
        rep(j, n) {
            bool b = (i >> j) & 1;
            if (!b) continue;
            rep(k, m) points[k] += books[j].points[k];
            price += books[j].price;
        }

        ll p = *min_element(points.begin(), points.end());
        if (p < x) continue;
        cmin(ans, price);
    }
    if (ans == INF) {
        cout << -1 << endl;
        ret();
    }
    cout << ans << endl;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n, m; cin >> n >> m;

    cout << (n-1) * (m-1);
}


Measured memory_bytes: 256
// You may see me struggle,but you will never see me quit!
#include <bits/stdc++.h>
 using namespace std;
#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define pb                      push_back
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define asort(c)                sort(all(c)) 
#define lbpos(x,v)              (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB 
#define ubpos(x,v)              (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB
#define PI                      3.14159265358979323846
#define int                     long long
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  long double                 ld;
#define debug(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
clock_t time_p=clock();
void timer()
{
    time_p=clock()-time_p;
    cerr<<"Execution Time: "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";
}


int32_t main()
{
  FIO;
 /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif*/
 
  int n,k,mi=mod;
  cin>>n>>k;
  int a[n+1];
  rep(i,1,n)
  cin>>a[i];
  sort(a+1,a+1+n);
  rep(i,1,n-k+1)
  mi=min(mi,a[i+k-1]-a[i]);
  cout<<mi;
 // timer();
  return 0;
}  

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        long mod = (long)Math.pow(10,9)+7;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] march = {'M','A','R','C','H'};
        long[] a = new long[5];
        for(int i = 0; i < n; i++){
            String s = sc.next();
            char f = s.charAt(0);
            for(int j = 0; j < 5; j++){
                if(march[j] == f){
                    a[j]++;
                    break;
                }
            }
        }
        long ans = 0;
        for(int i = 0; i < 5; i++){
            for(int j = i+1; j < 5; j++){
                for(int k = j+1; k < 5; k++){
                    ans += (a[i] * a[j] * a[k]); 
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 46024
n = int(input())
h = list(map(int, input().split()))

maxi = 0
cnt = 0

for i in range(n-1):
    if h[i] >= h[i+1]:
        cnt += 1
    else:
        maxi = max(maxi,cnt)
        cnt = 0
    maxi = max(maxi,cnt)
print(maxi)
    

Measured memory_bytes: 14252
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    static const double pi = 3.141592653589793;
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int minutes;
    minutes = h * 60 + m;
    double theta, a_theta, b_theta;
    a_theta = minutes * pi / 360;
    b_theta = minutes * pi / 30;

    theta = a_theta - b_theta;

    double c;

    c = pow(pow(a,2) + pow(b,2) - 2 * a * b * cos(theta), 0.5);

    cout << fixed << setprecision(20) << c << endl;

    return 0;
}

Measured memory_bytes: 4356
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	m := getNextInt(scanner)
	k := getNextInt(scanner)
	ans := make([]string, 1<<uint(m+1))

	if k == 0 {
		for i := 0; i < 1<<uint(m); i++ {
			ans[i*2] = fmt.Sprintf("%d", i)
			ans[i*2+1] = fmt.Sprintf("%d", i)
		}
		fmt.Println(strings.Join(ans, " "))
		return

	}

	if 1<<uint(m) <= k {
		fmt.Println(-1)
		return
	}
	check := k
	for i := 0; i < 1<<uint(m); i++ {
		if i == k {
			continue
		}
		check ^= i
	}

	if check != 0 {
		fmt.Println(-1)
		return
	}

	ans[1<<uint(m)-1] = fmt.Sprintf("%d", k)
	ans[1<<uint(m+1)-1] = fmt.Sprintf("%d", k)
	ii := 0
	for i := 0; i < 1<<uint(m); i++ {
		if i == k {
			continue
		}
		ii++
		ans[1<<uint(m)-1+ii] = fmt.Sprintf("%d", i)
		ans[1<<uint(m)-1-ii] = fmt.Sprintf("%d", i)
	}

	fmt.Fprintln(writer, strings.Join(ans, " "))
	writer.Flush()
}


Measured memory_bytes: 15616
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////
int H, W;
char A[1010][1010];
int d[1010][1010];
int main() {
	cin >> H >> W;
	queue<pii>Q;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				Q.push({ i,j });
				d[i][j] = 0;
			}
			else {
				d[i][j] = INF;
			}
		}
	}
	while (!Q.empty()) {
		int y = Q.front().first;
		int x = Q.front().second;
		Q.pop();
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i];
			int nx = x + dx[i];
			if (0 <= ny && ny < H && 0 <= nx && nx < W&&A[ny][nx] == '.'&&d[ny][nx]==INF) {
				Q.push({ ny,nx });
				d[ny][nx] = min(d[ny][nx],d[y][x] + 1);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (d[i][j] == 0)continue;
			ans = max(ans, d[i][j]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	ll n;
	cin >> n;
	ll x = n % 10;
	if (x == 3) {
		return cout << "bon", 0;
	}
	if (!x || x == 1 || x == 6 || x == 8) {
		return cout << "pon", 0;
	}
	cout << "hon";

}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int k,s,count = 0;;
	cin >> k >> s;
	for(int x = 0; x <= k; x++){
		for(int y = 0; y <= k; y++){
			if(x+y <= s && s-x-y <=  k) count ++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] as = new int[n];
        for (int i = 0; i < n; i++) as[i] = input.nextInt();
        StringBuilder sb = new StringBuilder();
        for (int i = n - 1; i >= 0; i--) sb.append(as[i]).append(' ');
        System.out.println(sb.toString().trim());
    }
}

Measured memory_bytes: 18124
#include "bits/stdc++.h"
using namespace std;

int main() {
    int N, L;
    cin >> N >> L;

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

    sort(vec.begin(), vec.end());

    for (int i = 0; i < N; i++) {
        cout << vec.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;
typedef long long ll;

int main(int argc, char* argv[])
{
    ll N;
    ll ret = 1e18;
    cin >> N;
    ll max = (ll)sqrt(N);
    for(ll k=max; k>0; k--){
        if(N%k==0){
            ret = N/k + k - 2;
            break;
        }
    }
    cout << ret << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  map<string,ll> cnt;
  for(ll i=0;i<n;i++) {
    string s;
    cin >> s;
    cnt[s]++;
  }
  ll m;
  cin >> m;
  for(ll i=0;i<m;i++) {
    string s;
    cin >> s;
    cnt[s]--;
  }
  ll ans=0;
  for(auto p:cnt) {
    ans=max(ans,p.second);
  }
  cout << ans << endl;
}

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

typedef int weight;
typedef pair<weight, int> P;

class edge {
public:
	int to, cap;
	weight cost;
	int rev;
	edge(int t, int ca, weight co, int r):to(t), cap(ca), cost(co), rev(r){};
};

vector<vector<edge> > G;

void init(int n) {
	G.clear();
	G.resize(n);
}

void add_edge(int from, int to, int cap, weight cost) {
	G[from].push_back(edge(to, cap, cost, G[to].size()));
	G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}

weight min_cost_flow(int s, int t, int f) {
	const int n = G.size();
	weight res = 0;
	vector<int> prevv(n), preve(n);
	vector<weight> h(n, 0);
	while(f > 0) {
		priority_queue<P, vector<P>, greater<P> > que;
		vector<weight> dist(n, INT_MAX);
		dist[s] = 0;
		que.push(P(0, s));
		while(!que.empty()) {
			const P p = que.top();
			que.pop();
			const int v = p.second;
			if(dist[v] < p.first)
				continue;

			for(int i = 0; i < G[v].size(); ++i) {
				const edge &e = G[v][i];
				if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
					dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
					prevv[e.to] = v;
					preve[e.to] = i;
					que.push(P(dist[e.to], e.to));
				}
			}
		}

		if(dist[t] == INT_MAX)
			return -1;

		for(int v = 0; v < n; ++v)
			h[v] += dist[v];

		int d = f;
		for(int v = t; v != s; v = prevv[v])
			d = min(d, G[prevv[v]][preve[v]].cap);

		f -= d;
		res += d * h[t];
		for(int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}

	return res;
}

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

	vector<int> p(n);
	for(auto &e : p) cin >> e;

	const int source = n + n;
	const int sink = source + 1;
	init(sink + 1);

	for(int i = 0; i < n; ++i) {
		add_edge(source, i, 1, 0);
		add_edge(i + n, sink, 1, 0);

		for(int j = 0; j < n; ++j) {
			if(p[i] == j + 1) continue;
			add_edge(i, j + n, 1, p[i] * abs(i - j));
		}
	}

	cout << min_cost_flow(source, sink, n) << endl;

	return 0;
}

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

class BIT
{
public:
	vector<ll> bit;
	int n;

	BIT(ll num):
		bit(vector<ll>(num+1)), n(num) {}

	ll sum(ll a) {
		ll ret = 0;
		for (int x = a; x > 0; x -= (x & -x))
		{
			ret += bit[x];
		}
		return ret;
	}

	void add(int a, ll w) {
		for (int x = a; x <= n; x += (x & -x))
		{
			bit[x] += w;
		}
		return;
	}

};

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> b(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> b[i];
		b[i] -= k;
	}
	vector<pair<ll, int> > p(n+1);
	for (int i = 0; i < n; ++i)
	{
		p[i+1].first = p[i].first + b[i];
		p[i+1].second = i+1;
	}
	sort(p.begin(), p.end());
	vector<ll> a(n+1);
	for (int i = 0; i < n+1; ++i)
	{
		a[p[i].second] = i+1;
	}
	
	BIT bit(n);
	
	ll ans = 0;
	for (int i = 0; i < n+1; ++i)
	{
		ans += bit.sum(a[i]-1);
		bit.add(a[i], 1);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define F first
#define S second

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-8, INF=1e12;

typedef complex<double> P;
bool sameline(int a,int b,int c,int p,int q,int r){
	if(a*q!=b*p)return 0;
	if(a==0)return b*r==c*q;
	return a*r==c*p;
}
void push(vector<P> &v,const P &p){
	rep(i,v.size())if(abs(v[i]-p)<EPS)return;
	v.pb(p);
}
P crosspoint(const pair<pi,int> &a,const pair<pi,int> &b){
	int a1=a.F.F,b1=a.F.S,c1=a.S,a2=b.F.F,b2=b.F.S,c2=b.S;
	double x=(-b2*c1+b1*c2)*1.0/(a1*b2-a2*b1),y=(a2*c1-a1*c2)*1.0/(a1*b2-a2*b1);
	return P(x,y);
}

int n,a,b,c,d,e,f;
vector<pair<pi,int> > ls;
vector<P> cps[20],cp;
vector<P> pts;

vector<P> cpLC(const pair<pi,int> &l){
	int a1=a,b1=b,c1=c,d1=d,e1=e,f1=f,d2=l.F.F,e2=l.F.S,f2=l.S;
	if(e2==0){
		swap(a1,c1); swap(d1,e1); swap(d2,e2);
	}
	vector<P> res;
	int p=a1*e2*e2-b1*e2*d2+c1*d2*d2;
	int q=-b1*e2*f2+2*c1*d2*f2+d1*e2*e2-e1*e2*d2;
	int r=c1*f2*f2-e1*e2*f2+f1*e2*e2;
	if(p==0){
		double x=-r*1.0/q, y=(-f2-d2*x)/e2;
		res.pb(P(x,y));
	}
	else{
		ll D=(ll)q*q-4ll*p*r;
		if(D==0){
			double x=-q/2.0/p,y=(-f2-d2*x)/e2;
			res.pb(P(x,y));
		}
		else if(D>0){
			double x1=(-q+sqrt(q*1.0*q-4.0*p*r))/2/p,y1=(-f2-d2*x1)/e2;
			double x2=(-q-sqrt(q*1.0*q-4.0*p*r))/2/p,y2=(-f2-d2*x2)/e2;
			res.pb(P(x1,y1)); res.pb(P(x2,y2));
		}
	}
	if(e2==0)rep(i,res.size())swap(res[i].real(),res[i].imag());
	
	return res;
}

int main(){
	cin>>n>>a>>b>>c>>d>>e>>f;
	rep(i,n){
		int a,b,c;
		cin>>a>>b>>c;
		rep(j,ls.size())if(sameline(ls[j].F.F,ls[j].F.S,ls[j].S,a,b,c)){
			n--;
			goto NEXT;
		}
		ls.pb(mp(mp(a,b),c)); NEXT:;
	}
	rep(i,n)rep(j,i)if(ls[i].F.F*ls[j].F.S!=ls[i].F.S*ls[j].F.F){
		push(cps[i],crosspoint(ls[i],ls[j]));
		push(cps[j],crosspoint(ls[i],ls[j]));
	}
	rep(i,n){
		vector<P> tmp=cpLC(ls[i]);
		rep(j,tmp.size())push(cp,tmp[j]), push(cps[i],tmp[j]);
	}
	rep(i,n)rep(j,cps[i].size())push(pts,cps[i][j]);

	int ans=1-(int)pts.size();
	rep(i,n)ans+=cps[i].size()+1;
	if(b*b<4*a*c)ans+=max(1,(int)cp.size());
	else if(b*b==4*a*c)ans+=cp.size()+1;
	else ans+=cp.size()+2;
	
	cout<<ans<<endl;
	
	return 0;
}

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


int digit(int n){
    int a = n % 10;
    return a;
}



int main(){
    int last = 10;
    int index = 0;  
    vector<int> vec(5);
    rep(i,5){
        cin >> vec[i];
    }
    rep(i, 5){
        int num = digit(vec[i]);
        if (num < last && num != 0){
            last = digit(vec[i]);
            index = i;
        }
    }
    int sum =0;
    rep(i, 5){
        int num = digit(vec[i]);
        if (i == index){
            sum += vec[i];
        }
        else {
            if (num != 0){
                sum += vec[i] + 10 - num;
            }
            else {
                sum += vec[i];
            }
        }
    }

    cout << sum << endl;


    // do {
    //     for (int i=0; i<5; i++){

    //     }
    // }while(next_permutation(vec.begin(), vec.end()));
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int H,W;
int shp_cnt = 0;
int dy[2] = {0,1};
int dx[2] = {1,0};
int dfs(pair<int,int> pos,const vector<vector<char>> &v, int depth) {
    auto goal = make_pair(H,W);
    if (depth == shp_cnt && goal==pos) return depth;
    if(v[pos.first][pos.second] == '.') return -1;
    auto pos1 = make_pair(pos.first+dy[0],pos.second+dx[0]);
    auto pos2 = make_pair(pos.first+dy[1],pos.second+dx[1]);

    int ret1 = dfs(pos1,v,depth+1);
    int ret2 = dfs(pos2,v,depth+1);

    return max(ret1,ret2);
}

void solve() {
    cin >> H >> W;
    vector<vector<char>> v(H+2,vector<char>(W+2,'.'));
    FOR(i,1,H+1) {
        FOR(j,1,W+1) {
            cin >> v[i][j];
            if (v[i][j]=='#') shp_cnt++;
        }
    }
    auto st = make_pair(1,1);
    auto ans = (dfs(st,v,1)==-1) ? "Impossible" : "Possible";

    cout << ans << endl;

}


int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)

  var result []int
  for{
    n := nextInt()
    x := nextInt()
	if n == 0 && x == 0 {
		break
	}
	count := 0
	for i := 1; i <= n ;i++ {
	  for j := 1; j <= n ;j++ {
	    for r := 1; r <= n ;r++ {
			if i + j + r == x && i != j && j != r && i != r{
				count++
			}
	    }
	  }
	}
	count = count / 6
	result = append(result, count)
 }
  length := len(result)
  for i := 0; i < length;i++ {
    fmt.Println(result[i])
  }
}


func getStdin() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

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

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}



Measured memory_bytes: 1064
using System;
using System.Linq;

namespace _2199
{
	class Program
	{
		static void Main(string[] args)
		{
			while (true)
			{
				int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
				if (x.Max() == 0) break;
				int[] plus = new int[x[1]];
				for (int i = 0; i < x[1]; i++) plus[i] = int.Parse(Console.ReadLine());
				long[] adp = new long[256];
				for (int i = 0; i < 256; i++) if (i != 128) adp[i] = (long)Math.Pow(10, 16);

				for (int i = 0; i < x[0]; i++)
				{
					long[] bdp = new long[256];
					for (int j = 0; j < 256; j++) bdp[j] = (long)Math.Pow(10, 16);
					long terget = long.Parse(Console.ReadLine());
					for (int j = 0; j < 256; j++)
					{
						for (int k = 0; k < x[1]; k++)
						{
							int changed = Math.Max(0, Math.Min(j + plus[k], 255));
							bdp[changed] = Math.Min(bdp[changed], adp[j] + (long)Math.Pow(changed - terget, 2));
						}
					}
					adp = bdp;
				}
				Console.WriteLine(adp.Min());
			}
		}
	}
}


Measured memory_bytes: 20504
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// fn main() {
//     input! {
//         S: chars,
//         T: chars,
//         n: i32,
//         m: i32,
//         U: chars
//     }
//     if S == U {
//         println!("{} {}", n-1, m);
//     } else {
//         println!("{} {}", n, m-1);
//     }
// }

fn main() {
    input! {
        S: chars
    }
    let L = S.len();
    for i in 0..L {
        print!("x");
    }
    println!();
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,x,sum=0,minx=1000000,maxx=-1000000;
  cin>>n;
  for(int i=1;i<=n;++i){
    cin>>x;
    sum+=x;
    maxx=max(maxx,x);
    minx=min(minx,x);
  }
  cout<<minx<<" "<<maxx<<" "<<sum<<endl;
  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
  int n;
  cin>>n;
  bool ok= true;
  set<int> s;
  for(int i=0; i<n ; i++){
    int tmp;
    cin>>tmp;
    s.insert(tmp);
  }
  if(s.size()==n) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
}

Measured memory_bytes: 9600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
  int X, gohaku, go;

  scanf("%d", &X);

  gohaku = X / 500;
  X = X - 500 * gohaku;
  go = X / 5;
  printf("%d\n", 1000*gohaku+5*go);

  return 0;
}


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

int main(){
  int a, b;
  cin >> a >> b;
  string str;
  cin >> str;
  for (int i = 0; i < a+b+1; i++){
    if (i != a){
      if (str[i] == '-'){
        printf("No\n");
        return 0;
      }
    }
    else{
      if (str[i] != '-'){
        printf("No\n");
        return 0;
      }
    }
  }
  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < (int)n;i++)
#define repb(i,n) for(int i = (int)n;i >= 0;i--)
#define reps(i,m,n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i,m,n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v,n) sort(v,v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int d;
    cin>>d;
    d-=24;
    cout << "Christmas";
    rep(i,10){

      if(d+i>0){
        cout <<  '\n';
        return 0;
      }
      cout << " Eve";

    }
    return 0;
}


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


void solve(long long K, std::string S){
    if(K >= S.size()) {
        cout << S << endl;
    }else { 
        for(int i = 0; i < K; i++) {
            cout << S[i];
        }
        cout << "..." << endl;
    }

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n);
  cin>>a;
  vi p = a;
  sort(rng(p));
  bool ok = false;
  if (a == p) ok = true;
  rep(i,n)rep(j,i) {
    vi b = a;
    swap(b[i],b[j]);
    if (b == p) ok = true;
  }
  if (ok) yn;
  return 0;
}






















Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.Maybe

solve :: String  -> String -> Maybe String
solve [] a =
  if (reverse.take 3) a == (take 3.reverse) a
    then Just a
    else Nothing
solve (_:_) [] = undefined
solve (_:_) [_] = undefined
solve (_:_) [_, _] = undefined
solve (c:s) (a1:a2:a3:as)
  | c == 'o' && a2 == 'S' && a1 == a3 = listToMaybe $ mapMaybe (\x-> solve s (x:a1:a2:a3:as)) "SW"
  | c == 'o' && a2 == 'W' && a1 /= a3 = listToMaybe $ mapMaybe (\x-> solve s (x:a1:a2:a3:as)) "SW"
  | c == 'x' && a2 == 'S' && a1 /= a3 = listToMaybe $ mapMaybe (\x-> solve s (x:a1:a2:a3:as)) "SW"
  | c == 'x' && a2 == 'W' && a1 == a3 = listToMaybe $ mapMaybe (\x-> solve s (x:a1:a2:a3:as)) "SW"
  | otherwise = Nothing

main = do
  _ <- read <$> getLine :: IO Int
  s <- getLine :: IO String
  case listToMaybe (mapMaybe (solve s) [[a1,a2,a3]|a1<-"SW",a2<-"SW",a3<-"SW"]) of
    Just ans ->
      putStrLn $ reverse $ init $ drop 2 ans
    Nothing -> putStrLn "-1"


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

#define int long long

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
const int INF = 1e18;

// idx, (未処理, 偶数左, 奇数, 偶数右)
const int VARI = 5;
int dp[200010][VARI];

signed main() {
  int N;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }

  const int one = 0; // 左のゼロ区間
  const int two = 1; // 右のゼロ区間
  const int three = 2; // 左の偶数区間
  const int four = 3; // 右の偶数区間
  const int five = 4; // 奇数区間

  // 初期化
  fill(dp[0], dp[N+1], INF);
  dp[0][one] = 0;
  dp[0][two] = 0;
  dp[0][three] = 0;
  dp[0][four] = 0;
  dp[0][five] = 0;

  // DP
  for (int i = 0; i < N; i++) {
    // 左のゼロ区間
    int cost1 = v[i];
    chmin(dp[i+1][one], dp[i][one] + cost1);

    // 左の偶数区間
    int cost2 = v[i] == 0 ? 2 : v[i] % 2;
    chmin(dp[i+1][two], min(dp[i][one], dp[i][two]) + cost2);

    // 奇数区間
    int cost3 = v[i] == 0 ? 1 : (v[i] % 2 == 0);
    chmin(dp[i+1][three], min({dp[i][two], dp[i][three], dp[i][one]}) + cost3);

    // 右の偶数区間
    int cost4 = v[i] == 0 ? 2 : v[i] % 2;
    chmin(dp[i+1][four], min({dp[i][three], dp[i][four], dp[i][two], dp[i][one]}) + cost4);

    // 右のゼロ区間
    int cost5 = v[i];
    chmin(dp[i+1][five], min({dp[i][four], dp[i][three], dp[i][two], dp[i][one], dp[i][five]}) + cost5);
  }

  int ans = INF;
  for (int i = 0; i < VARI; i++) {
    chmin(ans, dp[N][i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  if(n%1000==0){
    COUT(0);
  }
  else{
    COUT((n+999)/1000*1000-n);
  }
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  ll X;
  cin >> X;
  ll N = 100;
  ll cnt = 0;
  while(N < X) {
    cnt++;
    N *= 1.01;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3536
fn main() {
    let n: usize = read();
    let mut a = vec![vec![0;n];n];

    let mut stack = vec![(0,n,1)];
    while let Some((l,len,lv)) = stack.pop() {
        match len {
            1 => (),
            2 => a[l][l+1] = lv,
            _ => {
                for i in l..l+len/2 {
                    for j in l+len/2..l+len {
                        a[i][j] = lv;
                    }
                }
                stack.push((l,len/2,lv+1));
                stack.push((l+len/2,(len+1)/2,lv+1));
            }
        }
    }

    for i in 0..n-1 {
        for j in i+1..n {
            print!("{} ",a[i][j]);
        }
        print!("\n");
    }
}
fn get_line() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().to_owned()
}

fn read<T: std::str::FromStr>() -> T{
    get_line().parse().ok().unwrap()
}

Measured memory_bytes: 4604
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    int a[6],all=0;
    for(int i=0;i<5;i++){
        cin>>a[i];
        if(a[i]<40)a[i]=40;
        all+=a[i];
    }
    cout<<all/5<<endl;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(){
  char s[4];
  int i,count=0;
  scanf("%s",&s);
  for(i=0;i<3;i++){
      if(s[i]==s[i+1]) count++;
  }
  if(count==0)printf("Good\n");
  else printf("Bad\n");
  return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())

ans = 0

left = 0
right = 0

m = 10**9+7
for i in range(k-1):
    left += i

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


for i in range(k,n+2):
    left += i-1
    right += n-(i-1)
    ans += max(0,(right-left)+1)
    ans %= m
    # print(left,right,ans)

print(ans)

Measured memory_bytes: 9204
from collections import deque

H,W = map(int,input().split())
A = [input() for _ in range(H)]
check = [[-1]*W for _ in range(H)]

def bfs(l):
    ans = 0
    q = deque(l)
    for l_ in l:
        check[l_[0]][l_[1]] = 0
    while q:
        y,x = q.popleft()
        for dy,dx in [[1,0],[-1,0],[0,1],[0,-1]]:
            ny,nx = y+dy,x+dx
            if 0 <= ny < H and 0<= nx < W:
                if check[ny][nx] == -1 and A[ny][nx] == '.':
                    check[ny][nx] = check[y][x] + 1
                    ans = max(ans,check[ny][nx])
                    q.append([ny,nx])
    return ans 

L = []
for h,a in enumerate(A):
    for w,a_ in enumerate(a):
        if a_ == '#':
            L.append([h,w])
print(bfs(L))

Measured memory_bytes: 155100
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int n, k, r, s, p;
  scanf("%d %d", &n, &k);
  scanf("%d %d %d", &r, &s, &p);
  char t[n+1];
  scanf("%s", t);
  int ans = 0;
  for (int i=0; i<k; i++) {
    if (t[i] == 'r')
      ans += p;
    else if (t[i] == 's')
      ans += r;
    else
      ans += s;
    for (int j = i + k; j < n; j += k)
    {
      if (t[j] == t[j-k]) t[j] = 'o';
      else {
        if (t[j] == 'r')
          ans += p;
        else if (t[j] == 's')
          ans += r;
        else
          ans += s;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <cstring>
#include <string>
#include <limits.h>
#include <cmath>
#include <algorithm>

using namespace std;

typedef long long int LLN;

const int maxn = 100 + 5;
char grid[maxn][maxn];

int genCore(int num, const int max_col){
    int max_row = maxn;

    int cur_row = 0;
    while(cur_row < max_row && num > 0){
        for(int j = 0; j < max_col && num > 0;){
            if(cur_row % 2){
                grid[cur_row][j] = 0;
                grid[cur_row][j + 1] = 1;
            }
            else{
                grid[cur_row][j] = 1;
                grid[cur_row][j + 1] = 0;
            }

            --num;
            j += 2;

            if(num <= 0){
                break;
            }
        }

        ++cur_row;
    }

    return cur_row;
}

int genExtra(int diff, int offset_row, const int max_col){
    const int max_row = maxn;

    int cur_row = offset_row;
    while(cur_row < max_row && diff > 0){
        //for(int j = 0; j < max_col; ++j){
        //    grid[i][j] = 0;
        //}

        ++cur_row;
        for(int j = 0; j < max_col && diff > 0;){

            grid[cur_row][j] = 1;
            grid[cur_row][j + 1] = 0;

            --diff;
            j += 2;

            if(diff <= 0){
                break;
            }
        }
        ++cur_row;
    }

    return cur_row;
}

void color(char *index, const int max_row, const int max_col){
    for(int i = 0; i < max_row; ++i){
        for(int j = 0; j < max_col; ++j){
            grid[i][j] = index[grid[i][j]];
        }
    }
}

void print(const int max_row, const int max_col){
    for(int i = 0;i < max_row; ++i){
        printf("%s\n", grid[i]);
    }
}

void print_debug(const int max_row, const int max_col){
    printf("----------\n");
    for(int i = 0; i < max_row; ++i){
        for(int j = 0; j < max_col; ++j){
            printf("%d ", grid[i][j]);
        }
        printf("\n");
    }
    printf("----------\n");
}

int main(){
    int A, B;
    const int max_row = 100;
    const int max_col = 100;

    while(scanf("%d%d", &A, &B) != -1){
        memset(grid, 0, sizeof(grid));

        for(int i = 0; i < max_row / 2; ++i){
            for(int j = 0; j < max_col; ++j){
                grid[i][j] = '.';
                grid[i + max_row / 2][j] = '#';
            }
        }

        --B;
        --A;
        for(int i = 0; i < max_row / 2; i += 2){
            if(A == 0 && B == 0){
                break;
            }
            for(int j = 0; j < max_col; j += 2){
                if(B > 0){
                    grid[i][j] = '#';
                    --B;
                }
                if(A > 0){
                    grid[max_row - i - 1][max_col - j - 1] = '.';
                    --A;
                }
            }
        }

        printf("%d %d\n", max_row, max_col);
        print(max_row, max_col);
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;
bool f[1005];
int main(void){
	int N;cin >> N;
	int A[N+1][N+1];
	vector<int> v(1005,1);
	for(int i=1;i<=N;i++){
		for(int j=1;j<=N-1;j++){
			cin >> A[i][j];
		}
	}
	int ans = 0;
	bool ok = 1;

  //今日対戦する可能性のある人
  vector<int> nx(N);
  for(int i=1;i<=N;i++) nx[i-1] = i;
	
  while(ok){
		ok = 0;
		ans ++;
		//cout << ans <<"日目" << endl;
		for(int i=1;i<1005;i++)f[i] = 1;
    vector<int> tmp;
		for(int i:nx){
			if(v[i]==N)continue;
			int op = A[i][v[i]];//opは対戦相手の番号
			if(A[op][v[op]] == i && f[op]*f[i] == 1){
				//cout << i << "vs" << op << endl;
				v[op]++;
				v[i] ++;
				f[op] = 0;
				f[i]  = 0;
				ok = 1;
        tmp.emplace_back(i);
        tmp.emplace_back(op);
			}
		}
		if(!ok)ans--;
    nx = tmp; //更新された人をメモしておく
	}
	ok = 1;
	for(int i=1;i<=N;i++){
		if(v[i]!=N)ok = 0;
		
	}
	if(ok){
		cout << ans << endl;
	}else{
		cout << -1 << endl;
	}
}

Measured memory_bytes: 4224