akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<set>
#include<stack>
#include<map>

struct vert{
	int key;
	int prev;
};

void gpaphColoring(std::vector<int> &coloredNode, std::vector<std::vector<int>> graph){
	int color= 0;	
	for(int i=0; i<coloredNode.size(); i++){
		if(coloredNode[i]>= 0)
			continue;

		std::stack<int> path;
		std::stack<vert> dfs;
		dfs.push({i, -1});

		while(!dfs.empty()){
			int cur= dfs.top().key;
			dfs.pop();	

			coloredNode[cur]= color;
			path.push(cur);

			bool isLeaf= true;
			for(int i=0; i<graph[cur].size(); i++){
				int dst= graph[cur][i];
				if(coloredNode[dst]<0){
					dfs.push({dst, cur});
					isLeaf= false;
				}
			}

			if(isLeaf){
				while(!dfs.empty()){
					if(dfs.top().prev==path.top())
						break;
					else
						path.pop();
				}
			}
		}
		color++;	
	}

}

int main(){
	int n, k, l;
	std::vector<std::vector<int>> graph1;
	std::vector<std::vector<int>> graph2;
	std::vector<int> coloredNode1;
	std::vector<int> coloredNode2;
	std::cin>>n>>k>>l;

	coloredNode1.resize(n, -1);
	coloredNode2.resize(n, -1);

	graph1.resize(n);
	graph2.resize(n);

	for(int i=0; i<k; i++){
		int src, dst;
		std::cin>>src>>dst;
		graph1[src-1].push_back(dst-1);
		graph1[dst-1].push_back(src-1);
	}

	for(int i=0; i<l; i++){
		int src, dst;
		std::cin>>src>>dst;
		graph2[src-1].push_back(dst-1);
		graph2[dst-1].push_back(src-1);
	}

	gpaphColoring(coloredNode1, graph1);
	gpaphColoring(coloredNode2, graph2);

	std::map<long long, int> vertGroup;

	for(int i=0; i<n; i++){
		long long idx= (long long)n * (long long)coloredNode1[i] + (long long)coloredNode2[i];
		vertGroup[idx]=0;
	}

	for(int i=0; i<n; i++){
		long long idx= (long long)n * (long long)coloredNode1[i] + (long long)coloredNode2[i];
		vertGroup[idx]= vertGroup[idx]+1;
	}

	for(int i=0; i<n; i++){
		long long idx= (long long)n * (long long)coloredNode1[i] + (long long)coloredNode2[i];
		std::cout<< vertGroup[idx]<<std::endl;
	}

	return 0;
}

Measured memory_bytes: 27736
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N, M, K; cin >> N >> M >> K;
  vector<vector<int>> G(N);
  rep(i,M){
    int a, b; cin >> a >> b;
    --a, --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> num(N, -1);
  int c = 0;
  rep(i,N){
    if (num[i]!=-1) continue;

    queue<int> q;
    num[i] = c;
    q.push(i);
    while (!q.empty()){
      int v = q.front(); q.pop();
      for (auto p : G[v]){
        if (num[p]==-1) {
          num[p] = c;
          q.push(p);
        }
      }
    }
    c++;
  }
  vector<int> gnum(c+1,0);
  rep(i,N) gnum[num[i]]++;
  int ans[N];
  rep(i,N){
    ans[i] = gnum[num[i]]-1 - G[i].size();
  }

  vector<vector<int>> B(N);
  rep(i,K){
    int c, d; cin >> c >> d;
    --c, --d;
    if (num[c]==num[d]) {
      ans[c]--;
      ans[d]--;
    }
  }
  rep(i,N) {
    if (i>0) cout << " ";
    cout << ans[i];
  }
  cout << endl;


  




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 12504
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int INF=1e9,MAXN=1e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,m,a[MAXN],b[MAXN],c[MAXN],f[MAXN],s[MAXN],cir[MAXN],in[MAXN],out[MAXN];
vector<int>S[3];
int gf(int x){return f[x]==x?x:f[x]=gf(f[x]);}
inline void Merge(int x,int y){
	x=gf(x),y=gf(y);if(x==y)return;
	f[y]=x,s[x]+=s[y],cir[y]=0;
}
inline bool cmp(int x,int y){return x>y;}
inline int Solve(int cnt,int opt){
	sort(S[1].begin(),S[1].end(),cmp),sort(S[2].begin(),S[2].end(),cmp);
	for(auto o:S[0])cnt-=o;int ans=INF;
	if(!opt){
		if(!S[1].size())return INF;cnt-=S[1][0],S[1].erase(S[1].begin());int cur=S[2].size();ll sum=0;
		for(auto o:S[2])sum+=o;while(cur>=1&&sum-S[2][cur-1]>=cnt)sum-=S[2][--cur];
		if(sum>=cnt)ans=min(ans,1+2*cur);
		for(int i=0;i<S[1].size();i++){
			for(cnt-=S[1][i];cur>=1&&sum-S[2][cur-1]>=cnt;sum-=S[2][--cur]);
			if(sum>=cnt)ans=min(ans,1+i+1+2*cur);
		}return ans;
	}else{
		if(cnt<=0)return 0;
		int cur=S[2].size();ll sum=0;
		for(auto o:S[2])sum+=o;while(cur>=1&&sum-S[2][cur-1]>=cnt)sum-=S[2][--cur];
		if(sum>=cnt)ans=min(ans,2*cur);
		for(int i=0;i<S[1].size();i++){
			for(cnt-=S[1][i];cur>=1&&sum-S[2][cur-1]>=cnt;sum-=S[2][--cur]);
			if(sum>=cnt)ans=min(ans,i+1+2*cur);
		}return ans;
	}
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),m=read();
	Rep(i,1,n)f[i]=i,s[i]=1,cir[i]=1;
	Rep(i,1,m){
		a[i]=read(),b[i]=read(),c[i]=read();
		Merge(a[i],b[i]),in[b[i]]++,out[a[i]]++;
	}
	Rep(i,1,n)if(in[i]!=1||out[i]!=1)cir[gf(i)]=0;
	int cnt=0,ans=0,lft,key=0;
	Rep(i,1,n)if(f[i]==i)cnt+=cir[i]&&s[i]>=2;
	lft=cnt;
	Rep(i,1,m){
		ans+=a[i]!=b[i];
		if(c[i]>=2){
			if(cir[gf(a[i])])if(s[gf(a[i])]==1)S[2].pb(c[i]-2);else S[0].pb(c[i]-1);
			else if(a[i]==b[i])S[1].pb(c[i]-1);else lft-=c[i]-1,key=1;
		}
	}
	if(cnt==0)cout<<ans;
	else{
		int tmp=Solve(lft,key);
		if(tmp==INF)puts("-1");else cout<<ans+tmp+cnt;
	}
	return 0;
}




