akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long n;
  cin >> n;
  string s;
  int a = (int)sqrt(n);
  for(int i = a;i >= 1;i--){
    if(n % i == 0){
      s = to_string(n/i);
      cout << s.size() << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3752
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> f(1000001, 1);
	rep(i, 0, n)cin >> a[i];
	sort(all(a));
	rep(i, 0, n) {
		if (f[a[i]] == 0)continue;
		if (i != n - 1 && a[i] == a[i + 1])f[a[i]] = 0;
		int k = 1000000 / a[i] + 1;
		rep(i2, 2, k) {
			f[a[i] * i2] = 0;
		}
	}
	int ans = 0;
	rep(i, 0, n)ans += f[a[i]];
	printf("%d\n", ans);
	return 0;
}


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

int main(){
  int n,sum;
  int t[25],b[25];
  bool f;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++)cin >> t[i] >> b[i];

    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
	if(b[i] > b[j]){
	  swap(t[i],t[j]);
	  swap(b[i],b[j]);
	}
      }
    }

    sum = 0;
    f = true;
    for(int i=0;i<n;i++){
      sum += t[i];
      if(sum>b[i]){
	f = false;
	break;
      }
    }
    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}
      

Measured memory_bytes: 588
#include <iostream>

using namespace std;

int main()
{
    int a[4][10]= {0};
    int b[4][10]= {0};
    int c[4][10]= {0};
    int d[4][10]= {0};

    int n;
    cin>>n;

    int bil, f, r, v;


    while(n--)
    {
        cin>>bil>>f>>r>>v;

        if(bil == 1)
            a[f-1][r-1] = a[f-1][r-1] + v;

        else if(bil == 2)
            b[f-1][r-1] = b[f-1][r-1] + v;

        else if(bil == 3)
            c[f-1][r-1] = c[f-1][r-1] + v;

        else if(bil == 4)
            d[f-1][r-1] = d[f-1][r-1] + v;

    }

///Building A

    for(int i = 0; i<3; i++)
    {
        for(int j = 0; j<10; j++)
        {
            cout<<" "<<a[i][j];
        }
        cout<<endl;
    }

    cout<<"####################"<<endl;

///Building B

    for(int i = 0; i<3; i++)
    {
        for(int j = 0; j<10; j++)
        {
            cout<<" "<<b[i][j];
        }
        cout<<endl;
    }

    cout<<"####################"<<endl;

///Building C

    for(int i = 0; i<3; i++)
    {
        for(int j = 0; j<10; j++)
        {
            cout<<" "<<c[i][j];
        }
        cout<<endl;
    }

    cout<<"####################"<<endl;

///Building D

    for(int i = 0; i<3; i++)
    {
        for(int j = 0; j<10; j++)
        {
            cout<<" "<<d[i][j];
        }
        cout<<endl;
    }


    return 0;
}




