akhauriyash/Code-Regression huggingface dataset:
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(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)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve() {
	string s;
	cin >> s;
	lli dp[2019];
	for (lli i = 0; i < 2019; i++) dp[i] = 0;
	dp[s[0] - '0'] = 1;
	lli ret = 0;
	lli n = s.size();
	for (lli i = 1; i < n; i++) {
		lli dp2[2019];
		for (lli i = 0; i < 2019; i++) dp2[i] = 0;
		dp2[s[i] - '0']++;
		for (lli j = 0; j < 2019; j++) {
			if (dp[j] > 0) {
				//cout << j << " " << i << endl;
				lli rem = j * 10 + (s[i] - '0');
				rem %= 2019;
				if (rem == 0) ret += dp[j];
				//cout << rem << endl;
				dp2[rem] += dp[j];
			}
		}
		for (lli j = 0; j < 2019; j++) {
			dp[j] = dp2[j];
		}
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int C = 1e9+7;
int power(int A, int B) 
{ 
    // Base cases 
    if (A == 0) 
        return 0; 
    if (B == 0) 
        return 1; 
  
    // If B is even 
    long y; 
    if (B % 2 == 0) { 
        y = power(A, B / 2); 
        y = (y * y) % C; 
    } 
  
    // If B is odd 
    else { 
        y = A % C; 
        y = (y * power(A, B - 1) % C) % C; 
    } 
  
    return (int)((y + C) % C); 
} 
int main()
{
	int n;cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)cin>>arr[i];
	sort(arr,arr+n);
	int temp,pos,req;
	if(n%2==0){
		temp = 1;
		pos = 0;
		req = n;
	}
	else{
		temp = 2;
		pos = 1;
		req = n-1;
	} 
	int ans = 0;
	for(int i=pos;i<n;i=i+2){
		if(arr[i]==temp&&arr[i+1]==temp){
			ans += 2;
		}
		else break;
		temp += 2;
	}
	if(req == ans){
		cout<< power(2,n/2);
	}
	else cout<<0;
}

Measured memory_bytes: 640
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int t = 1; 
    // cin >> t; 
    while (t--) {
        int a, b;
        cin >> a >> b;
        cout << a * b << '\n';
    }
    
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 3760
#include<stdio.h>
 
int main (void)
{ 
  int A[100][100]={0};
  int b[100]={0}, c[100]={0};
  int i, j, n, m;
  
  scanf("%d %d", &n, &m);
  
  for(j=0; j < n; j++){
  	for(i=0; i < m; i++){
  		scanf("%d", &A[i][j]);
  	}
  }
  
  
  for(i=0; i < m; i++){
  		scanf("%d", &b[i]);
  	}
  
   for(j=0; j < n; j++){
  	for(i=0; i < m; i++){
  		c[j] += A[i][j]*b[i];
  	}
  }
  
  for(j=0; j < n; j++){
  	printf("%d\n", c[j]);
  }
  
  return 0;
}

Measured memory_bytes: 648
N = int(input())

if N & (N-1) == 0:
  print("No")
  exit()

print("Yes")
print(1, 2)
print(2, 3)
print(3, N+1)
print(N+1, N+2)
print(N+2, N+3)

for i in range(4, N, 2):
  print(i, i+1)
  print(i+1, N+1)
  print(N+1, N+i)
  print(N+i, N+i+1)

if N % 2 == 0:
  print(N, N-1)
  x = N^(N-1)^1
  if x % 2 == 0:
    print(N+x, 2*N)
  else:
  	print(x, 2*N)


Measured memory_bytes: 5780
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()

int main()
{
	int N, H, W;
	cin >> N >> H >> W;
	int ans = 0;
	rep(i, N) {
		int A, B;
		cin >> A >> B;
		if (A >= H && B >= W)
			ans++;
	}
	cout << ans << endl;
	return 0;
}


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

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

const int N=2e5+10;

int a[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i],a[i]-=i;
    sort(a+1,a+n+1);
    int b=a[(n-1)/2+1];
    int ans=0;
    for(int i=1;i<=n;i++)
        ans+=abs(a[i]-b);
    cout<<ans;
}