Measured memory_bytes: 6876
#include <iostream>
#include <algorithm>
using namespace std;
int a[100000+100];
int n;
int main() {	
	cin>>n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a+1, a+1+n); 
	
	long long s = 1;
	int num = 0;
	for (int i=n; i >= 2; i--) {
		if (a[i] == a[i-1]) {
			s = s*a[i];
			num = num+1;
			i--;
		}
		if (num==2) {
			break;
		}
	}
	if (num == 2) {
		cout<<s<<endl;
	}else {
		cout<<0<<endl;
	}
	return 0;
}


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

using namespace std;

std::vector <std::string> v;

std::string str;

int main() {
    //std::ifstream cin("A.in");
    //std::ofstream cout("A.out");
    int i, n, l;
    std::ios::sync_with_stdio(false);
    cin >> n >> l;
    for(i = 0; i < n; i++) {
        str.clear();
        cin >> str;
        v.push_back(str);
    }
    std::sort(v.begin(), v.end());
    for(i = 0; i < n; i++)
        cout << v[i];
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

n = read()
v = reads()

evens = sorted(((v, k) for k, v in Counter(v[::2]).items()), reverse=True) + [(0, -1)]
odds = sorted(((v, k) for k, v in Counter(v[1::2]).items()), reverse=True) + [(0, -1)]

if evens[0][1] != odds[0][1]:
  ans = n - evens[0][0] - odds[0][0]
else:
  ans = n - max(evens[0][0] + odds[1][0], evens[1][0] + odds[0][0])

print(ans)

Measured memory_bytes: 20808
# なんかまともに考えるとわからん
# テキトーに問題文読まずサンプルだけ眺めるとgcdになる

n = int(input())
a = list(map(int, input().split()))
ans = a[0]


def gcd(a, b):
    if a > b:
        return gcd(b, a)
    while a > 0:
        a, b = b % a, a
    return b


for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Measured memory_bytes: 20080
package main

import "fmt"

func max(vs []int) int {
	v := vs[0]
	for _, u := range vs {
		if u > v {
			v = u
		}
	}
	return v
}
func min(vs []int) int {
	v := vs[0]
	for _, u := range vs {
		if u < v {
			v = u
		}
	}
	return v
}

func main() {
	var n, m, x, y int
	fmt.Scan(&n, &m, &x, &y)
	xs := make([]int, n)
	ys := make([]int, m)
	for i := range xs {
		fmt.Scan(&xs[i])
	}
	for i := range ys {
		fmt.Scan(&ys[i])
	}

	xs = append(xs, x)
	ys = append(ys, y)

	if max(xs) < min(ys) {
		fmt.Println("No War")
	} else {
		fmt.Println("War")
	}
}


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

using namespace std;

int main(){
 char b;
  cin >> b;
  if(b=='A'){
    b='T';
  }
  else if(b=='T'){
    b='A';
  }
  else if(b=='G'){
    b='C';
  }
  else{
    b='G';
  }
  cout << b << endl;
}


Measured memory_bytes: 256
from itertools import permutations
N = int(input())
P, Q = input().replace(' ', ''), input().replace(' ', '')
a = b = x = 0
for d in permutations(''.join(map(str, range(1, N+1))), N):
  x += 1
  s = ''.join(d)
  if s == P:
    a = x
  if s == Q:
    b = x
print(abs(a - b))

Measured memory_bytes: 40300
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> l(n);
  for (i64 i = 0; i < n; i++)
    cin >> l[i];
  sort(l.begin(), l.end());
  i64 ans = 0;
  for (i64 i = 0; i < n; i++)
    for (i64 j = i + 1; j < n; j++)
    {
      i64 ma = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
      i64 mi = upper_bound(l.begin(), l.end(), abs(l[i] - l[j])) - l.begin();
      ans += ma - mi - (mi <= i && i <= ma) - (mi <= j && j <= ma);
    }
  cout << ans / 3 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    string z="Yes";
    if(w<x+r || h<y+r || 0>x-r || 0>y-r){
       z="No";
    }
    cout << z << endl;
    return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    auto start = clock();


    ll n, a, d; cin >> n >> a >> d;
    if (d < 0) {
        d *= -1;
        a *= -1;
    }
    a -= d;
    ll d_mod = 2LL * abs(d);
    if (d_mod > 0) {
        unordered_map<ll, vector<pair<ll, ll>>> otr;
        for (ll k = 0; k <= n; ++k) {
            ll start = a * (2LL * k - n) + d * (k * (k + 1LL) - n * (n + 1LL) / 2LL);
            ll end = a * (2LL * k - n) + d * (k * (2LL * n - k + 1LL) - n * (n + 1LL) / 2LL);
            ll ost = start % d_mod;
            if (ost < 0) ost += d_mod;
            otr[ost].pb({start, end});
        }
        ll ans = 0;
        for (auto c : otr) {
            auto vec = c.second;
            sort(vec.begin(), vec.end());
            bool flag = false;
            ll end = -inf * inf;
            ll start = end;
            int n = vec.size();
            for (int i = 0; i < n; ++i) {
                if (!flag || end >= vec[i].first) {
                    if (!flag) {
                        start = vec[i].first;
                        end = vec[i].second;
                    } else {
                        end = max(end, vec[i].second);
                    }
                    flag = true;
                } else {
                    ans += (end - start) / d_mod + 1;
                    end = vec[i].second;
                    start = vec[i].first;
                }
            }
            ans += (end - start) / d_mod + 1;
        }
        cout << ans;
    } else {
        set<ll> ans;
        for (ll k = 0; k <= n; ++k) {
            ans.insert(a * (2LL * k - n));
        }
        cout << ans.size();
    }


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

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

typedef long long ll;

ll N;
map<char, map<ll, set<double>>> Vs;
double R = 1e20;

void update(double t) {
  t = abs(t);
  double res = 1;
  for (char xy : {'x', 'y'}) {
    set<double> avs;
    for (const auto &d_vs : Vs[xy]) {
      ll d = d_vs.first;
      const auto &vs = d_vs.second;
      avs.insert(*vs.begin() + d * t);
      avs.insert(*vs.rbegin() + d * t);
    }
    res *= *avs.rbegin() - *avs.begin();
  }
  // cout << "@ t " << t << " res " << res << endl;
  R = min(R, res);
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    double x, y;
    char d;
    cin >> x >> y >> d;
    Vs['x'][d == 'R' ? 1 : d == 'L' ? -1 : 0].insert(x);
    Vs['y'][d == 'U' ? 1 : d == 'D' ? -1 : 0].insert(y);
  }
  update(0);
  for (char xy : {'x', 'y'}) {
    for (ll d : {0, 1, -1}) {
      if (!Vs[xy].count(d)) continue;
      for (ll d2 : {0, 1, -1}) {
        if (d == d2) continue;
        if (!Vs[xy].count(d2)) continue;
        const auto &vs = Vs[xy][d], &vs2 = Vs[xy][d2];
        update((*vs2.begin() - *vs.begin()) / (d - d2));
        update((*vs2.rbegin() - *vs.rbegin()) / (d - d2));
      }
    }
  }
  cout << setprecision(15) << R << endl;
  return 0;
}

