akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <utility>
#include <cstdio>
#include <vector>
#define pb push_back
#define MOD 1000000007
typedef long long ll;
typedef std::pair<int, int> data;
std::vector<data> vec; 
inline bool comp(const data &a, const data &b)
{
	return (ll)a.first * b.second < (ll)a.second * b.first;
}
int main()
{
	// freopen("CF17-QC-E.in", "r", stdin); 
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	ll ans = (ll)std::min(a, d + 1) * std::min(b, d + 1) % MOD * std::min(c, d + 1) % MOD;
	for (int i = 0; i <= d; i++)
	{
		if (i < a)
		{
			vec.pb({i, a});
			vec.pb({a - i - 1, a});
		}
		if (i < b)
		{
			vec.pb({i, b});
			vec.pb({b - i - 1, b});
		}
		if (i < c)
		{
			vec.pb({i, c});
			vec.pb({c - i - 1, c});
		}
	}
	std::sort(vec.begin(), vec.end(), comp);
	int curx = 0, cury = 0, curz = 0; 
	for (data &it : vec)
	{
		int dx = std::min(a - 1, curx + d) - std::max(0, curx - d) + 1; 
		int dy = std::min(b - 1, cury + d) - std::max(0, cury - d) + 1; 
		int dz = std::min(c - 1, curz + d) - std::max(0, curz - d) + 1; 
		int x = (ll)a * it.first / it.second; 
		int y = (ll)b * it.first / it.second; 
		int z = (ll)c * it.first / it.second; 
		if (x + d < a)
			(ans += (ll)(x - curx) * dy % MOD * dz) %= MOD; 
		if (y + d < b)
			(ans += (ll)(y - cury) * dx % MOD * dz) %= MOD; 
		if (z + d < c)
			(ans += (ll)(z - curz) * dx % MOD * dy) %= MOD; 
		curx = x; 
		cury = y; 
		curz = z; 
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> value(N);
    vector<int> sum(N+1, 0);
    for (int i = 0; i < N; i++) {
        cin >> value[i];
        sum[i+1] = sum[i] + value[i];
    }
    
    if (2*N <= K) {
        int pos = 0;
        for (auto v : value) if(0 < v) pos += v;
        cout << pos << endl;
        return 0;
    }
    
    if (N < K) {
        int ans = 0;
        for (int take = 0; take <= N; take++) {
            int dump = K-take;
            int res = 0;
            for (int L = 0; L <= take; L++) {
                int R = take - L;
                int score = sum[L] + (sum[N]-sum[N-R]);
                priority_queue<int> que;
                for (int i = 0; i < L; i++) if (value[i] < 0) que.push(-value[i]);
                for (int i = N-1; i > N-R; i--) if (value[i] < 0) que.push(-value[i]);
                for (int i = 0; i < dump; i++) {
                    if (que.empty()) break;
                    score += que.top(); que.pop();
                }
                res = max(res, score);
            }
            ans = max(ans, res);
        }
        cout << ans << endl;
        return 0;
    }
    
    int ans = 0;
    for (int take = 0; take <= K; take++) {
        int dump = K-take;
        int res = 0;
        for (int L = 0; L <= take; L++) {
            int R = take - L;
            int score = sum[L] + (sum[N]-sum[N-R]);
            priority_queue<int> que;
            for (int i = 0; i < L; i++) if (value[i] < 0) que.push(-value[i]);
            for (int i = N-1; i > N-R; i--) if (value[i] < 0) que.push(-value[i]);
            for (int i = 0; i < dump; i++) {
                if (que.empty()) break;
                score += que.top(); que.pop();
            }
            res = max(res, score);
        }
        ans = max(ans, res);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
int main(void)
{
    string S, T;
    cin >> S >> T;

    bool isMatch = true;
    int size = (int)S.size();
    for (int i = 0; i < size; i++) {
        if (S[i] != T[i]) {
            isMatch = false;
        }
    }

    if (isMatch) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3036
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs){
    var tenki = ["Sunny","Cloudy","Rainy","Sunny"];
    for(i = 0; i < 3;i++){
        if(inputs[0] == tenki[i]){
          console.log(tenki[i+1])
        }
    }
}


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

int main() {
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            string s;
            cin >> s;
            if(s == "snuke") {
                cout << char('A' + j) << i+1 << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    
    dp = [[0, 0] for i in range(N+1)]
    for i in range(M):
        if S[i] == 'AC':
            dp[p[i]][0] = 1
            
        else:
            if dp[p[i]][0] == 0:
                dp[p[i]][1] += 1

    ac = len([dp[i][0] for i in range(1, N+1) if dp[i][0] > 0])
    wa = sum([dp[i][1] for i in range(1, N+1) if dp[i][0] > 0])
    # print(dp[:10])
    # print([dp[i][0] for i in range(1, N+1)])
    print(ac, wa)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24448
n = int(input())
s = input()

both = 0
for i in range(1, n):
	a = list(set(s[0:i]))
	b = list(set(s[i:n]))
	botht = 0
	for al in a:
		if(al in b):
			botht += 1
	if(both < botht):
		both = botht
		
print(both)

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

int N;
int arr[3000];

int main()
{
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif*/

	cin >> N;
	for(int i = 1 ; i <= N ; i++)cin >> arr[i];
	sort(arr+1,arr+1+N);
	
	int ans = 0;
	for(int i = 1 ; i <= (N - 2) ; i++){
		for(int j = i + 1 ; j <= (N - 1) ;j++){
			for(int k = j + 1 ; k <= N ; k++){
				if(arr[i] + arr[j] > arr[k])++ans;
				else break;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	string key = "keyence";
	rep(i, key.size()){
		if(key[i] != s[i]){
			string subs = s.substr(s.size()-key.size()+i);
			string subk = key.substr(i);
			// cerr << subs << endl;
			// cerr << subk << endl;
			if(subs == subk){
				cout << "YES" << endl;
			}else{
				cout << "NO" << endl;
			}
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

int a[3][3];
bool cnt[3][3];
signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int n, b;
   string ans = "No";

   rep(i, 0, 3) rep(j, 0, 3) cin >> a[i][j];

   cin >> n;

   rep(i, 0, n)
   {
      cin >> b;
      rep(j, 0, 3) rep(k, 0, 3)
      {
         if (a[j][k] == b)
            cnt[j][k] = true;
      }
   }

   rep(i, 0, 3) if (cnt[i][0] && cnt[i][1] && cnt[i][2]) ans = "Yes";
   rep(i, 0, 3) if (cnt[0][i] && cnt[1][i] && cnt[2][i]) ans = "Yes";
   if (cnt[0][0] && cnt[1][1] && cnt[2][2])
      ans = "Yes";
   if (cnt[0][2] && cnt[1][1] && cnt[2][0])
      ans = "Yes";

   cout << ans << '\n';
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=200111;
vector<int> g[maxn];
int n,dist[maxn];
void dfs(int x,int f=0,int d=0)
{
	dist[x]=d;
	for(int i=0;i<(int)g[x].size();i++)if(g[x][i]!=f)
		dfs(g[x][i],x,d+1);
}
int main()
{
	get1(n);
	for(int i=1,u,v;i<n;i++)
	{
		get2(u,v);
		g[u].pb(v);g[v].pb(u);
	}
	dfs(1);
	int t=max_element(dist+1,dist+n+1)-dist;
	dfs(t);
	int l=*max_element(dist+1,dist+n+1);
	if(l%3==1)puts("Second");
	else puts("First");
	return 0;
}

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

int main(void) {
    int n, m, ans = 0;
    vector<int> g[10];
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    queue<pair<int, int>> que;
    pair<int, int> s;
    s.first = 0;
    s.second = 0;
    que.push(s);
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        p.second |= (1 << p.first);
        bool flag = true;
        for (int i = 0; i < n; i++) {
            if (!(p.second & (1 << i))) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ans++;
            continue;
        }
        for (int i = 0; i < g[p.first].size(); i++) {
            if (!(p.second & (1 << g[p.first][i]))) {
                que.push({g[p.first][i], p.second});
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()
 
using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
typedef pair<P,D> C;
 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<D,int> pdi;
 
const D EPS = 1e-10;
const D PI = acos(-1);
 
namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}
 
//for vector
inline P unit(P p){return p/abs(p);}
 
inline pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}
 
inline D dot(P x, P y){return real(conj(x)*y);}
 
inline D cross(P x, P y){return imag(conj(x)*y);}
 
//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}
 
//for line(segment)
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}
 
inline bool orth(L a,L b){return abs(dot(a.fs-a.sc,b.fs-b.sc))<EPS;}
 
inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}
 
inline D line_dis(L a,P x){return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);}
 
inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}
 
inline D seg_p_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}
 
inline D seg_seg_dis(L a,L b){
  D res = 1e10;
  res = min(res,seg_p_dis(a,b.fs));
  res = min(res,seg_p_dis(a,b.sc));
  res = min(res,seg_p_dis(b,a.fs));
  res = min(res,seg_p_dis(b,a.sc));
  return res;
}
 
int main(){
  int n[2];
  P p[2][100];
  L l[2][100];
 
  rep(i,2){
    cin >> n[i];
    rep(j,n[i]){
      int x,y;
      cin >> x >> y;
      p[i][j] = P(x,y);
      if(j==0)l[i][j] = L(P(0,1000*i), p[i][j]);
      else l[i][j] = L(p[i][j-1], p[i][j]);
    }
    l[i][n[i]] = L(p[i][n[i]-1], P(1000,1000*i));
  }
 
  D ans = 1e5;
  rep(i,n[0]+1){
    rep(j,n[1]+1){
      ans = min(ans, seg_seg_dis(l[0][i], l[1][j]));
    }
  }
 
  cout << fixed << setprecision(10) << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int cal(int val) {
  int ret = 0;
  while ((val & 1) == 0) {
    val >>= 1;
    ++ret;
  }
  return ret;
}

int main()
{
  int N; scanf("%d", &N);
  int a;
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &a);
    ans += cal(a);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }
 
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	public static void main(String[] args) {
		FastReader in = new FastReader();
		String a = in.next(), b = in.next();
		if((a.equals("H") && b.equals("H")) || (a.equals("D") && b.equals("D"))) System.out.println("H");
		else System.out.println("D");
	}
	

}


Measured memory_bytes: 20180
a=int(input())
b,c=input().split()
b=int(b)
c=int(c)
l=list(map(int,input().split()))
for i in range(a):
  l[i]=abs(c-(b-l[i]*0.006))
for i in range(a):
  if l[i]==min(l):
    print(i+1)

Measured memory_bytes: 9256
#include <stdio.h>
int main()
{
	unsigned long long n, m, ans=0;
	scanf("%lld%lld", &n, &m);
	m/=2;
	if(n>m){
		ans+=m;
	}
	else{
		ans+=n;
		m-=n;
		m/=2;
		ans+=m;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long   ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<ii, ll>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
#define tam 220000
#define offset 
const ll MOD= 1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int v[300];
int ans[tam];
int  main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n>>v['A']>>v['B']>>v['C'];
    string txt,ant;
    int m=v['A']+v['B']+v['C'];
    bool valid=1;
    forr(i,0,n)
    {
        cin>>txt;
        if (m<=1)
        {
            if (v[txt[0]]+v[txt[1]]==0)
                valid=0;
            else
            {
                if (v[txt[0]]==1)
                    ans[i]=txt[1],v[txt[0]]--,v[txt[1]]++;
                else
                    ans[i]=txt[0],v[txt[0]]++,v[txt[1]]--;
            }
        }
        else
        {
            if (v[txt[0]]+v[txt[1]]==0)
            {
                if (i-1<0)
                    valid=0;
                else
                {
                    if (ans[i-1]==ant[0])
                    {
                        ans[i-1]=ant[1];
                        v[ant[0]]-=2,v[ant[1]]+=2;
                    }
                    else
                    {
                        ans[i-1]=ant[0];
                        v[ant[1]]-=2,v[ant[0]]+=2;
                    }
                    if (v[ant[0]]<0|| v[ant[1]]<0)
                        valid=0;
                    //assert(v[ant[0]]>=0);
                    //assert(v[ant[1]]>=0);
                }
            }
            if (v[txt[0]]>0)
            {
                v[txt[0]]--,v[txt[1]]++;
                ans[i]=txt[1];
            }
            else
            {
                v[txt[1]]--,v[txt[0]]++;
                ans[i]=txt[0];
            }
        }
        ant=txt;
    }
    if (valid){
        cout<<"Yes\n";
        forr(i,0,n)
        {
            cout<<(char)ans[i]<<endl;
        }
    }
    else
        cout<<"No\n";
}
// PLUS ULTRA!
    


Measured memory_bytes: 4076
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

// 素数判定
func main() {
	sc := bufio.NewScanner(os.Stdin)
	n := stdin(sc)
	cnt := 0
	for i := 0; i < n; i++ {
		if isPrime(stdin(sc)) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func stdin(sc *bufio.Scanner) int {
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	return num
}

func isPrime(v int) bool {
	if v < 2 {
		return false
	}
	if v == 2 {
		return true
	}
	if v%2 == 0 {
		return false
	}
	n := int(math.Sqrt(float64(v)))
	for i := 3; i <= n; i += 2 {
		if v%i == 0 {
			return false
		}
	}
	return true
}



Measured memory_bytes: 1168
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        if (a >= 6 && a <= 12) {
            System.out.println(b / 2);
        } else if (a <= 5) {
            System.out.println(0);
        } else {
            System.out.println(b);
        }
    }
}

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

using namespace std;
#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()
const ll MOD = 1e9 + 7;
const int MAX = 5000010;
int lastInc[MAX] = {};

int main()
{
    string s;
    cin >> s;
    int cnt1 = 0, cnt2 = 0;

    for (size_t i = 0; i < s.size(); i++)
    {
        char ch, ch1;
        if (i % 2 == 0)
            ch = '0', ch1 = '1';
        else
            ch = '1', ch1 = '0';
        cnt1 += abs(ch - s[i]);
        cnt2 += abs(ch1 - s[i]);
    }
    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 512
n = int(input())
a_list = list(map(int, input().split()))

import collections
count_dic = collections.Counter(a_list)

count_dic_new = {}
for key, value in count_dic.items():
    if value == 1:
        count_dic_new[key] = 0
    elif value == 2:
        count_dic_new[key] = 1
    else: 
        count_dic_new[key] = (value * (value - 1)) // 2

fund_values = sum(list(count_dic_new.values()))

for a in a_list:
    if count_dic[a] == 1:
        a_value = fund_values
    elif count_dic[a] == 2:
        a_value = fund_values - 1
    else:
        n = count_dic[a]
        a_value = fund_values + (((n-1) * (n-2)) // 2) - (((n) * (n-1)) // 2) 

    print(a_value)


Measured memory_bytes: 32228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void) {
    int n,k,q;cin>>n>>k>>q;
    vector<int>V(n,0);
    int x;
    rep(i,q){
        cin>>x;
        V[x-1]++;
    }
    //rep(i,n)cout<<V[i]<<' ';
    //cout<<endl;
    rep(i,n){
        if(k-(q-V[i])>0)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
}    
    
    
    


Measured memory_bytes: 1408
#include <stdio.h>

int main( void )
{
	int digit[1000] = {};
	int number, num_cou, ans_sum, add_cou;
	
	num_cou = 0;
	ans_sum = 0;
	
	while( ( number = getchar() ) != EOF )
	{
		if( number != '\n' )
		{
			if( num_cou == 0 && number == '0' )
			{
				break;
			}else
			{
				digit[num_cou] = number - '0';
				num_cou++;
			}
		}else
		{
			for( add_cou =0; add_cou < num_cou; add_cou++ )
			{
				ans_sum += digit[add_cou];
			}
			printf( "%d\n", ans_sum );
			num_cou = 0;
			ans_sum = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
bool sosuu(int n){
  int d=pow(n,0.5)+1;
  if(n==2)return true;
  int i=2;
  while(i<=d){
    if(n%i!=0){i++;}
    else return false;
  }
  return true;
}
signed main() {
int q;
cin>>q;
int ans;
int l,r;
int s[100001];
s[1]=0;s[0]=0;
for(int i=3;i<=100001;i+=2){if(sosuu(i)&&sosuu((i+1)/2))s[i]=s[i-2]+1;else s[i]=s[i-2];}


for(int i=0;i<q;i++){
  cin>>l>>r;
  ans=0;
  if(l>=2)ans=s[r]-s[l-2];
  else ans=s[r];
  cout<<ans<<endl;
}

}


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

using namespace std;

int N, M, Q;
long long int ans = 0;
vector<int> a(50), b(50), c(50), d(50);

void solve(vector<int> &A, int index)
{
    if (index < N)
    {
        for (int i = A[index - 1]; i <= M; i++)
        {
            vector<int> AA(A);
            AA[index] = i;
            solve(AA, index + 1);
        }
    }
    else
    {
        long long int buf = 0;
        for (int i = 0; i < Q; i++)
            if ((A.at(b.at(i) - 1) - A.at(a.at(i) - 1)) == c.at(i))
                buf += d.at(i);

        ans = max(buf,ans);
    }
}

int main()
{

    cin >> N >> M >> Q;

    for (int i = 0; i < Q; i++)
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

    vector<int> A(N, 1);
    solve(A, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<pair<int,int>> q;
    priority_queue<int> p;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        q.push({-a,b});
    }    
    int now = 1;
    ll ans = 0;
    while(!q.empty() || !p.empty()){
        while(!q.empty() && -q.top().first == now){
            p.push(q.top().second);
            q.pop();
        }
        if(!p.empty()){
            ans += p.top();
            p.pop(); 
        }
        now++;
        if(now == m+1) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1908
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    int h,w;
    char line[256];

    while (1) {

        if (!fgets(line, sizeof(line), stdin)) {
            fprintf(stderr, "error input val\n");
            return -1;
        }

        if (sscanf(line, "%d %d", &h, &w) != 2) {
            fprintf(stderr, "error input format\n");
            return -1;
        }

        if (!h && !w) {
            return 0;
        }

        int i,j;

        for (i=0; i<h; i++){
            for (j=0; j<w; j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 588
package main

import "fmt"

func min(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}

	dp := make([]int, n)
	for i := range dp {
		dp[i] = 10000000000000 // +Inf
	}
	dp[0] = 0

	for i := 0; i < n; i++ {
		for j := i + 1; j <= i+k && j < n; j++ {
			dp[j] = min(dp[j], abs(h[i]-h[j])+dp[i])
		}
	}

	fmt.Println(dp[len(dp)-1])
}


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

int main() {

	int N;
	int first,second,third,fourth;
	
	cin >> N;
	first = N/1000;
	second = N%1000/100;
	third = N%1000%100/10;
	fourth = N%1000%100%10;
	
	
	if(((first == second) && (second == third)) || ((third == fourth) && (second == third))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int H, N, x;
	scanf("%d%d", &H, &N);
	int A[N], i=0, sum=0, t=1;
	while(scanf("%d", &x) == t) {
		A[i++] = x;
		sum += x;
		if(i == N) break;
	}
	if(sum < H) printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
n, c = [int(i) for i in input().split()]
D = [[int(i) for i in input().split()] for j in range(c)]
C = [[int(i) for i in input().split()] for j in range(n)]
 
X = [[0]*c for i in range(3)]
 
for i in range(n):
    for j in range(n):
        X[(i+j+2)%3][C[i][j]-1] += 1
 
cost = [[0]*c for i in range(3)]
 
for i in range(c):
    for j in range(c):
        cost[0][j] += X[0][i] * D[i][j]
        cost[1][j] += X[1][i] * D[i][j]
        cost[2][j] += X[2][i] * D[i][j]
 
ans = []
 
for i in range(c):
    for j in range(c):
        for k in range(c):
            if i != j and j != k and k != i:
                ans.append(cost[0][i] + cost[1][j] + cost[2][k])
 
print(min(ans))


Measured memory_bytes: 44380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll data[3001];
ll dp[3001][3001];
ll Solve(int a, int b, ll acum)
{
    if(dp[a][b] == 0) 
    {
        if (a == b)
            dp[a][b] = data[a];
        else 
        {
            Solve(a + 1, b, acum - data[a]);
            Solve(a, b - 1, acum - data[b]);
            dp[a][b] = acum - min(dp[a + 1][b], dp[a][b - 1]);
        }
    }
    return dp[a][b];
}
int main() {
    int n;
    cin >> n;
    ll acum = 0;
    for(int i = 1; i <= n; ++i) 
    {
        cin >> data[i];
        acum += data[i];
    }
    ll best = Solve(1, n, acum);
    cout << 2 * best - acum << "\n";
    return 0;
}

Measured memory_bytes: 70272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	while(cin>>s)
	{
		int n=s.size();
		int flag=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]==s[i+1]&&i+1<n)
			{
		
				cout<<i+1<<" "<<i+2<<"\n";
				flag=1;
				break;
			}
			if(s[i]==s[i+2]&&i+2<n)
			{
				cout<<i+1<<" "<<i+3<<"\n";
				flag=1;
				break; 
			}
		}
		if(!flag)
		cout<<-1<<" "<<-1<<"\n";	
	}

	return 0;
} 

Measured memory_bytes: 512
//34
#include<iostream>

using namespace std;

const int M=100000007;

int main(){
  int nnl[2][100001]={{}};
  int nlp[2][100001]={{}};
  for(int i=0;i<2;i++){
    int s=3+i*2;
    nnl[i][0]=nlp[i][0]=1;
    for(int j=1;j<=100000;j++){
      for(int k=1;k<=s;k++){
	if(j-k<0)break;
	nnl[i][j]=(nnl[i][j]+nnl[i][j-k])%M;
      }
      nlp[i][j]=(nnl[i][j]+((j-s<1)?0:nlp[i][j-s]))%M;
    }
  }
  for(char c;cin>>c,c!='#';){
    char p=0;
    int cc=0;
    long long a=1;
    for(;;cin.get(c)){
      if(c==p){
	cc++;
      }else{
	a=(a*nlp[p!='8'&&p!='0'][cc])%M;
	p=c;
	cc=1;
      }
      if(c=='\n')break;
    }
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 2712
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	S := next()
	for i := 0; i < len(S)-1; i++ {
		if S[i] == S[i+1] {
			fmt.Println("Bad")
			return
		}
	}

	fmt.Println("Good")
}

Measured memory_bytes: 640
a = list(map(int, input().split()))
for i in range(3):
    if a[i] % 2:
        print(0)
        exit()
ans = 0
while True:
    if len(set(a)) == 1:
        print(-1)
        exit()
    ans += 1
    t = tuple(a)
    a[0] = (t[1] + t[2])//2
    a[1] = (t[0] + t[2])//2
    a[2] = (t[0] + t[1])//2
    for i in range(3):
        if a[i] % 2:
            print(ans)
            exit()


Measured memory_bytes: 3064
n,m,x = map(int,input().split())
books = []
for i in range(n):
	books.append(list(map(int,input().split())))

mincost = 10**9
for i in range(2**n):
	cost = 0
	knowledge = [0]*m
	for j in range(n):
		if i%2 == 1:
			cost += books[j][0]
			for b in range(m):
				knowledge[b] += books[j][b+1]
		i = i >> 1
	if min(knowledge) >= x and cost < mincost:
		mincost = cost

if mincost == 10**9:
	print(-1)
else:
	print(mincost)

Measured memory_bytes: 9196
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7

# dsu / UnionFind


def init_unionfind(N):
    global parent, rank
    parent = [-1] * N
    rank = [0] * N


def find_root(x):
    p = parent[x]
    if p == -1:
        return x
    p2 = find_root(p)
    parent[x] = p2
    return p2


def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if x == y:
        return  # already united
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def is_connected(x, y):
    return (find_root(x) == find_root(y))

# acl/dsu


init = init_unionfind
merge = unite
# FIXME: return value

same = is_connected
leader = find_root


def size(a):
    raise NotImplementedError


def group(a):
    raise NotImplementedError
# ---


def debug(*x):
    print(*x, file=sys.stderr)


def main():
    # parse input
    N, Q = map(int, input().split())
    init(N)
    for _q in range(Q):
        q, u, v = map(int, input().split())
        if q == 0:
            merge(u, v)
        else:
            print(int(same(u, v)))


# tests
T1 = """
4 7
1 0 1
0 0 1
0 2 3
1 0 1
1 1 2
0 0 2
1 1 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
0
1
0
1
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 82336
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

int fib(int* f, int n) {
    if (f[n] == 0) {
        f[n] = fib(f, n-1) + fib(f, n-2);
    }
    return f[n];
}

int main() {
    int n;
    std::cin >> n;
    int f[50] = {1, 1};

    std::cout << fib(f, n) << "\n";
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M, l, r, L, R;
    cin >> N >> M;
    REP(i, M) {
        cin >> L >> R;
        if (i == 0) {
            l = L;
            r = R;
        } else {
            l = max(l, L);
            r = min(r, R);
        }
    }
    cout << max(r - l + 1, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
	if((r*100+g*10+b)%4==0){	
		printf("YES\n");
	}
	else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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 long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int r;
    
    cin >> r;
    
    if (r<1200){
    
    cout << "ABC" << endl;
    
    }else if(r>=1200 && r<2800){
    
    cout << "ARC" << endl;
    
    }else{
    
    cout << "AGC" << endl;
    
    }
    
    
    
    
    
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
/***
coded by adarsh
***/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef vector<ll> vec; 
typedef vector<vector<ll>> vec2;
typedef pair<ll,ll> pair1;
typedef pair<string,ll> pair2;
typedef pair<ll,string> pair3;
typedef pair<string,string> pair4;
#define fl(i,a,b) for(i=a;i<b;i++)
#define rfl(i,a,b) for(i=b-1;i>=a;i--)
#define f first
#define s second

int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b;cin>>a>>b;
    if(a*500>=b) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 3588
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

#ifndef M_PI
#define M_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406
#endif

int main() {
  double a, b, x;
  std::cin >> a >> b >> x;

  const double tan_theta = 2 * x >= a * a * b
    ? 2 * (a * a * b - x) / (a * a * a)
    : (a * b * b) / (2 * x);
  const double theta = std::atan(tan_theta);
  const double answer = theta / M_PI * 180.0;
  std::cout << std::fixed << std::setprecision(10) << answer << std::endl;

  return 0;
}

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

int main(){
    long N;
    long M = 0;
    int A[200002];
    int dp[200002];

    cin >> N;
    for(long i=1;i<=N;i++) cin >> A[i];
    for(long i=N;i>=1;i--){
        long counter = 0;
        long j = i;
        long coeff = 2;
        while(j*coeff <= N){
            counter += dp[j*coeff];
            coeff++;
        }
        dp[i] = (counter % 2) ^ A[i];
        if(dp[i] == 1) M++;
    }
    cout << M << endl;
    if(M ==0) return 0;
    for(long i=1;i<=N;i++){
        if(dp[i] == 1){
            cout << i << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
#define MAX_N 100011
#define N MAX_N
#define rank dfasfds
using namespace std;
typedef long long ll;
typedef vector<int>::iterator V;
int par[MAX_N],rank[MAX_N];
ll val[MAX_N];
vector<int> G[N];

void init(int n){for(int i=0;i<N;i++)par[i]=i,rank[i]=0;}

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

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

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

int used[N];
vector<int> path;
void dfs(int pos,int pre){
  if(used[pos]||pos!=find(pos)) {
    while(path.size())unite(0,path.back()),path.pop_back();
    return;
  }
  used[pos]=1;
  path.push_back(pos);
  for(V it=G[pos].begin();it!=G[pos].end();it++)if(*it!=pre)dfs(*it,pos);
  used[pos]=0;
  if(path.size()&&path.back()==pos) path.pop_back();
}

vector<int>col[N];
ll get_mx(int pos){
  used[pos]=1;
  ll res=0;
  for(int i=0;i<col[pos].size();i++)
    for(V it=G[col[pos][i]].begin();it!=G[col[pos][i]].end();it++)
      if(!used[find(*it)])res=max(res,get_mx(find(*it)));
  return res+val[find(pos)];
}

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>val[i];
  for(int i=0,a,b;i<m;i++){
    cin>>a>>b;a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  init(n);
  dfs(0,-1);
  for(int i=0;i<n;i++) col[find(i)].push_back(i);
  cout <<get_mx(find(0))<<endl;

  return 0;
}

Measured memory_bytes: 23800
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const ll MX = 1e10 + 7;

vector <ll> x;
set <ll> vis;

void rec(ll n) {
  if (n > MX) return;
  if (vis.count(n)) return;
  vis.insert(n);
  x.push_back(n);
  ll y = n % 10;
  rec(n * 10 + y);
  if (n % 10 != 9) {
    rec(n * 10 + y + 1);
  }
  if (n % 10 != 0) {
    rec(n * 10 + y - 1);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i < 10; i++) rec(i);
  sort(x.begin(), x.end());
  cout << x[n - 1] << '\n';
  return 0;
}

Measured memory_bytes: 11120
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local unpack = table.unpack or unpack
local insert = table.insert or insert
local max = math.max
----
local function adj_list(num_nodes)
    local t = {}
    for n=1, num_nodes do
        t[n] = {}
    end
    return t
end
----
local N, M = read.nn()
local edges = adj_list(N)
local rev_adj_mat = array(2, nil)
for i=1,M do
    local x, y = read.nn()
    edges[x][#edges[x] + 1] = y
    rev_adj_mat[y][x] = true
end
local function indeg_zero(n)
    for k, v in pairs(rev_adj_mat[n]) do
        if v then
            return false
        end
    end
    return true
end

local toposorted = {}
local q = {}
for n=1,N do
    if indeg_zero(n) then
        insert(q, n)
    end
end
local front = 1
local back = #q + 1
local function push(v)
    q[back] = v
    back = back + 1
end
local function pop()
    local r = q[front]
    front = front + 1
    return r
end
local function empty()
    return back - front == 0
end

while not empty() do
    local n = pop()
    insert(toposorted, n)
    for k, m in pairs(edges[n]) do
        rev_adj_mat[m][n] = nil
        if indeg_zero(m) then
            push(m)
        end
    end
end
--[[
for k, v in pairs(toposorted) do
    print(k, v)
end
]]
local lp_from = array(1, 0)
for _, n in pairs(toposorted) do
    for _, m in pairs(edges[n]) do
        lp_from[m] = max(lp_from[m], lp_from[n] + 1)
    end
end
local ans = 0
for _, lp in pairs(lp_from) do
    ans = max(ans, lp)
end
print(ans)

Measured memory_bytes: 64232
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
	ll N,M;
	cin >> N >> M;

	ll cnt=0;
	if (M >= N * 2) {
		M -= N*2;
		cnt += N;
		N=0;
	}
	else if(M>=2){
		cnt += M/2;
		N -= M/2;
		M %= 2;
	}
	else {
		cout << 0 << endl;
		return 0;
	}
	//cout << N <<" "<< M << endl;

	cnt += M/4;
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fe first
#define se second
#define endl "\n"
#define pii pair<int, int>

#define PI 3.14159265358979323846
const int N = 1e3 + 10;
int n,m;
char to[N][N];
int MOD=1e9+7;

void check(int& a,int b) {
	   a+=b;
	   if(a>=MOD)
	    a -= MOD;	
	}


void solve() {
    cin>>n>>m;
    for(int i=0;i<n;i++)
       cin>>to[i];
    vector<vector<int>> dp(n,vector<int>(m));
    dp[0][0]=1;
    for(int i=0;i<n;i++) {
		 for(int j=0;j<m;j++) {
			          int r2=i,col=j+1;
			          if(r2<n && col<m && to[r2][col]=='.') {
						      check(dp[r2][col],dp[i][j]);						  
						  }
						r2=i+1 ,col=j;
						if(r2<n && col<m && to[r2][col]=='.') {
							  check(dp[r2][col],dp[i][j]);
							}						  
				  
				  }	    
			 
			 }
 		
 		
 		cout<<dp[n-1][m-1];	
			
}		

int main() {
  cool;
  int t = 1;
  while (t--)
    solve();

  return 0;
}


Measured memory_bytes: 5248
a, b, m = map(int, input().split())

a_A = list(map(int, input().split()))
b_B = list(map(int, input().split()))

summ = min(a_A) + min(b_B)

x = []
y = []
c = []

for i in range(m):
    x, y, c = map(int, input().split())
    # x.append(x_t)
    # y.append(y_t)
    # c.append(c_t)
    discount = a_A[x - 1] + b_B[y - 1] - int(c)

    if discount < summ:
        summ = discount

print(summ)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,m;
int niz[100005];
vector<int> graf[100005];


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    string x;
    cin >> x;
    if(x == "ABC")cout << "ARC";
    else cout << "ABC";
    return 0;
}


Measured memory_bytes: 6008
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdint.h>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair<int ,int> pp;
typedef long long ll;
const ll MOD = 1000000007;
int weight[3000];
int value[3000];
int dp1[3001][3001];
int dp[3001][3001];

int main(){
    int n,t;
    cin>>n>>t;
    for(int i = 0; i < n; i++){
        cin>>weight[i]>>value[i];
    }
    for (int w = 0; w <= t; w++){
        dp[0][w] = 0;
        dp1[0][w] = 0;
    }
    for(int i = 0; i < n; i++){
        dp[i][0] = 0;
    }

    for (int i = 0; i < n; i++) {
        for (int w = 0; w <= t; w++) {
            if (w >= weight[i]) dp1[i+1][w] = max(dp1[i][w-weight[i]] + value[i], dp1[i][w]);
            else dp1[i+1][w] = dp1[i][w];
        }
    }


    for (int i = 0; i < n; i++) {
        for (int w = 0; w <= t; w++) {
            if (w >= weight[i]){
                dp[i+1][w] = max(dp[i][w-weight[i]] + value[i], dp[i][w]);
            }
            else dp[i+1][w] = dp[i][w];
            if(w > 0 && dp[i+1][w] < dp1[i][w-1] + value[i]){
                dp[i+1][w] = dp1[i][w-1] + value[i];
            }
        }
    }
    cout<<dp[n][t]<<endl;
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	vector<int>two(3,0);
	int ans=0;
	cin >>n;
	int bef;
	rep(i,n){
		cin>>bef;
		if(bef%4==0){
			two[2]++;
		}else if(bef%2==0){
			two[1]++;
		}else{
			two[0]++;
		}
	}
	cout<<solve(two[0] +(two[1]==0?-1:0) <=two[2])<<endl;
}

Measured memory_bytes: 384
// -----------------------------------
// Author     : MatsuTaku
// Affiliation: Tokushima University
// Country    : Japan
// Date       : 03/28/2020
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s; cin>>s;
  bool ans = s[2]==s[3] and s[4]==s[5];
  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int n,m;
long long ans;
long long fac(int a){
	long long sum=1;
	for(int i=1;i<=a;++i)
		sum=sum*i%MOD;
	return sum;
}
int main(){
	scanf("%d%d",&n,&m);
	if(abs(n-m)==1){
		ans=fac(n)*fac(m)%MOD;
	}else if(n==m){
		ans=fac(n)*fac(m)*2%MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256