akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    sort(all(s));
    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main() {
	// your code goes here
	int a, b, t;
	int count=0;
	int time = 0;
	
	cin >> a >> b >> t;
	
	for(int i=1 ; i<=t; i++) {
		if(i%a == 0)
		count += b;
		
	}
	
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }

string s = "0001001100110111011111111111111111111111111111111111111111111111111111111111111111111111111111111111";

int main(){
    int N;
    cin >> N;
    Yes(s[N - 1] - '0');
}


Measured memory_bytes: 256
import kotlin.math.abs
import kotlin.math.ceil

fun main() {
    val (_x, k, d) = readLine()!!.split(" ").map { it.toLong() }
    val x = abs(_x)

    val res = when {
        k < ceil(x.toDouble() / d) -> {
            x - k * d
        }
        (k - x / d) % 2 == 0L -> {
            x % d
        }
        else -> {
            abs(x % d - d)
        }
    }

    println(res)
}


Measured memory_bytes: 36508
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  vector<vector<char>> ss(n, vector<char>(10));
  for(int i=0; i<n; i++){
    for(int j=0; j<10; j++){
      cin>>ss.at(i).at(j);
    }
    sort(ss.at(i).begin(), ss.at(i).end());
  }
  
  sort(ss.begin(), ss.end());
  int64_t count =0;
  int64_t ans =0;
  vector<char> form(10);
  
  for(int i=0; i<n; i++){
    vector<char> tmp=ss.at(i);
    
    if(tmp==form) count ++;
    else{
      int64_t c=(count*(count+1))/2;
      ans+=c;
      count=0;
    }
    form =tmp;
  }
  int64_t d=(count*(count+1))/2;
  ans += d;

  cout<<ans<<endl;
}
        
    
    

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,0,n) cin >> a[i];
  vector<int> b = a;
  sort(b.rbegin(), b.rend());
  int f = b[0], s = b[1];
  rep(i,0,n) {
    if (a[i] != f) cout << f << endl;
    else cout << s << endl;
  }
  return 0;
}


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

int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, sum1 = 0;
cin >> n;
vector <int> d(n);
for (int i = 0; i < n; ++i){
cin >> d[i];
sum1 += d[i];
}
long long int sum = 0;
for (int j = 0; j < n; ++j){
sum1 -= d[j];
sum += d[j] * sum1;
}
cout << sum << "\n";
return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include<math.h>
#include<climits>
#define ll long long
#define VAL 100
using namespace std;
int main()
{
    int i,j,t;
    string str;
    cin>>str;
    int count=1;
    int maxcount=0;
    bool flag=false;
    if(str[0]=='R')
    {
        flag=true;
    }
    for(int i=1;i<str.length();i++)
    {
        if(str[i]=='R')
        {
            flag=true;
        }
        if((str.at(i)==str.at(i-1))&&(str[i]=='R'))
        {
                count++;
                maxcount=max(count,maxcount);
        }
        else
        {
            count=1;
        }
    }
    if(maxcount==0)
    {
        if(flag==true)
        {
            cout<<1<<endl;
        }
        else
        cout<<maxcount<<endl;
    }
    else
    {
        cout<<maxcount<<endl;
    }

    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



int main(){
  string a,b,c;
  cin >> a >> b >> c;
  printf("%c%c%c\n",a[0],b[1],c[2]);


  return 0;
}



Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <bitset>
#include <iostream>
#include <iomanip>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <numeric>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
typedef pair<double,double> Point;
const double eps = 1e-9;
Point P[305];

inline double Abs(const Point& p1,const Point& p2){
    return sqrt((p1.first - p2.first)*(p1.first - p2.first) + (p1.second - p2.second)*(p1.second - p2.second));
}
int main(void) {
//	cin.tie(0); ios::sync_with_stdio(false);
    int N;
    while(true){
        scanf("%d",&N);
        if(N == 0) break;
        for(int i = 0; i < N;i++){
            double x,y; scanf("%lf%lf",&x,&y);
            P[i] = Point(x,y);
        }
        if(N == 1){
            printf("1\n");
            continue;
        }
        int ans = 1;
        for(int i = 0; i < N;i++){
            for(int j = i + 1; j < N;j++){
                double dist = Abs(P[i],P[j]);
                if(dist > 2) continue;
                double r = sqrt(1 - dist*dist/4);
                Point cp = make_pair(-(P[i].second - P[j].second)*r/dist + (P[i].first + P[j].first)/2.0,
                                     (P[i].first - P[j].first)*r/dist + (P[i].second + P[j].second)/2.0);
                int cnt = 0;
                for(int k = 0; k < N;k++){
                    if(Abs(cp,P[k]) < 1.0 + eps) cnt++;
                }
                ans = max(ans,cnt);
            }
        }
        printf("%d\n",ans);
    }
	return 0;
}



Measured memory_bytes: 3220
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<tuple>
#include<iomanip>
using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    tuple<int,int,int> tmp[m];
    for(int i=0;i<m;i++){
        int p,y;
        cin >> p >> y;
        tmp[i]=make_tuple(y,p,i);
    }
    sort(tmp,tmp+m);
    vector<pair<int,int> > id(m);
    int cnt[n+1]={};
    for(int i=0;i<m;i++){
        int idx,p,y;
        tie(y,p,idx)=tmp[i];
        cnt[p]++;
        id[idx]=make_pair(p,cnt[p]);
    }
    for(int i=0;i<m;i++){
        cout << setw(6) << setfill('0') << id[i].first;
        cout << setw(6) << setfill('0') << id[i].second;
        cout << endl;
    }

}

