akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<string> vs;
int main () {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n,l;
  cin >> n >> l;
  string s;
  while (n--) {
    cin >> s;
    vs.push_back(s);
  }
  sort(vs.begin(),vs.end(),[](string a, string b) {return a + b < b + a;});
  for (string ss : vs) cout << ss;
  cout << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=205;
int n,ans,F[maxn][maxn],vis[maxn];
char mp[maxn][maxn];
bool DFS(int x,int y){
	if(vis[x]) return vis[x]==y;
	vis[x]=y;
	for (int i=1;i<=n;i++)
	if(mp[x][i]=='1')
	if(!DFS(i,y^3)) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%s",mp[i]+1);
	if(!DFS(1,1)) return puts("-1")&0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++) if(i^j)
	F[i][j]=mp[i][j]^'0'?1:1e9;
	for (int k=1;k<=n;k++)
	for (int i=1;i<=n;i++) if(i!=k)
	for (int j=1;j<=n;j++) if(j!=k&&j!=i)
	F[i][j]=min(F[i][j],F[i][k]+F[k][j]);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++) ans=max(ans,F[i][j]);
	printf("%d\n",ans+1);
	return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        r: i64,
    }
    let r = r as f64;
    println!("{}", r * 2. * std::f64::consts::PI);
}


Measured memory_bytes: 2200
local function sumDigits(num)
    local sum = 0
    while num > 0 do
        sum = sum + num % 10
        num = math.modf(num / 10)
    end
    return sum
end

local N, A, B = io.read("*n", "*n", "*n")
local total = 0
for i = 1, N do
    local sum = sumDigits(i)
    if sum >= A and sum <= B then
        total = total + i
    end
end
print(total)

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

int main(){
    int k,a,b ;
    cin >> k >> a >> b ;
    for (size_t i = a; i < b+1; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl ;
            return 0 ;
        }
        
    }
    cout << "NG" << endl ;
}

Measured memory_bytes: 3636
s = input()
l = len(s)
s = s[:l-1]
h = int(l / 2)

for i in range(len(s)):
    if l % 2 == 0:
        h = int(l / 2)
        a = s[:h]
        b = s[h:l]
        if a == b:
            print(l)
            break
    l -= 1


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

const int N = 50;

int dat[N+5];

int main() {
    int n; scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%d", dat+i);

    int res = 0;
    for (int i=1; i<=n; i++) for (int j=i+1; j<=n; j++) {
        res += dat[i] * dat[j];
    }

    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll k,n;
    cin>>k>>n;
    vector<ll> v(n);
    for(auto &x:v) {
    	cin>>x;
    }
    ll ans = INT_MAX;
    for(ll i=1;i<n;i++) {
    	ans = min(ans, k-(v[i]-v[i-1]));
    }
    ans = min(ans,v[n-1]-v[0]);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main(void)
{
	double v[100];
	int i, j, k, n, b;
	double x;
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%lf", &v[i]);
	}
	for(j=0;j<n;j++){
		for(k=0;k<n-j-1;k++){
			if(v[k]>v[k+1]){
				b=v[k];
				v[k]=v[k+1];
				v[k+1]=b;
			}
		}
	}

	x=v[0];
	for(i=1;i<n;i++){
		x=(x+v[i])/2.0;
	}
	printf("%lf", x);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
    //cin>>test;
    while(test--)
    {

           ll n,k;
           cin>>n>>k;
           vi v(n);
           fo(i,n)
           cin>>v[i];
           vector <bool> t(k+1,false);
           for(ll j=1;j<=k;j++)
           {
               fo(i,n)
               {
                   if((j-v[i]>=0) && (t[j-v[i]]==false))
                        {t[j]=true;break;}
               }
           }
           (t[k])?cout<<"First":cout<<"Second";

//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not




Measured memory_bytes: 3668
#include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int calc(int y1, int y2) {
	int a;
	a = y2/4-y1/4;
	if(y1%4==0) a++;
	a -= y2/100-y1/100;
	if(y1%100==0) a--;
	a += y2/400-y1/400;
	if(y1%400==0) a++;
	return a;
}
bool uruu(int y) {
	return y%4 == 0 && y%100 != 0 || y%400 == 0;  
}
int main() {
	int y1, m1, d1, y2, m2, d2;
	while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2 && (y1>=0 && m1>=0 && d1>=0 && y2>=0 && m2>=0 && d2>=0)) {
		int uy = calc(y1,y2);
		int ret = (y2-y1+1)*365+uy;
		int day = 0;
		rep(i,m1-1) day += d[i];
		for(int i=11; i>=m2; --i) day += d[i];
		day += d1-1, day += d[m2-1]-d2+1;
		if(uruu(y1) && m1>2) day++;
		if(uruu(y2) && m2<=2) day++;
		cout << ret - day << endl;
	}
	return 0;
}

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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int main()
{
	int n;
	cin >> n;
	string s;
	if (n == 0){
		cout << 0 << endl;
		return 0;
	}
	while(n){
		int p = abs(n % (-2));
		if (n < 0 && n % 2 != 0) n = n / (-2) + 1;
		else n /= (-2);
		s += '0' + p;
	}
	int len = s.size();
	for(int i = 0; i < len; i++) cout << s[len - 1 - i];
}


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

