akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_11_C
{
    class Program
    {
        const int N = 100;
        const int INFTY = 1145141919;
        static int n;
        static int[,] M = new int[N, N];

        static void bfs(int s)
        {
            var q = new Queue<int>();
            q.Enqueue(s);
            var d = Enumerable.Repeat(INFTY, n).ToArray();
            d[s] = 0;
            while(q.Any())
            {
                int u = q.Dequeue();
                for (int v = 0; v < n; v++)
                {
                    if (M[u,v] == 0) continue;
                    if (d[v] != INFTY) continue;
                    d[v] = d[u] + 1;
                    q.Enqueue(v);
                }
            }
            var sb = new StringBuilder();
            foreach (var t in d.Select((i, j) => new {i, j}))
            {
                sb.AppendLine(t.j + 1 + " " + ((t.i == INFTY) ? (-1) : t.i));
            }
            Console.Write(sb);
        }
        static void Main(string[] args)
        {
            n = scan()[0];
            for (int i = 0; i < n; i++)
            {
                var t = scan();
                for (int j = 0; j < t[1]; j++)
                {
                    M[t[0] - 1, t[j + 2] - 1] = 1;
                }
            }
            bfs(0);
        }
        static int[] scan()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
    }
}

Measured memory_bytes: 10716
class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N
        self.count = 0
        self.size = [1] * N
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self.rank[ra] < self.rank[rb]:
            
            # rbが所属するユニオンのノード数をraと合算する。raについてもrbと同じにする
            self.size[self.root(rb)] += self.size[self.root(ra)]
            self.parent[ra] = rb
            #self.size[self.root(ra)] = self.size[self.root(rb)]
            
        else:
            # 上と同じ
            self.size[self.root(ra)] += self.size[self.root(rb)]
            self.parent[rb] = ra
            #self.size[self.root(rb)] = self.size[self.root(ra)]
            
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1
    # aノードの所属するユニオンに所属しているノード数を戻す
    def nodes_in_same_union(self, a):
        return self.size[self.root(a)]


N,M = map(int, input().split())

AB = [tuple(map(int, input().split())) for _ in range(M)]

uf = UnionFind(N)
ans = [N*(N-1)//2]

#一番目を繋いでいるときの情報はいらないので最初以外
for a,b in list(reversed(AB))[:-1]:
    a,b = a-1, b-1
    if uf.is_same(a,b):
        tmp = 0
    else:
        tmp = uf.nodes_in_same_union(a) * uf.nodes_in_same_union(b)

    uf.unite(a,b)
    ans.append(max(ans[-1] - tmp, 0))

ans.reverse()

for i in ans:
    print(i)




Measured memory_bytes: 25500
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
  int a, b;
  int d, r;
  double f;
  cin >> a >> b;
  d = a/b;
  r = a%b;
  f = (double)a/b;
  cout << d << " "
       << r << " "
       << fixed <<  setprecision(5) << f
       << endl;
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int n, m, a[101];

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){cin >> a[i];}
	
	i64 cnt = 0, ans = 0;
	for(int i = 0; i < n; i++){
		if(cnt <= m) ans++;
		cnt += a[i];
	}
	if(cnt <= m) ans++;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod = 998244353;
const int N = 300000;
pair <int,int> b[N];
const int K = 33;
int dp[N][K];
bool cmp(pair <int, int> x, pair<int,int> y){
    return y.F * (1 + x.S) < x.F * (1 + y.S);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, t;
    cin >> n >> t;
    vector <pair<int,int>> a;
    vector <int> d;
    for (int i = 1; i <= n; i++){
        cin >> b[i].F >> b[i].S;
        if (b[i].F >= 1) a.pb(b[i]);
        if (b[i].F == 0) d.pb(b[i].S + 1);
    }
    sort(a.begin(), a.end(), cmp);
    int x = 0;
    for (int i = 0; i < a.size(); i++){
        for (int j = 0; j < K; j++){
            dp[i][j] = t + 1;
            if (i != 0) dp[i][j] = dp[i - 1][j];
            if (j != 0 && i != 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1 + min(t + 1, (1 + dp[i - 1][j - 1]) * a[i].F) + a[i].S);
            if (i == 0 && j == 0) dp[i][j] = 0;
            if (i == 0 && j == 1){
                dp[i][j] = 1 + a[i].S + a[i].F;
            }
            if (dp[i][j] > t) dp[i][j] = t + 1;
        }
    }
    int sz = (int)a.size() - 1;
    if (sz == -1){
        dp[0][0] = 0;
        for (int j = 1; j < K; j++) dp[0][j] = t + 1;
        sz = 0;
    }
    int ans = 0;
    sort(d.begin(), d.end());
    for (int j = 0; j < K; j++){
        if (dp[sz][j] > t) continue;
        ans = max(ans, j);
        int c = j;
        int x = dp[sz][j];
        for (auto y: d){
            x += y;
            if (x <= t) c++; else break;
            ans = max(ans, c);
        }
    }
    cout << ans;
}


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

