akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
    for (int i = 1, v, w; i <= n; i++)
    {
        scanf("%d %d", &v, &w);
        for (int j = 0; j <= m; j++)
        {
            if (j < w)
            {
                dp[i][j] = dp[i - 1][j];
            }
            else
            {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
            }
        }
    }
    printf("%d\n", dp[n][m]);
}


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

int main(int argc, char **argv) {
  int i;
  long long X;
  cin >> X;

  long A;
  long B;
  for (A = -500; A < 500; ++A) {
    for (B = -500; B < 500; ++B) {
      if ((pow(A, 5) - pow(B, 5)) == X)
        goto END;
    }
  }
END:

  cout << A << " " << B << endl;
  return 0;
}


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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double w;
  w = M_PI*11*( 60*H + M )/360;
  double y;
  y = pow(A,2) + pow(B,2)-2*A*B*cos(w);
  double x;
  x = sqrt(y);
  printf("%.15f\n", x);
}


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

const int maxn = 22;
int N, a[maxn][maxn];
const int M = 1e9+7;
int dp[maxn][1<<maxn];

void madd(int& a, int b) {
    a += b;
    while (a > M) a -= M;
}

int f(int i, int mask) {
    if (i == N) return 1;
    if (dp[i][mask] != -1) return dp[i][mask];
    dp[i][mask] = 0;
    for (int j = 0; j < N; j++) {
        if (!((1<<j) & mask) && a[i][j]) {
            madd(dp[i][mask],f(i+1,mask|(1<<j)));            
        }
    }
    return dp[i][mask];
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }
    memset(dp,-1,sizeof dp);
    int ans = f(0,0);
    cout << ans << '\n';


    return 0;
}



Measured memory_bytes: 360832
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll L,R,mini=10000;

ll co(ll a,ll b){
    if(a>b)return b;
    else return a;
}

int main(){
    cin>>L>>R;
    if(R-L>=2018)out(0);
    else{
        repi(i,L,R+1)repi(j,i+1,R+1)mini=co(mini,((i%2019)*(j%2019))%2019);
        out(mini);
    }

    
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{   char s[101];
    scanf("%s",s);
    int l=strlen(s),ans=0;
    for(int i=0;i<l/2;i++){
        if(s[i]!=s[l-i-1])ans++;
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a = in.nextInt();
		int b = in.nextInt();

		long answer;

		if(n==1 && a!=b){
			System.out.println(0);
		}else if(a>b){
			System.out.println(0);
		}else{
			Integer iB = b;
			BigInteger bigB = new BigInteger(iB.toString());
			Integer iA = a;
			BigInteger bigA = new BigInteger(iA.toString());
			Integer iN = n-2;
			BigInteger bigN = new BigInteger(iN.toString());

			BigInteger big = bigB.subtract(bigA);
			big = big.multiply(bigN);
			BigInteger one = new BigInteger("1");
			big = big.add(one);
			System.out.println(big);
		}
	}
}


Measured memory_bytes: 23892
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Numerics;

class Myon
{
    //chokudaiさんのコードをコピペ
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        Console.Read();

        return 0;
    }


    public void calc()
    {
        int n = cin.nextInt();
        double output =  (n -(n / 2)) / (double)n;
        Console.WriteLine(output);
    }



    public void backetSort(ref int[] a)
    {
        //max a << a.len に対して有効なソート
        //よってa = int[] とする
        long n = a.Length;
        var count = new int[n];
        var loc = new long[n];//loc[i] は i が終わる 位置 max index where c[index] = loc[i]
        for (long i = 0; i < n; i++) count[a[i]]++;
        loc[0] = count[0] - 1;
        for (long i = 0; i < n-1; i++) loc[i+1] = loc[i] + count[i+1]; 
        long index = 0;

        for(int i = 0; i < n; i++)
        {
            while (index <= loc[i]) a[index++] = i; //incex <= loc[i] == index < loc[i] + 1
        }
    }

    public static void showL(long n) { Console.WriteLine(n); }
    public static void showL(string s) { Console.WriteLine(s); }
}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

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

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

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

    public int nextInt()
    {
        return int.Parse(next());
    }

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

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

}