Measured memory_bytes: 1792
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int> data;
		data.clear();
		int sum = 0;
		for(int i =0; i <n;i++){
			int x;
			cin>>x;
			data.push_back(x);
			sum+=data[i];
		}
		sort(data.begin(),data.end(),greater<int>());
		int t =data.size()/m;
		for(int i =0; i<t;i++){
			sum-=data[i*m+m-1];
		}
		cout <<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 1228
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
n, a, b = map(int, input().split())
ans = (n // (a + b)) * a
# print(ans)
if n % (a + b) != 0:
    ans += min(n % (a + b), a)
print(ans)


Measured memory_bytes: 5560
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import javax.swing.text.DefaultStyledDocument.ElementSpec;

import java.util.HashSet;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int n = sc.nextInt();
        if (n < 1200) {
            System.out.println("ABC");
        } else if (n < 2800) {
            System.out.println("ARC");
        } else {
            System.out.println("AGC");
        }
    }
}

Measured memory_bytes: 21844
def find(n):
    yakusu=[]
    for i in range(1,n+1):
        if n%i==0:
            if (n/i) in yakusu:
                break
            else:
                yakusu.append(i)
                yakusu.append(n/i)
    return len(yakusu)

n=int(input())
num=0
for i in range(1,n+1,+2):
    if find(i)==8:
        num+=1
print(num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s.size()>=2&&s.size()%2==0)
  {
  for(int i=0;i<s.size();i++)
  {
    if(i%2==0&&s[i]!='h')
    {
      cout<<"No"<<endl;
      return 0;
    }
    else if(i%2!=0&&s[i]!='i')
    {
      cout<<"No"<<endl;
      return 0;
    }
  }
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;
  }

  return 0;
}

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