Measured memory_bytes: 9088
from math import ceil


def solve(string):
    b, a = map(int, string.split())
    h = 2 * ceil(max((a - 1) / 25, (b - 1) / 25)) + 1
    a -= 1
    b -= 1
    ans = []
    ans.append("{} {}".format(h, 100))
    for i in range(h):
        if i % 2 == 0:
            ans.append("." * 50 + "#" * 50)
        else:
            ma = min(a, 25)
            mb = min(b, 25)
            ans.append(".." * (25 - ma) + "#." * ma + "#." * mb + "##" * (25 - mb))
            a -= ma
            b -= mb
            a = max(a, 0)
            b = max(b, 0)
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3064
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int n,m,l;
    cin >> n >> m >> l;

    int a[n][m];
    int b[m][l];
    memset(a, 0, sizeof(int) * n * m);
    memset(b, 0, sizeof(int) * m * l);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int in;
            cin >> in;
            a[i][j] = in;
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            int in;
            cin >> in;
            b[i][j] = in;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            long int sum = 0;
            for (int k = 0; k < m; k ++) {
                sum += a[i][k] * b[k][j];
            }
            cout << sum;
            if (j < l-1)
                cout << " ";
        }
        cout << endl;
    }

    return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  
  int ans = T.size();
  
  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int count = 0;
    for (int j = 0; j < T.size(); j++) {
      if (T.at(j) != S.at(i + j)) count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<long long> t(n), a(n);
    for (int i = 0; i < n; i++) cin >> t[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    
    bool ok = (t[n-1] == a[0]);
    for (int i = 0; i < n-1; i++) {
        ok &= (t[i] <= t[i+1]);
        ok &= (a[i] >= a[i+1]);
    }

    long long ans = 1;
    for (int i = 0; i < n; i++) {
        long long tp = i ? t[i-1] : 0;
        long long an = (i+1 < n) ? a[i+1] : 0;
        if (tp < t[i] || a[i] > an) {
            if (tp < t[i]) ok &= a[i] >= t[i];
            if (a[i] > an) ok &= t[i] >= a[i];
            continue;   
        }
        ans = ans * min(tp, an) % mod; 
    }
    if (!ok) cout << 0 << "\n";
    else cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long a = 0;a < b;++a)
#define ALL(x) (x).begin(),(x).end()
void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}
void solve(){
    long long n, a, b;
    cin >> n >> a >> b;
    map<pair<ll, ll>,ll> go;
    go[make_pair(a, b)] = 0;
    int ok = 0;
    for (long long i = 1; i <= n; ++i) {
        if (i % 2 == 1) {
            a = a - b;
        }
        else {
            b = a + b;
        }
        if (ok == 1||go.find(make_pair(a, b)) == go.end()) {
            go[make_pair(a, b)] = i;
        }
        else {
            long long cnt = i - go[make_pair(a, b)];
            i += ((n - i) / cnt) * cnt;
            ok = 1;
        }
    }
    cout << a << " " << b << endl;
}
int main() {
    init();
    solve();
}