#define MAX 502

int n;
int a[MAX][MAX];


char s[502];

bool r[MAX][MAX];

set<int> can;

set<int> nott;

int dp[MAX][MAX];

int MINT[MAX];

int main(){
	memset(dp, -1, sizeof(dp));
	queue<pair<int, int> > q;
	cin >> n;
	for (int i = 0; i < n; i++){
		scanf("%s", s);
		for (int j = 0; j < n; j++){
			if (s[j] == '#'){
				r[i][j] = true;
				dp[i][j] = 0;
				q.push(make_pair(i, j));
				can.insert(j);
			}
			else{
				r[i][j] = false;
				nott.insert(j);
			}
		}
	}
	while (!q.empty()){
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		for (int j = 0; j <n; j++){
			if (dp[y][j] == -1){
				dp[y][j] = dp[x][y] + 1;
				q.push(make_pair(y, j));
			}
		}
	}
	for (int i = 0; i < n; i++){
		MINT[i] = INT_MAX;
		for (int j = 0; j < n; j++){
			if (dp[j][i] == -1){
				continue;
			}
			MINT[i] = min(MINT[i], dp[j][i]);
		}
	}
	int ans = INT_MAX;
	for (int i = 0; i < n; i++){
		int cnt = 0;
		for (int j = 0; j < n; j++){
			if (r[i][j] == false){
				cnt++;
			}
		}
		if (cnt&&MINT[i] == INT_MAX){
			continue;
		}
		ans = min(ans, cnt + (int)nott.size()+MINT[i]);
	}
	if (ans == INT_MAX){
		puts("-1");
		return 0;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  
  rep(i, S.size()) {
    int f = 1;
    rep(j, S.size()) {
      if(S[(j+i)%S.size()] != T[j]) f=0;
    }
    if(f == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
fun main() {
    val input = readLine()!!.split(" ").map { it.toInt() }
    val a = input[0]
    val b = input[1]
    val c = input[2]
    val d = input[3]
    val e = input[4]
    val f = input[5]

    val iMax = f / (a * 100)
    val jMax = f / (b * 100)
    val kMax = f / c
    val lMax = f / d

    var max = 0.0
    var answerSugarWater = 0
    var answerSugar = 0

    for (i in (0..iMax)) {
        for (j in (0..jMax)) {
            val water = 100 * a * i + 100 * b * j
            if (water in 1 until f) {
                for (k in (0..kMax)) {
                    for (l in (0..lMax)) {
                        val sugar = c * k + d * l
                        val total = water + sugar
                        val density = sugar * 100.0 / water
                        if (total <= f && density <= e.toDouble() && max <= density) {
                            max = density
                            answerSugarWater = total
                            answerSugar = sugar
                        }
                    }
                }
            }
        }
    }

    print("$answerSugarWater $answerSugar")
}

Measured memory_bytes: 37420
#include<bits/stdc++.h>
using namespace std;
const int mod=1e7+7;
const int maxi=10000000;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s,w;cin>>s>>w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3592
num = [s.split()[0] for s in open(0)]
num = list(map(int, list(num[0])))


for i in range(len(num)**2):
    comb = ""
    sum_num = 0
    for k in range(len(num)):
        if (i  >> k) & 1:
            sum_num += num[k]
            if k == 0:
                comb += str(num[k])
            else:
                comb += "+" + str(num[k])  
        else:
            sum_num -= num[k]
            if k == 0:
                comb += str(num[k])
            else:
                comb += "-" + str(num[k])  
        
    if sum_num == 7:
        break
        
print(comb + "=7")

Measured memory_bytes: 3064
k = int(input())
ls = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(ls[k-1])

Measured memory_bytes: 61752
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

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

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

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

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	LL X,Y;
	cin >> X >> Y;
	if( X%Y == 0 ){
		cout << -1 << endl;
	}else{
		cout << X << endl;
	}
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

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

Measured memory_bytes: 256
def main():
    def calc(v, w, i, j, ans):
        if v > 0:
            i[0] += 1
        elif v < 0:
            j[0] += 1
        else:
            if w > 0:
                ans[0] = min(ans[0], w)
                i[0] += 1
            else:
                j[0] += 1

    n = int(input())
    inf = 10**10
    ans = [inf]
    u_list, d_list, l_list, r_list = [], [], [], []
    for _ in range(n):
        x, y, d = input().split()
        x, y = int(x), int(y)
        if d == "D":
            d_list.append((x, y))
        elif d == "R":
            r_list.append((x, y))
        elif d == "L":
            l_list.append((x, y))
        else:
            u_list.append((x, y))
    ld, lr, ll, lu = len(d_list), len(r_list), len(l_list), len(u_list)
    # 1→u,d
    u_list.sort(key=lambda x: (x[0], x[1]))
    d_list.sort(key=lambda x: (x[0], x[1]))
    i, j = [0], [0]
    while(i[0] < lu and j[0] < ld):
        x, y = u_list[i[0]]
        p, q = d_list[j[0]]
        v = p-x
        w = (q-y)*5
        calc(v, w, i, j, ans)
    # 2→r,l
    r_list.sort(key=lambda x: (x[1], x[0]))
    l_list.sort(key=lambda x: (x[1], x[0]))
    i, j = [0], [0]
    while(i[0] < lr and j[0] < ll):
        x, y = r_list[i[0]]
        p, q = l_list[j[0]]
        v = q-y
        w = (p-x)*5
        calc(v, w, i, j, ans)
    # 3→u,l
    u_list.sort(key=lambda x: (x[0]-x[1], x[0]))
    l_list.sort(key=lambda x: (x[0]-x[1], x[0]))
    i, j = [0], [0]
    while(i[0] < lu and j[0] < ll):
        x, y = u_list[i[0]]
        p, q = l_list[j[0]]
        v = (p-q)-(x-y)
        w = (p-x)*10
        calc(v, w, i, j, ans)
    # 4→d,l
    d_list.sort(key=lambda x: (x[0]+x[1], x[0]))
    l_list.sort(key=lambda x: (x[0]+x[1], x[0]))
    i, j = [0], [0]
    while(i[0] < ld and j[0] < ll):
        x, y = d_list[i[0]]
        p, q = l_list[j[0]]
        v = (p+q)-(x+y)
        w = (p-x)*10
        calc(v, w, i, j, ans)
    # 5→u,r
    u_list.sort(key=lambda x: (x[0]+x[1], -x[0]))
    r_list.sort(key=lambda x: (x[0]+x[1], -x[0]))
    i, j = [0], [0]
    while(i[0] < lu and j[0] < lr):
        x, y = u_list[i[0]]
        p, q = r_list[j[0]]
        v = (p+q)-(x+y)
        w = (x-p)*10
        calc(v, w, i, j, ans)
    # 6→d,r
    d_list.sort(key=lambda x: (x[0]-x[1], -x[0]))
    r_list.sort(key=lambda x: (x[0]-x[1], -x[0]))
    i, j = [0], [0]
    while(i[0] < ld and j[0] < lr):
        x, y = d_list[i[0]]
        p, q = r_list[j[0]]
        v = (p-q)-(x-y)
        w = (x-p)*10
        calc(v, w, i, j, ans)
    if ans == [inf]:
        print("SAFE")
    else:
        print(ans[0])


main()


Measured memory_bytes: 62148
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<complex>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<ctime>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define Cpy(x,y) memcpy(x,y,sizeof(x))
#define Set(x,y) memset(x,y,sizeof(x))
#define FILE "a"
#define mp make_pair
#define pb push_back
#define RG register
#define il inline
using namespace std;
typedef unsigned long long ull;
typedef vector<int>VI;
typedef long long ll;
typedef double dd;
const int N=100010;
const int mod=19940417;
const int base=26;
const dd eps=1e-6;
const int inf=2147483647;
const ll INF=1ll<<60;
const ll P=100000;
il ll read(){
  RG ll data=0,w=1;RG char ch=getchar();
  while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
  if(ch=='-')w=-1,ch=getchar();
  while(ch<='9'&&ch>='0')data=data*10+ch-48,ch=getchar();
  return data*w;
}

il void file(){
  srand(time(NULL)+rand());
  freopen(FILE".in","r",stdin);
  freopen(FILE".out","w",stdout);
}

int n,m;char s[N];bool vis[N];
struct edge{int u,v;}E[N];
il void er(){puts("-1");exit(0);}
int main()
{
  scanf("%s",s+1);n=strlen(s+1);if(s[n]=='1')er();
  for(RG int i=1,j=n-1;i<=j;i++,j--){
    if(s[i]!=s[j])er();
    else if(s[i]=='0'){
      if(i==1)er();     
    }
    else{
      vis[i]=1;
    }
  }
  for(RG int i=n/2+1;i<n;i++)E[++m]=(edge){i,n};
  for(RG int i=n/2,p=n;i;i--){
    E[++m]=(edge){i,p};if(vis[i])p=i;
  }
  for(RG int i=1;i<=m;i++)printf("%d %d\n",E[i].u,E[i].v);
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    
    long long N,A[110]={};
    cin>>N;
    A[0]=2;
    A[1]=1;

    for(int i=2;i<=N;i++){
        A[i]=A[i-1]+A[i-2];
    }

    cout<<A[N]<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;



int main(int argc, char **argv) {
    i64 n;
    cin >>n;

    vector<i64> a(n);
    map<i64, i64> mp;
    i64 sum{0};
    mp[0]=1;
    for (i64 i=0; i<n; ++i) {
        cin >> a[i];
        sum += a[i];
        auto it = mp.find(sum);
        if (it == mp.end()) {
            mp[sum] = 0;
        }
        ++mp[sum];
    }

    i64 ans{0};

    for (auto kv : mp) {
        if (kv.second>1) {
            //cout << kv.first << " " << kv.second << std::endl;
            ans += (kv.second * (kv.second-1)) / 2;
        }
    }

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


Measured memory_bytes: 17164
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<long,long>> work;
    long a,b;
    rep(i,n){
        cin >> a >> b;
        work.push_back(make_pair(b,a));
    }
    sort(work.begin(),work.end(),greater<pair<long,long>>());
    long count = 0;
    long num = 0;
    long ans = 0;
    set<int> days;
    rep(i,m+1){
        days.insert(i);
    }
    int tem;
    while(count<m && num < n){
        auto itr = days.upper_bound(m-work[num].second);
        if(itr==days.begin()){
            tem = -1;
        }else{
            itr--;
            tem = *itr;
        }
        if(tem!=-1){
            days.erase(tem);
            ans+=work[num].first;
            count++;
        }
        num++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
 int n;
  cin>>n;
  int niza[n];
  for(int i=0; i<n; i++)
  {
    cin>>niza[i];
  }
  int cnt=0;
  for(int i=1; i<n-1; i++)
  {
   	if((niza[i]<niza[i+1]&&niza[i]>niza[i-1])||(niza[i]>niza[i+1]&&niza[i]<niza[i-1]))cnt++; 
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main()
{
	_fast_
	ll t = 1;
	//cin>>t;
	while(t--){
	ll n;
	cin>>n;
	if(n%2)
	{
		cout<<n/2+1<<"\n";
	}
	else
	{
		cout<<n/2<<"\n";
	}
	
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX 100001
#define NIL -1

struct Node { 
    int parent;
    int left;
    int right; 
};

void print(int i, Node array[], int d[]) {
    cout << "node " << i << ": ";
    cout << "parent = " << array[i].parent;
    cout << ", depth = " << d[i];
    cout << ", ";
    if (array[i].parent == NIL) cout << "root";
    else if (array[i].left == NIL) cout << "leaf";
    else cout << "internal node";
    cout << ", [";
    if (array[i].left != NIL) {
        int current = array[i].left;
        cout << current;
        while (array[current].right != NIL) {
            current = array[current].right;
            cout << ", " << current;
        }
    }
    cout << "]" << endl;
}

void depth(int n, int d, Node nodes[], int darray[]) {
    darray[n] = d;
    if (nodes[n].right != NIL) depth(nodes[n].right, d, nodes, darray);
    if (nodes[n].left != NIL) depth(nodes[n].left, d+1, nodes, darray);
}

int main() {
    int id, root, a, b, h, n, k;
    Node Taa[MAX];
    int Daa[MAX];
    cin >> n;
    for (int i=0; i<n; i++) Taa[i].parent = Taa[i].left = Taa[i].right = NIL;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        int left;
        for (int j = 0; j < k; j++) {
            cin >> h;
            if (j == 0) Taa[id].left = h;
            else Taa[left].right = h;
            Taa[h].parent = id;
            left = h;
        }
    }
    for (int i=0; i<n; i++) {
        if (Taa[i].parent == NIL) {
          root = i;
          break;
        }
    }
    depth(root, 0, Taa, Daa);
    for (int i=0; i<n; i++) print(i, Taa, Daa);
    return 0;
}



Measured memory_bytes: 9228
#include <iostream>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;
typedef pair<long long int, P> Q;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		priority_queue< Q, vector<Q>, greater<Q> > pq;
		Q q;
		for (int i = 0; i < n; i++) {
			cin >> (q.second).second >> q.first >> (q.second).first;
			pq.push(q);
		}
		long long int M = ((pq.top()).second).second;
		priority_queue< P, vector<P>, greater<P> > pqq;
		pqq.push((pq.top()).second);
		pq.pop();
		bool hantei = true;
		while (!pq.empty()) {
			if (!pqq.empty()) {
				if ((pq.top()).first < (pqq.top()).first) {
					M += ((pq.top()).second).second;
					pqq.push((pq.top()).second);
					pq.pop();
					if (M > 150) {
						hantei = false;
						break;
					}
				} else if ((pq.top()).first > (pqq.top()).first) {
					M -= (pqq.top()).second;
					pqq.pop();
				} else {
					M -= (pqq.top()).second;
					pqq.pop();
					M += ((pq.top()).second).second;
					pqq.push((pq.top()).second);
					pq.pop();
					if (M > 150) {
						hantei = false;
						break;
					}
				}
			} else {
				M += ((pq.top()).second).second;
				pqq.push((pq.top()).second);
				pq.pop();
			}
		}
		if (hantei) {
			cout << "OK" << endl;
		} else {
			cout << "NG" << endl;
		}
	}
	return 0;
}

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

class Program {
    static void Main() {
        while(true) {
            string[] stdin = Console.ReadLine().Split();
            int h = int.Parse(stdin[0]);
            int w = int.Parse(stdin[1]);
            if((h | w) == 0) break;
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) Console.Write("#");
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 17940
def c_bar():
	h, w = map(int, raw_input().split(" "))
	if h < 2 and w < 2:
		print "Wrong Input"
		return

	def get_min_dif(x, y):
		if x % 3 == 0 or y % 3 == 0:
			return 0
		# viewing x, get the first sub-rec
		ans = float("inf")
		for x1 in [x//3, x//3+1]:
			# view x oy y, get the other two sub-rec
			# view x
			x2 = (x - x1) // 2
			x3 = x-x1-x2
			sqrs1 = [x1*y, x2*y, x3*y]
			ans1 = max(sqrs1)-min(sqrs1)
			# view y
			y2 = y//2
			y3 = y-y2
			sqrs2 = [x1 * y, (x-x1) * y2, (x-x1) * y3]
			ans2 = max(sqrs2) - min(sqrs2)
			ans = min(ans, ans1, ans2)
		return ans
	print min(get_min_dif(h, w), get_min_dif(w, h))

if __name__ == "__main__":
	c_bar()

Measured memory_bytes: 2696
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	ans := inf
	for i := -100; i <= 100; i++ {
		cnt := 0
		for _, a := range as {
			x := (a - i) * (a - i)
			cnt += x
		}
		ans = min(ans, cnt)
	}

	fmt.Fprintln(wr, ans)
}

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

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
	int n;
	int a[100];
	int total=0;
	int m;

	int x, y;
	for (int i = 0; i<100; i++) {
		a[i] = 0;

	}


	cin >> n;
	for (int i = 0; i<n; i++) {
		cin >> a[i];
		total += a[i];
	}


	

	cin >> m;
	for (int i = 0; i<m; i++) {
		cin >> x >> y;


		if (a[x-1] > y) {
			cout << total - (a[x - 1] - y) << endl;
		}
		else {
			cout << total + (y - a[x - 1]) << endl;
		}
	}
	


	int stop;
	cin >> stop;

	return 0;

}

Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

X = [0]
for i in range(n):
    if i % 2 == 0:
        X.append(1)
    else:
        X.append(-1)

Y = [-x for x in X]

x = 0
AX = [0] + A
for i in range(1, n + 1):
    temporary = AX[i - 1] + AX[i]
    if temporary * X[i] > 0:
        AX[i] = temporary
    else:
        x += abs(temporary - X[i])
        AX[i] = X[i]

y = 0
AY = [0] + A
for i in range(1, n + 1):
    temporary = AY[i - 1] + AY[i]
    if temporary * Y[i] > 0:
        AY[i] = temporary
    else:
        y += abs(temporary - Y[i])
        AY[i] = Y[i]

print(min(x, y))


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

int main() {
  size_t n;
  std::cin >> n;

  std::vector<std::vector<int>> fr(n, std::vector<int>(26));
  for (size_t i = 0; i < n; ++i) {
    std::string S;
    std::cin >> S;
    for (auto c: S) ++fr[i][c-'a'];
  }

  std::string res;
  for (size_t j = 'a'; j <= 'z'; ++j) {
    int cur = 50;
    for (size_t i = 0; i < n; ++i)
      cur = std::min(cur, fr[i][j-'a']);

    res += std::string(cur, j);
  }

  std::cout << res << std::endl;
}


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

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define F first
#define S second
#define MSET(m,v) memset((m),(v),sizeof(m))
#define UB(c,v) (upper_bound((c).begin(),(c).end(),(v)))
#define LB(c,v) (lower_bound((c).begin(),(c).end(),(v)))
#define INREP int TC;cin>>TC;while(TC--)
#define CPPIO ios::sync_with_stdio(false);cin.tie(NULL);
#define PC(x) fixed<<setprecision(x)
#define FBO find_by_order
#define OOK order_of_key
#define PI acos(-1.0)
#define INF 0x7ffffff0
#define INFL 0x7ffffffffffffff0LL
#define si(x) scanInt(&x)
#define sll(x) x = scanLong()
#define nl putc_unlocked('\n', stdout)
#define gc getchar_unlocked
#define RI readint()
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;


void printNcR(int n, int r) 
{ 
  
        long long p = 1, k = 1; 
  
    if (n - r < r) 
        r = n - r; 
  
    if (r != 0) { 
        while (r) { 
            p *= n; 
            k *= r; 
  
            long long m = __gcd(p, k); 
  
            p /= m; 
            k /= m; 
  
            n--; 
            r--; 
        } 
  
    } 
  
    else
        p = 1; 
    cout << p << endl; 
} 


int main(){
 int N;
 cin>>N;
 int A[N][3],dp[N][3];
 for(int i=0;i<N;i++)
  cin>>A[i][0]>>A[i][1]>>A[i][2];
 
 dp[N-1][0] = A[N-1][0];
 dp[N-1][1] = A[N-1][1];
 dp[N-1][2] = A[N-1][2]; 
 
 
 for(int i=N-2;i>=0;i--){
  dp[i][0] = A[i][0] + max(dp[i+1][1],dp[i+1][2]);
  dp[i][1] = A[i][1] + max(dp[i+1][0],dp[i+1][2]);
  dp[i][2] = A[i][2] + max(dp[i+1][0],dp[i+1][1]);
  
 }
 
 cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<"\n";
} 

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N, M;
    void solve()
    {
        N = cin.nextint;
        var D = cin.scanint;
        Array.Sort(D);
        M = cin.nextint;
        var T = cin.scanint;
        Array.Sort(T);

        int now = 0;
        for (int i = 0; i < M; i++)
        {
            while (true)
            {
                if (now == N || D[now] > T[i])
                {
                    WriteLine("NO");
                    return;
                }
                if (D[now] == T[i])
                {
                    now++;
                    break;
                }
                else
                {
                    now++;
                }
            }
        }
        WriteLine("YES");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int n;
	cin >> n;

	cout << int((n+1)/2) / double(n) << endl;


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

from operator import mul
from functools import reduce

def cmb(n, r):
    r = min(n - r, r)
    if r == 0: return 1
    # reduce(mul, 範囲)で範囲までの階乗計算
    # range (n, n-r, -1) -> n から n-rまで，逆順
    # print(range(n, n - r, -1))
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def main():
    num = [0]*(((10**5) * 2) + 1)
    c_num = [0]*(((10**5) * 2) + 1)

    for i in range(N):
        num[A[i]] += 1

    for i in range(0,len(num)):
        if num[i] >= 2:
            c_num[i] = cmb(num[i],2)

    c_sum = sum(c_num)
    # print(c_sum)

    for i in range(N):

        if num[A[i]] >= 2:
            # print(num[A[i]])
            Def = cmb(num[A[i]],2)
            tmp = 0

            if num[A[i]]-1 >= 2:
                tmp = cmb(num[A[i]]-1,2)

            # print("{} {}".format(Def,tmp))
            print(c_sum-(Def-tmp))

        else:
            print(c_sum)
            # g = 0


    # print(num[1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 26140
# D - Candidates of No Shortest Paths

MAXI = 999999999

# 入力
N, M = map(int, input().split())
cost = [[-1 for i in range(N)] for j in range(N)]

for i in range(M):
    a, b, c = map(int, input().split())
    cost[a - 1][b - 1] = c
    cost[b - 1][a - 1] = c

# iからjへの最短距離を表すテーブルの初期化
dist = [[MAXI for i in range(N)] for j in range(N)]

# iからjへの辺があったら、最短距離をその辺のコストで初期化
for i in range(N):
    for j in range(N):
        if i == j:
            dist[i][j] = 0
        elif cost[i][j] != -1:
            dist[i][j] = cost[i][j]
            dist[j][i] = dist[i][j]

# ワーシャルフロイドで各i,j間の最短距離を求めておく
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

# print(dist)

ans = 0

for i in range(N):
    for j in range(i, N):
        if cost[i][j] != -1: # 各辺がどの異なる２点の最短経路にも含まれないかを調べる
            flag = 1

            for k in range(N):
                for l in range(k + 1, N):
                    # 一つでも最短経路に含まれていたならブレイク
                    if dist[k][l] == dist[k][i] + cost[i][j] + dist[j][l]:
                        flag = 0
                        break
            
            # 全ての異なる２点間の最短経路に含まれていなかったら+1カウント
            ans += flag


print(ans)

Measured memory_bytes: 44892
food = [int(input()) for i in range(5)]
a = 10
OK = 0

for i in range(5):
    OK += food[i] % 10
    
if OK == 0:
    print(sum(food))
else:
    for i in range(5):
        x = food[i] % 10
        if 0 < x < a:
            a = x
            remove = food[i]

    food.remove(remove)

    ans = remove

    for i in range(4):
        ans += -(-food[i]//10)*10

    print(ans)

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

const int MOD = 1000000007;
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  ll arr[n];
  for(int i = 0;i < n;i++)
    cin >> arr[i];
  sort(arr, arr + n);
  if(arr[n - 1] <= n - 1){
    cout << 0;
    return 0;
  }
  ll k = 0;
  ll res = 0;
  for(int i = n - 1;i >= 1;i--){
    ll op = (arr[i] - arr[i - 1]) / (n + 1);
    res += op * (n - i);
    for(int j = i;j < n;j++)
      arr[j] -= op * (i + 1);
    for(int j = 0;j < i;j++)
      arr[j] += op * (n - i);

  }
  if(arr[0] >= n){
    ll op = (arr[0] - (n - 1));
    res += n * op;
    for(int i = 0;i < n;i++)
      arr[i] -= op;
  }

  while(arr[n - 1] >= n){
    arr[n - 1] -= n;
    for(int j = 0;j < n - 1;j++)
      arr[j]++;
    for(int j = n - 1;j >= 1 && arr[j] < arr[j - 1];j--)
      swap(arr[j], arr[j - 1]);
    res++;
  }
  cout << res;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  ll mini = 1001001001001;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    mini = min(mini, a[i]);
  }
  while(mini > 1){
    ll tmp = mini;
    //cout << tmp << " ";
    int flag = 0;
    for(int i = 0; i < n; i++) {
      if(flag == 0 && a[i] == mini){
        flag = 1;
        continue;
      }
      if(a[i] >= mini){
        a[i] %= mini;
        if(a[i] != 0){
          tmp = min(tmp, a[i]);
        }
      }
    }
    flag = 0;
    for(int i = 0; i < n; i++) {
      if(a[i] > 0){
        flag++;
      }
    }
    if(flag > 1){
      mini = min(mini, tmp);
      //cout << mini << endl;
      continue;
    }else{
      break;
    }
  }
  cout << mini << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
const ll INF=2000000000;
const ll MOD=1000000007;
 
int main() {
    int n,k;
    cin >> n >> k;
    ll h[n];
    ll dp[n];
    rep(i,n) cin >> h[i];
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
        dp[i] = INF;
        ll m=min(i,k)+1;
        for (int j = 1; j <m; j++) {
            dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1792
# include <stdio.h>
int main()
{
    int n,i,r=0,a=0;

    char str[101];
    scanf("%d",&n);
    scanf(" %[^\n]",str);

    for(i=0;i<n;i++){
        if(str[i]=='I') {
            r=r+1;
        }
        if(str[i]=='D'){
            r=r-1;
        }
        if(r>a){
            a=r;
        }
        else a=a;

    }
    printf("%d",a);

 return 0;
}



Measured memory_bytes: 128
N=int(input())
s=input()

dicX={s[0]:1}
dicY={}
for i in range(1,N):
    if s[i] in dicY: dicY[s[i]]+=1
    else: dicY[s[i]]=1

ans=int(s[0] in dicY)

for i in range(1,N-1):
    if not s[i] in dicX: dicX[s[i]]=1
    
    if dicY[s[i]]>1: dicY[s[i]]-=1
    else: dicY.pop(s[i])
    
    tmp=0
    for j in dicX:
         if j in dicY: tmp+=1
    ans=max(tmp,ans)

print(ans)

Measured memory_bytes: 3064
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const tmp = readln.split.to!(int[]);
    writeln(tmp[1] % tmp[0] == 0 ? tmp[0] + tmp[1] : tmp[1] - tmp[0]);
}



Measured memory_bytes: 256
import Control.Applicative

type Dice    = [(Int, Int)]
type Command = Char

rev :: (a,a) -> (a,a)
rev (x,y) = (y,x)

roll :: Dice -> Command -> Dice
roll [a, b, c] com =
    case com of
        'N' -> [b, rev a, c]
        'E' -> [rev c, b, a]
        'S' -> [rev b, a, c]
        'W' -> [c, b, rev a]
        _   -> error "Invalid command."
roll _ _ = error "Invalid command."

fromList :: [Int] -> Dice
fromList [a, b, c, d, e, f] = [(a, f), (b, e), (c, d)]
fromList _ = error "Invalid dice."

spin :: Dice -> [Dice]
spin [a, b, c] = [ [a, b, c]
                 , [a, rev c, b]
                 , [a, rev b, rev c]
                 , [a, c, rev b]
                 ]
spin _ = error "Invalid dice."

dicePermutation :: Dice -> [Dice]
dicePermutation d = spin d ++ spin d' ++ concatMap (spin  . roll d) "NEWS"
  where d' = roll (roll d 'N') 'N'

equalDice :: Dice -> Dice -> Bool
equalDice d1 d2 = d1 `elem` dicePermutation d2

main :: IO ()
main = do
    d1 <- readDice
    d2 <- readDice
    putStrLn $ if equalDice d1 d2 then "Yes" else "No"
    where readDice = fromList . map read . words <$> getLine

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

int main()
{
    int N;
    int count = 1;
    string tmp;
    cin >> N;
    vector<string> list(N);//景品リスト

    for (int i = 0; i < N; i++)
    {
        cin >> list[i];
    }

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

    for (int i = 0; i < N - 1; i++)
    {
        if (list[i] != list[i + 1])
            count++;
    }

    cout << count;
}

Measured memory_bytes: 9584
#include<bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<int,int>
#define ll long long int
#define ull unsigned long long int
#define inf LONG_MAX;
using namespace std;
ll dp[100005], h[100005],n;
int main()
{
    fast_io
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    cout<<dp[n]<<endl;
}


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


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

	int ans = 1000000000;
	for(int A=1;A<N;A++) {
		int B = N - A;
		int C = A;
		int d = 0;
		while(B > 0) {
			d += B % 10;
			B /= 10;
		}
		while (C > 0) {
			d += C % 10;
			C /= 10;
		}
		ans = min(ans, d);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull; 

bool ok(int a,int b,int c)
{
	if(a==b || a==c || b==c) return false;
	if(a+b<=c || b+c<=a || a+c<=b) return false;
	return true;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--)
	{
		ll x,k,d;
		cin>>x>>k>>d;
		x=abs(x);
		if(x%d==0)
		{
			ll num=x/d;
			if(num<=k)
			{
				ll dif=k-num;
				if(dif%2==0) cout<<0<<endl;
				else cout<<d<<endl;
			}
			else cout<<x-k*d<<endl;
		}
		else
		{
			ll br=x/d;
			if(br<=k)
			{
				if(br==k) cout<<x-br*d<<endl;
				else 
				{
					ll pos=x-br*d;
					ll diff=k-br;
					if(diff%2==1) cout<<abs(pos-d)<<endl;
					else cout<<pos<<endl;
				}
			}
			else cout<<x-k*d<<endl;
		}
	}	
 	return 0;
}

Measured memory_bytes: 3648
use proconio::input;

fn main() {
    input! {
        n: i32,
        k: usize,
        mut p: [i32; n],
    }

    p.sort();
    let mut ans = 0;
    for i in 0 .. k {
        ans += p[i];
    }

    println!("{}", ans);
}


Measured memory_bytes: 2156
import std.algorithm;
import std.string;
import std.stdio;
import std.range;
import std.conv;

void main() {
	int N = readln.chomp.to!int;
	auto A = readln.chomp.split.to!(long[]).sort!"a < b",
               B = readln.chomp.split.to!(long[]).sort!"a < b",
	       C = readln.chomp.split.to!(long[]).sort!"a < b";

	long ans = 0;
	foreach (b; B)
           ans += A.lowerBound(b).length * C.upperBound(b).length;

	ans.writeln;
}

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

using ll = long long;

using namespace std;

int main() {
  int n;
  cin >> n;
  int arr[51];
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  if (is_sorted(arr + 1, arr + n + 1)) {
    cout << "YES\n";
    return 0;
  }
  vector<int> v;
  for (int i = 1; i <= n; i++) {
    if (arr[i] != i) {
      v.push_back(i);
    }
  }
  if (v.size() == 2) {
    swap(arr[v[0]], arr[v[1]]);
    if (is_sorted(arr + 1, arr + n + 1)) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  } else {
    cout << "NO\n";
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N1 = in.nextInt();
		int N2 = in.nextInt();
		int N3 =  in.nextInt();
		
		List<Integer> list = new ArrayList<Integer>();
		list.add(N1);
		if(N1 < N2) {
			list.add(N2);
		}else {
			list.add(0, N2);
		}
		if(N3 < list.get(0)) {
			list.add(0, N3);
		}else if(N3 < list.get(1)) {
			list.add(1, N3);
		}else {
			list.add(N3);
		}
	
		System.out.println(list.get(2)-list.get(0));
	
		in.close();
		
	}
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	ll h, w;
	vector<string> v;
	ll count = 0;

	cin >> h >> w;

	vector<vector<ll>> dist(h, vector<ll>(w, INF));

	REP(i, h) {
		string s;
		cin >> s;
		v.push_back(s);
	}

	REP(i, h) {
		REP(j, w) {
			if (v[i][j] == '.') {
				count++;
			}
		}
	}

	queue<pair<ll, ll>> q;
	q.push(make_pair(0, 0));
	dist[0][0] = 1;

	while (!q.empty()) {
		ll x = q.front().first;
		ll y = q.front().second;
		q.pop();
		ll dx[4] = { 1, 0, -1, 0 };
		ll dy[4] = { 0, 1, 0, -1 };
		REP(i, 4) {
			ll nx = x + dx[i];
			ll ny = y + dy[i];
			if (nx < 0 || ny < 0 || nx >= h || ny >= w || dist[nx][ny] <= dist[x][y] + 1 || v[nx][ny] == '#') {
				continue;
			}
			q.push(make_pair(nx, ny));
			dist[nx][ny] = dist[x][y] + 1;
		}
	}

	if (dist[h - 1][w - 1] == INF) {
		cout << -1 << endl;
	}
	else {
		cout << count - dist[h - 1][w - 1] << endl;
	}
}

Measured memory_bytes: 256