akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n - 1];
	int b[n - 1];
	std::set<int> hen[n];
	int deg[n];
	for (int i = 0; i < n; i++) deg[i] = 0;
	for (int i = 0; i + 1 < n; i++) a[i] = ri() - 1, b[i] = ri() - 1, deg[a[i]]++, deg[b[i]]++, hen[a[i]].insert(b[i]), hen[b[i]].insert(a[i]);
	
	int c[n];
	for (int i = 0; i < n; i++) c[i] = ri();
	std::sort(c, c + n);
	int res[n];
	int64_t sum = 0;
	for (int i = 0; i < n; i++) {
		int min = 1000000000;
		int index;
		for (int j = 0; j < n; j++) {
			if (deg[j] == 1000000000) continue;
			if (min > deg[j]) min = deg[j], index = j;
		}
		res[index] = c[i];
		sum += deg[index] * (int64_t) c[i];
		for (auto i : hen[index]) hen[i].erase(index), deg[i]--;
		hen[index].clear();
		
		deg[index] = 1000000000;
	}
	std::cout << sum << std::endl;
	for (int i = 0; i < n; i++) std::cout << res[i] << " ";
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
using namespace std;

typedef long long ll;
int p[100005];
int q[100005];
struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<int> sizes;
    UnionFind(int n): par(n), rank(n), sizes(n){
        for(int i = 0; i < n; i++){
            par[i] = i;
            rank[i] = 0;
            sizes[i] = 1;
        }
    }

    int root(int x){
        if(par[x] == x)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y) return;
        else {
            if(rank[x] < rank[y]){
                par[x] = y;
                sizes[y] += sizes[x];
            } else {
                par[y] = x;
                sizes[x] += sizes[y];
                if(rank[x] == rank[y]) rank[x]++;
            }
        }
    }

    int size(int x){
        return sizes[root(x)];
    }
};

int main(){
   int N, M;
   cin >> N >>M;
   for(int i = 1; i <= N; i++){
      cin >> p[i];
      q[p[i]] = i;
   }
   UnionFind uni(N+1);
   for(int i = 1; i <= M; i++){
      int x, y;
      cin >> x >> y;
      uni.unite(x, y);
   }
   int ans = 0;
   for(int i = 1; i <= N; i++){
      if(uni.root(i) == uni.root(q[i]))
         ans++;
   }
   cout << ans << endl;
}