Measured memory_bytes: 3216
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

char v[1001][1001];

int rpath[] = {1, -1, 0, 0};
int cpath[] = {0, 0, 1, -1};

bool check(int ci, int cj, int n, int m)
{
    if (ci >= 1 && cj >= 1 && ci <= n && cj <= m && v[ci][cj] != '#')
    {
        return true;
    }

    return false;
}
int dis[1001][1001];
void bfs(int a, int b, int n, int m)
{
    deque<int> rq;
    deque<int> cq;
    dis[a][b] = 0;
    rq.push_back(a);
    cq.push_back(b);
    while (!rq.empty() && !cq.empty())
    {
        int curri = rq.front();
        int currj = cq.front();
        rq.pop_front();
        cq.pop_front();
        for (int i = 0; i < 4; i++)
        {
            int ci = curri + rpath[i];
            int cj = currj + cpath[i];
            if (check(ci, cj, n, m) && dis[ci][cj]>dis[curri][currj])
            {
                dis[ci][cj]=dis[curri][currj];
                rq.push_front(ci);
                cq.push_front(cj);
            }
        }
        for(int x = curri-2;x<=curri+2;x++){
            for(int y = currj-2;y<=currj+2;y++){
                if(check(x,y,n,m)){
                    if(dis[x][y]>dis[curri][currj]+1){
                        dis[x][y]=dis[curri][currj]+1;
                        rq.push_back(x);
                        cq.push_back(y);
                    }
                }
            }
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,w;
    cin>>h>>w;
    int sx,sy,dx,dy;
    cin>>sx>>sy>>dx>>dy;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>v[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            dis[i][j] = INT_MAX;
        }
    }
    bfs(sx,sy,h,w);
    
    if(dis[dx][dy]==INT_MAX){
        cout<<-1<<"\n";
    }else{
        cout<<dis[dx][dy];
    }
    return 0;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

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

ll a,b,c,d;

int main(){
	cin.sync_with_stdio(false);
	cin>>a>>b>>c>>d;
	ll da=abs(a-c), db=abs(b-d);
	ll res=(da/gcd(da,db)+db/gcd(da,db)-1)*gcd(da,db);
	cout<<res<<endl;
	return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  string answer = "";
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) answer += v[i];
  cout << answer;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    ll l, r;
    cin >> l >> r;

    r = min(r, l + 4038);

    ll minv = 2020;
    for (ll i = l; i < r + 1; i++)
    {
        for (ll j = i + 1; j < r + 1; j++)
        {
            ll x = i * j % 2019;
            minv = min(minv,x);
        }
    }
        cout << minv << endl;
    return 0;
}

Measured memory_bytes: 256
#include<climits>
#include<algorithm>
#include<cstdio>

const int N_MAX = 100000;
int x[N_MAX];

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	for(int i=0;i<n;i++) {
		scanf("%d", &x[i]);
	}
	int m = INT_MAX;
	for(int i=0;i+k-1<n;i++){
		int l = x[i];
		int r = x[i+k-1];
		int t;
		if(l < 0 && r < 0) {
			t = -l;
		} else if(l > 0 && r > 0) {
			t = r;
		} else {
			t = std::min(r - 2 * l, 2 * r - l);
		}
		if(t < m) m = t;
	}
	printf("%d\n", m);
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q; cin>>q;
    while(q--){
        ll a,b; cin>>a>>b;
        ll l=0, r=a+b;
        while(r-l>1){
            ll c = (r+l)/2;
            ll A = a-1;
            ll B = c-b+1;
            ll s = min(A,B);
            ll t = max(A,B);
            s = min(c-1, max(s, 0ll));
            t = min(c-1, max(t, 0ll));
            auto f = [&](ll x){return (x>=A)?(x+2):(x+1);};
            auto g = [&](ll x){return (x>=B)?(c-x):(c-x+1);};
            ll maxi=0;
            ll lo=0,hi=s;
            // cout<<s<<", "<<t<<endl;
            while(hi-lo>2){
                ll c1 = (lo*2+hi)/3;
                ll c2 = (lo+hi*2)/3;
                ll v1 = f(c1)*g(c1);
                ll v2 = f(c2)*g(c2);
                if (v1<v2) lo = c1;
                else hi = c2;
            }
            chmax(maxi, f((lo+hi)/2)*g((lo+hi)/2));
            lo=s,hi=t;
            while(hi-lo>2){
                ll c1 = (lo*2+hi)/3;
                ll c2 = (lo+hi*2)/3;
                ll v1 = f(c1)*g(c1);
                ll v2 = f(c2)*g(c2);
                if (v1<v2) lo = c1;
                else hi = c2;
            }
            chmax(maxi, f((lo+hi)/2)*g((lo+hi)/2));
            lo=t,hi=c;
            while(hi-lo>2){
                ll c1 = (lo*2+hi)/3;
                ll c2 = (lo+hi*2)/3;
                ll v1 = f(c1)*g(c1);
                ll v2 = f(c2)*g(c2);
                if (v1<v2) lo = c1;
                else hi = c2;
            }
            chmax(maxi, f((lo+hi)/2)*g((lo+hi)/2));
            if (maxi<a*b) l=c;
            else r=c;
        }
        cout<<l<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    string s;
    cin>>s;

    cout<<s[0]<<s[1]<<s[2]<<s[3]<<" "<<s[4]<<s[5]<<s[6]<<s[7]<<s[8]<<s[9]<<s[10]<<s[11]<<endl;
}

Measured memory_bytes: 3564
N = gets.to_i
as = gets.split.map(&:to_i)

accum = as.dup
(N-1).times do |i|
    accum[i+1] += accum[i]
end

sum = accum[N-1]
ans = 10**20
(1..(N-3)).each do |center|
    s1 = accum[center]
    s2 = sum - accum[center]

    #s1
    lb = 0
    ub = center-1
    while ub-lb > 1
        mid = (ub+lb)/2
        if accum[mid] >= s1/2
            ub = mid
        else
            lb = mid
        end
    end
    s1a = [
        [accum[lb], s1 - accum[lb]],
        [accum[ub], s1 - accum[ub]]
    ]

    #s2
    lb = center+1
    ub = N-2
    while ub-lb > 1
        mid = (ub+lb)/2
        if accum[mid] - s1 >= s2/2
            ub = mid
        else
            lb = mid
        end
    end
    s2a = [
        [accum[lb] - s1, sum - accum[lb]],
        [accum[ub] - s1, sum - accum[ub]]
    ]

    s1a.each do |n1, n2|
        s2a.each do |n3, n4|
            arr = [n1, n2, n3, n4]
            max = arr.max
            min = arr.min
            ans = max-min if ans > max-min
        end
    end
end
puts ans

Measured memory_bytes: 23204
S = input()
T = input()

if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
    

ind = None
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == "?":
            continue
        elif S[i+j] == T[j]:
            continue
        else:
            break
    else:
        ind = i

if ind == None:
    print('UNRESTORABLE')
else:
    ans = list(S)
    for i in range(ind,ind+len(T)):
        ans[i] = T[i-ind]
    for i in range(len(ans)):
        if ans[i] == "?":
            ans[i] = "a"
    print("".join(ans))

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

list_num = [[] for i in range(n)]

for i in range(m):
  x,y = map(int, input().split())
  list_num[x - 1].append(y)
  list_num[y - 1].append(x)

count = 0

for i in range(n):
  check = 1
  for j in list_num[i]:
    if(h[i] <= h[j - 1]):
      check = 0
      break

  if(check == 1):
    count += 1

print(count)





Measured memory_bytes: 29564
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
#define nl '\n'
 
#define y1 aza_ibagaliev
 
#define f first
#define s second
	
#define ed end()
#define bg begin()
#define rbg rbegin()
 
#define rv reverse
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define ppf pop_front
 
#define sz size()
#define all(x) x.bg, x.ed
 
#define pll pair < ll, ll >
#define pii pair < int, int >
 
#define sqr(x) ((x) * 1ll * (x))
#define sqrd(x) ((x) * 1.0 * (x))
 
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define rnl cout << "----------------------------------------" << nl
 
#define bit __builtin_popcount
 
inline ll bip(ll x, ll n, ll mod){ll res=1;while(n){if(n & 1){res=(res*x)%mod;}x=(x*x)%mod;n>>=1;}return res;}
  
const int ppr = 257;
const ll INF = 2e18;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 2e6 + 123;
const ld pi = 3.1741592653589793238462643;
 
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
 
int r;

main() {             	
//  freopen(".in", "r", stdin);                          
//  freopen(".out", "w", stdout);
 
//	srand(time(NUll));
 
	speed;
 
    cin >> r;

    cout << r * r;

    return 0;                                        
}     

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, m, x;
    cin >> n >> m >> x;
    set<int> a;

    fo(i, m) {
        int b;
        cin >> b;
        a.insert(b);
    }

    int custon = 0, custo0 = 0;
    int at = x;
    while ( at < n ) {
        at++;
        if ( a.find(at) != a.end() ) custon++;
    }
    at = x;
    while ( at > 0 ) {
        at--;
        if ( a.find(at) != a.end() ) custo0++;
    }

    cout << min(custon, custo0) << endl;

    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	int n;
	cin >> n;
	int a = 0, b = 0, c = 0, d = 0;
	for(int i = 0; i < n; i++) {
		string str;
		cin >> str;
		if(str == "AC") a++;
		if(str == "WA") b++;
		if(str == "TLE") c++;
		if(str == "RE") d++;
	}
	cout << "AC x " << a <<endl;
	cout << "WA x " << b <<endl;
	cout << "TLE x " << c << endl;
	cout << "RE x " << d << endl;

}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<map>