Measured memory_bytes: 11092
#include <bits/stdc++.h> // Ishaan Gupta
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifdef IG_PC
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define endl '\n'
#define pb push_back
using ll = long long;
using ld = long double;
const ll MOD = 1e9l + 7;
const ll INF = 1e18l + 5;
inline ll add(ll a,ll b){return (a%MOD+b%MOD)%MOD;}
inline ll sub(ll a,ll b){return (a%MOD-b%MOD+MOD)%MOD;}
inline ll mult(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll power(ll a,ll b){a%=MOD;ll r=1;while(b){if(b&1)r=mult(r,a);a=mult(a,a);b>>=1;}return r;}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
#ifdef IG_PC
    freopen("input", "r", stdin);
    freopen("output", "w", stdout);
#endif
    ll h,w;
    cin >> h >> w;
    vector<string>grid(h);
    for(ll i=0;i<h;++i)
    {
        string row;
        cin >> row;
        grid[i]=row;
    }
    vector<vector<ll>>dp(h,vector<ll>(w,0));
    dp[0][0]=1;
    for(ll row = 0; row < h; ++row)
    {
        for(ll col = 0; col < w; ++col)
        {
            for(ll r2 : {row, row+1})
            {
                ll c2 = col;
                if(r2==row)
                    c2=col+1;
                if(r2<h && c2 < w && grid[r2][c2]=='.')
                    dp[r2][c2] = add(dp[r2][c2], dp[row][col]);
            }
        }
    }
    cout<<dp[h-1][w-1];

    return 0;
}

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

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n;
    int sum=0, now;
    
    scanf("%d", &n);
    
    now=n;
    
    while (now>0) {
        sum+=now%10;
        now=now/10;
    }
    
    if (n%sum==0) {
        printf("Yes");
    } else {
        printf("No");
    }
    
    return 0;
}


Measured memory_bytes: 1712
import sys
sys.setrecursionlimit(10**9)

MOD = 10**9 + 7

N, X = map(int, input().split())
Ss = list(map(int, input().split()))

Ss.sort(reverse=True)

def dfs(i, xNow):
    if memo[i][xNow] != -1:
        return memo[i][xNow]
    if i == N-1:
        ans = xNow % Ss[i]
    else:
        ans = dfs(i+1, xNow % Ss[i])
        ans += dfs(i+1, xNow) * (N-i-1)
    ans %= MOD
    memo[i][xNow] = ans
    return ans

memo = [[-1]*(X+1) for _ in range(N+1)]
dfs(0, X)

print(memo[0][X])


Measured memory_bytes: 188660
#include<iostream>
#include<bitset>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define INF 1e9
using namespace std;

long long min(long long a,long long b){return (a<b)?a:b;}