Measured memory_bytes: 3100
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  long long n;
  cin >> n;
  if(n%2==0){
    cout << n << endl;
  }else{
    cout << 2*n << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x;
int main()
{
    cin >> x;
    for(ll i = -1000; i <= 1000; i++){
        for(ll j = -1000; j <= 1000; j++){
            if(i*i*i*i*i-j*j*j*j*j == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


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

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

int num2 = 0;
int n = 1;
int pow2 = 2;
while (n <= N) {
    if (n == pow2) {
        pow2 = pow2 * 2;
        num2++;
    }
    n++;
}
cout << pow2 / 2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	long long int a, b, c, pa = -1, pb = -1, pc = -1, count = 0;
	scanf("%lld%lld%lld", &a, &b, &c);

	while (1) {
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) break;
		else if (pa == a && pb == b && pc == c) {count = -1; break;}
		else {
			pa = a; pb = b; pc = c;
			a = (pb + pc) / 2, b = (pa + pc) / 2, c = (pa + pb) / 2;
			//printf("%d %d %d\n", a, b, c);
			count++;
		}
	}

	printf("%lld\n", count);
	return 0;
}

Measured memory_bytes: 128
#%%
n, m = map(int, input().split())
l = [[] for _ in range(n)]

for i in range(m):
    a, b = input().split()
    a = int(a) - 1
    l[a].append(b)


ac = 0
wa = 0

for i in range(n):
    if l[i].count('AC') >= 1:
        ac += 1
        for j in range(len(l[i])):
            if l[i][j] == 'AC':
                break
            else:
                wa += 1
    else:
        pass

print(ac, wa)



Measured memory_bytes: 20376
using System;
using System.Linq;
class Program{
	static void Main(){
		long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long[] h=new long[s[0]];
		for(int i=0;i<s[0];i++){h[i]=long.Parse(Console.ReadLine());}
		long a=0,c=s[1]-s[2],ub=h.Max()/s[2]+1,lb=0,mid=0;
		while(ub-lb>1){
			mid=(ub+lb)/2;
			a=0;
			for(int i=0;i<s[0];i++){
				long d=h[i]-mid*s[2];
				if(d>0){a+=d/c+(d%c==0?0:1);}
			}
			if(mid>=a){ub=mid;}
			else{lb=mid;}
		}
		Console.WriteLine("{0}",ub);
	}
}

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

vector<pair<int, int>> edges[1000], rev[1000];
bitset<200000> cond1, cond2;

bitset<1000> visited;
void dfs(int i){
    if(visited[i]) return;
    visited[i] = 1;
    for(auto& p : edges[i]) if(!visited[p.second]) dfs(p.second);
}

int main(){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back({i, b-1});
        rev[b-1].push_back({i, a-1});
    }
    for(int i=0; i<N; i++){
        visited.reset();
        dfs(i);
        for(auto& p : rev[i]) if(visited[p.second]) cond1[p.first] = 1;
    }

    for(int i=0; i<N; i++){
        for(int t=0; t<2; t++){
            visited.reset();
            visited[i] = 1;
            for(auto& p : edges[i]){
                if(visited[p.second]) cond2[p.first] = 1;
                dfs(p.second);
            }
            reverse(edges[i].begin(), edges[i].end());
        }
    }

    for(int i=0; i<M; i++){
        cout << (cond1[i] == cond2[i] ? "same" : "diff") << endl;
    }
    return 0;
}


Measured memory_bytes: 7424
#include<stdio.h>

int main()
{
    int i,j,problems,drinks,p1,x1;
    scanf("%d",&problems);
    int time[problems+1];
    for(i=1;i<=problems;i++)
    {
        scanf("%d",&time[i]);
    }
    scanf("%d",&drinks);
    for(i=1;i<=drinks;i++)
        {
            int sum=0;
            scanf("%d %d",&p1,&x1);
            for(j=1;j<=problems;j++)
            {
                if(j==p1)
                {
                    continue;
                }
                else
                {
                    sum = time[j] + sum;
                }
            }

            printf("%d\n",sum+x1);
        }
}


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

const int Maxn = 100;

int A, B;
char res[Maxn][Maxn];

int main()
{
	scanf("%d %d", &A, &B);
	printf("%d %d\n", Maxn, Maxn);
	for (int i = 0; i < Maxn / 2; i++)
		for (int j = 0; j < Maxn; j++)
			res[i][j] = '.';
	for (int i = Maxn / 2; i < Maxn; i++)
		for (int j = 0; j < Maxn; j++)
			res[i][j] = '#';
	for (int i = 0; i + 1 < Maxn / 2; i += 2)
		for (int j = 0; j < Maxn; j += 2) {
			if (B > 1) { res[i][j] = '#'; B--; }
		}
	for (int i = Maxn / 2 + 1; i < Maxn; i += 2)
		for (int j = 0; j < Maxn; j += 2) {
			if (A > 1) { res[i][j] = '.'; A--; }
		}
	for (int i = 0; i < Maxn; i++) {
		for (int j = 0; j < Maxn; j++)
			printf("%c", res[i][j]);
		printf("\n");
	}
	return 0;
}

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

namespace ConsoleApp1 {
	class Program {
		static void Main(string[] args) {
			var uinps = Console.ReadLine().Split(new char[] { ' ' });
			int a = int.Parse(uinps[0]);
			int b = int.Parse(uinps[1]);
			if (a + b >= 10) Console.WriteLine("error");
			else Console.WriteLine(a + b);
		}
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;

int64_t divceil(int64_t a, int64_t b) {
    return a / b + (a > 0 && a % b ? 1 : 0);
}

int main() {
    int A, B;
    cin >> A >> B;
    cout << divceil(B - 1, A - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
// atcoder/abc138/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s, t;
  while (cin >> s >> t) {
    {
      set<char> vis(s.begin(), s.end());
      bool f = true;
      each (c, t) f = f && vis.count(c);
      unless (f) {
        cout << -1 << endl;
        continue;
      }
    }

    string u = s + s;
    const int N = 1e5 * 2 + 5;
    static map<char, lli> next[N];
    for (int i = 0; i < N; ++i) {
      next[i].clear();
    }
    map<char, lli> last;

    last.clear();
    for (int i = u.size() - 1; 0 <= i; --i) {
      next[i] = last;
      last[u[i]] = i;
    }

    lli x = 0, y = 0, z = 0;
    if (s[0] != t[0]) {
      char c = t[0];
      if (next[x].count(c)) {
        y = x = next[x][c];
      }
    }

    for (int i = 1; i < t.size(); ++i) {
      char c = t[i];
      if (next[x].count(c)) {
        y = next[x][c];
      }
      if (s.size() < y) {
        y -= s.size();
      }
      z += (y <= x);
      x = y;
    }
    cout << y + z * s.size() + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 335056
h,w=gets.split.map(&:to_i)
maths = []
h.times do
  maths<<gets.chomp.split("")
end
maths.each_with_index do |line, hIndex|
  line.each_with_index do |value, wIndex|
    maths[hIndex][wIndex] = 0 if value == "."
  end
end
maths.each_with_index do |line, hIndex|
  line.each_with_index do |value, wIndex|
    next if value != "#"
    [-1,0,1].repeated_permutation(2){|hIndexPlus, wIndexPlus|
      tempHIndex = hIndex + hIndexPlus  
      tempWIndex = wIndex + wIndexPlus
      next if tempHIndex < 0 || tempWIndex < 0 
      next if tempHIndex > h - 1 || tempWIndex > w - 1
      tempValue = maths[tempHIndex][tempWIndex]
      maths[tempHIndex][tempWIndex] += 1  if tempValue != "#" && tempValue != "."
      }
  end
end
maths.map{|line|puts line.join}

Measured memory_bytes: 2172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final long MOD = (long)Math.pow(10, 9) + 7;
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if (a > 0 && b > 0) {
			System.out.println("Positive");
		} else if (a == 0 || b == 0) {
			System.out.println("Zero");
		} else if (a < 0 && b > 0) {
			System.out.println("Zero");
		} else if (a < 0 && b < 0) {
			int cnt = Math.abs(b - a) + 1;
			
			if (cnt % 2 == 1) {
				System.out.println("Negative");
			} else {
				System.out.println("Positive");
			}
		}
	}
	
	static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 22612
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n, s = 0;
  cin >> n;
  for (char c : to_string(n)) s += c - '0';
  cout << (n % s == 0 ? "Yes" : "No") << endl;
}



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

using namespace std;
int main()
{
    int n; cin >> n;
    string s; char t;
    cin >> t;
    s.push_back(t);
    for( int i = 1; i < n; ++ i )
    {
        cin >> t;
        if( t == s.back() )
            continue;
        else s.push_back(t);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
n,m,s,t = map(int,input().split())
uvab = [list(map(int,input().split())) for i in range(m)]
gyen = [[] for i in range(n+1)]
gsnu = [[] for i in range(n+1)]
for u,v,a,b in uvab:
  gyen[u].append((v,a))
  gyen[v].append((u,a))
  gsnu[u].append((v,b))
  gsnu[v].append((u,b))
import heapq as hq
def dijkstra(start,graph):
  dist = [10**18]*(n+1)
  dist[start] = 0
  q = [(0,start)]
  hq.heapify(q)
  while q:
    _,x = hq.heappop(q)
    for y,dd in graph[x]:
      if dist[y] > dist[x]+dd:
        dist[y] = dist[x]+dd
        hq.heappush(q,(dist[y],y))
  return dist
distyen = dijkstra(s,gyen)
distsnu = dijkstra(t,gsnu)
ans = []
for i in range(n,0,-1):
  x = 10**15-(distyen[i]+distsnu[i])
  if i == n:
    ans.append(x)
  else:
    ans.append(max(ans[-1],x))
ans = ans[::-1]
print(*ans,sep="\n")

Measured memory_bytes: 123612
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]

l = [[] for i in range(n+1)]
for a, b in ab:
    l[a].append(b)
    l[b].append(a)

value = [0 for i in range(n+1)]
for p, x in px:
    value[p] += x

s = [1]
flag = [False]*(n+1)
while s:
    v = s.pop()
    flag[v] = True
    for e in l[v]:
        if flag[e]:
            continue
        value[e] += value[v]
        s.append(e)

print(*value[1:])


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

#define ll long long
#define N 100005
#define mod 1000000007

vector<pair<ll,ll> > adj[N];
ll visited[N]={},k;

void dfs(ll v)
{
    for(ll i=0;i<adj[v].size();i++)
    {
        ll to1=adj[v][i].first;
        ll to2=adj[v][i].second;
        if(to1!=k && !visited[to1])
        {
        visited[to1]=visited[v]+to2;
        dfs(to1);
        }
    }
}


int main() 
{
    ll n,q,u,v,len ; 
    
    cin>>n;
    ll n1=n-1;
    
    while(n1--)
    {
        cin>>u>>v>>len;
        adj[u].push_back({v,len});
        adj[v].push_back({u,len});
    }
    
    cin>>q>>k;
    
    visited[k]=0;
    dfs(k);
   
    while(q--)
    {
        cin>>u>>v;
        cout<<visited[u]+visited[v]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int N;
	
	cin >>N;
	
	
	cout <<800*N-(N/15)*200<< endl;
}


Measured memory_bytes: 256
var log = console.log;
if (typeof process != "undefined") {
	var input = "";
	process.stdin.resume();
	process.stdin.setEncoding('utf8');
	process.stdin.on('data', function (chunk) {
		input += chunk;
	});
	process.stdin.on('end', function () {
		var lines = input.split("\n");
		main(lines);
	});
}

//-----

function main(lines) {
	lines.shift();
	while (lines.length > 0) {
		var dataset = lines.slice(0, 2);
		dataset = dataset.map(function (row) {
			return row.split("").filter(function (e) {
				var code = e.charCodeAt(0);
				return (97 <= code && code <= 122)||(65 <= code && code <= 90);
			}).join("");
		});
		processDataset(dataset);
		lines = lines.slice(2);
	}
}

function processDataset(dataset) {
	var A = [];
	var f = dataset[0];
	var s = dataset[1];
	for (var i = 0; i < f.length; i++) {
		A[i] = [];
		for (var j = 0; j < s.length; j++) {
			if (f.charAt(i) == s.charAt(j)) {
				A[i][j] = 1;
			} else {
				A[i][j] = 0;
			}
			if (i == 0 && j == 0) {
				A[i][j] += 0;
			} else if (i == 0) {
				A[i][j] = Math.max(A[i][j - 1], A[i][j]);
			} else if (j == 0) {
				A[i][j] = Math.max(A[i - 1][j], A[i][j]);
			} else {
				A[i][j] = Math.min(Math.max(A[i - 1][j], A[i][j - 1]), Math.min(i, j) + 1);
				if(A[i - 1][j] == A[i][j - 1] && A[i][j-1] == A[i-1][j-1] && f.charAt(i) == s.charAt(j) ){
					A[i][j]++;
				}
			}
			1;
			if(i == f.length - 1 && j == s.length - 1){
				log(A[i][j]);
			}
		}
	}
}

Measured memory_bytes: 98220
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scan(&k, &a, &b)
	result := "NG"

	for i := a; i <= b; i++ {
		if i%k == 0 {
			result = "OK"
		}
	}
	fmt.Println(result)
}


Measured memory_bytes: 1752
/*
                        Author: Ankit Kaul
**********************Code Belongs to Respective Author Only************************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}      
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi
    int a,b,c;
    cin>>a>>b>>c;
    int res=a/(b+c);
    int ans=a%(b+c);
    if(ans==0)
    cout<<b*res;
    else
    {   if(ans>b)
        cout<<b+(res*b);
        else
        cout<<(res*b)+ans;
    }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll n=in();vector<ll>a(n),b(n),c(n);
    for(ll i=0;i<n;++i)a[i]=in()-1;
    for(ll i=0;i<n;++i)b[i]=in();
    for(ll i=0;i<n-1;++i)c[i]=in();
    ll ans=0;
    for(ll i=0;i<n;++i)ans+=b[a[i]]+(i!=n-1&&a[i+1]==a[i]+1?c[a[i]]:0);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
main()
{
int a,b,c,x,y,z;
scanf("%d%d%d",&a,&b,&c);
 if(a > b )
{
 x=a;
 a=b;
 b=x;
}
if(b > c )
{
 y=b;
 b=c;
 c=y;
}
if(a > b )
{
 z=a;
 a=b;
 b=z;
}
   
  printf("%d %d %d\n",a,b,c);
   
  return 0;
}

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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*（๑•﹏•๑｀) */

int main() {
	int num[102] = {};
	vector<pair<string,int> > PS;
	int N; cin >> N;
	REP(i,N){
		string S;
		int P;
		cin >> S >> P;
		num[P] = i+1;
		PS.PB(MP(S,-P));
	}

	sort(ALL(PS));

	REP(i,N){

	    cout << num[-PS[i].snd] << endl;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000000000000 //10^15
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  vector<ll> pos(0);
  vector<ll> neg(0);
  sort(all(A));
  reverse(all(A));
  bool fu = false;
  rep(i, N){
    if(A.at(i) < 0){
      fu = true;
    }
    if(fu){
      neg.push_back(A.at(i));
    }
    else{
      pos.push_back(A.at(i));
    }
  }
  vector<pair<ll, ll>> z(N);
  rep(i, N){
    if(A.at(i) >= 0){
      z.at(i) = make_pair(A.at(i), 1);
    }
    else{
      z.at(i) = make_pair(-1*A.at(i), -1);
    }
  }
  sort(all(z));
  reverse(all(z));
  bool pp = false;
  ll x = sz(pos);
  ll y = sz(neg);
  ll w = K - sz(pos);
  bool s = y > w;
  bool t = sz(pos) != 0;
  if((K - sz(pos)) % 2 == 0){
    pp = true;
  }
  else if(y > w && sz(pos) != 0){
    pp = true;
  }
  mint ans = 1;
  sort(all(pos));
  sort(all(neg));
  if(pp){
    vector<ll> dn(0);
    rep(i, sz(neg)/2){
      dn.push_back(neg.at(2*i)*neg.at(2*i+1));
    }
    if(K % 2 == 1){
      ans *= pos.at(sz(pos)-1);
      pos.pop_back();
      K--;
    }
    reverse(all(pos));
    rep(i, sz(pos)/2){
      dn.push_back(pos.at(2*i)*pos.at(2*i+1));
    }
    sort(all(dn));
    reverse(all(dn));
    rep(i, K/2){
      ans *= dn.at(i);
    }
  }
  else{
    sort(all(z));
    rep(i, K){
      ans *= z.at(i).first * z.at(i).second;
    }
  }
  cout << ans << endl; 
}

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

int main(void) {
	for (;;) {
		int n;
		cin >> n;
		if (n == 0)
			break;

		int s[100];
		int max = 0, min = 1000;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			if (max < s[i]) {
				max = s[i];
			}
			if (min > s[i]) {
				min = s[i];
			}
		}

		bool flag_max = true;
		bool flag_min = true;
		int total = 0;
		for (int i = 0; i < n; i++) {
			if ((s[i] == max) && flag_max) {
				flag_max = false;
				continue;
			} else if ((s[i] == min) && flag_min) {
				flag_min = false;
				continue;
			} else {
				total += s[i];
			}
		}
		int ave = total / (n - 2);
		printf("%d\n", ave);
	}
	return 0;
}

Measured memory_bytes: 1144
N, A, B, C, D = map(int, input().split())
S = list(input())
A -= 1
B -= 1
C -= 1
D -= 1

def cd():
    two_block_flg = False
    for s in S[A:C+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    two_block_flg = False
    for s in S[B:D+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    return 'Yes'

def dc():
    two_block_flg = False
    for s in S[A:C+1]:
        if two_block_flg:
            if s=='#':
                return 'No'
            else:
                two_block_flg = False
        else:
            if s=='#':
                two_block_flg = True
    for i in range(B, D+1):
        if S[i-1]=='.' and S[i]=='.' and S[i+1]=='.':
            return 'Yes'
    return 'No'  


if C<D:
    print(cd())
else:
    print(dc())

Measured memory_bytes: 6260
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll H;
    cin >> H;
    ll count  = 0;
    ll step = 0;
    while(H > 0){
        if(H == 1){
            count += pow(2, step);
            H = 0;
        }else{
            count += pow(2, step);
            step++;
            H = H / 2;
        }
    }
    cout << count << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=100005,inf=0x3f3f3f3f;
int n,js,a[N],s[N],c[N];LL res,num;
void msort(int l,int r) {
	int mid=(l+r)>>1;
	for(RI k=l,i=l,j=mid+1;k<=r;++k)
		if(j>r||(i<=mid&&s[i]<=s[j])) c[k]=s[i++];
		else c[k]=s[j++];
	for(RI k=l;k<=r;++k) s[k]=c[k];
}
void work(int l,int r) {
	if(l==r) return;
	int mid=(l+r)>>1;
	work(l,mid),work(mid+1,r);
	for(RI i=l,j=mid+1;j<=r;++j) {
		while(i<=mid&&s[i]<=s[j]) ++i;
		res+=i-l;
	}
	msort(l,r);
}
int check(int x) {
	for(RI i=1;i<=n;++i) s[i]=s[i-1]+(a[i]>=x?1:-1);
	res=0,work(0,n);
	return res>=(num+1)/2;
}
int main()
{
	int l=inf,r=0,ans;
	n=read();num=1LL*n*(n-1)/2+n;
	for(RI i=1;i<=n;++i)
		a[i]=read(),l=min(a[i],l),r=max(a[i],r);
	while(l<=r) {
		int mid=(l+r)>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
import numpy as np


def calc_mul4_dp(n, aaa):
    # result[i] = aaa[i] 以右をascendingにするために4をかける必要のある回数

    # 「支配的」である数と位置を記録するstack
    # 支配的: それを4倍すると、それより右で次に支配的な数までは全て4倍する必要のある数
    # (支配的な数, ←をいじらなかった場合の支配区間の最後の数, 最初の数の位置)
    # 第2項は巨大になり得るが、A_iの最大値 10^9 を超えたら常に末尾までが支配区間となるので、適当に上限でclip
    stack = [(10 ** 12, 10 ** 12, n), (aaa[-1], aaa[-1], n - 1)]
    INF = 10 ** 11
    result = [0, 0]

    for i in range(n - 2, -1, -1):
        a = aaa[i]
        c = a
        inc = 0
        while (c << 2) > stack[-1][0]:
            b, e, j = stack.pop()
            mul = 0
            while c > b:
                b <<= 2
                mul += 1
            inc += mul * (stack[-1][2] - j)
            c = min(e << (2 * mul), INF)
        stack.append((a, c, i))
        result.append(inc)
        # print(a, stack, result)
    result = np.add.accumulate(result, dtype=np.int64)[::-1]
    return result


def solve(n, aaa):
    fdp = calc_mul4_dp(n, aaa)
    bdp = calc_mul4_dp(n, aaa[::-1])[::-1]
    # print(fdp)
    # print(bdp)
    return ((fdp + bdp) * 2 + np.arange(n + 1, dtype=np.int64)).min()


def test():
    import random
    n = 200000
    # aaa = random.choices(range(1, 10 ** 9), k=n)
    # aaa = [1, 10 ** 9] * (n // 2)
    aaa = list(range(10 ** 9, 10 ** 9 - n, -1))
    print(n)
    # print(aaa)
    print(solve(n, aaa))


# test()

n = int(input())
aaa = list(map(int, input().split()))
print(solve(n, aaa))


Measured memory_bytes: 34204
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cassert>
#include <vector>
#include <string>
#include <cmath>
#include <map> 
#include <sstream>
#include <cstdio>
#include <complex>
#include <cstring>
using namespace std;
 
const int MAX= 10000100;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
#define ll long long int
#define gcd(a,b) __gcd(a,b)
#define pb(a) push_back(a)
int GCD(int a, int b) {if(!b) return a; return gcd(b, a%b);}
int lcm(int a, int b) {return a*b / gcd(a, b);}

int main(void){
  int n;
  cin>>n;
  vector<long> a(n);
  rep(i,n)cin>>a[i];
  int cnt = 0;
  rep(i,n){
    //cout<<a[a[i]-1]<<" "<<i+1<<endl;
    if(a[a[i]-1] == i+1){
      cnt ++;
    }
  }
  cout<<cnt/2<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;


struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint calc(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    

    mint ans=2;
    ans=ans.pow(n);

    ans-=1;
    ans-=(calc(n,a)+calc(n,b));
    cout<<ans.x;

    
    
}

Measured memory_bytes: 384
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut d: Vec<u64> = sc.vec(n);
    d.sort();

    let x = n / 2;

    println!("{}", d[x] - d[x - 1]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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


int main() {
  long n;
  cin>>n;
  long ans=0;
  rep2(i,1,n+1){
    ans+=(n/i)*(n/i+1)/2*i;
  }
  cout<<ans<<endl;
}

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

struct Combination {
    static ll mpow(ll x, ll n) { ll y = 1; for (; n > 0; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1; for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2); for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator ()(int n, int k) { return k < 0 || k > n ? 0 : fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(3e5 + 5);

int main() {
    ll N, A, B, K;
    cin >> N >> A >> B >> K;

    ll ans = 0;
    rep(i, 0, N + 1) {
        ll sub = K - A * i;

        if (sub % B == 0) {
            int j = sub / B;

            ans = (ans + C(N, i) * C(N, j)) % MOD;
        }
        else {
            continue;
        }
    }

    write(ans);
}

Measured memory_bytes: 4992
#include<stdio.h>

int main(void){
  int n,G[100][100],i,j,u,k,v;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[i][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(j!=n-1)
	printf("%d ",G[i][j]);
      else
	printf("%d\n",G[i][j]);
    }
  }
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int main() {
    int N; cin >> N;
    int h[N]; for(int i = 0;i < N; ++i) cin >> h[i];
    int res = 1;
    for (int i = 1; i < N; ++i) {
        bool f = true;
        for (int j = 0; j < i; j++) {
            f &= h[j] <= h[i]; 
        }
        if (f) ++res;
    }
    cout << res << endl;
}


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

int main() {
	int n,black= 0,sum,white=0,minv=200005;//blackは黒に、whiteは白にぬりかえるもの
	int j;
	cin >> n;
	string s;
	cin >> s;
	for (int i = 0; i < n; ++i) {
		if (s[i] == '.')++white;
	}
	for (int i = 0; i <= n; ++i) {
		if (i) {
			if (s[i-1] == '#') ++black;
			else --white;
		}
		sum = white + black;
		minv = min(sum, minv);
	}
	cout << minv << endl;
	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll mypow(ll a, ll b) {
    ll ret = 1;
    while (b--) {
        ret *= a;
    }
    return ret;
}

int main() {
    ll x, t;
    cin >> x >> t;
    cout << max(0ll, x - t) << "\n";
    return 0;
}

Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
    int N;
    cin>>N;
    unsigned long long L[N];
    for(int i=0;i<N;i++)
    {
        cin>>L[i];
    }
    unsigned long long count = 0;
    for(int i = 0;i<N-2;i++)
    {
        for(int j = i+1;j<N-1;j++)
        {
            for(int k=j+1;k<N;k++)
            {
                if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[k]+L[i]>L[j]){
                    if(L[i]!=L[j] &&L[i]!=L[k]&&L[j]!=L[k])
                    {
                        count++;
                    }
                }
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3608
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

balls = Counter(A)
s = 0
for k, v in balls.most_common():        
    if v >= 2:
        s += v * (v - 1) // 2

for i in range(N):
    c = balls[A[i]]
    d = (c * (c - 1) / 2) - ((c - 1) * (c - 2) / 2)
    print(int(s-d))

Measured memory_bytes: 97228
#include <iostream>
using namespace std;
int main() {
int n,a=0,b=0,c=0,d=0;
string s;
cin>>n;
while(n--){
  cin>>s;
  if(s=="AC"){
a+=1;
  }else{
    if(s=="WA"){
      b+=1;
    }else{
      if(s=="TLE"){
        c+=1;
      }else{
        d+=1;
      }
    }
  }
}
cout<<"AC"<<" x "<<a<<endl<<"WA"<<" x "<<b<<endl<<"TLE"<<" x "<<c<<endl<<"RE"<<" x "<<d;
}

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

using namespace std;

int F[5][5];
bool u[5][5];
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

struct Die{
  int p[6];
  bool f;
  int b;
  Die():p{},f(),b(){
  }
  void set(int x){
    if(p[0]){
      f=true;
    }else{
      p[0]=x;
      b|=1<<x;
    }
  }
  void rot(int *x){
    int t=p[x[0]];
    p[x[0]]=p[x[1]];
    p[x[1]]=p[x[2]];
    p[x[2]]=p[x[3]];
    p[x[3]]=t;
  }
  void rot(int x){
    if(x>=2){
      rot(x^2);
      rot(x^2);
      rot(x^2);
    }else{
      static int r[][4]={
	{0,4,5,1},
	{0,2,5,3},
      };
      rot(r[x]);
    }
  }
  bool is_valid(){
    return b+2==1<<7&&!f&&p[0]+p[5]==7&&p[1]+p[4]==7&&p[2]+p[3]==7;
  }
};

void dfs(int y,int x,Die &d){
  if(y<0||5<=y||x<0||5<=x||F[y][x]==0||u[y][x]++)return;
  d.set(F[y][x]);
  for(int i=0;i<4;i++){
    int ny=y+dy[i];
    int nx=x+dx[i];
    d.rot(i);
    dfs(ny,nx,d);
    d.rot(2^i);
  }
}

int main(){
  int N;
  cin>>N;
  while(N--){
    bool f=true;
    int y=0,x=0;
    int c=0;
    for(int i=0;i<5;i++){
      for(int j=0;j<5;j++){
	cin>>F[i][j];
	if(F[i][j]){
	  y=i;
	  x=j;
	  c++;
	}
      }
    }
    fill(u[0],u[5],false);
    Die d;
    dfs(y,x,d);
    cout<<boolalpha<<(c==6&&d.is_valid())<<endl;
  }
}

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

int main()
{
    int n,k,p,ans=0;
    vector<int>v;
    cin>>n>>k;

    for(int i=0;i<n;i++)
    {
        cin>>p;
        v.push_back(p);
    }
    sort(v.begin(),v.end());
    for(int i=0;i<k;i++)
    {
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF = 0x1fffffffffffffff;
int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    if(x==1)ans+=300000;
    else if(x==2)ans+=200000;
    else if(x==3)ans+=100000;
    if(y==1)ans+=300000;
    else if(y==2)ans+=200000;
    else if(y==3)ans+=100000;
    if(x==1&&y==1)ans+=400000;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
def main():
    nn,mm=map(int,input().split())
    n=max(nn,mm)
    m=min(nn,mm)
    temp=10**9 +7
    if n-m>=2:
        print(0)
        return
    fact=[0,1]
    for i in range(2,n+1):
        fact.append(fact[i-1]*i%temp)
    ans=fact[n]*fact[m]%temp
    if n-m==0:
        ans=ans*2%temp
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 7060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;

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

    ll N, x;
    cin >> N >> x;
    vector<ll> A(N);
    for (auto&& a : A) {
        cin >> a;
    }

    vector<ll> b(N, INF);

    ll ans = INF;
    for (ll k = 0; k < N; k++) {
        ll sum = 0;
        for (ll i = 0; i < N; i++) {
            ll idx = (i - k + N) % N;
            b[i] = min(b[i], A[idx]);
            sum += b[i];
        }
        sum += k * x;
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;
}



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

int main(){
    int i=0, x[10000];
    while(true){
        cin >> x[i];
        if(x[i]==0){break;}
        i++;
    }

    for(int j=0; j<i; j++){
        cout << "Case " << j+1 << ": " << x[j] << endl;
    }

    return 0;
}


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

    long n,ans = 0;
    long tate=0,yoko=0;
int main(){
    cin >> n;
    vector<long> a(n,0);;
    for(int i =0;i<n;i++){
        long hoge;
        cin >> hoge;
        a[i] = hoge;
    }
    sort(a.begin(),a.end(),std::greater<long>());


    for(int i=0;i<n;i++){
        if(a[i] == a[i+1]){
            tate = a[i];
            a.erase(a.begin()+i,a.begin()+i+2);
            break;
        }
    }

    for(int i =0;i<n;i++){
        if(a[i] == a[i+1]){
            yoko = a[i];
            break;
        }
    }

    if(tate != 0 && yoko !=0){
        ans = tate*yoko;
    }


    cout << ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N, Q;
  cin >> N >> Q;
  int a[N - 1], b[N - 1];
  // 隣接リスト
  vector<int> adj[N];
  for (int i = 0; i < N - 1; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    adj[a[i]].push_back(b[i]);
    adj[b[i]].push_back(a[i]);
  }
  int p[Q];
  ll x[Q];
  ll c[N]{};
  for (int i = 0; i < Q; i++) {
    cin >> p[i] >> x[i];
    p[i]--;
    c[p[i]] += x[i];
  }
  ll t = 0;
  deque<int> q;
  q.push_back(0);
  int vis[N]{};
  vis[0] = 1;
  while(!q.empty()) {
    int u = q.front();
    q.pop_front();
    for (int i : adj[u]) {
      if (vis[i] == 1) continue;
      vis[i] = 1; 
      c[i] += c[u];
      q.push_back(i);
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == N - 1) {
      cout << c[i] << "\n";
    } else {
      cout << c[i] << " ";
    }
  }
  return 0;
}

Measured memory_bytes: 20980