Measured memory_bytes: 2176
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        String s=in.nextLine();
        String s1=s+s;
        String check=in.nextLine();
        if(s1.contains(check)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26352
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>

using namespace std;

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

#define INF 1050000000




int main() {

	int N,A,B;

	cin >> N>>A>>B;

	if (N * A >= B) {
		cout << B << endl;
	}
	else {
		cout << N*A << endl;
	}

	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll = long long;
int main(){
  string str;
  cin >> str;
  for(ll i=0;i<str.size();i++){
    if(str[i]!='?') cout << str[i];
    else  cout << 'D';
  }
  cout << endl;
}

Measured memory_bytes: 3728
#include "bits/stdc++.h"
using namespace std;
const int maxn = 3555;
int G[maxn][maxn];
long long get_gcd(long long a, long long b){
    if(a < b) swap(a, b);
    if(a < maxn) return G[a][b];
    return get_gcd(b, a % b);
}
int M(){
    long long n;
    if(!(cin >> n)) return 0;
    if(n % 2 == 0)
        printf("%lld %lld %lld\n", n, n, n / 2);
    else{
        for(int e = 1; e <= 3500; e++)
            for(int f = 1; f <= 3500; f++){
                long long num0 = e + f;
                long long den0 = e * f;
                long long den1 = den0 * n;
                long long num1 =  - n * e - n * f + 4 * e * f;
                if(num1 <= 0) continue;
                long long gc = __gcd(den1, num1);
                if(num1/gc == 1){
                    // assert(e * f * den1)
                    printf("%lld %lld %lld\n", (long long)e, (long long)f, den1 / gc);
                    return 1;
                }
            }
    }
    return 1;
}
int main(){
    for(int e = 0; e < maxn; e++)
        G[0][e] = G[e][0] = e;
    for(int e = 1; e < maxn; e++)
        for(int f = 1; f < maxn; f++){
            int a = e, b = f;
            if(a < b) swap(a, b);
            G[e][f] = G[b][a%b];
        }
    while(M());
    return 0;
}


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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  int a,b;
  cin >> a >> b;
  a-b > 0?print(a-b):print(0);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i;
  int a[3],b[3];
  int num1 = 0;
  int num2 = 0;
  int num3 = 0;
  int num4 = 0;

  for(i = 0; i < 3; i++){
    scanf("%d %d",&a[i],&b[i]);
    if (a[i] == 1)
      num1 += 1;
    if (a[i] == 2)
      num2 += 1;
    if (a[i] == 3)
      num3 += 1;
    if(a[i] == 4)
      num4 += 1;
    if (b[i] == 1)
        num1 += 1;
    if (b[i] == 2)
        num2 += 1;
    if (b[i] == 3)
        num3 += 1;
    if (b[i] == 4)
        num4 += 1;
      }

  if (num1 > 2 || num2 > 2 || num3 > 2 || num4 > 2)
     puts("NO");
  else
     puts("YES");



  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,mod= 998244353;
class node{
    public:
    int bit[200005];
    int get(int p){
        int re=0;
        while(p){
            re+=bit[p];
            p-=p&(-p);
        }
        RE re;
    }
    void add(int p,int x){
        while(p<=n){
            bit[p]+=x;
            p+=p&(-p);
        }
    }
};
node tree1,tree2;
struct data{
    int x,y,id;
};
data a[200005];
P<int,int> num[200005];
bool cmp(data s1,data s2){RE s1.x<s2.x;}
int pow2(int p){
    int s=2,re=1;
    while(p){
        if(p&1)re=re*s%mod;
        s=s*s%mod;
        p=p/2;
    }
    RE re;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
    FOR(i,1,n){
        cin>>a[i].x>>a[i].y;
        num[i].S=i;
        num[i].F=a[i].y;
    }
    sort(num+1,num+n+1);
    FOR(i,1,n)a[num[i].S].id=i;
    sort(a+1,a+n+1,cmp);
    int ans=0;
    FOR(i,1,n)tree2.bit[i]=i&(-i);
    int A,B,C,D;
    FOR(i,1,n){
        tree2.add(a[i].id,-1);
        A=pow2(tree1.get(a[i].id));
        B=pow2(tree1.get(n)-tree1.get(a[i].id));
        C=pow2(tree2.get(a[i].id));
        D=pow2(tree2.get(n)-tree2.get(a[i].id));
        tree1.add(a[i].id,1);
        ans=(ans+(A-1)*B%mod*C%mod*(D-1))%mod;
        ans=(ans+A*(B-1)%mod*(C-1)%mod*D)%mod;
        ans=(ans-(A-1)*(B-1)%mod*(C-1)%mod*(D-1)%mod+mod)%mod;
        ans=(ans+pow2(n-1))%mod;
    }
    cout<<ans;
	RE 0;
}



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

using namespace std;

int main(){
    int N;
    scanf("%d", &N);
    if(N == 1){
        printf("Hello World\n");
    }
    if(N == 2){
        int A;
        int B;
        scanf("%d %d", &A, &B);
        printf("%d\n", A+B);
    }
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }
    val cnt = IntArray(N)
    
    for (i in 1..M) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() - 1}
        cnt[a]++
        cnt[b]++
    }
    
    println(if (cnt.all { it % 2 == 0 }) "YES" else "NO")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 57844
#include <iostream>
#include <cstdint>
 
using namespace std;
 
int main(void)
{
	int_least64_t n, a, b;
	cin >> n >> a >> b;
 
	int_least64_t sum_min{ a * (n - 1) + b };
	int_least64_t sum_max{ b * (n - 1) + a };
 
	int_least64_t result;
	if( (n == 1 && a != b) || a > b ) {
		result = 0;
	}
	else {
		result = sum_max - sum_min + 1;
	}
 
	cout << result << endl;
}


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

kisu = [str(v) for i,v in enumerate(V) if i % 2 == 1]
gusu = [str(v) for i,v in enumerate(V) if i % 2 == 0]

from collections import Counter

kisu_c = Counter(kisu).most_common()
gusu_c = Counter(gusu).most_common()

ans = 0


if len(kisu_c) == 1 and len(gusu_c) == 1:
    if kisu_c[0][0] == gusu_c[0][0]:
        print(kisu_c[0][1])
    else:
        print(0)
    exit()
elif len(kisu_c) == 1:
    gusu_c.pop(0)

    for i in gusu_c:
        ans += i[1]
    print(ans)
    exit()
elif len(gusu_c) == 1:
    kisu_c.pop(0)

    for i in kisu_c:
        ans += i[1]
    print(ans)
    exit()



if kisu_c[0][0] == gusu_c[0][0]:
    if kisu_c[0][1] < gusu_c[0][1]:
        gusu_c.pop(0)
        kisu_c.pop(1)
    elif kisu_c[0][1] > gusu_c[0][1]:
        gusu_c.pop(1)
        kisu_c.pop(0)
    else:
        if kisu_c[1][1] > gusu_c[1][1]:
            kisu_c.pop(1)
            gusu_c.pop(0)
        else:
            kisu_c.pop(0)
            gusu_c.pop(1)