Measured memory_bytes: 3840
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)



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

	string N;
	cin >> N;
	for (int i = 0; i < 3; i++) {
		if (N[i] == '7') {
			puts("Yes"); return 0;
		}
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 3604
import sys
from collections import deque

# 最短経路に閉路がくっついているとは限らなかった・・・

read = sys.stdin.read
N, M, *uv, S, T = map(int, read().split())

graph = [[] for _ in range(N + 1)]
for u, v in zip(*[iter(uv)] * 2):
    graph[u].append(v)

INF = 10 ** 15
# [けん,けんけん,けんけんぱ] * (N + 1)
dist = [[INF] * (N + 1) for _ in range(3)]
stack = deque([(0, S)])

while stack:
    cost, v = stack.popleft()
    if dist[cost % 3][v] != INF:
        continue

    dist[cost % 3][v] = cost
    for i in graph[v]:
        stack.append((cost + 1, i))

if dist[0][T] == INF:
    print(-1)
else:
    print(dist[0][T] // 3)


Measured memory_bytes: 35020
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] ans = new int[N];
        for(int i=0;i<N-1;i++){
            ans[sc.nextInt()-1]++;
        }

        for(int i=0;i<N;i++)
        System.out.println(ans[i]);

    }

}









Measured memory_bytes: 63148
module Main

open System

let nms = Console.ReadLine().Split(' ')
        |> Array.map int

let ma = nms.[1]
let mb = nms.[2]
let n = nms.[0]

let abcs = [| for _ in 1..n ->
                Console.ReadLine().Split(' ')
                    |> Array.map int
            |]

let z = 401
let m = 4001
let mutable xs = Array3D.init (n + 1) z z (fun _ _ _ -> m)
xs.[0, 0, 0] <- 0

for i in 0..(n - 1) do
    for a in 0..(z - 1) do
        for b in 0..(z - 1) do
            let ai = abcs.[i].[0]
            let bi = abcs.[i].[1]
            let ci = abcs.[i].[2]

            let x = xs.[i, a, b]
            if x <> m then
                if xs.[i + 1, a, b] > x then
                     xs.[i + 1, a, b] <- x

                if xs.[i + 1, a + ai, b + bi] > x + ci then
                    xs.[i + 1, a + ai, b + bi] <- x + ci

let mutable r = m
for i in 1..n do
    for a in 1..(z - 1) do
        for b in 1..(z - 1) do
            if a * mb = b * ma && r > xs.[i, a, b] then
                r <- xs.[i, a, b]

Console.WriteLine(
    if r = m then
        -1
    else
        r
)


Measured memory_bytes: 39252
//????????????4????????????????????????[A->B] -> [B->A]???????§?????????¨, [A->B] -> [A->B]????????????????????¨??????????????¨??????????????????????????????
//?????£????????´???????????\??¬????????§???????????°?????????O(n + m)
#include <iostream>
#include <stack>
using namespace std;

int n, m;
stack<int> stk[3];

void input() {
	int i;
	for (i = 0; i < 3; i++) { while (!stk[i].empty()) stk[i].pop(); }
	for (i = 0; i < 3; i++) {
		int num, value;
		cin >> num;
		for (int j = 0; j < num; j++) {
			cin >> value;
			stk[i].push(value);
		}
	}
}

bool operate(stack<int> *s, int &pos) {
	if (s[pos].empty() && s[pos + 1].empty()) return false;
	else if (s[pos].empty()) { s[pos].push(s[pos + 1].top()); s[pos + 1].pop(); }
	else if (s[pos + 1].empty()) { s[pos + 1].push(s[pos].top()); s[pos].pop(); }
	else if (s[pos].top() < s[pos + 1].top()) { s[pos].push(s[pos + 1].top()); s[pos + 1].pop(); }
	else { s[pos + 1].push(s[pos].top()); s[pos].pop(); }
	pos = !pos;
	return true;
}

int simurate(int pos) {
	int i;
	stack<int> s[3];
	
	for (i = 0; i < 3; i++) s[i] = stk[i];
	for (i = 0; i <= m; i++) {
		if (s[0].size() == n || s[2].size() == n) return i;
		if (!operate(s, pos)) return m + 1;
	}
	return i;
}

int main() {
	while (cin >> n >> m) {
		if (!n) break;
		input();
		int ans = min(simurate(0), simurate(1));
		if (ans <= m) { cout << ans << endl; }
		else { cout << -1 << endl; }
	}
	return 0;
}

Measured memory_bytes: 3104
using System;

class Program
{
    static int n;
    static int m;
    static bool[,] d;
    static int[] p;