int main(){
  int n,m,r,a,b,c;
  cin>>n>>m>>r;
  int need[r];
  rep(i,r){
    cin>>need[i];
    need[i]--;
  }
  long long dist[n][n];
  rep(i,n)rep(j,n)dist[i][j]=INF;
  rep(i,m){
    cin>>a>>b>>c;
    a--;b--;
    dist[a][b]=dist[b][a]=c;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n){
	dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  long long dp[(1<<(r+1))][r];
  rep(i,(1<<r))rep(j,r)dp[i][j]=INF;
  rep(i,r)dp[(1<<i)][i]=0;
  rep(i,(1<<r)){
    rep(j,r){
      if(i&(1<<j)==0)continue;
      rep(k,r){
	if(i&(1<<k))continue;
	dp[i|(1<<k)][k]=min(dp[i|(1<<k)][k],dp[i][j]+dist[need[j]][need[k]]);
      }
    }
  }
  long long ans=INF;
  rep(i,r){
    ans=min(ans,dp[(1<<r)-1][i]);
  }
  cout<<ans<<endl;
  return 0;
}


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

long long pow2(long long x, long long n, int mod=0) {
  if (n == 0) return 1;
  if (mod) {
    if (n & 1) return x * pow2(x, n - 1, mod) % mod;
    long long y = pow2(x, n / 2, mod);
    return y * y % mod;
  } else {
    if (n & 1) return x * pow2(x, n - 1);
    long long y = pow2(x, n / 2);
    return y * y;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k; cin >> n >> k;
  int c1 = n / k;
  long long cnt;
  if (k & 1) {
    cnt = pow(c1, 3);
  } else {
    int c2 = n / (k / 2);
    cnt = pow2(c1, 3) + pow2(c2 - c1, 3);
  }
  cout << cnt << '\n';
  return 0;
}

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

struct Item {
    int a, b;
};

int main() {
    int n, t;
    std::cin >> n >> t;

    std::vector<Item> items(n);
    for (auto& x : items) {
        std::cin >> x.a >> x.b;
    }

  	// 時間について昇順ソート
    std::sort(items.begin(), items.end(),
              [](Item x, Item y) { return x.a < y.a; });

  	// ナップザックDP
    std::vector<int> dp(t, 0);
    int ans = 0;
    for (auto& x : items) {
      	// xを最後にする場合
        ans = std::max(ans, dp.back() + x.b);
      	
      	// DPテーブルの更新
        for (int w = t - 1; w >= x.a; --w) {
            dp[w] = std::max(dp[w], dp[w - x.a] + x.b);
        }
    }

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


Measured memory_bytes: 256
from collections import defaultdict
n = int(input())
balls = []
diffs = [[None] * n for _ in range(n)]
for _ in range(n):
    x, y = [int(i) - 1 for i in input().split()]
    balls.append((x, y))

d = defaultdict(int)

# 各ボールの差分を計算する
for i in range(n):
    for j in range(n):
        ax, ay = balls[i]
        bx, by = balls[j]
        diffs[i][j] = (bx - ax, by - ay)
        if bx - ax != 0 or by - ay != 0:  # p≠0 または q≠0
            d[(bx - ax, by - ay)] += 1

_max = 0

for k, v in d.items():
    _max = max(_max, v)

print(n - _max)


Measured memory_bytes: 74152
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;

ll bit[200010];
ll n;

vector<int> G[1010], ans;

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= n)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return pow_mod(x, mod - 2);
}



int main(void)
{
	string s;
	ll k;
	vector<ll> vec;
	cin >> s >> k;
	ll sum = 1, ans = 0;
	for (int i = 1; i < s.length(); i++)
	{
		if (s[i] == s[i - 1])
		{
			sum++;
		}
		else
		{
			vec.push_back(sum);
			sum = 1;
		}
	}
	vec.push_back(sum);

	if (vec.size() == 1)
	{
		ans = s.length() * k / 2;
	}
	else if (s[0] == s[s.length() - 1])
	{
		for (int i = 1; i < vec.size() - 1; i++)
		{
			ans += vec[i] / 2;
		}
		ans *= k;
		ans += (vec[0] + vec[vec.size() - 1]) / 2 * (k - 1);
		ans += vec[0] / 2 + vec[vec.size() - 1] / 2;
	}
	else
	{
		for (int i = 0; i < vec.size(); i++)
		{
			ans += vec[i] / 2;
		}
		ans *= k;
	}

	cout << ans << endl;

	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <cstdio>

using namespace std;

int main() {
    int n, a;
    list<int> lst;


    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        scanf("%d", &a);
        if(i%2) lst.push_front(a);
        else    lst.push_back(a);
    }

    if(n%2) {
        list<int>::reverse_iterator it = lst.rbegin();

        while(1) {
            cout << *it;
            if(++it != lst.rend()) {
                cout << ' ';
            }
            else {
                cout << endl;
                break;
            }
        }
    }
    else {
        list<int>::iterator it = lst.begin();

        while(1) {
            cout << *it;
            if(++it != lst.end()) {
                cout << ' ';
            }
            else {
                cout << endl;
                break;
            }
        }
    }

    return 0;
}

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

int	Q(int i) {
	cout <<i <<endl;
	string S;
	cin >>S;
	if ('M'==S.at(0))
		return 1;
	else if ('F'==S.at(0))
		return 2;
	else
		return 0;
}

int	main() {
	int N;
	cin >>N;
	int l=0;
	int h=N-1;
	int L=-1;
	int H=-1;
	L=Q(l);
	if (0==L)
		return 0;
	H=Q(h);
	if (0==H)
		return 0;
	while(true) {
		int m=(h+l)/2;
		if (1==m%2)
			m--;
		if (l==m)
			m++;
		int M=Q(m);
		if (0==M)
			return 0;
		if (L==M) {
			l=m;
		} else {
			h=m;
		}
	}
	return 0;
}


Measured memory_bytes: 852
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Scanner;

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

		int n = src.nextInt();	//n要素数


		ArrayList<Integer> list = new ArrayList<>();	//list

		for(int i=0; i<n; i++) {
			list.add(src.nextInt());
		}


		LinkedHashSet<Integer> set = new LinkedHashSet<>(list);	//
		ArrayList<Integer> list2 = new ArrayList<>(set);


		for(int i=0; i<list2.size()-1; i++) {
			System.out.print(list2.get(i) + " ");
		}
		System.out.println(list2.get(list2.size()-1));
	}
}


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

const ll mod = 1e9 + 7;
const int maxn = 3010;
ll dp[maxn][maxn];