int main()
{
	int n;
	cin>>n;
	if (n%2 != 0)
		cout<<"No";
	else
	{
		string s;
		cin>>s;
		for (int i = 0; i < s.size()/2 ; i++)
			if (s[i] != s[s.size()/2 + i])
			{
				cout<<"No";
				return 0;
			}
		cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	a = (a + 12) % 13;
	if (a == 0) {
		a = 13;
	}
	b = (b + 12) % 13;
	if (b == 0) {
		b = 13;
	}
	if (a > b) {
		cout << "Alice" << endl;
	}
	else if (a == b) {
		cout << "Draw" << endl;
	}
	else {
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	static int F => int.Parse(Str);
	static long FL => long.Parse(Str);
	static int[] G => Strs.Select(int.Parse).ToArray();
	static decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	static long[] GL => Strs.Select(long.Parse).ToArray();
	static string Str => ReadLine();
	static string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	static int N;
	void Solve()
	{
		var I = G;
		N = I[0];
		WriteLine(ToString(Calc(Get(), Get(), I[1] - 1)));
	}
	static int[] Get() => G.Select(i => i - 1).ToArray();
	static string ToString(int[] p) => string.Join(" ", p.Select(i => i + 1));
	static int[] Calc(int[] p, int[] q, int K)
	{
		if (K == 0) return p;
		if (K == 1) return q;
		if (K < 6) return Calc(q, Mult(q, Inv(p)), K - 1);
		int[] ip = Inv(p), iq = Inv(q), x = Mult(q, ip, iq, p), y = Mult(ip, q, p, iq);
		switch (K % 6)
		{
			case 0: return Mult(Pow(x, K / 6), q, p, iq, Pow(y, K / 6 - 1));
			case 1: return Mult(Pow(x, K / 6), q, Pow(y, K / 6));
			case 2: return Mult(Pow(x, K / 6), q, ip, Pow(y, K / 6));
			case 3: return Mult(Pow(x, K / 6), q, ip, iq, Pow(y, K / 6));
			case 4: return Mult(Pow(x, K / 6 + 1), iq, Pow(y, K / 6));
			default: return Mult(Pow(x, K / 6 + 1), p, iq, Pow(y, K / 6));
		}
	}
	static int[] Inv(int[] a)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[a[i]] = i;
		return c;
	}
	static int[] Mult(int[] a, int[] b)
	{
		var c = new int[N];
		for (var i = 0; i < N; i++) c[i] = a[b[i]];
		return c;
	}
	static int[] Mult(params int[][] a)
	{
		if (a.Length == 0) return MakeArray(N, i => i);
		var x = a[0];
		for (var i = 1; i < a.Length; i++) x = Mult(x, a[i]);
		return x;
	}
	static int[] Pow(int[] a, int b)
	{
		var p = new int[N];
		var done = new bool[N];
		for (var i = 0; i < N; i++)
			if (!done[i])
			{
				done[i] = true;
				var cycle = new List<int> { i };
				var x = a[i];
				while (x != i) { cycle.Add(x); done[x] = true; x = a[x]; }
				var L = cycle.Count;
				var c = b % L;
				for (var j = 0; j < L; j++) p[cycle[j]] = cycle[(j + c) % L];
			}
		return p;
	}
}


Measured memory_bytes: 42672
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define ld long double
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=1e6+5;
const ll mod=1e9+7;

vector<ll> spf(maxn,-1);
vector<bool> p(maxn,true);
void sieve(){
	for(ll i=2;i<=maxn;++i){
		if(p[i]){
			spf[i]=i;
			for(ll j=2*i;j<=maxn;j+=i){
				p[j]=false; 
				spf[j]=i;
			}
		}
	
	}
}
int main(){
	fast;
	ll n,k,i,j,x,res;
	cin>>n;
	vector<ll> a(n);
	for(i=0;i<n;i++){
		cin>>a[i];
		if(i>0)
		res=__gcd(res,a[i]);
		else
		res=a[0];
	}
	
	sieve();
	set<ll> s2;
	ll f=0;
	for(ll x : a){
		set<ll> s1;
		if(x>1){
			while(x>1){
				s1.insert(spf[x]);
				x/=spf[x];
			}
			ll p1=(ll)s1.size();
			ll p2=(ll)s2.size();
			for(ll x : s1){
				s2.insert(x);
			}
			if((ll)s2.size()==(p1+p2)){
				
			}
			else{
				f=1;
				break;
			}
		}
	}
	if(!f){
		cout<<"pairwise coprime";
	}
	else if(res==1){
		cout<<"setwise coprime";
	}
	else
		cout<<"not coprime";
	
		
	
	
}

Measured memory_bytes: 18968
#include <bits/stdc++.h>
using namespace std;
long long f(long long in){
    if(in%2==0){
        return in/2;
    }else{
        return (3*in+1);
    }
}
int main(){
    long long s;
    cin >> s;
    vector <long long> a;
    a.push_back(s);
    long long cnt = 1;
    while(true){
        cnt++;
        long long tmp = f(a.back());
        for(long long i = 0; i < a.size(); i++){
            if(a[i]==tmp){
                cout << cnt << endl;
                return 0;
            }
        }
        a.push_back(tmp);
    }
    return 0;
}


Measured memory_bytes: 3512
N, M = map(int, input().split())
XY = [list(map(int, input().split())) for i in range(M)]
boxes = [1] * (N+1)
reded = [False] * (N+1)
boxes[0] = 0
reded[1] = True

for x, y in XY:
    boxes[x] -= 1
    boxes[y] += 1

    if reded[x]:
        reded[y] = True

    if boxes[x] == 0:
        reded[x] = False

ans = 0
for n, r in zip(boxes, reded):
    if n and r:
        ans += 1
print(ans)

Measured memory_bytes: 28836
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;

uint32_t conv(string s){
        if (s ==  "1") return 1;
        if (s ==  "2") return 2;
        if (s ==  "3") return 3;
        if (s ==  "4") return 4;
        if (s ==  "5") return 5;
        if (s ==  "6") return 6;
        if (s ==  "7") return 7;
        if (s ==  "8") return 8;
        if (s ==  "9") return 9;
        return 0;
}
int main(void)
{
    string s;
    cin >> s;
    
    uint32_t min_error = -1;
    for (uint32_t i = 0; i <= s.size()-3; i++) {
        int32_t num = conv(s.substr(i,1))*100 + conv(s.substr(i+1,1))*10 + conv(s.substr(i+2,1));
        //cout << num << endl;
        if (std::abs(num-753) < min_error) min_error = std::abs(num-753);
    }

    cout << min_error;

    return 0;
}



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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ll l, r;
  cin >> l >> r;
  int ans = 2018;
  r = min(r, l + 4038);
  FOR(i, l, r + 1) {
    FOR(j, i + 1, r + 1) {
      int m = (i * j) % 2019;
      ans = min(ans, m);
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	string s;
	cin >> s;
	int mi = 1 << 30;
	for(int i = 0; i < s.length() - 2; ++i)
	{
		mi = min(mi, abs(((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0') * 1) - 753));
	}
	printf("%d\n", mi);
}

Measured memory_bytes: 256
H, W = map(int, input().split())
ans = min(((W+2)//3 - W//3)*H, ((H+2)//3 - H//3)*W)
S = H * W
s = [0]*3

for w in range(1,W):
    s[0] = (H+1)//2*w
    s[1] = H//2*w
    s[2] = S - (s[0]+s[1])
    ans = min(ans,max(s)-min(s))

for h in range(1,H):
    s[0] = (W+1)//2*h
    s[1] = W//2*h
    s[2] = S - (s[0]+s[1])
    ans = min(ans,max(s)-min(s))

print(ans)

Measured memory_bytes: 3064
N,C=map(int,input().split(' '))
D=[]
for _ in range(C):
  D.append([ x for x in map(int,input().split(' '))])

c=[]
for _ in range(N):
  c.append([ x for x in map(int,input().split(' '))])

x=float('inf')

memo={}

counter=[[0]*C for _ in range(3)]
for i in range(N):
  for j in range(N):
    b=i%3
    cur=c[i][j]
    counter[(j+b)%3][cur-1]+=1
    #s+=D[cur-1][seq[(j+b)%3]]

for c0 in range(C):
  for c1 in range(C):
    if c1==c0:
      continue
    for c2 in range(C):
      if c2==c0 or c2==c1:
        continue
      s=0
      for i, cx in enumerate(counter[0]):
        s+=D[i][c0]*cx
      for i, cx in enumerate(counter[1]):
        s+=D[i][c1]*cx
      for i, cx in enumerate(counter[2]):
        s+=D[i][c2]*cx
      if s<x:
        x=s


print(x)



Measured memory_bytes: 5492
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.max;
import static java.lang.System.exit;
import static java.util.Arrays.fill;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void solve() throws Exception {
		int n = scanInt();
		boolean edge[][] = new boolean[n][n];
		for (int i = 0; i < n; i++) {
			String l = scanString();
			for (int j = 0; j < n; j++) {
				edge[i][j] = l.charAt(j) == '1';
			}
		}
		int dist[] = new int[n], queue[] = new int[n];
		int maxDist = 0;
		for (int i = 0; i < n; i++) {
			fill(dist, Integer.MAX_VALUE);
			dist[i] = 0;
			queue[0] = i;
			int queueHead = 0, queueTail = 1;
			do {
				int cur = queue[queueHead++];
				for (int j = 0; j < n; j++) {
					if (edge[cur][j] && dist[j] == Integer.MAX_VALUE) {
						maxDist = max(maxDist, dist[j] = dist[cur] + 1);
						queue[queueTail++] = j;
					} else if (edge[cur][j] && dist[j] == dist[cur]) {
						out.print(-1);
						return;
					}
				}
			} while (queueHead != queueTail);
		}
		out.print(maxDist + 1);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

//	高橋君はタップダンスをすることにしました。タップダンスの動きは文字列 
//	S
//	 で表され、
//	S
//	 の各文字は L, R, U, D のいずれかです。各文字は足を置く位置を表しており、
//	1
//	 文字目から順番に踏んでいきます。
//
//	S
//	 が以下の 
//	2
//	 条件を満たすとき、またその時に限り、
//	S
//	 を「踏みやすい」文字列といいます。
//
//	奇数文字目がすべて R, U, D のいずれか。
//	偶数文字目がすべて L, U, D のいずれか。
//	S
//	 が「踏みやすい」文字列なら Yes を、そうでなければ No を出力してください。

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String text = sc.next();
		
		for(int i = 0; i < text.length(); i++) {
			char c = text.charAt(i);
			if((c == 'U') || (c == 'D')) {
				continue;
			}
			if(i%2 == 0) {
				if(c != 'R') {
					System.out.println("No");
					return;
				}
			}else if(i%2 == 1) {
				if(c != 'L') {
					System.out.println("No");
					return;
				}
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 22612
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Aman
 */


#include<bits/stdc++.h>

using namespace std;

#include <iostream>


#define ll   long long
#define F first
#define S second
#define pll pair<ll, ll>

void __print(int x) { cout << x; }

void __print(long x) { cout << x; }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cout << '{';
    __print(x.first);
    cout << ',';
    __print(x.second);
    cout << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cout << '{';
    for (auto &i: x) cout << (f++ ? "," : ""), __print(i);
    cout << "}";
}

void _print() { cout << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cout << ", ";
    _print(v...);
}


#ifdef LOCAL
#else
#define dbg(x...)
#endif


class DLeapingTak {
public:

    void solve2(std::istream &cin, std::ostream &cout) {
        ll n, k, m = 998244353;
        cin >> n >> k;
        vector<ll> dp(n + 1, 0), p(n + 1, 0);
        dp[1] = 1;
        p[0] = 0;
        vector<pll > v(k);
        for (auto &i:v) cin >> i.F >> i.S;
        for (ll i = 1; i <= n; i++) {
            for (pll e:v) {
                ll l = e.F, r = e.S;
                if (i < l) continue;
                l = i - l;
                r = i - r;
                dp[i] += p[l] - (r > 0 ? p[r - 1] : 0);
                dp[i] %= m;
                if (dp[i] < 0) dp[i] += m;
            }
            p[i] = (p[i - 1] + dp[i]) % m;
        }
        cout << dp[n];
    }

    void solve(std::istream &cin, std::ostream &cout) {
        ll t = 1;
//            cin >> t;
        while (t--) {
            solve2(cin, cout);
        }
    }

};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    DLeapingTak solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 6360
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    p.sort(reverse=True)
    q.sort(reverse=True)
    r = p[:x]+q[:y]+r
    r.sort(reverse=True)
    print(sum(r[:x+y]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 29508
(w, h, n) = map(int, raw_input().split())

ans = 0
(nx, ny) = (0, 0)
for i in range(n):
  (x, y) = map(int, raw_input().split())

  if i != 0:
    dx = x - nx
    dy = y - ny

    ans += abs(dx) + abs(dy)
    if dx * dy > 0:
      ans -= min(abs(dx), abs(dy))

  nx = x
  ny = y

print ans

Measured memory_bytes: 4244
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> w,c,dp;


int main()
{
    int i,j;
    string s,t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size()+1,vector<int> (t.size()+1,0)),m(s.size()+1,vector<int> (t.size()+1,-1));

    for(i = 1;i <= s.size();i++){
        for(j=1; j<= t.size();j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else if(dp[i-1][j] > dp[i][j-1]){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = dp[i][j-1];
            }
        }
    }
 
    string ans = "";
    int n = s.size(),mp = t.size();
    for(i = n,j=mp;i >0 && j>0;){
       if(s[i-1] == t[j-1]){
           ans = s[i-1]+ans;
           i--;
           j--;
       }
       else if(dp[i-1][j] > dp[i][j-1]){
           i--;
       }
       else{
           j--;
       }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 70784
import * as fs from 'fs';

namespace AtCoder.abc137 {

    export class Program {
        args: string[];

        constructor(args: string[]) {
            this.args = args;
        }

        /**
         * in
         * 3 7
         * out
         * 5 6 7 8 9
         */
        main(): void {
            const [k, x] = this.args[0].split(' ').map(Number);

            let min: number = 0;
            let max: number = 0;

            min = x - k;
            max = x + k;
            // min = (x - k < -1000000) ? -1000000 : x - k;
            // max = (x + k > 1000000) ? 1000000 : x + k;

            let ans: string = '';
            for (let i = min + 1; i < max; i++) {
                ans += i.toString() + ' ';
            }
            console.log(ans.trim());


        }
    }

}

const args = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const prg = new AtCoder.abc137.Program(args);
prg.main();




Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
int i,j,k,n;
bool dislike[10];

bool cek(int x)
{
	while (x>0)
	{
		int buntut=x%10;
		if (dislike[buntut])
		 return false;
		x/=10;
	}
	return true;
}

int main()
{
	memset(dislike,0,sizeof(dislike));
	cin>>n>>k;
	for (i=1;i<=k;i++)
	{
		cin>>j;
		dislike[j]=1;
	}
	while (1)
	{
		if (cek(n))
		{
			cout<<n<<"\n";
			return 0;
		}
		n++;
	}
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, k, ans = 0;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++)
  {
    int x;
    scanf("%d", &x);
    ans += MIN(x, abs(k - x)) * 2;
  }
  printf("%d\n", ans);
  return 0;
}

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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 100005;

int n, M;
int dp_down[N], dp_up[N], res[N];
vector<int> g[N];

void add(int &x, int y){
  x += y;
  if(x >= M) x -= M;
}

void mul(int &x, int y){
  x *= y;
  x %= M;
}

void dfs(int u, int p = -1){
  dp_down[u] = 1;
  for(int v : g[u]){
    if(v == p) continue;
    dfs(v, u);
    mul(dp_down[u], (long long)(1 + dp_down[v]) % M);
  }
}

void dfs1(int u, int p = -1){
  vector<int> children;
  for(int v : g[u]){
    if(v == p) continue;
    children.push_back(v);
  }
  int tot = children.size();
  if(!tot) return;
  vector<int> pref(tot), suf(tot);
  pref[0] = (1 + dp_down[children[0]]) % M;
  for(int i = 1; i < tot; ++i){
    pref[i] = (pref[i - 1] * (1 + dp_down[children[i]]) % M) % M;
  }
  suf[tot - 1] = (1 + dp_down[children[tot - 1]]) % M;
  for(int i = tot - 2; i >= 0; --i){
    suf[i] = (suf[i + 1] * (1 + dp_down[children[i]]) % M) % M;
  }
  for(int i = 0; i < tot; ++i){
    int tempAns = 1;
    if(i > 0) mul(tempAns, pref[i - 1]);
    if(i < tot - 1) mul(tempAns, suf[i + 1]);
    dp_up[children[i]] = (1 + (dp_up[u] * tempAns) % M) % M;
  }
  for(int v : g[u]){
    if(v != p)
      dfs1(v, u);
  }
}

int32_t main(){

//  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  
  cin >> n >> M;
  for(int i = 0; i < n - 1; ++i){
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }
  dfs(1); // get dp_down values
  dp_up[0] = dp_up[1] = 1;
  dfs1(1); // get dp_up values
  for(int i = 1; i <= n; ++i){
    int tempAns = (dp_up[i] * dp_down[i]) % M;
    cout << tempAns << '\n';
  }

	return 0;
}



Measured memory_bytes: 24960
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }




int main() {
	int ans = 0;
	string s;
	
	while (cin>>s) {
		string t = s;
		reverse(all(t));
		if (t==s) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

class UnionFind
{
public:
	UnionFind(ll size) : parent(size), rank(size),diff_weight(size) {
		for (ll i = 0; i < size; i++) {
			parent[i] = i;
			rank[i] = 0;
			diff_weight[i] = 0;
		}
	};

	ll root(ll x) {
		if (parent[x] == x) {
			return x;
		}
		else {
			ll p = root(parent[x]);
			diff_weight[x] += diff_weight[parent[x]];
			return parent[x] = p;
		}
	}

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

	bool unite(ll x, ll y,ll w) {
		w += weight(x) - weight(y);

		x = root(x);
		y = root(y);
		if (x == y) return false;

		if (rank[x] < rank[y]) {
			parent[x] = y;
			diff_weight[x] = -w;
		}
		else {
			parent[y] = x;
			diff_weight[y] = w;
			if (rank[x] == rank[y]) rank[x]++;
		}

		return true;
	}

	ll weight(ll x) {
		root(x);
		return diff_weight[x];
	}

	ll diff(ll x, ll y) {
		return diff_weight[y] - diff_weight[x];
	}

private:
	//parent[i]==j  : iの親がj
	vector<ll> parent;
	vector<ll> rank;
	vector<ll> diff_weight;

};

//変数
ll N, M;
ll k;

//解法
void solve() {

	cin >> N >> M;

	UnionFind UF(N);

	bool ans = true;

	rep(i, M) {
		ll L=0, R=0, D=0;
		cin >> L >> R >> D;
		L--; R--;

		if (UF.same(L, R) == true) {
			if (UF.diff(L, R) != D) {
				ans = false;
				break;
			}
		}
		else {
			UF.unite(L, R, D);
		}

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

	return;
}

int main() {

	//入力

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 2560
s=input()
form=int(s[:2])
latt=int(s[2:])

if 0<form<=12:
  if 0<latt<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif 0<latt<=12:
  print("YYMM")
else:
  print("NA")

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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
  std::vector<std::set<int64_t>> no(n, std::set<int64_t>());

  for (int64_t i = 0; i < n - 1; i++) {
    int64_t a, b;
    std::cin >> a >> b;
    a--;
    b--;
    if (n <= a || n <= b || a < 0 || b < 0) {
      std::cout << "kasu" << std::endl;
      return 0;
    }
    no[a].insert(b);
    no[b].insert(a);
  }

  constexpr int64_t mod = 1000000007;

  std::vector<int64_t> fac(std::max(1l, k - 1));
  fac[0] = 1;
  for (int64_t i = 1; i < k - 1; i++) {
    fac[i] = fac[i - 1] * (k - i - 1) % mod;
  }

  int64_t ans = k % mod;
  std::vector<bool> flag(n, false);
  flag[0] = true;

  for (int64_t i = 1; i <= no[0].size(); i++) {
    ans *= k - i;
    ans %= mod;
  }

  std::deque<int64_t> q;
  for (const auto i : no[0]) {
    q.push_back(i);
  }

  while (!q.empty()) {
    const auto i = q.front();
    q.pop_front();
    std::vector<int64_t> tmp;
    flag[i] = true;
    for (const auto j : no[i]) {
      if (!flag[j]) {
        tmp.push_back(j);
      }
    }

    if (fac.size() <= tmp.size()) {
      std::cout << 0 << std::endl;
      return 0;
    }
    ans *= fac[tmp.size()];
    ans %= mod;
    for (const auto i : tmp) {
      q.push_back(i);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}


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

namespace Q1
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');

            int X = int.Parse(strs[0]);
            int A = int.Parse(strs[1]);

            if (X < A)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine("10");
            }
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    String[] s = new String[N];
    for (int i = 0; i < N; i++) {
      s[i] = sc.next();
    }
    Arrays.sort(s);
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < N; i++) {
      builder.append(s[i]);
    }
    System.out.println(builder.toString());
  }
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int H, W;
	vector<string> a;

	cin >> H >> W;
	a.resize(H);
	for(int i = 0; i < H; i++)
		cin >> a[i];

	set<int> h,w;
	for(int i = 0; i < H; i++)
		if(a[i] == string(W,'.'))
			h.insert(i);

	for(int i = 0; i < W; i++){
		bool check = true;
		for(int j = 1; j < H; j++)
			if(a[j][i] != a[j-1][i])
				check = false;
		if(check && a[0][i] == '.' && H > 1)
			w.insert(i);
	}

	for(int i = 0; i < H; i++){
		bool check = false;
		for(int j = 0; j < W; j++)
			if(h.find(i) == h.end() && w.find(j) == w.end()){
				cout << a[i][j];
				check = true;
			}
		if(check)
			cout << endl;
	}

	return 0;
}

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

using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<ll> s(n);
    for(int i=0;i<n;i++) cin>>s[i];

    auto calc=[&](vector<vector<ll>> &sum){
        for(int i=1;i<n;i++){
            sum[i].push_back(0);
            for(int j=0;j<n;j+=i){
                sum[i].push_back(sum[i].back()+s[j]);
            }
        }
    };
    vector<vector<ll>> sum0(n);
    calc(sum0);
    reverse(s.begin(),s.end());
    vector<vector<ll>> sum1(n);
    calc(sum1);
    reverse(s.begin(),s.end());

    vector<vector<int>> divs(n);
    for(int i=1;i<n;i++){
        for(int j=i;j<n;j+=i){
            divs[j].push_back(i);
        }
    }

    ll res=0;
    auto f0=[&](int X,int t0){
        return sum0[X][t0];
    };
    auto f1=[&](int X,int p){
        return sum1[X][p];
    };
    for(int A=2;A<n-1;A++){
        for(auto X:divs[n-1-A]){
            if(X>=A) continue;
            int t0=(n-1-A)/X;
            int t=A/X;
            int p=(n-1-A)/X+1;
            if(t*X==A && t<=t0) continue;
            res=max(res,f0(X,t0+1)+f1(X,p));
        }
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    if ("Sunny" == s) {
        cout << "Cloudy" << endl;
        return 0;
    }
    if ("Cloudy" == s) {
        cout << "Rainy" << endl;
        return 0;
    }
    if ("Rainy" == s) {
        cout << "Sunny" << endl;
        return 0;
    }
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n = in();
    vint a = in(n), b = in(n), c = in(n);

    sort(ALL(a), greater<int>());
    sort(ALL(c));
    ll ans = 0;
    rep(i, n)
    {
        auto aitr = upper_bound(ALL(a), b[i], greater<int>());
        auto citr = upper_bound(ALL(c), b[i]);

        ans += (ll)(n - (aitr - a.begin())) * (n - (citr - c.begin()));
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1408
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if a > b:
    A = a - v*t
    B = b - w*t
    if A <= B:
        print("YES")
    else:
        print("NO")
else:
    A = a + v*t
    B = b + w*t
    if A >= B:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 9092
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    string str;
    cin>>str;
    int sum=0,len=str.size();
    bool judge=false;//标记前一个子串是否为两个字符，true为是
    int i;
    sum++;
    for(i=1;i<len-1;i++)
    {
        if(str[i]==str[i-1]&&judge==false)
        {
            judge=true;
            sum++;
            i++;
        }
        else
        {
            judge=false;
            sum++;
        }
    }
    if(i==(len-1))//最后剩一个字符
    {
        if(str[len-2]==str[len-1]&&judge==false);
        else sum++;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <limits>
#include <string>
#include <algorithm>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include "math.h"
#include "assert.h"

using namespace std;

#define ll long long

#define BUFF ios::sync_with_stdio(false)
#define epsilon 1e-07
#define pi 2 * acos(0.0);
#define mod 1000000007   // 1e9+7
#define cerr if(false)cerr
#define watch(x) cerr << #x << " = " << x << endl;

#define inf std::numeric_limits<int>().max();

int main() {
	double n;
	cin >> n;
	double p = 0;
	for(int i=1; i<=n; i++) {
		if (i%2) p++; 
	}
	cout << p/n << endl;
}


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

int main() {
string a,b,c;
cin>>a>>b>>c;
int A,B;
A=a.size();
B=b.size();
char w,x,y,z;
w=a.at(A-1);
x=b.at(0);
y=b.at(B-1);
z=c.at(0);
if(w==x&&y==z){
  cout  <<  "YES"  <<  endl;
}
else cout <<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,y;
	cin>>n>>y;
	if(n*10000<y||n*1000>y||y%1000!=0)
	{
		cout<<"-1 -1 -1"<<endl;
		return 0;
	}
	for(int i=0;i<=n;i++)
	for(int j=0;j<=n-i;j++)
	for(int k=0;k<=n-i-j;k++)
	if(10000*i+5000*j+1000*k==y&&i+j+k==n)
	{
		cout<<i<<" "<<j<<" "<<k<<" "<<endl;
		return 0;
	}
	cout<<"-1 -1 -1"<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> d(n);
    REP(i, n){
        cin >> d.at(i);
    }
    ll ans = 0;
    REP(i, n){
        for(ll j = i + 1; j < n; ++j){
            ans += d.at(i) * d.at(j);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
int n,m,q;
int vec[100000][100];
int cnt[100000];
int group[100000];
int id=1;

void setID(int s){
    int i;

    group[s]=id;
    for(i=0;i<cnt[s];i++){
	if(group[vec[s][i]]==0) setID(vec[s][i]);
    }
}

int main(void){
    int i,j;
    int a,b;

    scanf("%d%d",&n,&m);
    for(i=0;i<m;i++){
	scanf("%d%d",&a,&b);
	vec[a][cnt[a]++]=b;
	vec[b][cnt[b]++]=a;
    }

/*
    for(i=0;i<n;i++){
	printf("%d:",i);
	for(j=0;j<cnt[i];j++){
	    printf("%d ",vec[i][j]);
	}
	printf("\n");
    }
*/

    for(i=0;i<n;i++){
	if(group[i]==0){
	    setID(i);
	    id++;
	}
    }

    scanf("%d",&q);
    for(i=0;i<q;i++){
	scanf("%d%d",&a,&b);
	if(group[a]==group[b]) printf("yes\n");
	else printf("no\n");
    }

    return 0;
}

Measured memory_bytes: 43548
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
   int n, m;
   cin >> n >> m;
   vector<vector<int>>a(m);
   rep(i,m){
      int k;
      cin >> k;
      rep(j,k){
         int x;
         cin >> x;
         x--;
         a[i].push_back(x);
      }
   }
   vector<int>p(m);
   rep(i,m)cin >> p[i];
   int ans = 0;
   rep(i,1<<n){
      int num = 0;
      rep(j,m){
         int cnt = 0;
         for(int x: a[j]){
            if(i&(1<<x))cnt++;
         }
         if(cnt %2==p[j])num++;
      }
      if(num == m)ans++;
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
import sys,heapq,time
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

n,x = inm()
blu = []
pt = 0
for i in range(n):
    b,l,u = inm()
    s = u*(x-b) + l*b
    v = s/x
    t = x
    heapq.heappush(blu, (-v,s,t,b,l,u,i))
    pt -= l*b

if pt==0:
    print(0)
    exit()

ans = []
reached = False
sum = 0
while len(blu)>0:
    mv,s,t,b,l,u,r = heapq.heappop(blu)
    nxtpt = pt + s
    ddprint("v {} s {} t {} b {} l {} u {} pt {} nx {} sum {}".format(-mv,s,t,b,l,u,pt,nxtpt,sum))
    if nxtpt < 0:
        ans.append((s,b,l,u))
        pt = nxtpt
        sum += t
        continue
    elif nxtpt == 0: # < (u if pt+l*b<0 else l):
        if not reached:
            ans.append((s,b,l,u))
            pt2 = pt + u*x - u*b + l*b
        sum += t
        break
    else:  # nxtpt > 0
        m = pt + l*b
        ddprint("m {}".format(m))
        if m>=0:
            t = (-pt+l-1)//l
        else:
            m = -m
            t = b + (m+u-1)//u
        if not reached:
            ans.append((s,b,l,u))
            pt2 = pt + u*x - u*b + l*b
            reached = True
        s = -pt
        ddprint("s/t {} s {} t {}".format(s/t,s,t))
        heapq.heappush(blu, (-s/t,s,t,b,l,u,-1))

sum2 = x * (len(ans)-1)
for z in ans[:-1]:
    s,b,l,u = z
    pt = pt2 - s
    m = pt + l*b
    if m>=0:
        t = (-pt+l-1)//l
    else:
        t = b+(-m+u-1)//u
    if sum2+t < sum:
        sum = sum2+t
print(sum)


Measured memory_bytes: 93524