using namespace std;


int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    vector<int> K(N);

    for (int  i = 0; i < N; i++)
    {
        cin >> S[i] >> P[i];
        K[i] = i + 1;
    }

    string str;
/*
    int j = N;
    for(int  i = 0; i < j-1; i++)
    {
        if(S[i] > S[i+1])
        {
            str = S[i];
            S[i] = S[i+1];
            S[i+1] = str;
        }

        if(S[i] == S[i+1]){
            if(P[i] < P[i+1]){
                str = S[i];
                S[i] = S[i+1];
                S[i+1] = str;
            }
        }

        j--;
        if(j == 1) break;
    }
*/   
    int j = 0 ,p = 0, k =0;
    for (int  j = 0; j < N-1; j++)
    {
        for (int  i = N - 1; j < i;i--)
        {
            if(S[i] < S[i-1])
            {
                //cout << S[i] << " S[i-1] = " << S[i-1] << endl;
                str = S[i];
                S[i] = S[i-1];
                S[i-1] = str;

                p = P[i];
                P[i] = P[i-1];
                P[i-1] = p;

                k = K[i];
                K[i] = K[i-1];
                K[i-1] = k;
                }

            if(S[i] == S[i-1]){
                if(P[i] > P[i-1]){
                    str = S[i];
                    S[i] = S[i-1];
                    S[i-1] = str;

                    p = P[i];
                    P[i] = P[i-1];
                    P[i-1] = p;

                    k = K[i];
                    K[i] = K[i-1];
                    K[i-1] = k;       
                }
            }
        }
    }

    for (int  i = 0; i < N; i++)
    {
        cout << K[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
/*
g++ -ggdb -fsanitize=address -std=c++14 D.cpp && ./a.out <<< "5 2 4"
*/

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

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename A>
string to_string(A v) { int cnt = 0; string res; for (const auto &x : v) { if (cnt++) res += " "; res += to_string(x); } return "[" + res + "]"; }
string to_string(const string& s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n, x, y; cin >> n >> x >> y;

    vector<vi> Adj(n + 1);
    for (int i = 1; i <= n; i++) {
        Adj[i].push_back(i - 1);
        Adj[i - 1].push_back(i);
    }
    Adj[x].push_back(y);
    Adj[y].push_back(x);

    int INF = 1e9;

    vi Ans(n + 1, 0);
    for (int u = 1; u <= n; u++) {
        vi D(n + 1, INF);
        vi Q{ u };
        D[u] = 0;
        int index = 0;
        while (index < sz(Q)) {
            int node = Q[index];
            trav(sib, Adj[node])
                if (D[sib] > D[node] + 1) {
                    D[sib] = D[node] + 1;
                    Q.push_back(sib);
                }
            index++;
        }

// debug(u, D, Q);

        for (int v = u + 1; v <= n; v++)
            Ans[D[v]]++;
    }

    for (int d = 1; d < n; d++)
        printf("%d\n", Ans[d]);
}

Measured memory_bytes: 384
import math
xyzk = list(map(int,input().split()))
abc = [list(map(int,input().split())) for a in range(3)]
ab=[]
for a in abc[0]:
    for b in abc[1]:
        ab.append(a+b)
ab.sort()
ab.reverse()
abc[2].sort()
abc[2].reverse()
abc2=[]
for c in range(len(abc[2])):
    for a in range(min([math.ceil(xyzk[3]/(c+1)),len(ab)])):
        abc2.append(abc[2][c]+ab[a])
abc2.sort()
abc2.reverse()
for a in range(xyzk[3]):
    print(abc2[a])

Measured memory_bytes: 55380
import java.util.*;
public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int x = sc.nextInt();
      int y = sc.nextInt();

      int cost = 0;

      if (x <= y) {
         if (a + b <= 2 * c) {
            cost += (a + b) * x;
            if (b <= 2 * c) {
               cost += b * (y - x);
            } else {
               cost += 2 * c * (y - x);
            }
         } else {
            cost += 2 * c * x;
            if (b <= 2 * c) {
               cost += b * (y - x);
            } else {
               cost += 2 * c * (y - x);
            }
         }
      } else {
         if (a + b <= 2 * c) {
            cost += (a + b) * y;
            if (a <= 2 * c) {
               cost += a * (x - y);
            } else {
               cost += 2 * c * (x - y);
            }
         } else {
            cost += 2 * c * y;
            if (a <= 2 * c) {
               cost += a * (x - y);
            } else {
               cost += 2 * c * (x - y);
            }
         }
      }
      
      System.out.println(cost);

   }
}