int main() {
	ios_base::sync_with_stdio(false);

	int n;
	string s;
	cin >> n >> s;
	dp[1][1] = 1;
	for (int i = 2; i <= n; i++) {
		ll pref[i];
		pref[0] = 0;
		for (int j = 1; j < i; j++) {
			pref[j] = (pref[j - 1] + dp[i - 1][j]) % mod;
		}
		for (int j = 1; j <= i; j++) {
			int l, r;
			if (s[i - 2] == '<') {
				l = 1, r = j - 1;
			} else {
				l = j, r = i - 1;
			}
			if (l <= r) {
				dp[i][j] = (pref[r] - pref[l - 1] + mod) % mod;
			}
		}
	}
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans = (ans + dp[n][i]) % mod;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 49744
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N;
    ll H[MAX_N];
    ll answer;

    cin >> N;
    rep(i, N) cin >> H[i];

    rep(i, N - 1){
        if (H[N - 2 - i] - 1 == H[N - 1 - i]) H[N - 2 - i] --;
        else if (H[N - 2 - i] > H[N - 1 - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<ll,P>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr double EPS = 1e-8;

bool solve(){
    int w, h;
    cin >> w >> h;
    if(w == 0) return true;
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin >> s[i];
    }
    vector<vector<int> > c(h, vector<int>(w,0));
    vector<vector<bool> > visited(h, vector<bool>(w));
    for(int t=0;t<2;t++){
        for(auto& v : visited) fill(v.begin(), v.end(), false);
        queue<P> que;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(s[i][j] == (t%2 ? 'W' : 'B')) que.push(P(i,j));
            }
        }
        while(!que.empty()){
            auto p = que.front();
            que.pop();
            int i = p.first, j = p.second;
            for(int k=0;k<4;k++){
                int ni = i+di[k], nj = j+dj[k];
                if(ni < 0 || ni >= h) continue;
                if(nj < 0 || nj >= w) continue;
                if(visited[ni][nj] || s[ni][nj] != '.') continue;
                visited[ni][nj] = true;
                que.push(P(ni,nj));
                c[ni][nj] += (t%2 ? -1:1);
            }
        }
    }
    int cnt[2]{};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(c[i][j] > 0) cnt[0]++;
            if(c[i][j] < 0) cnt[1]++;
        }
    }
    cout << cnt[0] << " " << cnt[1] << endl;
    return false;
}

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


Measured memory_bytes: 3208
mod = 10 ** 9 + 7

n, k = gets.to_s.split.map{|e|e.to_i}

# ans = (k..n+1).map{|i| i * (n + n - i + 1) / 2 - i * ( i - 1 ) / 2 + 1 }.sum % mod
ans = n - k + 2
(k..n+1).each do |i|
  
  ans += i * (n - i + 1) 
  ans %= mod if ans >= mod
end

puts ans

Measured memory_bytes: 14412
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 


int main()
{ 
    int n;
    cin>>n;
    LL m;
    cin>>m;
    LL a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    LL s[n];
    for(int i=0;i<n;i++){
        if(i==0){s[0]=a[0];}
        else{s[i]=s[i-1]+a[i];}
    }
    
    LL min=2;
    LL max=10000000001;
    LL x[n];//0以上の人と握手する。
    LL p=0;//回数
    while(max-min>1){
        LL k=(max+min)/2;
        LL cnt=0;
        for(int i=0;i<n;i++){
            int Min=0;
            int Max=n-1;
            if(a[n-1]<k-a[i]){x[i]=n;}
            else if(a[0]>=k-a[i]){cnt=cnt+n;x[i]=0;}
            else{
                while(Max-Min>1){
                    int K=(Max+Min)/2;
                    if(a[K]>=k-a[i]){Max=K;}
                    else{Min=K;}
                }
                cnt=cnt+n-Min-1;
                x[i]=Min+1;
            }
        }
        if(cnt<m){max=k;}
        else{min=k;}
    }
    /*for(int i=0;i<n;i++){
        cout<<i<<' '<<a[i]<<' '<<s[i]<<' '<<x[i]<<endl;
    }*/
    for(int i=0;i<n;i++){p=p+n-x[i];}
    LL ans=0;
    for(int i=0;i<n;i++){
        if(x[i]>0){ans=ans+a[i]*(n-x[i])+s[n-1]-s[x[i]-1];}
        else{ans=ans+a[i]*n+s[n-1];}
    }
    ans=ans+min*(m-p);
    cout<<ans<<endl;
    return 0;
}

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

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b, n;
  cin >> a >> b >> n;
  n = min(n, b - 1);
  cout << (a * n / b) - a * (n / b) << '\n';
}
    

Measured memory_bytes: 3660
#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 limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#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 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;

int main()
{
  int n, k;
  cin >> n >> k;
  k--;
  vi c(n);
  rep(i, n)
  {
    cin >> c[i];
  }

  ll ans = 1001001001;

  rep(i,n){
    ll con = 0;
    if(i+k>=n) break;
    ll s =i;
    ll e = s+k;
    ll d = abs(c[s]-c[e]);
    con+= min(abs(c[s]),abs(c[e]));
    con+=d;
    mins(ans,con); 
  }

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int> > v(H, vector<int>(W));
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) cin >> v[i][j];

    vector<vector<int> > t;
    for (int i = 0; i < H; i++) for (int j = 0; j < W - 1; j++) {
        if (v[i][j] % 2 == 1) {
            t.push_back({i+1, j+1, i+1, j+2});
            //cout << i+1 << ' ' << j+1 << ' ' << i+1 << ' ' << j+2 << '\n';
            v[i][j+1]++;
        }
    }

    for (int i = 0; i < H - 1; i++) {
        if (v[i][W-1] % 2 == 1) {
            t.push_back({i+1, W, i+2, W});
            // cout << i+1 << ' ' << W << ' ' << i+2 << ' ' << W << '\n';
            v[i+1][W-1]++;
        }
    }
    cout << t.size() << '\n';
    for (int i = 0; i < t.size(); i++) {
        for (int j = 0; j < 4; j++) {
            cout << t[i][j];
            cout << ((j == 3) ? '\n' : ' ');
        }
    }
}