else:
    kisu_c.pop(0)
    gusu_c.pop(0)


for i in kisu_c:
    ans += i[1]
for i in gusu_c:
    ans += i[1]

print(ans)


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

string in;
vector<string> V;

string change(string in){
  for(int i = 0; i < in.length(); i++){
    if(in[i] != 'a') in[i]--;
    else in[i] = 'z';
  }
  return in;
}
string solve(){
  int status = 0;
  while(1){
    for(int i = 0; i < V.size(); i++){
      string str = V[i];
      if(str != "." && str != " ") V[i] = change(str);
      if(V[i] == "the" || V[i] == "this" || V[i] == "that") status = 1;
    }
    if(status)break;
  }
  string out;
  for(int i = 0; i < V.size(); i++){
    out += V[i];
  }
  return out;
}
int main(){
  while(getline(cin,in)){
    V.clear();
    in += "\n";
    string str;
    for(int i = 0; i < in.length(); i++){
      if(in[i] < 'a' || in[i] > 'z'){
	V.push_back(str);
	str = "";
	if(in[i] == '.') V.push_back(".");
	if(in[i] == ' ') V.push_back(" ");
      }else str += in[i];
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N,K = gets.split.map(&:to_i)
steps = gets.split.map(&:to_i)
inf = 10**12
dp = Array.new(N){inf}
dp[0] = 0
dp[1] = (steps[0]-steps[1]).abs

(2...N).each do |i|
  (1..K).each do |k|
    next if k > i
    d = dp[i-k] + (steps[i-k] - steps[i]).abs
    dp[i] = d if d < dp[i]
  end
end

puts dp[N-1]


Measured memory_bytes: 11404
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
ans = 10**18
for i in range(1,n):
    j = n-i
    s = str(i).rjust(6,"0")[::-1]
    t = str(j).rjust(6,"0")[::-1]
    res = 0
    for i,j in zip(s,t):
        res += int(i)+int(j)
    ans = min(res,ans)

print(ans)



Measured memory_bytes: 73808
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        N_Slimes solver = new N_Slimes();
        solver.solve(1, in, out);
        out.close();
    }

    static class N_Slimes {
        long[] a;
        Long[][] dp;
        long[] pref;

        long go(int i, int j) {
            if (i == j) {
                return 0;
            }
            if (dp[i][j] != null)
                return dp[i][j];
            dp[i][j] = pref[j + 1] - pref[i];
            long cost = Long.MAX_VALUE;
            for (int k = i; k < j; k++) {
                cost = Math.min(go(i, k) + go(k + 1, j), cost);
            }
            dp[i][j] += cost;
            return dp[i][j];
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            a = in.nal(n);
            dp = new Long[n][n];

            pref = new long[n + 1];
            for (int i = 0; i < n; i++) {
                pref[i + 1] = pref[i] + a[i];
            }
            go(0, n - 1);
            out.println(dp[0][n - 1]);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

        public long nl() {
            return Long.parseLong(ns());
        }

        public long[] nal(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nl();
            return a;
        }

    }
}



Measured memory_bytes: 29564
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long A = sc.nextLong();
    long B = sc.nextLong();
    long C = sc.nextLong();
    if(A%2==0||B%2==0||C%2==0){
      System.out.println(0);
      return;
    }
    System.out.println(Math.min(A*B,Math.min(B*C,C*A)));

  }

  
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int x;cin >> x;
  LL a = x/500;
  a *= 1000;
  x %= 500;
  a += 5*(x/5);
  cout << a << endl; 
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
Total = 0

for i in range(N):
    if A[i] < B[i]:
        Total += A[i]
        B[i] -= A[i]
        if A[i + 1] < B[i]:
            Total += A[i + 1]
            A[i + 1] = 0
        else:
            Total += B[i]
            A[i + 1] -= B[i]
    else:
        Total += B[i]
        A[i] -= B[i]

print(Total)


Measured memory_bytes: 19648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
const int N=15;		//n是魔法书 
const int M=15;		//m是魔法 

int a[N][M],c[N],s[M];
bool vis[N];
int n,m,x;
int ans=INT_MAX;

void add_one(int i)
{
	for(int j=1; j<=m; j++)
		s[j]+=a[i][j];
}

void del_one(int i)
{
	for(int j=1; j<=m; j++)
		s[j]-=a[i][j];
}

bool check()
{
	bool f=true;
	for(int i=1; i<=m; i++)
	{
		if(s[i]<x)
		{
			f=false;
			break;
		}
	}
		
	return f;
}

void dfs(int i,int sum)
{
	if(check())
	{
		ans=min(ans,sum);
		return ;
	}
	
	for(int j=i+1; j<=n; j++)
	{
		if(!vis[j])
		{
			vis[j]=true;
			add_one(j);
			dfs(j,sum+c[j]);
			vis[j]=false;
			del_one(j);
		}
	}
}

int main()
{
	cin>>n>>m>>x;
	
	for(int i=1; i<=n; i++)
	{
		cin>>c[i];
		for(int j=1; j<=m; j++)
			cin>>a[i][j];
	}
	
	for(int i=1; i<=n; i++)
	{
		vis[i]=true;
		add_one(i);
		dfs(i,c[i]);
		vis[i]=false;
		del_one(i);
	}
	
	if(ans==INT_MAX)
		cout<<-1<< endl;
	else
		cout<<ans<< endl;
		 
	return 0;
}


Measured memory_bytes: 3632
/*Shivam Bhalla */
  /* f2016941@pilani.bits-pilani.ac.in */



  #include <iostream>
  #include <cstdio>
  #include <cstring>
  #include <cstdlib>
  #include <cctype>
  #include <algorithm>
  #include <map>
  #include <vector>
  #include <list>
  #include <set>
  #include <queue>
  #include <deque>
  #include <stack>
  #include <iostream>
  #include <string>
  #include <cmath>
  #include <cassert>
  #include <bits/stdc++.h>
  #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
  using namespace std;
  long long maxv = 1e9;


  int main()
  {
    fast_cin();
    int N;
    int A,B;
    cin>>N;
    vector<int>arr(N);
    for(int i=0;i<N;i++)
      cin>>arr[i];
    int total=0;
    for(int i=1;i<N-1;i++){
      if((arr[i+1]>=arr[i] && arr[i-1]<=arr[i])||(arr[i+1]<=arr[i] && arr[i-1]>=arr[i]))
        total+=1;
    }
    cout<<total;
    return 0;
  }


Measured memory_bytes: 256
from sys import stdin
import math
import itertools


def makeIntMatrix(lines):
    intMatrix = []
    for a in makeStringMatrix(lines):
        intMatrix.append([int(b) for b in a])
    return intMatrix
 
 
def makeStringMatrix(lines):
    stringMatrix = [line.split() for line in lines]
    return stringMatrix
 
 
def makeInt(line):
    return int(line.rstrip())
 
 
def makeMultiInteger(line):
    return [int(x) for x in line.rstrip().split()]


def solve(input_string):
    N, M = makeMultiInteger(input_string[0])
    S = makeIntMatrix(input_string[1:])
    c = 0
    ra = range(1, N+1)
        
    min_range = ra
    min_l = ra[0]
    min_r = ra[-1]
    for s in S:
        l = s[0]
        r = s[1]
        if l > min_range[0]:
            min_l = l
        if r < min_range[-1]:
            min_r = r
        min_range = range(min_l, min_r+1)
        if len(min_range) == 0:
            return 0
    #if ra[-1] >= min_range[-1]:
    return len(min_range)
    #else:
    #    return len(ra)



def main():
    input_lines = stdin.readlines()
    answer = solve(input_lines)
    print(answer)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
  freopen ("input.txt", "r", stdin);
  freopen ("outt.txt", "w", stdout);
#endif
 ios_base::sync_with_stdio(NULL) ;
 int n;
 cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
   cin>>arr[i];
  }
  
  sort(arr,arr+n);
  reverse(arr,arr+n);
  
  long ans=arr[0];
  int cnt = n-2;
  
  for(int i=2;i<n && cnt>0;i++){
    
    
    ans+=  arr[i-1] + (cnt>1 ? arr[i-1]:0);
    cnt-=2;
    
  }
  
  cout<<ans<<endl;
  
  
  
}

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll cost[33][3];