    static void Main(string[] args)
    {
        var nm = Console.ReadLine().Split();
        n = int.Parse(nm[0]);
        m = int.Parse(nm[1]);

        d = new bool[m, n];
        for (int i = 0; i < m; i++)
        {
            var k = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            for (int j = 1; j <= k[0]; j++)
            {
                d[i, k[j] - 1] = true;
            }
        }

        p = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

        var ans = 0;
        for (int i = 0; i < Math.Pow(2, n); i++)
        {
            if (all(i)) ans++;
        }

        Console.WriteLine(ans);
    }

    static bool all(int x)
    {
        for (int i = 0; i < m; i++)
        {
            var count = 0;
            for (int j = 0; j < n; j++)
            {
                if (d[i, j] && (x >> j & 1) == 1)
                {
                    count++;
                }
            }
            if (count % 2 != p[i])
            {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int N;
	char c[101];
	while(cin >> N){
		if(N == 0){
			break;
		}
		int* p = new int[N];
		cin >> c;
		for(int i = 0; i < N; i++){
			p[i]=0;
		}
		int i = 0,Ba = 0;
		while(c[i] != '\0'){
			if(c[i] == 'M'){
				p[(i % N)]++;
			}else if(c[i] == 'S'){
				Ba += (p[(i % N)] + 1);
				p[(i % N)] = 0;
			}else if(c[i] == 'L'){
				p[(i % N)] += (Ba + 1);
				Ba = 0;
			}
			i++;
		}
		sort(p, p+N);
		for(int i = 0; i < N; i++){
			cout << p[i] << ' ';
		}
		cout << Ba <<endl;
		delete[] p;	
	}	
	return 0;
}


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

#define llint long long int

using namespace std;

int main(){
    int N;

    cin >> N;

    int iti = N % 10;

    if(iti == 2 || iti == 4 || iti == 5 || iti == 7 || iti == 9){
        cout << "hon" << endl;
    }else if(iti == 3){
        cout << "bon" << endl;
    }else{
        cout << "pon" << endl;
    }
}

Measured memory_bytes: 3596
R,G,B,N = map(int,input().split())
ans = 0
for i in range(0,N//R+1):
  for j in range(0,N//G+1):
    k = N - i*R -j*G
    if k%B == 0 and k>= 0:
      ans += 1
print(ans)


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c;
  
  if (a > b) {
    x = a;
    a = b;
    b = x;
  }
  if (b > c) {
    x = b;
    b = c;
    c = x;
  }
  if (a > b) {
    x = a;
    a = b;
    b = x;
  }
  cout << a << " " << b << " " << c << endl;
  
  return 0;
  
}



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

int main(){
    int N;
    cin >> N;
    ll ans = 0;
    for(int i = 1;i <= N;i++){
        int l = N / i;
        ll last = i * l;
        ans += (i+last) * l / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (ll)1000000007

int N;
ll dp[3100][3100];
int main()
{
    cin >> N;
    ll a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++)
    {
        dp[i][i] = 0;
    }
    for (int leng = 1; leng <= N; leng++)
    {
        for (int i = 0; i + leng <= N; i++)
        {
            int j = i + leng;
            if ((N - leng) % 2 == 0)
            {
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
            }
            else
            {
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
            }
        }
    }
    cout << dp[0][N] << endl;
}


Measured memory_bytes: 73984
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
} 
ll Logn(ll  n, ll r) 
{ 
    return (n > r - 1) ? 1 + Logn(n / r, r) : 0; 
}
 
int main()
{
	FAST
	int t=1;
//	cin>>t;
	while(t--)
	{	
		ll n,m,x;
		cin>>n>>m>>x;
		vector<int> a[n];
		for(int i=0;i<n;i++)
		{
			int a1;
			cin>>a1;
			a[i].pb(a1);
			for(int j=0;j<m;j++)
			{
				cin>>a1;
				a[i].pb(a1);
			}
		}
		int min1=INT_MAX;
		for(int i=0;i<pow(2,n+1);i++)
		{
			int r=i;
			vector<int> b(m,0);
			int sum=0;
			for(int j=0;j<n;j++)
			{
				if(r%2==1)
				{
					sum+=a[j][0];
					for(int k=0;k<m;k++)
					{
						b[k]+=a[j][k+1];
					}
				}
				r/=2;
			}
			int temp=0;
			for(int j=0;j<m;j++)
			{
				if(b[j]<x)
				{
					temp=1;
					break;
				}
			}
			if(temp==0)
			min1=min(min1,sum);
			
		}
		if(min1==INT_MAX)
		cout<<-1;
		else
		cout<<min1;
	}
    return 0;
}
  
 
 
 
 






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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

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


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

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


Measured memory_bytes: 3624
s = raw_input()
ss = s.split()
d = int(ss[0])
n = int(ss[1])
i = 1
while 1:
	x = i
	c = 0
	while x % 100 == 0:
		x //= 100
		c += 1
	if c == d:
		n -= 1
		if n == 0:
			print i
			break
	i += 1


Measured memory_bytes: 2568
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  long X = sc.nextLong();
	  Long Y = sc.nextLong();
	  int cnt = 0;
	  for (long num = X; num <= Y; num=2*num) { 
        if(num > Y) {
			 break;
		 }
        cnt++;
	  }
	  System.out.println(cnt);
	}

}

Measured memory_bytes: 35636
package main

import "fmt"

type Dice struct {
	side [6]int
	topnum int
	rightnum, leftnum, forwardnum, backnum, bottomnum int
}
func (dice *Dice) init() {
	for i:=0; i<6; i++ {
		fmt.Scan(&(dice.side[i]))
	}
	dice.topnum, dice.rightnum, dice.leftnum, dice.forwardnum, dice.backnum, dice.bottomnum = 0, 2, 3, 4, 1, 5
}
func (dice *Dice) dtonum(d int) int {
	for i:=0; i<6; i++ {
		if dice.side[i]==d {
			return i
		}
	}
	return 0
}
func (dice *Dice) inittopback(top, back int) {

	dice.topnum, dice.rightnum, dice.leftnum, dice.forwardnum, dice.backnum, dice.bottomnum = top, 2, 3, 5-back, back, 5-top
	topbackpairs := [6][4]int{{3,1,2,4},{0,3,5,2},{0,1,5,4},{1,0,4,5},{2,5,3,0},{2,1,3,4}}
	for i:=0; i<6; i++ {
		for j:=0; j<4; j++ {
			if top==topbackpairs[i][j] && back==topbackpairs[i][(j+1)%4] {
				dice.rightnum = i
				dice.leftnum = 5-i
				break
			}
		}
	}

}
func (dice *Dice) rotate(dir string) {
	temp := dice.topnum

	switch dir {
	case "N" :	
		dice.topnum = dice.backnum
		dice.backnum = dice.bottomnum
		dice.bottomnum = dice.forwardnum
		dice.forwardnum = temp
	case "E" :
		dice.topnum = dice.leftnum
		dice.leftnum = dice.bottomnum
		dice.bottomnum = dice.rightnum
		dice.rightnum = temp
	case "W" :
		dice.topnum = dice.rightnum
		dice.rightnum = dice.bottomnum
		dice.bottomnum = dice.leftnum
		dice.leftnum = temp
	case "S" :
		dice.topnum = dice.forwardnum
		dice.forwardnum = dice.bottomnum
		dice.bottomnum = dice.backnum
		dice.backnum = temp
	}
}
func (dice1 *Dice) checksameside(dice2 Dice) bool {

	if dice1.side[dice1.topnum] == dice2.side[dice2.topnum] && dice1.side[dice1.leftnum] == dice2.side[dice2.leftnum] && dice1.side[dice1.rightnum] == dice2.side[dice2.rightnum] && dice1.side[dice1.forwardnum] == dice2.side[dice2.forwardnum] && dice1.side[dice1.backnum] == dice2.side[dice2.backnum] && dice1.side[dice1.bottomnum] == dice2.side[dice2.bottomnum] {
			
		return true
	} else {
		return false
	}
}
func (dice1 Dice) havesameside(dice2 Dice) bool {
	
	for i:=0; i<4; i++ {
		if dice1.checksameside(dice2) {
			return true
		} else {
			for j:=0; j<4; j++ {
				dice1.rotate("E")
				if dice1.checksameside(dice2) {
					return true
				}
			}
		}
		dice1.rotate("N")
	}
	dice1.rotate("E")
	for i:=0; i<4; i++ {
		if dice1.checksameside(dice2) {
			return true
		} else {
			for j:=0; j<4; j++ {
				dice1.rotate("E")
				if dice1.checksameside(dice2) {
					return true
				}
			}
		}
		dice1.rotate("N")
	}
	return false
}

func main() {

	var n int
	fmt.Scan(&n)
	dices := make([]Dice, n)
	for i:=0; i<n; i++ {
		dices[i].init()
	}

	differentdices := true
	for i:=0; i<n-1; i++ {
		for j:=i+1; j<n; j++ {
			differentdices = differentdices && !(dices[i].havesameside(dices[j]))
		}
	}
	
	if differentdices {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1168
import std.stdio, std.conv, std.algorithm, std.array;

bool error;

char conv(int i, int j) {
  if (1 <= i && i <= 6 && 1 <= j && j <= 5) {
    int n = (i - 1) * 5 + j - 1;
    if (0 <= n && n < 26) {
      return cast(char)('a' + n);
    }
    else if (26 <= n && n < 30) {
      return [26: '.', 27: '?', 28: '!', 29: ' '][n];
    }
    else
      error = true;
  }
  else error = true;
  return '0';   // dummy
}

void main() {
  string str;
  while(readf("%s\n", &str)) {
    int[] nums = str.map!((x) => x.to!int - '0').array;
    char[] line;
    error = false;
    if ((nums.length & 1) == 1) error = true;
    for(int i = 0; i < nums.length - 1; i += 2) {
      line ~= conv(nums[i], nums[i + 1]);
    }
    writeln(error ? "NA" : line);
  }
}

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

int main()
{
  int n;
  cin >> n;
  int a[n], b[n];
  int all =0;
  a[0] = 0;
  b[0] = 0;
  for(int i=1;i<n;++i){
    cin >> a[i];
    b[i] = 0;
  }
  for(int i= n-1;i >0 ;--i){
    b[a[i]-1] += 1;
  }
  for(int i=0;i<n;++i){
    cout << b[i] << endl;
  }
}


Measured memory_bytes: 5188
#include <stdio.h>
int check(long long);
int solve(void);

int n,k;
long long W[100000];

int main(){
  int i,P;
  scanf("%d %d",&n,&k);
  for(i = 0; i < n; i++){
  scanf("%d",&W[i]);
}
  P = solve();
  printf("%d\n",P);
  return 0;
}
int check(long long P){
  int i = 0,j;
  long long sum;
  for(j = 0; j < k; j++){
    sum=0;
    while(sum + W[i] <= P){
      sum += W[i];
      i++;
      if(i == n) return n;
    }
  }
}

int solve(void){
  long long left = 0;
  long long right = 100000 * 10000;
  long long mid;
  int v;
  while(right - left > 1){
    mid = (left + right) / 2;
    v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }
  return right;
}

Measured memory_bytes: 1376
<?php
$nx = explode(' ', trim(fgets(STDIN)));
$n  = $nx[0];
$x  = $nx[1];
$m  = [];
while (true) {
    $input = trim(fgets(STDIN));
    if (empty($input)) {
        break;
    }
    array_push($m, $input);
}

$x = $x - array_sum($m);

$min = 1001;
for ($i = 0; $i < count($m); $i++) {
    if ($m[$i] < $min) {
        $min = $m[$i];
    }
}

$remain_count = floor($x / $min);

print count($m) + $remain_count;

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

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

ii d[MAXn];
ll dp[MAXn][MAXn];
int main(){
    IOS();
    ll n;
    cin >> n;
    REP1 (i,n) {
        cin >> d[i].X;
        d[i].Y = i;
    }
    sort(d+1,d+n+1,greater<ii>());
    ll ans = 0;
    REP1 (i,n) {
        REP (j,i+1) {
            ll k = i-j;
            if (j > 0) dp[j][k] = max(dp[j][k],dp[j-1][k] + (d[i].Y-j)*d[i].X);
            if (k > 0) dp[j][k] = max(dp[j][k],dp[j][k-1] + (n-k+1 - d[i].Y) * d[i].X);
            if (i == n) ans = max(ans,dp[j][k]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 26284
# -*- coding: utf-8 -*-

S = input()

C = "R"

R = 0
L = 0
Scan = []
for D in S:
    if D == "R":
        if C == "L":
            Scan.append( (R, L) )
            R = 0
            L = 0
        R += 1
    elif D == "L":
        L += 1
    C = D

Scan.append( (R,L) )

Ans = []
for R,L in Scan:
    CR = int((R + 1)/2) + int(L/2)
    CL = int(R/2) + int((L + 1)/2)
    Ans += [0] * (R - 1)
    Ans += [CR]
    Ans += [CL]
    Ans += [0] * (L - 1)


Atext = map(str, Ans)
print(" ".join(Atext))


Measured memory_bytes: 14068
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define INF 0x7fffffffffffffff

typedef long long ll;
const double PI=3.1415926535897931;
const long long mod=1e9+7;
const int MA= 1e7+10;
const int ma= 5*1e5+10;
const int few=1e3+10;
const int maxn=1e8+10;
using namespace std;
//////////////////////////////////////////////
char s[ma];
int tree[26][ma<<2];
int t[26];


void pushup(int nod)
{
    for(int i=0; i<26; i++)
    {
        tree[i][nod]=tree[i][nod<<1]|tree[i][(nod<<1)+1];
    }
}

void build(int l,int r,int nod)
{
    if (l == r)
    {
        tree[s[l]-'a'][nod] = 1;
        return ;
    }
    int mid = (l + r ) >> 1;
    build(l,mid,nod<<1);
    build(mid+1,r,(nod<<1)+1);
    pushup(nod);
}

void update(int l,int r,int k,int pos,int v)
{
    if (l == r)
    {
        for (int i=0; i<26; i++)
        {
            tree[i][k] = 0;
        }
        tree[v][k] = 1;
        return ;
    }
    int mid = (l + r) >> 1;
    if (pos <= mid)
    {
        update(l,mid,k<<1,pos,v);
    }
    else
    {
        update(mid+1,r,(k<<1)+1,pos,v);
    }
    pushup(k);
}

void query(int L,int R,int l,int r,int k)
{
    if (L <= l && R >= r)
    {
        for (int i=0; i<26; i++)
        {
            t[i] |= tree[i][k];
        }
        return ;
    }
    int mid = (l + r) >> 1;
    if (L <= mid)
    {
        query(L,R,l,mid,k<<1);
    }
    if (R > mid)
    {
        query(L,R,mid+1,r,(k<<1)+1);
    }
}

int main()
{
    int n;
    cin>>n;
    cin>>s+1;
    int q;
    cin>>q;
    build(1,n,1);
    while(q--)
    {
        int choose;
        cin>>choose;
        if(choose==1)
        {
            int i;
            char c;
            cin>>i>>c;
            update(1,n,1,i,c-'a');
        }
        else
        {
            int l,r;
            cin>>l>>r;
            int ans=0;
            query(l,r,1,n,1);
            for (int i=0; i<26; i++)
            {
                if (t[i])
                {
                    ans++;
                    t[i] = 0;
                }
            }
            cout<<ans<<endl;

        }
    }
    return 0;
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

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

    vector<int> visit(r);

    rep(i, r){
        cin >> visit[i];
    }

    vector<vector<int>> dist(n + 1, vector<int>(n + 1, INT_MAX_HALF));

    int a,b,c;

    rep(i, m){
        
        cin >> a >> b >> c;

        dist[a][b] = c;
        dist[b][a] = c;
    }

    rep(k, n + 1){
        rep(i, n + 1){
            rep(j, n + 1){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = INT_MAX;

    sort(ALL(visit));

    do{

        int tmp = 0;

        for(int i = 1; i < r; i++){
            tmp += dist[visit[i - 1]][visit[i]];
        }

        ans = min(ans, tmp);

    }while(next_permutation(ALL(visit)));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_7_B&lang=jp
*/

#include<iostream>
#include<string>
using namespace std;
#define NIL -1

struct Node{int p,l,r;};
Node Tree[25];
int D[25],H[25];

//height
int height(int u){
  int h1=0,h2=0;
  if(Tree[u].l!=NIL) h1=height(Tree[u].l)+1;
  if(Tree[u].r!=NIL) h2=height(Tree[u].r)+1;
  return H[u]=h1>h2?h1:h2;
}

//sibling
int sibling(int u){
  if(Tree[u].p==NIL) return NIL;
  int x=Tree[Tree[u].p].l;
  int y=Tree[Tree[u].p].r;
  return x==u? y:x;
}
//degree
int degree(int u){
  if(Tree[u].l==NIL&&Tree[u].r==NIL) return 0;
  else if(Tree[u].l!=NIL&&Tree[u].r!=NIL) return 2;
  else return 1;
}
//depth
int rec(int u,int p){
  D[u]=p;
  if(Tree[u].r!=NIL) rec(Tree[u].r,p+1);
  if(Tree[u].l!=NIL) rec(Tree[u].l,p+1);
}
//type
string type(int k){
  if(Tree[k].p==-1) return "root";
  else if(Tree[k].l==NIL&&Tree[k].r==NIL) return "leaf";
  else return "internal node";
}
void make_tree(int n){
  int left,right,k;
  for(int i=0;i<n;i++){
    cin>>k>>left>>right;
    Tree[k].l=left; Tree[k].r=right;//子設定
    if(left!=NIL || right!=NIL){
      Tree[left].p=Tree[right].p=k; //親設定
    }
  }
}
void print(int n){
  for(int i=0;i<n;i++){
    cout<<"node "<<i<<": parent = "<<Tree[i].p<<", ";
    cout<<"sibling = "<<sibling(i)<<", degree = "<<degree(i)<<", ";
    cout<<"depth = "<<D[i]<<", height = "<<H[i]<<", "<<type(i)<<"\n";
  }
}
int main(){
  int n,r;
  cin>>n;
  //初期化
  for(int i=0;i<25;i++) Tree[i].p=Tree[i].l=Tree[i].r=NIL;
  make_tree(n);
  for(int i=0;i<n;i++){
    height(i);
    if(Tree[i].p==NIL) r=i;
  }
  rec(r,0);
  print(n);
  //for(int i=0;i<n;i++) cout<<Tree[i].p<<" ";
}



Measured memory_bytes: 3124
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for ( i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for ( k = left; k < right; k++ ) {
    if ( L[i].value <= R[j].value )
      A[k] = L[i++];
    else
      A[k] = R[j++];
  }
}

void mergeSort(struct Card A[], int left, int right) {
  int mid;
  if ( left + 1 < right ) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p - 1;
  for ( j = p; j < r; j++ )
    if ( A[j].value <= x.value ) {
      i++;
      t = A[i]; A[i] = A[j]; A[j] = t;
    }
  t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
  return i + 1;
}

void quickSort(struct Card A[], int p, int r) {
  int q;
  if ( p < r ) {
    q = partition(A, p, r);
    quickSort(A, p, q - 1);
    quickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, 0, n);
  quickSort(B, 0, n - 1);

  for ( i = 0; i < n; i++ )
    // マージソートとクイックソートの結果を比べる
    if ( A[i].suit != B[i].suit ) stable = 0;

  if ( stable == 1 ) printf("Stable\n");
  else printf("Not stable\n");
  for ( i = 0; i < n; i++ )
    printf("%c %d\n", B[i].suit, B[i].value);

  return 0;
}


Measured memory_bytes: 5100
h,w,k = map(int,input().split())
a = [input() for i in range(h)]
c = 1
cou = 1
for i in range(h):
  if '#' not in a[i]:
    cou += 1
  else:
    ans = [c]*(a[i].index('#')+1)
    for j in range(a[i].index('#')+1,w):
      if a[i][j] == '#':
        c += 1
        ans.append(c)
      else:
        ans.append(c)
    [print(*ans) for i in range(cou)]
    break
for i in range(cou,h):
  if '#' not in a[i]:
    print(*ans)
  else:
    c += 1
    ans = [c]*(a[i].index('#')+1)
    for j in range(a[i].index('#')+1,w):
      if a[i][j] == '#':
        c += 1
        ans.append(c)
      else:
        ans.append(c)
    print(*ans)

Measured memory_bytes: 45532
#include <bits/stdc++.h>
using namespace std;
long Gcd(long m, long n){
	long temp;
	while (m % n != 0){
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}
int main(){
    int n;
    cin>>n;
    long rt=0,gcd=0;
    for(int i = 0; i < n; i++){
        long t;
        cin>>t;
        if(rt != 0){
            gcd = Gcd(rt,t);
            rt = (rt/gcd)*t;
        }
        else
            rt = t;
   }
   cout<<rt;
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.Set as Set
main=do
 [n,m]<-map read.words<$>getLine
 ab<-replicateM m (words<$>getLine)
 putStrLn(k (show n) m ab Set.empty)
  where k _ 0 _ _ = "IMPOSSIBLE"
        k n m (["1",x]:l) s = if (Set.member x s) then"POSSIBLE"else(k n (m-1) l (Set.insert x s))
        k n m l s = if ((l!!0)!!1)==n then (if(Set.member ((l!!0)!!0) s) then"POSSIBLE"else(k n (m-1) (tail l) (Set.insert ((l!!0)!!0) s)))
                                      else (k n (m-1) (tail l) s)

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

int main(void){

	int m, f, r;

	while(true){
		cin >> m >> f >> r;

		if (m + f + r == -3){
			break;
		}
		else if (m == -1 || f == -1){
			cout << 'F' << endl;
		}
		else if (m + f >= 80){
			cout << 'A' << endl;
		}
		else if (65 <= m+f && m+f < 80){
			cout << 'B' << endl;
		}
		else if (50 <= m+f && m+f < 65){
			cout << 'C' << endl;
		}
		else if (30 <= m+f && m+f < 50){
			cout << (r >= 50 ? 'C' : 'D') << endl;
		}
		else if (m + f < 30){
			cout << 'F' << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename V> class BIT {
private:
    int n; vector<V> bit;
public:
    void add(int i,V x){ i++; while(i < n) bit[i] += x, i += i & -i;}
    V sum(int i){ i++; V s = 0; while(i>0) s += bit[i], i -= i & -i; return s;}
    BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //?????????????????????0?????´???
    BIT(vector<V> v){ n = (int)v.size()+1; bit.resize(n); rep(i,n-1) add(i,v[i]);}
    void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
    void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1????????????
};

//u,v???????´????0~n-1??¨??????
ll inv_count(vector<int>& u,vector<int>& v)
{
    int n = len(u);
    vector<int> p(n);
    BIT<int> bt(n);
    ll ans = 0;
    rep(i,n){
        p[v[i]] = i;
    }
    rep(i,n){
        ans += i-bt.sum(p[u[i]]);
        bt.add(p[u[i]],1);
    }
    return ans;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi u(n),v(n);
    iota(all(v),0);
    rep(i,n){
        cin >> u[i];
    }
    vi tmp = u;
    sort(all(tmp));
    rep(i,n){
        u[i] = lower_bound(all(tmp),u[i]) - tmp.begin();
    }
    cout << inv_count(u,v) << "\n";
    return 0;
}

Measured memory_bytes: 6836
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, K, p, m;
ll Plus[int(2e5 + 5)], Minus[int(2e5 + 5)];
ll ans = 1;

int main(){
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    ll A; cin >> A;
    if (A >= 0) Plus[p] = A, p++;
    if (A < 0) Minus[m] = -1 * A, m++;
  }

  if (m == N && K % 2 != 0){
    sort(Minus, Minus + m);
    for (int i = 0; i < K; i++){
      ans *= Minus[i]; ans %= MOD;
    }
    ans *= -1;
    ans %= MOD; ans += MOD;
    cout << ans << endl;
    return 0;
  }

  if (p + m == N && N == K){
    for (int i = 0; i < p; i++){
      ans *= Plus[i]; ans %= MOD;
    }
    for (int i = 0; i < m; i++){
      ans *= -1 * Minus[i]; ans %= MOD; 
    }
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
  }

  sort(Plus, Plus + p, greater<ll>());
  sort(Minus, Minus + m, greater<ll>());
  int cnt = 0, cntp = 0, cntm = 0;

  while (cnt < K){
    if (cnt == K - 1 || cntm == m - 1){
      ans *= Plus[cntp]; ans %= MOD;
      cntp++; cnt++;
      continue;
    }

    if (Plus[cntp] * Plus[cntp+1] <= Minus[cntm] * Minus[cntm+1]){
      ans *= Minus[cntm]; ans %= MOD;
      ans *= Minus[cntm+1]; ans %= MOD;
      cntm+=2; cnt+=2;
    }else{
      ans *= Plus[cntp]; ans %= MOD;
      cntp++; cnt++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5164
# coding: utf-8
import itertools
N, M, Q = map(int,input().split())
L = list(itertools.combinations_with_replacement(range(1, M + 1), N))
D = []
for i in range(Q):
    D.append(list(map(int,input().split())))

#print(l)
#全てのA

ans = 0
for A in L:
    tmp = 0
    for i in range(Q):
        a = D[i][0]
        b = D[i][1]
        c = D[i][2]
        d = D[i][3]
        if A[b-1] - A[a-1] == c:
            tmp += d
        
        ans = max(ans,tmp)

print(ans)

Measured memory_bytes: 85060
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
int main(){
  int N,W;cin>>N>>W;
  vector<LL>w(N+1),v(N+1);
  for(int i=1;i<=N;i++)cin>>w[i]>>v[i];
  vector<LL>dp(100*1000+1,10000000000L);
  dp[0]=0;
  int ans=0;
  for(int i=1;i<=N;i++){
    for(int j=100*1000;j>=v[i];j--){
      dp[j]=min(dp[j-v[i]]+w[i],dp[j]);
      if(dp[j]<=W)ans=max(ans,j);
    }
  }
  for(int j=0;j<=100*1000;j++){
    if(dp[j]<=W)ans=max(ans,j);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int MOD=1000000007;

int main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>=pow(k,ans)){
        ans++;
    }
    cout<<ans;
    return 0;
}

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

int main() {

  int N, K;
  cin >> N >> K;

  double answer = 0.0;
  double n = N;

  for (int i = 1; i <= N; i++) {
    int v = i;
    int count = 0;
    while (v < K) {
      v *= 2;
      count++;
    }
    answer += pow(0.5, count) / n;
  }
  
  cout << setprecision(15) << answer << endl;

}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

i64 calc (i32 n, i32 *a, i32 *b) {
  i32 x[3], y[3];
  i32 len = 0;
  for (i32 i = 0; i < 3; ++i) {
    if (b[i] > a[i]) {
      x[len] = a[i];
      y[len++] = b[i];
    }
  }
  if (len == 0) return n;
  if (len == 1) {
    return n % x[0] + (i64) n / x[0] * y[0];
  }
  if (len == 2) {
    i64 res = n % x[0] + (i64) n / x[0] * y[0];
    for (i32 i = 1; x[1] * i <= n; ++i) {
      i64 m = n - i * x[1];
      res = MAX(res, m % x[0] + (i64) m / x[0] * y[0] + (i64) i * y[1]);
    }
    return res;
  }
  i64 *dp = ALLOC (n + 1, i64);
  for (i32 i = 0; i <= n; ++i) {
    dp[i] = i;
  }
  for (i32 i = 0; i < 3; ++i) {
    for (i32 j = x[i]; j <= n; ++j) {
      dp[j] = MAX(dp[j], y[i] + dp[j - x[i]]);
    }
  }
  return dp[n];
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = ALLOC (6, i32);
  for (i32 i = 0; i < 6; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  n = calc (n, a, a + 3);
  i64 ans = calc (n, a + 3, a);
  printf ("%" PRIi64 "\n", ans);
}

int main (void) {
  run();
  return 0;
}


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

class Node {
public :
	int location;
	int p, l, r;
	Node() {};
};

class Point {
public:
	int id, x, y;
	Point() {};
	Point(int id, int x, int y) :id(id), x(x), y(y) {};
	bool operator < (const Point &p) const {
		return id < p.id;
	}

	void print() {
		printf("%d\n", id);
	}

};

const int maxx = 1000010;
const int NIL = -1;

int n;
Point p[maxx];
Node T[maxx];
int np;

bool lessX(const Point &p1, const Point &p2) { return p1.x < p2.x; }
bool lessY(const Point &p1, const Point &p2) { return p1.y < p2.y; }

int makeKDTree(int l, int r, int depth) {
	if (l >= r)
		return NIL;
	int mid = (l + r) / 2;
	int t = np++;
	if (depth % 2 == 0)
		sort(p + l, p + r, lessX);
	else
		sort(p + l, p + r, lessY);

	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = p[T[v].location].x;
	int y = p[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty)
		ans.push_back(p[T[v].location]);

	if (depth % 2 == 0) {
		if (T[v].l != NIL && sx <= x)
			find(T[v].l, sx, tx,sy, ty, depth + 1, ans);
		if (T[v].r != NIL && x <= tx)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	}else {
		if (T[v].l != NIL && sy <= y)
			find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		if (T[v].r != NIL && y <= ty)
			find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
	}
}
int main()
{
	int x, y;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &x, &y);
		p[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}

	np = 0;
	int root = makeKDTree(0, n, 0);

	int q;
	int sx, tx, sy, ty;
	vector<Point> ans;
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++)
			ans[j].print();
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 16476
#include<stdio.h>

void Output(int *A, int N);

int main(){
	int *A;
	int N = 0;
	scanf("%d", &N);
	A = new int[N];

	for( int i = 0; i < N; i++ ){
		scanf("%d", &A[i]);
	}

	for( int i = 0; i < N; i++ ){
		int temp = A[i];
		for( int j = i - 1; j >= 0; j-- ){
			if( temp < A[j] ){
				A[j+1] = A[j];
				A[j] = temp;
			}
		}
		Output(A, N);
	}

	return 0;
}

void Output(int *A, int N){
	printf("%d", A[0]);
	for( int i = 1; i < N; i++ ){
		printf(" %d", A[i]);
	}
	printf("\n");
	return;
}

Measured memory_bytes: 1032