Measured memory_bytes: 10032
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M; cin >>N>>M;
    long long A[N];
    for (int i=0;i<N;i++) cin >> A[i];
    priority_queue<int> Q;
    for (int i=0;i<N;i++) Q.push(A[i]);
    for (int i=0;i<M;i++) {
        int a = Q.top();
        Q.pop();
        Q.push(a/2);
    }
    long long total=0;
    for (int i=0;i<N;i++) {
        int a = Q.top();
        Q.pop();
        total +=a;
    }
    cout << total <<"\n";
}


Measured memory_bytes: 1660
n = int(input())
a = dict()
ans = 0
for i in range(n):
    string = input()
    b = ''.join(sorted(string))
    if b in a:
        a[b] += 1

    else:
        a[b] = 1
for i in a.values():
    if i > 1:
        ans += int(i*(i-1)/2)
print(ans)

Measured memory_bytes: 17892
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>
 
using namespace std;
#define mod 1000000007
#define ll long long 
 
 
ll n,w, a[100009], b[100009];
ll dp[109][100009];
 
// map<int, map<ll, ll> > dp;
 
ll solve(int r, int idx) {
    if(idx == n)
        return r == 0 ? 0 : INT_MAX;
 
    if(dp[idx][r] != -1)
    	return dp[idx][r];
 
    ll ans = solve(r, idx + 1);
    if(b[idx] <= r)
    	ans = min(ans, a[idx] + solve(r - b[idx], idx + 1));
 
    return dp[idx][r] = ans;
}
 
int s(int v_max) {
 
	for(int i = v_max; i >= 0; i--) {
		if(solve(i, 0) <= w)
			return i;
	}
	return 0;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n>>w;
        memset(dp, -1, sizeof(dp));
 
        int v_max = 0;
 
        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i];
            v_max += b[i];
        }
 
        cout<<s(v_max)<<endl;
 
}

Measured memory_bytes: 88792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N, K;
	cin >> N;
	cin >> K;
	vector<int> v(N, 0);
	for (int i = 0; i < N; ++i) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	int d_min = v[K-1] - v[0];
	for (int i = 1; i <= N - K; ++i) {
		int d = v[K + i - 1] - v[i];
		if (d_min > d) {
			d_min = d;
		}
	}
	cout << d_min;
}

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

namespace ABC121cs
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var y = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var result = (x[0] - y[0]) * (x[1] - y[1]);
            Console.WriteLine(result);
        }
    }
}


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

const int INF = 100010001000;

int n,m,cost[1010],miti[1010],memo[1010][1010];

int a(int day,int basho){
    if(memo[day][basho]>=0)return memo[day][basho];
    else if(basho==n)return 0;
    else if(day==m)return INF;
    else{
        return memo[day][basho]=min(a(day+1,basho+1)+cost[day]*miti[basho],a(day+1,basho));
    }
}

signed main()
{
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        cout << s[i];
        if(i==3)cout << " ";
    }
    cout << endl;
    return 0;
}


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

int main(){

string W; cin >> W;
string T;

for(int i=0;i<W.length();i++){
	if(!(islower(W[i])))
		W[i]=tolower(W[i]);
}
int cnt = 0;
while(cin >> T, T != "END_OF_TEXT"){
	for(int i=0; i<T.length(); i++){
		if(!(islower(T[i])))
			T[i]=tolower(T[i]);
	}
	if(W==T)
		cnt++;
}
cout << cnt << endl;

return 0;
}

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

using std::string;

int main() {
        string ans[] = {
                "light fly",
                "fly",
                "bantam",
                "feather",
                "light",
                "light welter",
                "welter",
                "light middle",
                "middle",
                "light heavy",
                "heavy"
        };
        float weight[] = {
                48.00,
                51.00,
                54.00,
                57.00,
                60.00,
                64.00,
                69.00,
                75.00,
                81.00,
                91.00,
                160.0
        };
        float w;

        while (scanf("%f", &w) != EOF) {
                int i = 0;
                while (w > weight[i]) {
                        i++;
                }
                printf("%s\n", ans[i].c_str());
        }

        return 0;
}