int main(){cout<<fixed<<setprecision(20);
		   int n,c;
           cin>>n>>c;
           vvin d(c,vin (c));
           rep(i,0,c)rep(j,0,c)cin>>d[i][j];
           vvin k(n,vin (n));
           rep(i,0,n)rep(j,0,n){
             cin>>k[i][j];
             k[i][j]--;
           }
           rep(p,0,c){
             rep(i,0,n)rep(j,0,n){
               if((i+j)%3==0){
                 cost[p][0]+=d[k[i][j]][p];
               }
               else if((i+j)%3==1){
                 cost[p][1]+=d[k[i][j]][p];
               }
               else{
                 cost[p][2]+=d[k[i][j]][p];
               }
             }
           }
           ll ans=INF;
           rep(p,0,c){//0
            rep(q,0,c){
              rep(r,0,c){
                if(p==q||q==r||r==p)continue;
                chmin(ans,cost[p][0]+cost[q][1]+cost[r][2]);
              }
            }
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 4604
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



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

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

int main(){
int n,a;
cin>>n;
string s;
double b,sum=0.0;
while(n--){
  cin>>b>>s;
  if(s=="BTC"){
    sum=sum+b*380000.0;
  }
  sum=sum+b;
}
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
    using namespace std;
    using namespace __gnu_pbds;
    #define ll long long
    #define int long long
    #define pb push_back
    #define For(i,n) for(ll  i=0;i<n;i++)
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;clock_t clk = clock();
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define mod 998244353
    #define ld long double
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define fi first
    #define se second
    #define pii pair<ll,ll>
    #define what_is(x) cerr << #x << " is " << x << endl;
    #define time cerr << "Time (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';
    const double pi=3.14159265358979323846264;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;

/**********************************************************************************************************************/

signed main()/*Check flow ---question galat mat padhna */
{
    fast;
    ll n;
    cin>>n;
    ll a[n];
    ll check=0;
    For(i,n)
    {
        cin>>a[i];
        if(a[i]==0)check++;
    }
    ll ans=1;
    if(check)
    {
        cout<<0<<endl;
        return 0;
    }

    For(i,n)
    {
        
        if(ans>(ll)(1e18)/a[i])
        {
            cout<<-1<<endl;return 0;
        }
        ans*=a[i];
        if(ans>(1e18))
        {
            cout<<-1<<endl;return 0;
        }
    }
    cout<<ans<<endl;
}   

Measured memory_bytes: 4436
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 105, V = 1004;
const ll inf = (ll) 1e18;

ll dp[N][N*V];
int n, mxv, W;
int w[N], v[N];

void solve() {
   for (int i = 0; i <= n; ++i) for (int j = 0; j <= mxv; ++j)
      dp[i][j] = inf;

   dp[0][0] = 0;

   for (int i = 1; i <= n; ++i) for (int j = 0; j <= mxv; ++j)
   {
      dp[i][j] = dp[i-1][j];
      if (j >= v[i]) dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]] + w[i]);
   }

   int mx_val = 0;
   for (int i = mxv; i >= 0; --i) {
      if (dp[n][i] <= W) {
         mx_val = i;
         break;
      }
   }
   cout << mx_val << '\n';
}