void chmax(ll &a, ll b){ 
  if( a < b ){ swap(a,b);}
  
  return ;
} 

int main(){
  
  ll ans = 0;
  
  ll N,K; cin >> N >> K;
  vector<ll> A(N),B(N);
  for(ll i = 0; i < N; i++){ cin >> A[i] >> B[i];}
  
  for(ll i = 0; i < N; i++){ 
    if( (K | A[i]) == K ){ ans += B[i];}
  }
  
  ll mask = 0;
  
  for(ll i = 0; i <= 30; i++){ 
    // 1が出現する桁を探す
    
    if( (K >> i) & 1 ){ 
      ll pos = (K >> (i+1) ) << (i+1);
      
      ll now = mask|pos;
      
      ll sum = 0;
      
      for(ll j = 0; j < N; j++){ 
        if( (now | A[j]) == now ){ sum += B[j];}
      }
      
      ans = max(ans, sum);
  }
    
    mask |= (1<<i);
    
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};


int main(){
    LL n,m;cin >> n >> m;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(ALL(a));
    LL l = 0,r = LINF;
    while(r - l > 1){
        LL mm = (r - l) / 2 + l;
        LL sum = 0;
        for (int i = 0; i < n; i++) {
            LL res = lower_bound(ALL(a),mm - a[i]) - a.begin();
            LL r = (LL)a.size() - res;
            sum += r;
        }
        if(m <= sum) l = mm;
        else r = mm;
    }
    vector<LL> cum(n+1,0);
    sort(RALL(a));
    for (int i = 0; i < n; i++) {
        cum[i+1] = cum[i] + a[i];
    }
    sort(ALL(a));
    LL ans = 0;
    LL ss = 0;
    for (int i = 0; i < n; i++) {
        LL res = lower_bound(ALL(a),l - a[i]) - a.begin();
        LL r = (LL)a.size() - res;
        ans += r * a[i] + cum[r];
        ss += r;
    }
    cout << ans - (ss - m) * l << endl;
    return 0;
}


Measured memory_bytes: 1792
n,m=map(x->parse(Int,x),split(readline()))
a=[]
for i=1:n
	push!(a,readline())
end
b=[]
for i=1:m
	push!(b,readline())
end
s=0
for i=0:n-m
	for j=0:n-m
		f=1
		for k=1:m
			for l=1:m
				if a[i+k][j+l]!=b[k][l]
					f=0
				end
			end
		end
		s+=f
	end
end
print(s>0?"Yes":"No")


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

int main(){
    int n, k;
    cin >> n;
    for(int i = 1; ; i++){
        if(i * (i - 1) / 2 == n){
            k = i;
            break;
        }
        if(i * (i - 1) / 2 > n){
            cout << "No" << endl;
            return 0;
        }
    }
    vector<int> v[k+1];
    int num = 1;
    for(int i = 0; i < k; i++){
        for(int j = i + 1; j < k; j++){
            v[i].push_back(num);
            v[j].push_back(num);
            num++;
        }
    }
    cout << "Yes" << endl;
    cout << k << endl;
    for(int i = 0; i < k; i++){
        cout << v[i].size();
        for(int j = 0; j < v[i].size(); j++){
            cout << " " << v[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
    	
    	int N = sc.nextInt();
    	
    	int[] b = new int[N];
    	
    	for(int i=0;i<N;i++){
    		b[i] = sc.nextInt();
    	}
    	
    	int[] gsol = new int[N];
    	
    	boolean can = true;
    	int solnum = 0;

    	while(can && solnum != N){
    		for(int i= N-1-solnum;i>=0;i--){
    			if(b[i] == i+1){
    				gsol[solnum] = i+1;
    				solnum += 1;
    				
    				for(int j=i;j<N-1;j++){
    					b[j] = b[j+1];
    				}
    				
    				break;
    			}
    			else if(i == 0){
    				can = false;
    			}
    		}
    	}
    	
    	if(can){
        	for(int i=N-1;i>=0;i--){
        		System.out.println(gsol[i]);
        	}
    	}
    	else{
    		System.out.println(-1);
    	}
    	
    }
    
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
typedef long long ll;
const int INF = 1001001001;
const int mod = 1000000007;

int n, A, B, C;
vector<int> l(10);
vector<int> cost_list;

void dfs(int idx, int cs, int a, int b, int c) {
    if(idx == n) {
        if(a >= 1) {
            cs -= 10;
        }
        if(b >= 1) {
            cs -= 10;
        }
        if(c >= 1) {
            cs -= 10;
        }
        if(a != 0 && b != 0 && c != 0) {
            int cost = cs + abs(A - a) + abs(B - b) + abs(C - c);
            cost_list.push_back(cost);
        }
        return;
    }
    dfs(idx + 1, cs + 10, a + l[idx], b, c);
    dfs(idx + 1, cs + 10, a, b + l[idx], c);
    dfs(idx + 1, cs + 10, a, b, c + l[idx]);
    dfs(idx + 1, cs, a, b, c);
    return;
}

int main() {
    cin >> n >> A >> B >> C;
    rep(i, n) cin >> l[i];

    dfs(0, 0, 0, 0, 0);
    int ans = INF;
    for(int cost : cost_list) {
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

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

using vi = vector<int>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(0);

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

    vvi g(n + 1);

    for(int i = 0; i < m; i++)
    {
        int a, b; cin >> a >> b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 1;

    for(int i = 1; i <= n; i++)
        ans &= g[i].size() % 2 == 0;

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 5376
n = gets
a = gets.chomp.split.map(&:to_i)

if a.include?(0)
  puts 0
else
  res = 1
  f = true
  a.each do |x|
    res *= x
    if res > 1e18
      f = false
      puts -1
      break
    end
  end
  if f
    puts res
  end
end


Measured memory_bytes: 23496
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    set<int> numbers;
    int N;
    cin >> N;
    repeat (i, N) {
        int number;
        cin >> number;
        set<int>::iterator position = numbers.find(number);
        if (position == numbers.end()) {
            numbers.insert(number);
        } else {
            numbers.erase(position);
        }
    }
    cout << numbers.size() << endl;
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	string str;
	int i;
	cin>>str;
	for(i=0;i<3;i++){
		if(str.at(i)=='1'){
			cout<<'9';
		}else if(str.at(i)=='9'){
			cout<<'1';
		}else{
			cout<<str.at(i);
		}
	}
}


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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef double db;
typedef long long LL;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = (1<<18)+5;
const int mo = 998244353;

LL quickmi(LL x,LL tim){
	LL ret=1;
	for(;tim;tim/=2,x=x*x%mo)
		if (tim&1)ret=ret*x%mo;
	return ret;
}

int n;
LL f[N],g[N],ans[N];

int main(){
	n=get();
	LL s=0;
	fo(i,0,(1<<n)-1)s+=(f[i]=get());
	LL NY=quickmi(s,mo-2);
	fo(i,0,(1<<n)-1)f[i]=f[i]*NY%mo;
	for(int i=1;i<(1<<n);i<<=1)
		for(int j=0;j<(1<<n);j+=i<<1)
			for(int k=0;k<i;k++){
				LL l=f[j+k],r=f[i+j+k];
				f[i+j+k]=l<r?l-r+mo:l-r;
				f[j+k]=l+r>=mo?l+r-mo:l+r;
			}
	LL all=1,v=0;
	fo(i,1,(1<<n)-1){
		v=(v*(mo+1-f[i])+all*f[i])%mo;
		all=all*(mo+1-f[i])%mo;
	}
	v=(mo-v)%mo;
	LL A=v;
	g[0]=v;
	fo(i,1,(1<<n)-1){
		g[i]=all*quickmi((mo+1-f[i])%mo,mo-2)%mo*f[0]%mo;
		g[i]=(mo-g[i])%mo;
		A=(A+g[i])%mo;
	}
	for(int i=1;i<(1<<n);i<<=1)
		for(int j=0;j<(1<<n);j+=i<<1)
			for(int k=0;k<i;k++){
				LL l=g[j+k],r=g[i+j+k];
				g[i+j+k]=l<r?l-r+mo:l-r;
				g[j+k]=l+r>=mo?l+r-mo:l+r;
			}
	LL na=quickmi(all,mo-2)%mo;
	fo(i,0,(1<<n)-1){
		LL B=g[i];
		ans[i]=B<A?B-A+mo:B-A;
		ans[i]=ans[i]*na%mo;
	}
	ans[0]=0;
	fo(i,0,(1<<n)-1)printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N , A , B{} , ans{1} , d{};
    cin >> N >> B;
    while (cin >> A) {
        if (!d && A != B){
            d = A > B ? 1 : -1;
        }
        else if (d * (A - B) < 0){
            ans++;
            d = 0;
        }
        B = A;
    }
    cout << ans << endl;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n, k;
vector<pair<ll, int>> vec_td;

unordered_map<int, int> ump;

ll ans;

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);

  for (int i = 0; i < n; ++i) {
    int t;
    ll d;
    scanf("%d %lld", &t, &d);
    vec_td.push_back(make_pair(d, t));
  }

  sort(vec_td.begin(), vec_td.end(), greater<pair<ll, int>>());

  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;

  ll acc = 0LL;

  for (int i = 0; i < k; ++i) {
    auto cur = vec_td[i];

    acc += cur.first;
    ump[cur.second] += 1;
    if (ump[cur.second] > 1) pq.push(cur);
  }

  ans = acc + (ll)(ump.size()) * (ll)(ump.size());

  for (int i = k; i < n; ++i) {
    if (pq.empty()) break;

    auto cur = vec_td[i];
    if (ump.find(vec_td[i].second) != ump.end()) continue;

    auto last = pq.top();
    pq.pop();

    ump[last.second] -= 1;
    acc -= last.first;

    ump[cur.second] += 1;
    acc += cur.first;

    ans = max(ans, acc + (ll)(ump.size()) * (ll)(ump.size()));
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 6256
n, x, m = map(int, input().split())
li = [x]
se = {x}
for i in range(n-1):
    x = x*x%m
    if x in se:
        idx = li.index(x)
        break
    li.append(x)
    se.add(x)
else:
    print(sum(li))
    exit(0)
ans = sum(li) + sum(li[idx:])*((n-len(li)) // (len(li)-idx)) + sum(li[idx:idx+(n-len(li)) % (len(li)-idx)])
print(ans)

Measured memory_bytes: 76356
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int i,j,d[50],n,s=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>d[i];
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            s=s+d[i]*d[j];
        }
    }
    cout<<s;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <string>
#include <map>
#include <utility>
const int maxn = 1e5+1;
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m,d;
    cin>>n>>m>>d;
    cout.precision(20);
    if (d==0){
        cout<<(long double)1*(n-d)*(m-1)/n/n;
        return 0;
    }
    cout<<(long double)2*(n-d)*(m-1)/n/n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 20;
int h,w;
int grid[20][20];

int getdist(pair<int,int> start){
  int visited[h][w];
  memset(visited, 0, sizeof(visited));
  queue<pair<int,int>> q;
  q.push(start);
  visited[start.first][start.second] = 1;


  auto isValid = [&](int dx, int dy){
    if( dx < 0 or dx >= h or dy < 0 or dy>= w){ return false; }
    if( grid[dx][dy] == 1 ){ return false; }
    return true;
  };
  int maxx = 0;
  while(!q.empty()){
    auto pt = q.front(); q.pop();
    int x = pt.first;
    int y = pt.second;
    vector<int> dx = {1, -1, 0 , 0};
    vector<int> dy = {0, 0, 1 , -1};
    for(int i=0; i<4; ++i){
      if( isValid(x+dx[i], y+dy[i]) and visited[x+dx[i]][y+dy[i]] == 0 ){
        visited[x+dx[i]][y+dy[i]] = 1 + visited[x][y];
        maxx = max( maxx, visited[x+dx[i]][y+dy[i]]);
        pair<int,int> nxt = {x+dx[i], y+dy[i]};
        q.push(nxt);
      }
    }
  }
  return maxx;
}




int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  cin>>h>>w;
  vector<pair<int,int>> pts;
  for(int i=0; i<h; ++i){
    string x; cin>>x;
    for(int j=0; j<w; ++j){
      if( x[j] == '.' ){ grid[i][j] = 0; pts.push_back({i,j});}
      else{ grid[i][j] = 1;  }
    }
  }
  int max_ans = 0;
  for(auto i : pts){
    max_ans = max( max_ans ,getdist(i));
  }
  cout<<max_ans-1<<'\n';

	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
using namespace std;

int main() {
    string s, ans;
    cin >> s;
    
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '0')ans += '0';
        else if (s[i] == '1')ans += '1';
        else if (!ans.empty())ans.pop_back();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class MyClass
{
    static void Main(string[] args)
    {
        int n = 0;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            int s = -n;
            for (int i = 1; i <= Math.Sqrt((double)n); i++)
            {
                if (n % i == 0)
                {
                    s += (i == n / i) ? i : (i + n / i);
                }
            }
            if (s == n)
            {
                Console.WriteLine("perfect number");
            }
            else if (s > n)
            {
                Console.WriteLine("abundant number");
            }
            else
            {
                Console.WriteLine("deficient number");
            }
        }
    }
}


Measured memory_bytes: 5292
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


set<int> SET;

int main(){

	int num_query;
	scanf("%d",&num_query);

	int command,x;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d %d",&command,&x);

		if(command == 0){

			SET.insert(x);
			printf("%lld\n",SET.size());

		}else{

			printf("%lld\n",SET.count(x));
		}
	}

	return 0;
}




Measured memory_bytes: 12532
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    auto p = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1];
    int x, y;
    scan(x, y);
    writeln(p[x] == p[y] ? "Yes" : "No");
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

// Description: ????????????
// Verifyed: various problem 
using namespace placeholders;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
using L=struct{P s,t;};
using VP=vector<P>;
using C=struct{P c;R r;};

auto& operator >> (istream& is,P& p){ R x,y; is >> x >> y,p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline P vec(L l){return l.t-l.s;}
auto sdot = bind(sgn,bind(dot,_1,_2,_3));
auto sdet = bind(sgn,bind(det,_1,_2,_3));

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/vec(l)); return (1-u)*l.s+u*l.t;}

// vertical parallel
// verified: AOJ CGL_2_A
bool vertical(L a,L b) {return sdot(0,vec(a),vec(b))==0;}
bool parallel(L a,L b) {return sdet(0,vec(a),vec(b))==0;}
bool eql(L a,L b){ return parallel(a,b) and sdet(a.s,a.t,b.s)==0;}

// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
	int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
	int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
	return max(sa,sb)<0;
}

// crossing point 
// verified: AOJ CGL_2_C
P cross(L a,L b){
	R u=det(a.s,b.s,b.t)/det(0,vec(a),vec(b));
	return (1-u)*a.s+u*a.t;
}
	
// distance 
// verified: AOJ CGL_2_D
R dsp(L l,P p){
	P h=proj(l,p);
	if(sdot(l.s,l.t,p)) h=l.s;
	if(sdot(l.t,l.s,p)) h=l.t;
	return abs(p-h);
}

R dss(L a,L b){return iss(a,b)?0:min({dsp(a,b.s),dsp(a,b.t),dsp(b,a.s),dsp(b,a.t)});}

int main(void){
	int n;
	cin >> n;
	cout.precision(20);
	rep(i,n){
		P a,b,c,d;
		cin >> a >> b >> c >> d;
		L s1={a,b},s2={c,d};
		if(parallel(s1,s2))
			cout << 2 << endl;
		else if(vertical(s1,s2))
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


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


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    N = int(input())
    edges = []
    for _ in range(N - 1):
        U, V = map(int, input().split())
        edges.append((U, V))

    ans = 0
    for i in range(1, N + 1):
        ans += i * (N - i + 1)

    for u, v in edges:
        if u > v:
            u, v = v, u
        ans -= u * (N - v + 1)
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 36820
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
li = na()
c = Counter(li)
hen = [i[0] for i in c.items() if i[1] >= 2]
hen2 = [i for i in hen if c[i] >= 4]
hen.sort()
if len(hen) <= 1:
    if len(hen2) == 0:
        print(0)
    else:
        print(max(hen2) ** 2)
else:
    if len(hen2) == 0:
        print(hen[-1] * hen[-2])
    else:
        print(max(hen[-1] * hen[-2], max(hen2) ** 2))


Measured memory_bytes: 18600
#include<stdio.h>
int main(){
int n,i,min,max;
long long sum;
int ai[10000];

scanf("%d", &n);

for(i=0; i<n; i++){
 scanf("%d", &ai[i]);
}

min = ai[0];
for(i=1; i<n; i++){
if(min > ai[i])
 min = ai[i];
}

max = ai[0];
for(i=1; i<n; i++){
if(max < ai[i])
 max = ai[i];
}

for(i=0; i<n; i++){
sum += ai[i];
}

printf("%d %d %ld\n", min, max, sum);

return 0;

}

Measured memory_bytes: 640
import bisect

n = int(input())
al = list(map(int, input().split()))
al.sort()

if n == 1:
    print(1)
    exit()
elif n == 2:
    if abs(al[0] - al[1]) <= 2:
        print(2)
        exit()
    else:
        print(1)
        exit()

ans = 0
for i in range(n):
    idx = bisect.bisect_right(al, al[i] + 2)
    tmp = idx - i
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 20500
/*
Author Shivam
*/
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define m_p			make_pair
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i =a, i>=b;i--)
#define sz(x)       (int)x.size()
#define F			first
#define S			second
#define debug(x)	for(int i=0;i<x;i++) cout<<"##########"<<endl
#define M			1000000007 
#define int			long long int
#define lMax		LLONG_MAX
#define pii 		pair<int ,int >
#define	all(a)		a.begin(), a.end()
#define vi 			vector<int> 
#define vii 		vector<pii> 
#define ve          vector
#define endl		"\n"
#define double 		long double
#define couts		cout<<setprecision(12)<<fixed					
// queue<int> , prefix_sum(a,a+n) , reverse(a,a+n) , priority_queue <int> max heap , priority_queue <int, vector<int>, greater<int> > min heap;
// == > != precedence gretaer then & , << precedence greater than <= == => , 
//int chk, cnt, fl, pos, in, src, tar, val, res. dummy;  fill (myvector.begin(),myvector.begin()+4,5), freq;					
// can

double dp[3*300+1][2*300+1][301+1];
int n;
double call(int i, int j, int k)
{	
	
	double &res=dp[i][j][k];
	//cout<<i<<" "<<j<<" "<<k<<" "<<n<<" "<<res<<endl;
	if(res!=-1) return res;
	double x1=0, x2=0, x3=0, sum=i+j+k;
	if(sum==0) return 0;
	if(i) x1=call(i-1,j,k);
	if(j) x2=call(i+1,j-1,k);
	if(k) x3=call(i,j+1,k-1);
	res=n*((x1+1)*i/n+(x2+1)*j/n+(x3+1)*k/n+(n-sum)/n)/sum;
	
	return res;

}
void solve()
{
	cin>>n;
	int arr[n], sum=0;
	//int mp[4]={0,0,0,0};
	rep(i,0,n)
	{ 
		cin>>arr[i], sum+=arr[i];
	///	mp[a[i]]++;
	}
    int table[n][n]; 
  
    // Fill table using above recursive formula. Note  
    // that the table is filled in diagonal fashion (similar 
    // to http:// goo.gl/PQqoS), from diagonal elements to 
    // table[0][n-1] which is the result. 
    for (int gap = 0; gap < n; ++gap) { 
        for (int i = 0, j = gap; j < n; ++i, ++j) { 
  
            // Here x is value of F(i+2, j), y is F(i+1, j-1) and 
            // z is F(i, j-2) in above recursive formula 
            int x = ((i + 2) <= j) ? table[i + 2][j] : 0; 
            int y = ((i + 1) <= (j - 1)) ? table[i + 1][j - 1] : 0; 
            int z = (i <= (j - 2)) ? table[i][j - 2] : 0; 
  
            table[i][j] = max(arr[i] + min(x, y), arr[j] + min(y, z)); 
        } 
    } 
  
    cout<<2*table[0][n - 1]-sum; 
}
signed main()
{
		ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t;
		t=1;
		while(t--)
		{
			solve();
		}
}	


Measured memory_bytes: 70272
using System;

namespace Branch_on_Condition
{
    class Small__Large__or_Equal
    {
        static void Main(string[] args)
        {
            var token = Console.ReadLine().Split(' ');
            int a = int.Parse(token[0]);
            int b = int.Parse(token[1]);
            if (a > b) Console.WriteLine("a > b");
            if (a < b) Console.WriteLine("a < b");
            if (a == b) Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8956
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#define ll long long

using namespace std;

int main(){
    int N,T;
    cin >> N >> T;
    int c,t;
    vector<vector<int>> vec(N,vector<int>(2,0));
    for(int i=0;i<N;i++){
        cin >> c >> t;
        vec[i][0]=c;
        vec[i][1]=t;
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(vec[i][1]<=T){
            if(ans==0){
                ans=vec[i][0];
            }
            else if(vec[i][0]<ans){
                ans=vec[i][0];
            }
        }
    }
    if(ans!=0){
        cout << ans << endl;
    }
    else{
        cout << "TLE" << endl;
    }
    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

ostream& operator<<(ostream &out, const pii &a) { return out << '(' << a.x << ", " << a.y << ')'; }
istream& operator>>(istream &in, pii &a) { return in >> a.x >> a.y; }

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// cerr << boolalpha;
	(cout << fixed).precision(10);

	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i += 2) {
		cout << S[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 592
N = int(input())
A = list(map(int, input().split()))
check1 = 0
check2 = 0
for i in range(N):
    if A[i]%2 == 0:
        check1+=1
for i in range(N):
    if A[i]%2 == 0:
        if A[i]%3 == 0 or A[i]%5 == 0 :
            check2+=1
        else:
            check2+=0
    else:
        check2+=0
if check1 == check2:
    print("APPROVED")
elif check1 != check2:
    print("DENIED")


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
int main(void)
{
	int C;
	int M = 0;
	int nc = 0;
	cin >> C;
	int H[C];
	for (int i = 0; i < C; ++i)
	{
		int H;
		cin >> H;
		if(M <= H)
		{
			nc++;
			M = H;
		}
	}
	cout << nc << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, i;
	int flag = 0;
	char s[101];

	scanf("%d", &n);
	scanf("%s", s);

	//文字数が偶数でなければNoを出力する
	if (n % 2 != 0) {
		printf("No\n");
		return 0;
	}

	//文字列を二度繰り返したものでなければ flag を 1 にする
	for (i = 0; i < n / 2; i++) {
		if (s[i] != s[i + (n / 2)]) {
			flag = 1;
		}
	}

	if (flag == 1) //flagが1であり、文字列を二度繰り返したものではないとき
	{
		printf("No\n");
	}
	else //文字列を二度繰り返したものであるとき
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().solve();

	}
	
	void solve(){
		int n,p;
		int oldp=0;
		int playn=0;
		int haven[];
		Scanner sc=new Scanner(System.in);
		while(true){
			n=sc.nextInt();
			p=sc.nextInt();
			playn=0;
			oldp=p;
			if(n+p==0)break;
			haven=new int[n];
			while(true){
				if(p>0){
					p--;
					haven[playn]++;
					if(haven[playn]==oldp){
						System.out.println(playn);
						break;
					}
				}else{
					p+=haven[playn];
					haven[playn]=0;
				}
				playn=(playn+1)%n;
			}
		}		
	}

}

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

class Rolling_Hash{
private:
  ll n;
  static constexpr ll base1=1007,base2=2009;
  static constexpr ll mod1=(1e9+7),mod2=(1e9+9);
  vector<ll> hash1,hash2,mpow1,mpow2;
public:
  Rolling_Hash(const string& s){
    n=s.size();
    hash1.resize(n+1,0);
    hash2.resize(n+1,0);
    mpow1.resize(n+1,1);
    mpow2.resize(n+1,1);
    for(ll i=0;i<n;++i){
      hash1[i+1] = (hash1[i]*base1+s[i])%mod1;
      hash2[i+1] = (hash2[i]*base2+s[i])%mod2;
      mpow1[i+1] = (mpow1[i]*base1)%mod1;
      mpow2[i+1] = (mpow2[i]*base2)%mod2;
    }
  }
  auto get(ll l,ll r){
    ll lefval = hash1[r]-hash1[l]*mpow1[r-l]%mod1;
    ll rigval = hash2[r]-hash2[l]*mpow2[r-l]%mod2;
    if(lefval<0)lefval+=mod1;
    if(rigval<0)rigval+=mod2;
    return make_pair(lefval,rigval);
  }
  auto get_LCP(ll a,ll b){
    ll len = min( n-a+1,n-b+1 );
    ll low=0,high=len;
    while( high-low>1 ){
      ll mid=(high+low)>>1;
      if(get(a,a+mid)!=get(b,b+mid))high=mid;
      else low=mid;
    }
    return low;
  }
};

main(){

  ll n;
  string s;
  cin>>n>>s;

  Rolling_Hash rh(s);
  auto judge = [&](ll len)->bool{
    using pll=pair<ll,ll>;
    map<pll,ll> mp;
    for(ll i=0;i+len<=n;++i){
      auto hash_v=rh.get(i,i+len);
      if( mp.count(hash_v) ){
        if( mp[hash_v]+len <= i )return true;
      }
      else mp[hash_v]=i;
    }
    return false;
  };
  ll low=0,high=n/2+1;
  while(high-low>1){
    ll mid=(low+high)/2;
    if( judge(mid) )low=mid;
    else high=mid;
  }
  cout<<(low)<<endl;

}


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

int n;
vector<ll> dp, scores;
vector<int> rem;
const ll INF = 1e18;

void recursion(int r, int mask, ll score, int grp) {
	if (r == (int)rem.size()) {
		dp[mask] = max(dp[mask], score + scores[grp]);
		return;
	}
	recursion(r + 1, mask, score, grp);
	recursion(r + 1, mask ^ (1 << rem[r]), score, grp ^ (1 << rem[r]));
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	int a[n][n];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	scores.resize(1 << n, 0);
	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = 0; i < n; i++) {
			if (mask & (1 << i)) {
				for (int j = i + 1; j < n; j++) {
					if (mask & (1 << j)) {
						scores[mask] += a[i][j];
					}
				}
			}
		}
	}
	dp.resize(1 << n, -INF);
	dp[0] = 0;
	for (int mask = 0; mask < (1 << n); mask++) {
		rem.clear();
		for (int i = 0; i < n; i++) {
			if (!(mask & (1 << i))) {
				rem.push_back(i);
			}
		}
		recursion(0, mask, dp[mask], 0);
	}
	cout << dp[(1 << n) - 1];

	return 0;
}

Measured memory_bytes: 4324
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <map>
#include <limits>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n,m) for(int i=n;i<m;i++)
template <typename Container> void P(const Container &c) {
    for (const auto& x : c) cout << x << ' '; cout << '\n';
}
struct point { int x, y; };
int main()
{
    int N, K; cin >> N >> K;
    vector<point> points;
    REP(i, N) { int x, y; cin >> x >> y; points.push_back({x, y}); }
    vector<int> xs, ys;
    for (auto p : points) { xs.push_back(p.x); ys.push_back(p.y); }
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    vector<vector<int>> S(ys.size()); // S[y_id][x_id] = number of elem in [0..y][0..x]
    REP(i, ys.size()) S[i].resize(xs.size());
    map<int, int> x2xid; REP(i, xs.size()) x2xid[xs[i]] = i;
    map<int, int> y2yid; REP(i, ys.size()) y2yid[ys[i]] = i;
    for (auto p : points) {
        FOR(y, y2yid[p.y], ys.size()) FOR(x, x2xid[p.x], xs.size()) S[y][x]++;
    }
    Int minarea = numeric_limits<Int>::max();
    FOR (y0, 0, ys.size()) FOR (y1, y0+1, ys.size())
    FOR (x0, 0, xs.size()) FOR (x1, x0+1, xs.size()) {
        int sum = 0;
        if      (x0 == 0 && y0 == 0) sum = S[y1][x1];
        else if (x0 == 0 && y0 != 0) sum = S[y1][x1] - S[y0-1][x1];
        else if (x0 != 0 && y0 == 0) sum = S[y1][x1] - S[y1][x0-1];
        else sum = S[y1][x1] - S[y0-1][x1] - S[y1][x0-1] + S[y0-1][x0-1];
        if (sum >= K) {
            minarea = min(minarea, (Int)(ys[y1] - ys[y0]) * (xs[x1] - xs[x0]));
        }
    }
    cout << minarea << endl;
    return 0;
}


Measured memory_bytes: 384
//Sani buyuk Osman Pasa Plevneden cikmam diyor.
//FatihSultanMehmedHan
//Abdulhamid Han
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long int lo;
typedef pair< int,int > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(lo i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b,a[li],k,flag,d[li];
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&m);
	d[0]=0;
	if(0<=m)cev++;
	FOR{
		scanf("%lld",&a[i]);
		d[i]=d[i-1]+a[i];
		if(d[i]<=m)cev++;
	}
	printf("%lld\n",cev);
	return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>

void
swp(int *a, int *b)
{
        int tmp;
        tmp = *a;
        *a = *b;
        *b = tmp;
}

int
main(int argc, char *argv[])
{
        int dat[3] = {0};
        int in, i;

        for (i = 0; i < 10; i++) {
                scanf("%d", &in);
                if (dat[2] < in) {
                        dat[2] = in;
                        if (dat[1] < dat[2]) {
                                swp(&dat[1], &dat[2]);
                                if (dat[0] < dat[1]) 
                                        swp(&dat[0], &dat[1]);
                        }
                }
        }
        for (i = 0; i < 3; i++)
                printf("%d\n", dat[i]);

        return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int             long long
#define endl            '\n'
#define ff              first
#define ss              second
#define ull        unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si                 set<int>        
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)        for(int i=a;i<n;++i)
#define repd(i,a,n)        for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}


void c_p_p()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
}

int32_t main()
{
    c_p_p();
    int n;
    cin>>n;
    bool flag=0;
    while(n>0)
    {
        if(n%10==7)flag=1;
        n/=10;
    }
    if(flag)cout<<"Yes";
    else cout<<"No";
    return 0;
}
    

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
   int x,y; cin >> x >>  y;
   string ans = "No\n";
    rep(i,0,100){
        rep(j,0,100){
            if(i+j == x && 2*i+4*j == y){
                ans = "Yes\n";
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		for(int i = 0; i < N; i++) {
			int[] A = new int[3];
			for(int j = 0; j < 3; j++) {
				A[j] = Integer.parseInt(sc.next());
			}

			Arrays.sort(A);
			double a = Math.pow(A[2], 2);
			double b = Math.pow(A[0], 2) + Math.pow(A[1], 2);
			if(a == b) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}
		sc.close();
	}

}



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

int h1, m1, h2, m2, k;

int main() {
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << (h2 - h1) * 60 + m2 - m1 - k << endl;
  return 0;
}


Measured memory_bytes: 3636
//Problem *
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,d[N],dp[N],s[N],t[N],S;
vector<int>e[N];
int main(){
	scanf("%d%d",&n,&m);
	while(m--){
		int a,b;scanf("%d%d",&a,&b);
		e[a].push_back(b),++d[b];
	}
	for(int i=1;i<=n;i++)if(!d[i])t[++t[0]]=i;
	while(t[0]){
		int v=t[t[0]--];s[++s[0]]=v;
		for(int i=0;i<(int)e[v].size();i++){
			int u=e[v][i];--d[u];
			if(!d[u])t[++t[0]]=u;
		}
	}
	for(int i=n;i;i--){
		int v=s[i];
		for(int j=0;j<(int)e[v].size();j++)dp[v]=max(dp[v],dp[e[v][j]]+1);
		S=max(S,dp[v]);
	}
	printf("%d",S);
	return 0;
}

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

const int dx[]={0,-1,0,1};
const int dy[]={-1,0,1,0};

struct Node{
    int x1,y1,x2,y2,depth;
    Node(int a,int b,int c,int d,int e):
        x1(a),y1(b),x2(c),y2(d),depth(e){}
    Node(){}
};

int W,H,tx,ty,kx,ky;
int fld[50][50];
bool done[50][50][50][50];
bool check(int x,int y){
    return x>=0&&x<W&&y>=0&&y<H&&fld[y][x]==0;
}
void solve(){
    queue<Node>Q;
    Q.push(Node(tx,ty,kx,ky,0));
    fill_n(***done,50*50*50*50,false);

    while(Q.size()){
        Node a=Q.front();Q.pop();
        if(a.depth>=100)continue;
        if(done[a.x1][a.y1][a.x2][a.y2])continue;
        done[a.x1][a.y1][a.x2][a.y2]=true;

        if(a.x1==a.x2&&a.y1==a.y2){
            cout<<a.depth<<endl;
            return;
        }

        for(int d=0;d<4;d++){
            Node next(a.x1+dx[d],a.y1+dy[d],a.x2-dx[d],a.y2-dy[d],a.depth+1);
            if(!check(next.x1,next.y1)){
                next.x1=a.x1;next.y1=a.y1;
            }
            if(!check(next.x2,next.y2)){
                next.x2=a.x2;next.y2=a.y2;
            }

            Q.push(next);
        }
    }

    cout<<"NA"<<endl;
}

int main(){
    while(cin>>W>>H,W||H){
        cin>>tx>>ty>>kx>>ky;
        tx--;ty--;kx--;ky--;
        for(int i=0;i<H;i++)
        for(int j=0;j<W;j++)
            cin>>fld[i][j];

        solve();
    }
    return 0;
}

Measured memory_bytes: 8508