Measured memory_bytes: 2800
#include<stdio.h>
int main(void){
  char b;
  scanf("%c",&b);
  switch (b) {
    case 'A': printf("T\n"); break;
    case 'T': printf("A\n"); break;
    case 'C': printf("G\n"); break;
    case 'G': printf("C\n"); break;
  }
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,m;
	int a[1000],b[1000],sum[1000];
	int i,j,max,maxi;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	for(j=0;j<n;j++){
		sum[j]=0;
	}
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			if(a[j]<=b[i]){
				sum[j]++;
				break;
			}
		}
	}
//	for(i=0;i<n;i++){
//		printf("%d\n",sum[i]);
//	}
	max=-1;
	for(j=0;j<n;j++){
		if(sum[j]>=max){
			max=sum[j];
			maxi=j+1;
		}
	}
	printf("%d\n",maxi);
	return 0;
}
	

Measured memory_bytes: 1868
#include <iostream>
#include <queue>

using namespace std;

const int INF = 100000;

typedef pair<int, int> P;

int main(){
    int H, W;
    char A[1000][1000];
    int dist[1000][1000];

    cin >> H >> W;
    queue<P> que;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> A[i][j];
            if(A[i][j] == '#') {
                dist[i][j] = 0;
                que.push(P(i, j));
            }
            else dist[i][j] = INF;
        }
    }
    while(!que.empty()){
        P top = que.front();
        que.pop();
        int i = top.first;
        int j = top.second;
        if(i-1 >= 0 && dist[i-1][j] == INF){
            dist[i-1][j] = dist[i][j]+1;
            que.push(P(i-1, j));
        }
        if(i+1 <= H-1 && dist[i+1][j] == INF){
            dist[i+1][j] = dist[i][j]+1;
            que.push(P(i+1, j));
        } if(j-1 >= 0 && dist[i][j-1] == INF){
            dist[i][j-1] = dist[i][j]+1;
            que.push(P(i, j-1));
        } if(j+1 <= W-1 && dist[i][j+1] == INF){
            dist[i][j+1] = dist[i][j]+1;
            que.push(P(i, j+1));
        } 
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
}

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

int main(){
    string s[3]={"Sunny","Cloudy", "Rainy"};
    string w;
    cin >> w;
    for(int i=0;i<3;i++){
        if(s[i]==w) cout << s[(i+1)%3] << endl;
    } 
    return 0;
}

Measured memory_bytes: 256
S = input()

first_zero_count = 0
first_one_count = 0

i = 0

buf = '0'
while i < len(S):
    if S[i] == buf:
        first_zero_count += 1

    if buf == '0':
        buf_buf = '1'
    else:
        buf_buf = '0'

    if S[i] == buf_buf:
        first_one_count += 1
    if buf == '0':
        buf = '1'
    else:
        buf = '0'
    i += 1

print(min(first_zero_count, first_one_count))

Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int A[][] = new int[N][2];
		int maxA = 0;
		for(int i = 0; i < N; i++) {
			A[i][0] = sc.nextInt();
			A[i][1] = sc.nextInt();
			maxA = Math.max(maxA, A[i][0]);
		}
		
		int dp[][] = new int[N + 1][H + maxA + 1];
		for(int i = 0; i < N + 1; i++) {
			Arrays.fill(dp[i], Integer.MAX_VALUE / 2);
		}
		dp[0][0] = 0;
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < H + maxA; j++) {
				if(j >= A[i][0]) {
					dp[i + 1][j] = Math.min(dp[i][j], dp[i + 1][j - A[i][0]] + A[i][1]);
				} else {
					dp[i + 1][j] = dp[i][j];
				}
			}
		}
		int ans = Integer.MAX_VALUE;
		for(int i = H; i < H + maxA; i++) {
			ans = Math.min(dp[N][i], ans);
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 82668
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int dfs(const vv<int>& tree, int v, int p) {
    int g = 0;
    for (int u : tree[v]) {
        if (u == p) continue;
        int r = dfs(tree, u, v);
        g ^= r + 1;
    }
    return g;
}

int main() {
    int N;
    cin >> N;
    vv<int> tree(N);
    rep(i, N - 1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        tree[x].push_back(y);
        tree[y].push_back(x);
    }

    write(dfs(tree, 0, -1) ? "Alice" : "Bob");
}

Measured memory_bytes: 12032
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(int i=0;i<n;i++)
#define Rip(i,n) for(int i=1;i<n;i++)
#define ll long long
#define ld long double
#define pi 3.1415926535897932384626433832795028841971693993
#define mod 1000000007
#define MOD mod
#define sec setprecision
#define RAND_MAX 0x7fffffff
using namespace std;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
int ketasuu(ll h) {
	if (h < 0)return(-(ketasuu(-h)));
	else if (h < 10)return(1);
	else return(1 + ketasuu(h / 10));
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a)%mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	
}
int main() {
	int a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}

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