signed main() {
   IOS; PREC;
   cin >> n >> W;
   mxv = 0;
   for (int i = 1; i <= n; ++i)
      cin >> w[i] >> v[i], mxv += v[i];
   solve();


   return EXIT_SUCCESS;
}


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

int main(){
    long long n;
    cin>>n;
    long long m;
    cin>>m;
    long long a[m];
    for(long long i=0;i<m;i++){
        cin>>a[i];
    }
    long long sum=0;
    for(long long i=0;i<m;i++){
        sum+=a[i];
    }
    long long ans=n-sum;
    if(ans<0){
        cout<<-1<<endl;
    }
    else{
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>

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

using namespace std;

typedef long long ll;

char grid[2003][2003];
int R[2003][2003];
int L[2003][2003];
int U[2003][2003];
int D[2003][2003];

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int h, w;
  cin >> h >> w;

  rep(i, h) {
    rep(j, w) {
      cin >> grid[i][j];
    }
  }

  // update R[i][j]
  rep(i, h) {
    int cur = 0;
    for (int j = w-1; j >= 0; j--) {
      cur++;
      if ( grid[i][j] == '#' ) { cur = 0; }
      R[i][j] = cur;
    }
  }
  // update L[i][j]
  rep(i, h) {
    int cur = 0;
    rep(j, w) {
      cur++;
      if ( grid[i][j] == '#' ) { cur = 0; }
      L[i][j] = cur;
    }
  }
  // update U[i][j]
  rep(j, w) {
    int cur = 0;
    for (int i = h-1; i >= 0; i--) {
      cur++;
      if ( grid[i][j] == '#' ) { cur = 0; }
      U[i][j] = cur;
    }
  }
  // update D[i][j]
  rep(j, w) {
    int cur = 0;
    rep(i, h) {
      cur++;
      if ( grid[i][j] == '#' ) { cur = 0; }
      D[i][j] = cur;
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      ans = max(ans, R[i][j] + L[i][j] + U[i][j] + D[i][j]-3);
    }
  }

  cout << ans << endl;

  return 0;
}

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

// Loops
#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 < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(long long a, long long b) {
  string s;
  rep(i,b) s += (char)('0'+a);
  
  string t;
  rep(i,a) t += (char)('0'+b);
  if(s<t) cout << s << endl;
  else cout << t << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  long long a;
  std::cin >> a;
  long long b;
  std::cin >> b;
  solve(a, b);
  return 0;
}