Measured memory_bytes: 22100
#include <stdio.h>
int n,i,j,player[200][4];
int main() {
    scanf("%d",&n);
    for (i=0; i<n; i++) {
        for (j=0; j<3; j++) {
            scanf("%d",&player[i][j]);
        }
        player[i][3]=0;
    }
    for (i=0; i<3; i++) {
        int num[100];
        for (j=0; j<100; j++) {
            num[j]=200;
        }
        for (j=0; j<n; j++) {
            if (num[player[j][i]-1]==200) {
                num[player[j][i]-1]=j;
            }else{
                num[player[j][i]-1]=-1;
            }
        }
        for (j=0; j<100; j++) {
            if (num[j]!=-1&&num[j]!=200) {
                player[num[j]][3]+=j+1;
            } 
        }
    }
    for (i=0; i<n; i++) {
        printf("%d\n",player[i][3]);
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
typedef pair<int,int> P;

#define INF 1000000
struct road{int to,cost;};
int d[10];
int n,m;

int main(){
  while(1){
    cin >> n;
    if(!n)break;
    m = 0;
    vector<road> roads[10];
    for(int i=0;i<n;i++){
      int x,y,z;
      scanf("%d%d%d",&x,&y,&z);
      if(m<x||m<y){
        m = max(x,y);
      }
      roads[x].push_back((road){y,z});
      roads[y].push_back((road){x,z});
    }
    m++;

    int minIndex;
    int mini = INF;
    for(int i=0;i<m;i++){
      priority_queue<P, vector<P>, greater<P> > que;
      que.push(P(0,i));
      fill(d,d+m,INF);
      d[i] = 0;
      while(que.size()){
        P p = que.top(); que.pop();
        int dist = p.first;
        int pos = p.second;
        if(d[pos]<dist) continue;
        for(int j=0;j<roads[pos].size();j++){
          int to = roads[pos][j].to;
          int cost = roads[pos][j].cost;
          if(d[to]>d[pos]+cost){
            d[to] = d[pos] + cost;
            que.push(P(d[to],to));
          }
        }
      }
      int sum = 0;
      for(int j=0;j<m;j++){
        //printf("%3d%c",d[j],j==m-1?'\n':' ');
        sum += d[j];
      }
      if(mini>sum){
        mini = sum;
        minIndex = i;
      }
    }
    cout << minIndex << " " << mini << endl;
  }
}

Measured memory_bytes: 1268
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;
typedef pair<int, int> P;

int main(){
  int n;cin>>n;
  vector<int> memo(26, 50);
  for(int i=0;i<n;i++){
  	string s;cin>>s;
    vector<int> tmp(26, 0);
    for(int j=0;j<(int)s.size();j++){
      tmp[int(s[j]-'a')]++;
    }
    for(int j=0;j<26;j++){
      memo[j]=min(memo[j], tmp[j]);
    }
  }
  for(int i=0;i<26;i++){
  	cout<<string(memo[i], char('a'+i));
  }
  cout<<endl;
}


Measured memory_bytes: 256
s=list(map(int, list(input())))

length=len(s)
target_1=[]
target_2=[]
for i in range(length):
    if i%2==0:
        target_1.append(1)
        target_2.append(0)
    else:
        target_1.append(0)
        target_2.append(1)
sum_1=0
sum_2=0
for i in range(length):
    if target_1[i]!=s[i]:
        sum_1=sum_1+1
    if target_2[i]!=s[i]:
        sum_2=sum_2+1

print(min(sum_1, sum_2))


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  vector<string> v = {"dream","dreamer","erase","eraser"};
  string s;
  cin >> s;
  rep(i,4)reverse(ALL(v[i]));
  reverse(ALL(s));
  bool ok = true;
  rep(i,s.size()){
    int nu = -1;
    rep(j,4){
      bool is = true;
      rep(k,v[j].size())if(i+k < s.size()){
        if(s[i+k] != v[j][k])is = false;
      }else{
        is = false;
      }
      if(is){
        nu = j;
        break;
      }
    }
    if(nu == -1)ok = false;
    else i += v[nu].size()-1;
  }
  cout << (ok ? "YES" : "NO") << endl;




  return 0;
}

Measured memory_bytes: 512
//
// Created on 2020/08/18.
//


#include <iostream> // cout, endl, cin
#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
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;



int main() {
    int n;
    cin>>n;
    vector<int>L(n);
    for (int i = 0; i < n; ++i) {
        cin>>L[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if(L[i] != L[j] && L[j] != L[k] &&  L[k] != L[i] && L[i]+L[j] > L[k] && L[j] + L[k] > L[i] && L[k] + L[i] > L[j]){
                    ans ++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
n,m,q = gets.chomp.split(" ").map(&:to_i)
l = q.times.map{ gets.chomp.split(" ").map(&:to_i) }
sums = [*1..m+n-1].combination(n).map{|i|
  l.reduce(0){|sum,(a,b,c,d)|
    i[b-1]-i[a-1]-(b-a)==c ? sum + d : sum
  }
}
puts sums.max

Measured memory_bytes: 15532
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  map<string,int> a;
  int k=1;
  vector<int> co(n,0);
  vector<string> rema;
  for(int i=0;i<n;i++){
    string x;
    int y;
    cin >> x >> y;
    if(a[x]==0){
      a[x]=k;
      k++;
      rema.push_back(x);
    }
    co[a[x]-1]+=y;
  }
  sort(rema.begin(),rema.end());
  for(int j=1;j<=5;j++){
    for(int i=0;i<rema.size();i++){
      if(rema[i].size()==j)cout << rema[i] << " " <<co[a[rema[i]]-1] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3160
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

template<size_t N> struct solve {

	lint lun[N + 5];

	constexpr solve() : lun() {

		for (int i = 1; i <= 9; i++) lun[i] = i;

		for (int st = 1, idx = 10; idx <= N; st++) {

			bool m_ok = (lun[st] % 10 != 0);
			lun[idx*m_ok] = lun[st] * 10 + lun[st] % 10 - 1;
			idx += m_ok;

			lun[idx++] = lun[st] * 10 + lun[st] % 10;

			bool p_ok = (lun[st] % 10 != 9);
			lun[idx*p_ok] = lun[st] * 10 + lun[st] % 10 + 1;
			idx += p_ok;

		}

	}

};

constexpr solve<100000> S;

int main() {

	int N;
	scanf("%d", &N);
	printf("%lld", S.lun[N]);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll n;
Vi d;Vi e;
Vi a,b;

int main(){
	cin>>n;ll aa,bbb;ll suma=0;ll w=0;
	rep(i,n){
		cin>>aa;a.pb(aa);
	}
	rep(i,n){
		cin>>bbb;b.pb(bbb);
		suma += a[i]-bbb;
		if(a[i]-b[i]>0){
			d.pb(a[i]-b[i]);
		}else if(a[i]-b[i]<0){
			e.pb(a[i]-bbb);
			w+= -a[i]+bbb;
		}////
	}
	if(suma<0){
		cout<<-1<<endl;
	}else{
  		Sort(d);
		ll tmp =0;
		rep(i,d.size()){
			if(tmp>=w){
				cout<<i+e.size()<<endl;
				return 0;
			}
			tmp+=d[i];
		}
		if(tmp>=w){
				cout<<d.size()+e.size()<<endl;
				return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3828
from typing import List


def answer(n: int, t: int, a: int, hs: List[int]) -> int:
    import sys
    
    result = 0
    temperature_difference = sys.maxsize
    
    for i, h in enumerate(hs, start=1):
        temp = abs(a - (t - h * 0.006))
        if temp < temperature_difference:
            temperature_difference = temp
            result = i

    return result


def main():
    n = int(input())
    t, a = map(int, input().split())
    hs = list(map(int, input().split()))
    print(answer(n, t, a, hs))


if __name__ == '__main__':
    main()

Measured memory_bytes: 10200
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n,a,b;
	cin>>n>>a>>b;
	ll ans=0;
	rep(i,n+1){
		int sum=0;
		int j=i;
		while(j){
			sum+=j%10;
			j/=10;
		}
		if(a<=sum&&sum<=b){
			ans+=i;
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 ll factorial[3000009];
// we need to define a pow function to raise a to m-2
// function below calculates (a^b)%mod
ll power(ll a, ll b, ll mod){
	ll x = 1, y = a;
	while (b > 0){
		if (b%2){
			x = (x*y)%mod;
		}
		y = (y*y)%mod;
		b /= 2;
	}
	return x%mod;
}	
 
ll modular_inverse(ll n, ll mod){
	return power(n, mod-2, mod);
}
 
ll nCr(ll n, ll k, ll mod){
	return (factorial[n]*((modular_inverse(factorial[k],mod)*modular_inverse(factorial[n-k],mod))%mod))%mod;
}
    int main(){
    	factorial[0] = 1;
    	ll x,y,i,j,k,t,o,INF,a,b;
    	INF=1e9+7;
    	t=0;o=0;
    	for(i = 1 ; i <= 1000004 ; i++)
    		factorial[i] = (factorial[i-1]*i)%INF;
		cin>>x>>y;
		k=0;
		for (i=y;i<=x+1;i++)
		{
			a=((i-1)*(i)/2);
			b=((x)*(x+1)/2)-((x-i)*(x+1-i)/2);
			k=(k+b-a+1)%INF;
		}
		cout<<k<<endl;
    }

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

#define pb push_back

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	int a, b; cin >> a >> b;
	cout << (a*b) << endl;
	
	return 0;
}

Measured memory_bytes: 3652
import sys
import math
def Ii():return int(sys.stdin.readline().rstrip())
def Mi():return map(int,sys.stdin.readline().split())
def Li():return list(map(int,sys.stdin.readline().split()))
n = Ii()
a = Li()
sa = 0
ans = 0
mod = 10**9+7
for i in range(n-1):
  sa += a[i]
  ans += sa*a[i+1]
  ans %= mod
  
print(ans)

Measured memory_bytes: 31700