signed main() {
	vector<int> a(5), b(5);
	for (int i = 0; i < 5; ++i) {
		cin >> a[i];
		while (a[i] % 10 != 0) {
			a[i]++;
			b[i]++;
		}
	}

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

	cout << accumulate(a.begin(), a.end(), 0) - b[4] << endl;
}



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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x[3],y[3];
	for(int i=0;i<3;i++){
		cin >> x[i] >> y[i];
	}
	double a,b,c;
	double e,r;
	//2x = max(a,b,c)*(1- x/r);
	a = sqrt( (x[0]-x[1])*(x[0]-x[1]) + (y[0]-y[1])*(y[0]-y[1]));
	b = sqrt( (x[0]-x[2])*(x[0]-x[2]) + (y[0]-y[2])*(y[0]-y[2]));
	c = sqrt( (x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]));
	//r=2S/(a+b+c)
	double s = (a+b+c)/2;
	double S = sqrt( s*(s-a)*(s-b)*(s-c) );
	double d = max(a,max(b,c));
	r = 2*S/(a+b+c);
	double ans = (d*r)/(2*r+d);
	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long x,i,j;
int main() {
 scanf("%lld",&x);
 for(i=-5000;i<=5000;i++)
  for(j=-5000;j<=5000;j++)
   if(i*i*i*i*i-j*j*j*j*j==x) {
    printf("%lld %lld\n",i,j);
    return 0;
   }
}