Measured memory_bytes: 3564
<?php

$input = STDIN;

$suit = array('S', 'H', 'C', 'D');

$cards = array();

foreach ($suit as $s) {
    $cards[$s] = array_fill(1, 13, true);
}

$n = intval(trim(fgets($input)));

for ($i = 0; $i < $n; $i++) {
    list($s, $rank) = explode(' ', trim(fgets($input)));
    $cards[$s][(int)$rank] = false;
}

foreach ($suit as $s) {
    foreach (range(1, 13) as $n) {
        if ($cards[$s][$n]) {
            print("{$s} {$n}\n");
        }
    }
}


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

int n, p1[30010], p2[30010], p3[30010];
int c1, c2, c3, t1, t2, t3;

int main() {

	int i;
	cin >> n;
	for(i = 1; i <= 30000; i++) {
		if(i % 2 == 0 && i % 3 == 0) p3[++c3] = i;
		else if(i % 2 == 0) p1[++c1] = i;
		else if(i % 3 == 0) p2[++c2] = i;
	}
	if(n == 3) {
		printf("2 5 63\n");
		return 0;
	}
	if(n & 1) printf("%d ", p3[++t3]), n--;
	n -= 2;
	printf("%d ", p2[++t2]);
	printf("%d ", p2[++t2]);
	while(n > 0 && t1 < c1) {
		n -= 2;
		printf("%d ", p1[++t1]);
		printf("%d ", p1[++t1]);
	}
	while(n > 0 && t2 < c2) {
		n -= 2;
		printf("%d ", p2[++t2]);
		printf("%d ", p2[++t2]);
	}
	while(n > 0 && t3 < c3) {
		n--;
		printf("%d ", p3[++t3]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  string s;
  cin >> s;

  int size = s.size();
  int cnt = 0;

  if(size%2 == 0) {
    string a = s.substr(0, size/2);
    string b = s.substr(size/2);
    rep(i, size/2) {
      if(a[i] != b[(size/2)-1 -i]) cnt++;
    }
  } else {
    string a = s.substr(0, size/2);
    string b = s.substr(size/2+1);
    rep(i, size/2) {
      if(a[i] != b[(size/2)-1-i]) cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc072/tasks/abc072_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

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


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val alpha = ('a'..'z').toHashSet()
    val s = sc.next().toHashSet()
    val rem = alpha.subtract(s)
    if (rem.isEmpty()) {
        println("None")
    } else {
        println(rem.sorted()[0])
    }
}

Measured memory_bytes: 36768
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
#define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
#define Fo(i,k,n) for(i=k;k<n?i<=n:i>=n;k<n?i+=1:i-=1)
#define endl '\n'
#define MOD 1000000007//998244353
#define pbb push_back
#define mpp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mset(arr,val) memset(arr,val,sizeof(arr))
ll dp[100005][2];
ll answer(ll u,ll par,ll col,vi* graph){
    if(dp[u][col]>=0) return dp[u][col];
	ll i,j,ans=1;
	for(auto v:graph[u]){
        if(v==par) continue;
		if(col==0){
            ans*=answer(v,u,1,graph);
            ans%=MOD;
        }else{
            ans*=answer(v,u,0,graph)+answer(v,u,1,graph);
            ans%=MOD;
        }
	}
	return dp[u][col]=ans;
}
void solve(ll caseno){
	ll i,j,n,x,y,ans;
	cin>>n;
	vi* graph = new vi[n];
	fo(i,0,n-1){
		cin>>x>>y;
		x--;y--;
		graph[x].pbb(y);
		graph[y].pbb(x);
	}
    mset(dp,-1);
	ans = answer(0,-1,0,graph) + answer(0,-1,1,graph);
    ans%=MOD;
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 18892
#include <cstdio>
#include <cstdlib>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

map <string,bool> mapa;
string s,aux;
vector <string> rez;

int main()
{
    int l,i,k,j;
    cin>>s>>k;
    for(l=1; l<=s.size() && l<=5; l++)
    {
        for(i=l-1; i<s.size(); i++)
        {
            for(j=i-l+1; j<=i; j++)
                aux.push_back(s[j]);
            if(!mapa[aux])
            {
                mapa[aux]++;
                rez.push_back(aux);
            }
            aux.clear();
        }
    }
    sort(rez.begin(),rez.end());
    /*for(i=0; i<rez.size(); i++)
    {
        cout<<rez[i]<<"\n";
    }*/
    cout<<rez[k-1];
}


Measured memory_bytes: 2048
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	string str;
	getline(cin, str);

	int apple = str.find("apple");
	int peach = str.find("peach");
	rep(i, str.size()){
		if(apple == i){
			printf("peach");
			i += 4;
			apple = str.find("apple", i);
		}else if(peach == i){
			printf("apple");
			i += 4;
			peach = str.find("peach", i);
		}else
			putchar(str[i]);
	}
	puts("");

	return 0;
}

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

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

    int n,d;
    cin >> n >> d;
    int x[n][d];
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }
    
    int count = 0;
    double ans;
    
    rep(i,n){
        for(int j=i+1; j<n; j++){
            
            ans = 0;
            
            rep(k,d){
                ans += (double) (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            
            ans = sqrt(ans);
            
            int tr = floor(ans);
            
            if(ans == tr) count++;
        }
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;
#define N_MAX 100
#define input(d) cin >> d;
#define inputs(n,d) for(int i=0;i<n;i++) {cin >> d[i];}
#define inputxy(n,x,y) for(int i=0;i<n;i++) {cin >> x[i] >> y[i];}
#define output(d) cout << d << endl;
#define outputs(n,d) for(int i=0;i<n;i++) {cout << d[i] << endl;}
#define outputxy(n,x,y) for(int i=0;i<n;i++) {cout << x[i] << y[i] << endl;}
#define f0(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<b;i++)
#define l long
#define ll long long
#define s string

int main(){
    ll n,x=0,y,ans=0;
    ll d[N_MAX];

    input(n);
    inputs(n,d);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                ll a;
                if(d[i]>d[j]){
                    a=d[i];
                }else{
                    a=d[j];
                }
                if(a<d[k]){
                    a=d[k];
                }
                if(d[i]==d[j] || d[j]==d[k] || d[k]==d[i]){
                    continue;
                }
                ll e = d[i]+d[j]+d[k]-a;
                if(a<e){
                    ans++;
                }
            }
        }
    }

    output(ans);
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    int n,m,i;
    cin>>m>>n;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    int sum=0;
    for(i=0;i<n;i++)
        sum+=a[i];
    int x;
    if(m<sum)
        x=-1;
    else
        x=m-sum;
    cout<<x;
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#define N 100

int main(){
  int A[N][N];
  int n, u, k, v; 
  int i, j;

  scanf("%d",&n);

  for ( i=0 ; i<n ; i++ ){
    for ( j=0 ; j<n ; j++ )
      A[i][j] = 0;
  }
  
  for ( i=0 ; i<n ; i++ ){
    scanf("%d %d",&u,&k);
    u--;
    
    for ( j=0 ; j<k ; j++ ){
      scanf("%d",&v);
      v--;
      A[u][v] = 1;
    }
  }
  
  for ( i=0 ; i<n ; i++ ){
    for ( j=0 ; j<n ; j++ ){
      if( j != 0 )
	printf(" ");
      printf("%d",A[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2088
open Batteries
let () =
  let n,m = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d %d %d " (fun a b c -> a,b,c)) in

  let res = ref 0 in

  for i = 0 to 1 do
    let i = if i = 0 then -1 else 1 in
    for j = 0 to 1 do
      let j = if j = 0 then -1 else 1 in
      for k = 0 to 1 do
        let k = if k = 0 then -1 else 1 in
        let lst = List.map (fun (x,y,z) -> x*i + y*j + z*k) lst in
        let lst = List.sort (fun x y -> compare y x) lst in
        let lst = List.filteri (fun i _ -> i < m) lst in
        let sum = List.fold_left (+) 0 lst in
        if sum > !res then res := sum
      done;
    done;
  done;

  Printf.printf "%d\n" !res



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

using namespace std;
const int VALUE = 2019;

int Find(const long L, const long R)
{
	int ans = VALUE;
	for (long i = L; i <= R; ++i)
	{
		for (long j = i + 1; j <= R; ++j)
		{
			ans = min(ans, static_cast<int>((i*j) % VALUE));
			if (ans == 0)
			{
				return ans;
			}
		}
	}
	return ans;
}

int main()
{
	long L, R;
	cin >> L >> R;

	cout << Find(L, R) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>

int main(int argc, char* argv[])
{
  int A, B;
  std::cin >> A >> B;

  std::string judge = "Yes";
  if ((A * B) % 2 == 0) {
    judge = "No";
  }

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


Measured memory_bytes: 256
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Dynamic;
using System.Globalization;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = ReadInts();
            WriteLine(AB[0] * AB[1]);
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27236
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <cassert>
using namespace std;
const int num = 9, ud[] = { -1, 0, 1, 0 }, lr[] = { 0, -1, 0, 1 }, nd = 3;
const char wa[] = { 'u', 'l', 'd', 'r' };
struct puzzle {
	int sp, p[num];
	string way;
	bool operator < (const puzzle &pu) const {
		for (int i = 0; i < num; i++) {
			if (p[i] == pu.p[i]) continue;
			return p[i] < pu.p[i];
		}
		return false;
	}
};
inline bool fin(puzzle pu) {
	for (int i = 0; i < num; i++)
		if (pu.p[i] != i + 1) return false;
	return true;
}
inline string bfs(puzzle pu) {
	queue<puzzle> q;
	map <puzzle, bool> m;
	q.push(pu);
	m[pu] = true;
	puzzle x, y;
	int row, col, ns, ro, co;
	while (!q.empty()) {
		x = q.front(); q.pop();
		if (fin(x)) return x.way;
		ro = x.sp / nd;
		co = x.sp % nd;
		for (int i = 0; i < 4; i++) {
			row = ro + ud[i];
			col = co + lr[i];
			if (row >= nd || row < 0 || col >= nd || col < 0) continue;
			y = x;
			ns = row*nd + col;
			swap(y.p[x.sp], y.p[ns]);
			y.sp = ns;
			if (!m[y]) {
				m[y] = true;
				y.way += wa[i];
				q.push(y);
			}
		}
	}
}
int main() {
	puzzle fi;
	for (int i = 0; i < num; i++) {
		cin >> fi.p[i];
		if (!fi.p[i]) { 
			fi.sp = i; 
			fi.p[i] = num;
		}
	}
	cout << bfs(fi).size() << endl;
	return 0;
}

Measured memory_bytes: 30600
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h,ke,hi;
    cin>>a>>b;
    cin>>c>>d;
    cin>>e>>f>>g>>h;
    hi=a*e+b*f+(a/10)*g+(b/20)*h;
    ke=c*e+d*f+(c/10)*g+(d/20)*h;
    if(ke>hi){
        cout<<"kenjiro"<<endl;
    }else if(ke<hi){
        cout<<"hiroshi"<<endl;
    }else{
        cout<<"even"<<endl;
    }
    
}



Measured memory_bytes: 3100
def main():
    """
    N=2*10^5
    毎回sortは無理
    sort済みにして計算量を落とす

    元が偶数個なので中央値を考えてsortしたとき
    中央付近には2つ,sort済み値が存在する m1<=m2
    1つ除外したとき
        除外したものがm1以下: 小さい方にずれるのでm2
        除外したものがm2以上: 大きい方にずれるのでm1
    """
    N = int(input())
    *X, = map(int, input().split())

    X_sorted = sorted(X)
    mid = N // 2
    m1 = X_sorted[mid-1]
    m2 = X_sorted[mid]
    for i in range(N):
        if X[i] <= m1:
            ans = m2
        else:
            ans = m1

        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25564
#include <stdio.h>

int main(){

  int i=0, x[2], y[2], r[2], rplus, rminus,rdistance;

  while(i<2){
    scanf("%d%d%d", &x[i],&y[i],&r[i]);
    i++;
  }

  rdistance = (x[0]-x[1])*(x[0]-x[1]) +	(y[0]-y[1])*(y[0]-y[1]); //２乗すればsqrtが不要               
  rplus = (r[0]+r[1])*(r[0]+r[1]);
  rminus = (r[0]-r[1])*(r[0]-r[1]); //２乗して、|r1-r2|の絶対値を必要なくしている.他も２乗する.       

  if(rdistance > rplus)	printf("4\n");
  else if(rdistance == rplus) printf("3\n");
  else if(rminus < rdistance &&	rdistance < rplus) printf("2\n");
  else if(rdistance == rminus) printf("1\n");
  else if(rdistance < rminus) printf("0\n");



  return 0;
}




Measured memory_bytes: 2672
n = gets.to_i
p = gets.chomp.split.map(&:to_i)
cnt = 0
(1..n-2).each do |i|
  if p[i] != [p[i-1],p[i],p[i+1]].max && p[i] != [p[i-1],p[i],p[i+1]].min
    cnt += 1
  end
end
puts cnt

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)

long long INF = 1000000007;

int main(){
  int N, M;  
  cin >> N >> M;
  int s[M], c[M];
  rep(i, M)
    cin >> s[i] >> c[i];
  //

  int start, end;
  if(N==1){
    start = 0;
    end = 9;
  }
  else if(N == 2){
    start = 10;
    end = 99;
  }
  else{
    start = 100;
    end = 999;
  }
  
  for(int n=start; n<=end; n++){
    bool flag = true;
    int tmp;
    rep(i, M){
      tmp = n;
      rep(j, N-s[i])
	tmp /= 10;
      flag = flag*(tmp%10==c[i]);
    }
    if(flag){
      cout<< n <<endl;
      return 0;
    }
  }
    


  
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 3556