Measured memory_bytes: 3232
n = int(input())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = sorted([a for a, b in AB])
B = sorted([b for a, b in AB])
if n % 2 == 0:
    print((B[n // 2 - 1] + B[n // 2]) - (A[n // 2 - 1] + A[n // 2]) + 1)
else:
    print(B[n // 2] - A[n // 2] + 1)


Measured memory_bytes: 41272
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  int N; cin >> N;
  vector<ll> H(N);
  rep(i, N) {
    cin >> H[i];
  }
  int ans = 0;
  for (int i=0; i < N-1;) {
    int cnt = 0;
    bool flag = false;
    while (H[i] >= H[i+1]) {
      cnt++;
      i++;
      if (i == N-1) {
        flag = true;
        break;
      }
    }
    ans = max(ans, cnt);
    if (flag) {
      break;
    }
    i++;
    if (i == N-1) {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(check(a,b));
    }

    public static String check(int a, int b) {
        return (a*b % 2 == 0) ? "Even" : "Odd";
    }
}


Measured memory_bytes: 35792
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=200011;
template<typename TP>void read(TP &kk){
    #define ak *
    TP phy=0,ioi=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')ioi=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){phy=phy*10+ch-'0';ch=getchar();}
    kk=phy ak ioi;
}
int n;
struct sumireko
{
    int to,ne;
}e[N*2];
int he[N],ecnt;
void addline(int f,int t)
{
    e[++ecnt].to=t;
    e[ecnt].ne=he[f];
    he[f]=ecnt;
}
int fa[N];
int rnd[N],hp;
bool vv[N],onr[N];
int sp;
int ip[N],iar;
void find()
{
    int x=1;
    while(!vv[x]) vv[x]=1,x=fa[x];
    while(!onr[x]) onr[x]=1,rnd[++hp]=x,x=fa[x];
}

int dp[N],g[N],tmp;
void dfs(int x)
{
    for(int i=he[x],t;i;i=e[i].ne)
    {
        t=e[i].to;
        if(!onr[t]) dfs(t);
    }
    tmp++;
    for(int i=he[x],t;i;i=e[i].ne)
    {
        t=e[i].to;
        if(!onr[t]) g[dp[t]]=tmp;
    }
    dp[x]=0;
    while(g[dp[x]]==tmp) dp[x]++;
}

int ma=-1,mi=19260817;
int xi,yi,wi;
int main()
{
    read(n);
    for(int i=1;i<=n;i++)
    {
        read(fa[i]);
        addline(fa[i],i);
    }
    find();
    if(hp&1)
    {
        for(int i=1;i<=hp;i++)
        {
            int x=rnd[i];
            dfs(x);
            ma=max(ma,dp[x]),mi=min(mi,dp[x]);
        }
        if(ma==mi) puts("IMPOSSIBLE");
        else puts("POSSIBLE");
    }else puts("POSSIBLE");
    return 0;
}

Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int total_sum=0;
		int r=sc.nextInt();
		int c=sc.nextInt();
		int[][] cell=new int[r+1][c+1];
		for(int i=0; i<r; i++) {
			int sum=0;
			for(int j=0; j<c; j++) {
				cell[i][j]=sc.nextInt();
				sum+=cell[i][j];
				cell[r][j]+=cell[i][j];
			}
			cell[i][c]=sum;
			
			total_sum+=sum;
		}
		cell[r][c]=total_sum;
		
		for(int i=0; i<r+1; i++) {
			for(int j=0; j<c; j++) {
				System.out.printf("%d ", cell[i][j]);
			}
			System.out.printf("%d", cell[i][c]);
			System.out.println();
		}
	}
}



Measured memory_bytes: 51228
#include<stdio.h>

int main(void)
{
        int w = 0,m = 0;
        int n = 0, i = 0, j = 0;
        int a = 0, b = 0;

        scanf("%d",&w);

        int weight[w];
        for(i = 1;i <= w; i++)
        {
                weight[i] = i;
        }

        scanf("%d",&n);

        for(i = 1;i <= n ; i++)
        {
                scanf("%d,%d", &a, &b);
                m = weight[a];
                weight[a] = weight[b];
                weight[b] = m;
        }

        for(i = 1;i <= w; i++)
        {
                printf("%d\n",weight[i]);
        }

        return 0;
}

Measured memory_bytes: 596
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: i64,
   }
   let mut res = n;
   for i in 0..n + 1 {
      let mut cc = 0;
      let mut t = i;
      while t > 0 {
         cc += t % 6;
         t /= 6;
      }
      t = n - i;
      while t > 0 {
         cc += t % 9;
         t /= 9;
      }
      res = std::cmp::min(res, cc);
   }
   println!("{}", res);
}


Measured memory_bytes: 4352
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int INF = 1e9;

class C{
  public:
    int n, w, m;
    C(){}
    C(int _n, int _w, int _m){ n = _n; w = _w; m = _m; }
    bool operator > (const C &c) const {
      if(w != c.w) return w > c.w;
      return m < c.m;
    }
};

int main() {
  int M, N;
  while(cin >>M >>N && M){
    vector<int> v(N + 1); FOR(i, 1, N + 1) cin >>v[i];
    FOR(i, 1, v.size()) v[i] += v[i - 1];
    priority_queue<C, vector<C>, greater<C> > open;
    open.push(C(1, 0, 0)); 
    vector< vector<int> > closed(N + 1, vector<int>(M + 1, INF));
    closed[1][0] = 0;
    while(!open.empty()){
      C tmp = open.top(); open.pop();
      int n = tmp.n, w = tmp.w, m = tmp.m;
      //cout <<"n = " <<n <<", w = " <<w <<", m = " <<m <<endl;
      if(m == M){ cout <<w <<endl; break; }
      if(n == N && m == M){ cout <<w <<endl; break; }
      if(m + 1 == M){
        int nw = v[N] - v[n - 1];
        if(closed[N][m + 1] <= nw) open.push(C(N, max(w, nw), m + 1));
        open.push(C(N, max(w, nw), m + 1));
        continue;
      }
      FOR(next, n, N + 1){
        int nw = v[next] - v[n - 1];
        //cout <<"    " <<next + 1 <<", " <<max(w, nw) <<", " <<m + 1 <<" | " <<closed[next][m + 1] <<", " <<max(w, nw) <<endl;
        if(closed[next][m + 1] <= max(w, nw)) continue;
        //cout <<"    " <<"!" <<endl;
        closed[next][m + 1] = nw;
        open.push(C(next + 1, max(w, nw), m + 1));
      }
    }
  }
  return 0;
}

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

int main() {
	int a[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10);
	for (int i = 9; i > 6; i--) {
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<" : "<<x, nl
#define ll long long int
#define u unsigned
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define ci m(char, ll)
#define ii m(ll, ll)
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(x,y))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{
    ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x);
    return v;}
void out(vl v){
    fl(i,v)cout<<i;
}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;
}

void solve(){
    string S,T;
    cin>>S>>T;
    ll c=0;
    f(i,3)
    if(S.at(i) == T.at(i))
    c++;

    cout<<c;
}

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

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int A[105];

int main()
{
	int N, M, X;
	cin >> N >> M >> X;
	int index = 0;
	REP(i, M)
	{
		cin >> A[i];
		if (A[i] < X)index = i + 1;
	}

	cout << std::min(index, M - index) << endl;

	return 0;
}

Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())

max_c = 0
ans_sw = A*100
ans_s = 0

water = set()
for a in range(0, F + 1, A * 100):
    for b in range(0, F - a + 1, B * 100):
        water.add(a + b)

suger = set()
for c in range(0, F + 1, C):
    for d in range(0, F - c + 1, D):
        suger.add(c + d)

for w in water:
    for s in suger:
        
        if s <= E * w // 100 and 0 < w + s <= F:
            c = s / (w + s)
            if max_c < c:
                max_c = c
                ans_sw = s + w
                ans_s = s

print(ans_sw, ans_s)                


Measured memory_bytes: 3188