akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate
N,K = map(int,input().split())
td = [tuple(map(int,input().split())) for i in range(N)]

td = [(x[0]-1,x[1]) for x in td]
td.sort(key=lambda x:-x[1])

t = [-1]*N
for i in range(N):
    t[td[i][0]] = 0
tdK = td[:K]
for i in range(K):
    t[tdK[i][0]] = 1

t_used = [i for i in range(N) if t[i]==1]
t_not_used = [i for i in range(N) if t[i]==0]

d_top = [0]*N
d_top_candi = [0]*N
d_rest = []
d_candi = []

for i in range(K):
    if d_top[td[i][0]] == 0:
        d_top[td[i][0]] = td[i][1]
    else:
        d_rest.append(td[i][1])
for i in range(K,N):
    if t[td[i][0]] == 0:
        if d_top_candi[td[i][0]] == 0:
            d_top_candi[td[i][0]] = 1
            d_candi.append(td[i][1])
l = len(t_used)
s = sum(d_top)
ans = l**2 + s
d_rest.sort()
d_candi.sort(key=lambda x:-x)

d_rest_cum = list(accumulate(d_rest))
d_candi_cum = list(accumulate(d_candi))

if len(d_rest) == 0:
    print(ans)
else:
    ans += d_rest_cum[-1]
    s += d_rest_cum[-1]
    for k in range(min(len(d_rest),len(d_candi))):
        ans = max((l+k+1)**2 + s + d_candi_cum[k] - d_rest_cum[k],ans)

    print(ans)

Measured memory_bytes: 30388
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define DEBUG(i) cout << #i << ": " << i << endl;
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int N, W;
pll P[100];
vector<ll> q[4];

int main(void) {
  cin >> N >> W;
  REP(i, 0, N) cin >> P[i].fi >> P[i].se;

  ll m = min_element(P, P + N)->fi;
  sort(P, P + N);
  reverse(P, P + N);
  REP(i, 0, 4) q[i].push_back(0);
  REP(i, 0, N) q[P[i].fi - m].push_back(P[i].se);
  REP(i, 0, 4) REP(j, 1, q[i].size()) q[i][j] += q[i][j - 1];

  ll ans = 0;
  REP(i, 0, q[0].size() + 1) {
    REP(j, 0, q[1].size() + 1) {
      REP(k, 0, q[2].size() + 1) {
        REP(l, 0, q[3].size() + 1) {
          if(i * m + j * (m + 1) + k * (m + 2) + l * (m + 3) <= W) {
            ans = max(ans, q[0][i] + q[1][j] + q[2][k] + q[3][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
#define MAX 5000
using namespace std;
bool p_judge(int x) {
    for(int i=2; i<=x/2; i++) {
        if(x%i==0)
            return false;
    }
    return true;
}
 
int main(void) {
    int n, i, j=1;
    cin >> n;
    for(i=11; j<=n; i+=10) {
        if(p_judge(i)) {
            printf("%d ", i);
            j++;
        }
    }
}

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

int d[100005];
int p[100005];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1; i<n; i++) cin>>d[i];
    for(int i=1; i<=m; i++) cin>>p[i];
    long long int ans=0;
    int w=1;
    for(int i=1; i<=m; i++){
        if(p[i]>=0) for(int j=w; j<w+p[i]; j++) ans+=d[j];
        else for(int j=w-1; j>=w+p[i]; j--) ans+=d[j];
        w+=p[i];
    }
    cout<<ans%100000<<endl;
}

Measured memory_bytes: 3860
#include <stdio.h>
#include <string.h>
int main(){
    int n,i;
    char s[100005];
    scanf("%s",s);
    n=strlen(s);
        for(i=0;i<n;i++){
            if(i%2==0)printf("%c",s[i]);
        }
    return 0;
}

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

int n, k, uniq = 0, a[100005];
bool has1[100005];
int freq[100005];

int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    has1[a[i]] = true;
  }
  for (int i = 1; i <= k; i++) {
    if (!has1[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  int l = 1, r = 0;
  while (uniq != k) {
    freq[a[++r]]++;
    if (a[r] <= k && freq[a[r]] == 1) {
      uniq++;
    }
  }
  int ans = r - l + 1;
  while (r <= n) {
    // shrink left bound
    if (uniq == k)
      while (a[l] > k || freq[a[l]] > 1)
	freq[a[l++]]--;
    if (uniq == k)
      ans = min(ans, r - l + 1);
    freq[a[++r]]++;
    if (a[r] <= k && freq[a[r]] == 1)
      uniq++;
    if (a[l] <= k && freq[a[l]] == 1)
      uniq--;
    freq[a[l++]]--;
  }
  cout << ans << endl;
}



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

using namespace std;

int main(){
    string s;bool flag = true;
    cin >> s;
    if(s.size()%2 == 1)flag = false;
    for(int i = 1;i < s.size();i+=2){
        if(s.substr(i-1,2) != "hi")flag = false;
    }
    if(flag)cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int h = sc.nextInt();
            int w = sc.nextInt();

            if (h == 0 && w == 0)
                break;

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++)
                    System.out.print('#');
                System.out.println();
            }
            System.out.println();
        }
    }
}

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

using namespace std;

typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#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()
#define psb push_back
#define ppb pop_back

const int INF = 1000000000;

int main() {
    int s = 4;
    char in[s];
    int t = 7;

    cin >> in[0] >> in[1] >> in[2] >> in[3];
    rep (i, s) in[i] = in[i]-'0';

    int ans;
    rep (i, 1 << s) {
        int c = in[0];
        string f = to_string(c);
        rep (j, s-1) {
            if ((i >> j) & 1) {
                c += in[j+1];
                f += "+";
                f += to_string(in[j+1]);
            } else {
                c -= in[j+1];
                f += "-";
                f += to_string(in[j+1]);
            }
        }
        if (t == c) {
            f += "=7";
            cout << f << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
typedef priority_queue<int,vector<int>,greater<int> > small_heap;
typedef priority_queue<int> big_heap;
pii a[1009];
int dp[20009];
int h,n;
int main()
{
    scanf("%d%d",&h,&n);
    for(int i=1;i<=n;i++)scanf("%d%d",&a[i].first,&a[i].second);
    memset(dp,0x3f, sizeof(dp));
    dp[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=a[i].first;j<=20000;j++)
        {
            dp[j]=min(dp[j],dp[j-a[i].first]+a[i].second);
        }
    }
    int ans=INT_MAX;
    for(int i=h;i<=20000;i++)
    {
        ans=min(ans,dp[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;
using ll = long long;

int main() {

    int n;
    cin >> n;
    ll a[n];
    ll dp[n][n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    
    for(int l = n - 1; l >= 0; --l) {

        for(int r = l; r < n; ++r) {

            ll sum = 0;
            for(int i = l; i <= r; ++i) 
                sum += a[i];
            
            if(l == r)
                dp[l][r] = 0;
            else {

                dp[l][r] = 1e18L + 10;
                for(int i = l; i < r; ++i) {

                    dp[l][r] = min(dp[l][r], sum + dp[l][i] + dp[i + 1][r]);
                }
            }
        }
    }

    cout << dp[0][n - 1];

    return 0;
}

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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a


using ll = long long;

int main() {
    int ans = 0;
    IN(int, n);
    IN(int, k);
    while (n > 0) {
        n /= k;
        ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<ll> a(3 * n);
  for(int i = 0; i < 3 * n; i++) cin >> a.at(i);
  
  ll keep1, keep2;
  priority_queue<ll, vector<ll>, greater<ll>> pq1;
  priority_queue<ll> pq2;
  for(int i = 0; i < n; i++){
    keep1 += a.at(i);
    pq1.push(a.at(i));
    keep2 += a.at(3 * n - i - 1);
    pq2.push(a.at(3 * n - i - 1));
  }
  
  vector<ll> x(n + 1), y(n + 1);
  x.at(0) = keep1;
  y.at(n) = keep2;
  for(int i = 1; i <= n; i++){
    keep1 += a.at(n + i - 1);
    pq1.push(a.at(n + i - 1));
    keep1 -= pq1.top();
    pq1.pop();
    x.at(i) = keep1;
  }
  for(int i = n; i > 0; i--){
    keep2 += a.at(n + i - 1);
    pq2.push(a.at(n + i - 1));
    keep2 -= pq2.top();
    pq2.pop();
    y.at(i - 1) = keep2;
  }
  
  ll ans = -1e18;
  for(int i = 0; i <= n; i++){
    ans = max(ans, x.at(i) - y.at(i));
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 5996
#include <iostream>
#include <cstdio>
using namespace std;

int n, mx, c;
string a;
int main()
{
	int i, j;
	cin >> n >> a;
	for (i = 1; i < n; i++) {
		for (j = c = 0; j < n && c < i; j++) {
			if (a[j] == a[j + i]) c++, mx = max(mx, c);
			else c = 0;
		}
	}
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 256
import math
N, D = map(int, input().split())
coordinates = []
count = 0
for i in range(N):
    coordinate = [int(i) for i in input().split()]
    coordinates.append(coordinate)

for i in range(N):
    for j in range(i + 1, N):
        distance = 0
        for k in range(D):
            distance += abs(coordinates[i][k] - coordinates[j][k]) ** 2
        distance = math.sqrt(distance)
        if distance.is_integer():
            count += 1
print(count)

Measured memory_bytes: 3064
s = input()
t = input()
char_1 = list(s)
char_2 = list(t)
count = 0
max_num = 0
for i in range(len(char_1)-len(char_2)+1):
    count = 0
    for j in range(len(char_2)):
        if(char_1[i+j]==char_2[j]):
            count += 1
    if(max_num<=count):
        max_num = count
        
print(len(char_2)-max_num)

Measured memory_bytes: 9044
import java.util.Scanner;
public class Main{
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int h = S/3600;
        int m = (S-h*3600)/60;
        int s = ((S-h*3600)-m*60);
        
        System.out.println(h+":"+m+":"+s);
    }
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}


            
        
        
        

Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+18;

int main() {
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    Int res = 0;
    stack<char> st;
    for (Int i = 0; i < s.size(); i++) {
        if (!st.empty() && st.top() != s[i]) {
            st.pop();
            res += 2;
        }
        else {
            st.push(s[i]);
        }
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

int main() {
  int a, b;
  cin >> a >> b;
  if(a+b == 3) cout << 3 << endl;
  else if(a+b == 5) cout << 1 << endl;
  else if(a+b == 4) cout << 2 << endl;
  return 0;
}

Measured memory_bytes: 3620
def cal(a,b):
    if 4*a*b-A*(a+b)>0:
        return (A*a*b)/(4*a*b-A*(a+b))
    else:
        return -1
A = int(input())
for i in range(1,3501):
    for j in range(i,3501):
        t = cal(i,j)
        if t == -1:
            continue
        if t == int(t):
            print(i,j,int(t))
            exit()

Measured memory_bytes: 41436
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
# 1から
rec=[-1]*(n+1)
rec[1]=0
now=1
wp=0
flag=False
while k>wp:
    rec[now]=wp
    nx=a[now]
    rest=k-wp
    loop=rec[now]-rec[nx]+1
    if rest<loop:
        flag=True

    if rec[nx]==-1 or flag:
        wp+=1
        now=nx
    else:
        rest%=loop
        wp=k-rest
        flag=True
print(now)

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

int main()
{
    ll n,k, ans=0, a, b;
    cin>>n>>k;
    for(ll i=k;i<=n+1;++i)
    {
        a = (i*(i-1))/2;
        b = ((n*(n+1))/2) - (((n-i)*(n-i+1))/2);
        ans += (b-a+1);
        ans %= mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner in=new Scanner(System.in);
        float d=in.nextFloat(),t=in.nextFloat(),s=in.nextFloat();
        if((d/s)<=t)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 37288
//If you are reading this then you are at wrong place.
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
bool prime [1000001];
void debug(int a){cout<<a<<endl;}
int sieve(int a){memset(prime,true,sizeof(prime));int p,i;for(p=2;p*p<=a;p++){if(prime[p]==true){for(i=p*2;i<=a;i+=p)prime[i]=false;}}return 0;}
int main()
{
	//your code goes here
	//input for the testcase 
	//ifstream cin("testcase.txt");
	//ofstream cout("output.txt");	
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);	
	int t,i,j;
	//cin>>t;
	t=1;
	int counter1=0;
	while(t--)
	{
		counter1++;
		int a,b;
		cin>>a>>b;
		a+=b;
		a=a%24;
		cout<<a<<endl;
		//cout<<"Case #"<<counter1<<" ";
		//print your final answer here
		//cout<<fixed<<setprecision(5)<<answer<<endl;
		cout<<endl;	
	}	
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main(){
	int R[MAX],n;
	cin >> n;
	for(int i = 0;i < n; i++) cin >> R[i];
	int maxv = -2000000000;  //设置一个足够小的初始值 
	int minv = R[0];
	for(int i = 1;i < n; i++){  //如果每次都在这一阶段读取R[i],那么可以省去数组 
		maxv = max(maxv,R[i] - minv);//更新最大值 
		minv = min(minv,R[i]);//暂存现阶段最小值 
	}
	cout << maxv << endl;
	return 0;
}


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

const int N = 6005;

int n, m;
int a[N], b[N], c[N];
int d[N], e[N], f[N];

bool seg[N][N];

bool valid(int x, int y) {
  return x >= 0 && x < N && y >= 0 && y < N;
}

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

bool inf;
bool vis[N][N];
void bfs(int x, int y) {
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  vis[x][y] = true;

  while (q.size()) {
    int x, y;
    tie(x, y) = q.front();
    q.pop();

    for (int k = 0; k < 4; ++k) {
      int nx = x + dx[k], ny = y + dy[k];
      if (!valid(nx, ny)) {
        inf = true;
        continue;
      }
      if (seg[nx][ny]) continue;
      if (vis[nx][ny]) continue;
      vis[nx][ny] = true;
      q.push(make_pair(nx, ny));
    }
  }
}

int solve() {
  scanf("%d %d", &n, &m);

  vector<int> xs = {0}, ys = {0};

  for (int i = 0; i < n; ++i) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
    xs.push_back(a[i]); xs.push_back(b[i]);
    ys.push_back(c[i]);
  }

  for (int i = 0; i < m; ++i) {
    scanf("%d %d %d", &d[i], &e[i], &f[i]);
    xs.push_back(d[i]);
    ys.push_back(e[i]); ys.push_back(f[i]);
  }

  sort(xs.begin(), xs.end()); xs.resize(unique(xs.begin(), xs.end()) - xs.begin());
  sort(ys.begin(), ys.end()); ys.resize(unique(ys.begin(), ys.end()) - ys.begin());

  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin();
    b[i] = lower_bound(xs.begin(), xs.end(), b[i]) - xs.begin();
    c[i] = lower_bound(ys.begin(), ys.end(), c[i]) - ys.begin();

    for (int k = a[i]*2; k <= b[i]*2; ++k) {
      seg[k][c[i]*2] = true;
    }
  }

  for (int i = 0; i < m; ++i) {
    d[i] = lower_bound(xs.begin(), xs.end(), d[i]) - xs.begin();
    e[i] = lower_bound(ys.begin(), ys.end(), e[i]) - ys.begin();
    f[i] = lower_bound(ys.begin(), ys.end(), f[i]) - ys.begin();

    for (int k = e[i]*2; k <= f[i]*2; ++k) {
      seg[d[i]*2][k] = true;
    }
  }

  bfs((lower_bound(xs.begin(), xs.end(), 0) - xs.begin()) * 2, (lower_bound(ys.begin(), ys.end(), 0) - ys.begin()) * 2);

  if (false) for (int i = 0; i <= xs.size() * 2; ++i) {
    for (int j = 0; j <= ys.size() * 2; ++j) {
      if (seg[i][j]) printf("#");
      else if (vis[i][j]) printf(",");
      else printf(".");
    }
    printf("\n");
  }

  if (inf) return 0 * printf("INF\n");

  long long ans = 0;
  for (int i = 1; i < N; i += 2) {
    for (int j = 1; j < N; j += 2) {
      if (!vis[i][j]) continue;
      ans += 1LL * (xs[(i+1)/2] - xs[(i-1)/2]) * (ys[(j+1)/2] - ys[(j-1)/2]);
    }
  }

  printf("%lld\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 72716
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	vector<int> A(3);
	IN(A); SO(A);
	int sum = A[2] * 2 - A[0] - A[1];
	int ans = 0;
	if (sum % 2 == 0) {
		ans = sum / 2;
	}
	else {
		ans++;
		sum++;
		ans += sum / 2;
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 384
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    asum = sum(A)

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

    ans = asum - sum(A)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 19004
#include <iostream>
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int main() {
	int n; string s;
	cin >> n >> s;
	int ans = 0;
	REP(i,n) {
		int cnt = 0;
		bool use[26] = {false};
		FOR(j,0,i) use[s[j] - 'a'] = true;
		FOR(j,i,n) {
			if ( use[s[j] - 'a'] ) {
				use[s[j] - 'a'] = false;
				++cnt;
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
}

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

using namespace std;

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

  int res = accumulate(s.begin(), s.end(), 0, [](int a, int e) {
      return a + ('1' == e);
    }
  );

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    way = [[] for i in range(n+1)]
    for _ in range(m):
        u,v = map(int,ipt().split())
        way[u].append(v)
    dist = [[-1]*3 for _ in range(n+1)]
    s,t = map(int,ipt().split())
    dist[s][0] = 0
    q = queue.Queue()
    q.put((s,0))
    while not q.empty():
        pi,pd = q.get()
        for i in way[pi]:
            if dist[i][(pd+1)%3] == -1:
                dist[i][(pd+1)%3] = (pd+1)//3
                q.put((i,pd+1))
    print(dist[t][0])

    return

if __name__ == '__main__':
    main()


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

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

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

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

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a; cin>>a;
    string s; cin>>s;
    if (a>=3200){
        cout<<s<<"\n";
    }else{
        cout<<"red\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld ;
#define pb push_back
#define fi first
#define se second
const int N = 1e5+6;
const ll mod = 1e9+7;
int cnt[11][11];
int f(int x){
    int ret = 0;
    while(x){
        ret = x%10;
        x/=10;
    }
    return ret;
}
int l(int x){
    return x%10;
}
void solve(){
    int n;
    cin>>n;
    ll ans = 0;
    for(int i=1;i<=n;i++){
        int a = f(i);
        int b = l(i);

        ans+=2*cnt[a][b];
        if(a==b)ans++;
        cnt[b][a]++;
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//    preprocess();
    int t =1;
//    cin>>t;
    while(t--)solve();
    return 0;
}




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

int main()
{
	int x;
	cin >> x;
	if (x >= 400 && x <= 599) cout << 8 << endl;
	else if (x >= 600 && x <= 799) cout << 7 << endl;
	else if (x >= 800 && x <= 999) cout << 6 << endl;
	else if (x >= 1000 && x <= 1199) cout << 5 << endl;
	else if (x >= 1200 && x <= 1399) cout << 4 << endl;
	else if (x >= 1400 && x <= 1599) cout << 3 << endl;
	else if (x >= 1600 && x <= 1799) cout << 2 << endl;
	else if (x >= 1800 && x <= 1999) cout << 1 << endl;
}

Measured memory_bytes: 3124
from sys import stdin
input = stdin.readline
from collections import Counter
def solve():
    N = int(input())
    a = list(map(int,input().split()))
    assert N & 1 == 0
    s = 0
    res = []
    for v in a:
        s ^= v
    for v in a:
        res.append(s^v)
    print(' '.join(map(str,res)))







if __name__ == '__main__':
    solve()


Measured memory_bytes: 121764
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int e = 2*1e5 + 69;
vector<ll>adj1[e];
vector<ll>adj2[e];
bool visited[e];
vector<ll>ans[e];
map<ll,ll>kt;
map<ll,ll>kt1;
ll dem = 0;
ll dem1 = 0;
void dfs(ll n)
{
    visited[n] = false;
    kt[n] = dem;
    for(auto i:adj1[n])
    {
        if(visited[i] == true)
        dfs(i);
    }
}
void dfs1(ll n)
{
    kt1[n] = dem1;
    //ans[dem].pb(n);
    visited[n] = false;
    for(auto i:adj2[n])
    {
        if(visited[i] == true)
        {
            dfs1(i);
        }
    }
}
int main()
{
    ll n, k , l;
    cin >> n >> k >> l;
    for(ll i=1; i<=k; i++)
    {
         ll a, b;
         cin >> a >> b;
         adj1[a].pb(b);
         adj1[b].pb(a);
    }
    for(ll i=1; i<=l; i++)
    {
        ll a, b;
        cin >> a >> b;
        adj2[a].pb(b);
        adj2[b].pb(a);
    }
    memset(visited, true, sizeof(visited));
    for(ll i=1; i<=n; i++)
    {
        if(visited[i] == true)
        {
            dem ++;
            dfs(i);
        }
    }
    memset(visited, true, sizeof(visited));
    for(ll i=1; i<=n; i++)
    {
        if(visited[i] == true)
        {
            dem1++;
            dfs1(i);
        }
    }
    map<ll,map<ll,ll>>ans;
    for(ll i=1; i<=n; i++)
    {
        ans[kt[i]][kt1[i]]++;
    }
    for(ll i=1; i<=n; i++)
    {
        cout << ans[kt[i]][kt1[i]]<<" ";
    }

}


Measured memory_bytes: 72320
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  vector<pair<int,pair<int,int> > > recs;
  FOR(i,1,150){
    FOR(j,1,i){
      recs.PB(MP(i*i+j*j,MP(j,i)));
    }
  }
  SORT(recs);
  for(;;){
    int h,w;
    cin >> h >> w;
    if(!h&&!w) return 0;
    pair<int,int> answer = (*(upper_bound(ALL(recs),MP(h*h+w*w,MP(h,w))))).second;
    cout << answer.first << ' ' << answer.second << endl;
  }
}

Measured memory_bytes: 1328
s = input()
even = []

def listtostring(some):
    str1 = ""

    for ele in some:
        str1 += ele

    print(str1)

for i in range(len(s)):
    moji = s[i]
    if i % 2 == 0:
        even.append(moji)

listtostring(even)

Measured memory_bytes: 9260
import java.util.Scanner;

public class Main {
    static private final String ACGT = "ACGT";

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String S = scanner.next();
        scanner.close();

        int ans = 0;
        int tmp = 0;
        for (int i = 0; i < S.length(); ++i) {
            if (ACGT.contains((String.valueOf(S.charAt(i))))) {
                ans = Math.max(ans, ++tmp);
            } else {
                tmp = 0;
            }
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22612
/*input
*/
#include<bits/stdc++.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORd(i, a, b) for (ll i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
#define db(x) cerr << #x << " = " << (x) << " "<<endl;
#define endln cerr << "\n";
const ll MN = 1e6+3 ;
void output()
{
    ll n,k ;
    cin>>n>>k ;
    ll a[n] ;
    map<ll,ll> vals ;
    FOR(i,0,n)
    {
        cin>>a[i] ;
        vals[a[i]]++ ;
    }
    vector<ll> mins ;
    for(pair<ll,ll> p : vals)
    {
        mins.pb(p.second) ;
    }
    sort(mins.begin(),mins.end()) ;
    ll ans = 0 ;
    if(mins.size()>=k)
    {
        FOR(i,0,mins.size()-k)
        {
            ans+=mins[i] ;
        }
        cout<<ans<<endl ;
    }
    else
    {
        cout<<0<<endl ;
    }

}
int main()
{
    #ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1 ;
    FOR(i,0,t)
    {
        output() ;
    }
    return 0 ;
}

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

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

    int r,g,b;
    cin >> r >> g >> b;
    int n = r*100 + g*10 + b;
    cout << (n%4 == 0? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, A;
  cin >> N >> A;
  int B = N % 500;
  
  if (A < B) {
    cout << "No" << endl;
  }
    
  else {
    cout << "Yes" << endl;
  }
  
  
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{ 
 
 
    static long mod=1000000007;
    static int dx[]={1,-1,0,0};
    static int dy[]={0,0,1,-1};
    // static int dx[]={1,-1,0,0,1,1,-1,-1};
    // static int dy[]={0,0,1,-1,1,-1,1,-1};
    // PriorityQueue<Integer> que = new PriorityQueue<Integer>(); 
    //HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        // ArrayList<Integer> lis = new ArrayList<Integer>();
    // ArrayList<Integer> map[]=new ArrayList[26];
    static HashMap<Integer,Long> map = new HashMap<Integer,Long>();

    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // long n=sc.nextLong();
        // char c[][] = new char[h][w];
        // long a[] = new long [n];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        // int n=sc.nextInt();
        int n=sc.nextInt();
        int d[]=new int[n+2];
        long s=0,a=0,c=0;
        for (int i=1;i<=n ;i++ ) {
            d[i]=sc.nextInt(); 
            s+=abs(d[i]-d[i-1]);
        }
        s+=abs(d[n]);
        // db(s);
        for (int i=1;i<=n ;i++ ) {
            a = s - abs(d[i-1] - d[i]) - abs(d[i+1] - d[i]) + abs(d[i-1]-d[i+1]);
            out.println(a);
        }
        
        // out.println(ans);
        out.flush();
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
     
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class XY {
    int x,y,d;
    XY(int x, int y, int d) {
        this.x=x;
        this.y=y;
        this.d=d;
    } 
}
 
class P implements Comparable<P>{
    int x,y;
    P(int x, int y) {
        this.x=x;
        this.y=y;
    } 
      
    public int compareTo(P p){
        return -x + p.x;//des
    } 
}
 
class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 38856
n, k = map(int, input().strip().split())

aa = list(map(int, input().strip().split()))

aa = [0] + aa
bb = [False] * len(aa)

crn = 1
cnt = 1

route2 = [1]

while True:
  nxt = aa[crn]
  if bb[nxt]:
    break
  bb[nxt] = True
  crn = nxt
  route2 += [crn]
  cnt += 1
  
start = nxt
count = cnt

crn = 1
cnt = 1

route1 = [1]

while True:
  nxt = aa[crn]
  if nxt == start:
    break
  crn = nxt
  route1 += [crn]
  cnt += 1
  
route2 = route2[len(route1):]

c1 = len(route1)
c2 = len(route2)

if k < c1:
  print(route1[k])
else:
  k -= c1
  k %= c2
  print(route2[k])


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

using namespace std;

int N,A[200005];
long long int K;

int used[200005];

vector<int> V, W;
int S;

long long int ans = -1;

void visit(int i, long long int k) {

	if (k == K) { ans = i; }
	used[i] = 1;
	V.push_back(i);

	if (used[A[i]] == 1) { S = A[i]; }
	else { visit(A[i], k + 1); }
}

int main(void) {

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

	visit(1, 0);

	//for (auto u : V) { cout << " " << u; } cout<< endl;

	if (ans == -1) {

		int I = 0;
		for (int i = 0; i < (int)V.size(); i++) {
			if (V[i] != S) { K--; continue; }
			else { I = i; break; }
		}

		for (int i = I; i < (int)V.size(); i++) {
			W.push_back(V[i]);
		}
		//for (auto u : W) { cout << " " << u; }cout << endl;

		int Y = W.size();
		ans = W[K%Y];

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 14768
#include <iostream>

using namespace std;

int main(){
	
	long long int N;
	
	cin >> N;
	
	long long int count = 0;
	long long int ans = 0;
	
	for(long long int i = 0; i < 100000; i++){
		count += i;
		if(N <= count){
			ans = i;
			break;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		int[] h = new int[n];
		for(int i=0; i<n; i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
		}
		int H = 0;
		int Cx = 0;
		int Cy = 0;
		boolean flag = false;
		for(int cx=0; cx<=100; cx++){
			for(int cy=0; cy<=100; cy++){
				flag = false;
				int index = 0;
				for(int i=0; i<n; i++){
					if(h[i]!=0){
						index = i;
					}
				}
				H = h[index] + Math.abs(x[index]-cx) + Math.abs(y[index]-cy);
				for(int i=0; i<n; i++){
					if(h[i] != Math.max(H - Math.abs(x[i]-cx) - Math.abs(y[i]-cy), 0)){
								flag = true;
								break;
					}
				}
				if(flag==false){
					Cy = cy;
					break;
				}
			}
			if(flag==false){
				Cx = cx;
				break;
			}
		}
		System.out.println(Cx + " " + Cy + " " + H);
	}
}

Measured memory_bytes: 22992
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void){
  long long N;
  cin >> N;

  long long ans = 0;
  for (long long ni = 1; ni <= N; ni++){
    if (ni % 3 != 0 && ni % 5 != 0) {
      ans += ni;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>

using namespace std;

int solve(int sub, int add){
  if(add < sub) return 0;
  int nex = add + sub;
  if(nex%2) return 0;
  //  cout << sub << " " << add << endl; 
  return 1;
}

int toInt(const string& s){
  if(s == "") return 0;
  int res = 0;
  for(int i = 0; i < (int)s.length(); i++){
    res *= 10;
    res += s[i]-'0';
  }
  return res;
}

int main(){

  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < (int)s.length(); i++){
    string right = s.substr(i);
    if(right.length() > 0 && right[0] == '0') continue;
    ans += solve(toInt(s.substr(0,i)), toInt(right));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1192
M = ['M', 'A', 'R', 'C', 'H']
m = [0]*5
result = 0
n = int(input())
for i in range(n):
    name = input()[0]
    if name in M:
        index = M.index(name)
        m[index] += 1

for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            result += m[i]*m[j]*m[k]
print(result)

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

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    for(int i=0; i<K; i++){
        if(i%2==0){
            if(A%2!=0){
                A--;
                A/=2;
                B+=A;
            }else{
                A/=2;
                B+=A;
            }
        }else{
            if(B%2!=0){
                B--;
                B/=2;
                A+=B;
            }else{
                B/=2;
                A+=B;
            }
        }
    }
    cout << A << ' ' << B;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int A,B;cin>>A>>B;
  
  if(A%3==0||B%3==0||(A+B)%3==0){
    cout<<"Possible"<<endl;
  }
  else{
    cout<<"Impossible"<<endl;
  }
}

Measured memory_bytes: 3632
N = int(input())
A = list(map(int, input().split()))

l = 0 # start index
r = 0 # end index + 1
S = 0 # sum of As
X = 0 # XOR sum of As

ans = 0
while l<N:
    if S==X and r<=N:
        if r<N:
            S += A[r]
            X ^= A[r]
        r += 1
    else:
        S -= A[l]
        X ^= A[l]
        ans += r - l - 1
        l += 1

print(ans)


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


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int r, d, x; cin >> r >> d >> x;
  for(int i = 0; i < 10; i++) {
    x = r * x - d;
    cout << x << "\n";
  }
}

Measured memory_bytes: 256
#import heapq
from collections import deque
h,w,k = list(map(int, input().split()))
x1,y1,x2,y2 = list(map(int, input().split()))
x1,y1,x2,y2 = x1-1,y1-1,x2-1,y2-1
dp = [[-1]*w for _ in range(h)]
#que = []
que = deque()
c = [input() for _ in range(h)]

dp[x1][y1] = 0
#heapq.heappush(que, (dp[x1][y1], [x1,y1]))
que.append((x1,y1))
dx = [1,0,-1,0]
dy = [0,1,0,-1]
while que:
  #p= heapq.heappop(que)[1]
  #x,y= p[0],p[1]
  x,y = que.popleft()
  if (x == x2) & (y == y2):exit(print(dp[x2][y2]))
  for i in range(4):
    for j in range(1,k+1):
      nx = x + dx[i]*j
      ny = y + dy[i]*j
      if not ((0 <= nx < h) & (0 <= ny < w)):break
      if c[nx][ny] == '@':break
      if 0 <= dp[nx][ny] <= dp[x][y]:break
      if dp[nx][ny] == -1:
        #heapq.heappush(que, (dp[nx][ny], [nx,ny]))
        que.append((nx,ny))
      dp[nx][ny] = dp[x][y] + 1

print(-1)


Measured memory_bytes: 36564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    while(1) {
        ll n;
        cin >> n;
        if(!n) break;
        ll idx = 0;
        map<PII,ll> mp;
        REP(i, n) {
            ll x, y;
            char c;
            cin >> x >> y >> c;

            if(c == 'x') {
                if(mp.find({x,y}) == mp.end()) mp[{x, y}] = idx++;
                if(mp.find({x+1,y}) == mp.end()) mp[{x+1, y}] = idx++;
            }
            else {
                if(mp.find({x,y}) == mp.end()) mp[{x, y}] = idx++;
                if(mp.find({x,y+1}) == mp.end()) mp[{x, y+1}] = idx++;            
            }
        }

        dump(mp);

        vector<vector<ll>> g(idx);
        auto add_edge = [&](ll a, ll b) {
            g[a].push_back(b);
        };

        ll dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0};
        for(auto p: mp) {
            PII pt = p.first;
            REP(i, 4) {
                ll nx = pt.first + dx[i], ny = pt.second + dy[i];
                if(mp.find({nx,ny}) == mp.end()) continue;
                add_edge(p.second, mp[{nx, ny}]);
            }
        }

        dump(g);

        vector<ll> val(idx);
        function<void(ll,ll)> dfs = [&](ll v, ll c) {
            val[v] = c;
            for(auto to: g[v]) {
                if(val[to] != -1) continue;
                ll nc = c;
                if(v%2 && to==v-1) nc = 1-c;
                else if(to%2 && v==to-1) nc = 1-c;
                dfs(to, nc);
            }
        };

        auto check = [&] {
            bool ret = true;
            REP(i, idx) {
                for(auto to: g[i]) {
                    if((i%2 && to==i-1) || (to%2 && i==to-1)) {
                        if(val[i] == val[to]) ret = false;
                    } else {
                        if(val[i] != val[to]) ret = false;
                    }
                }
            }
            return ret;
        };

        val.assign(idx, -1);
        REP(i, idx) if(val[i] == -1) dfs(i, 0);
        dump(val);
        if(check()) {
            cout << "Yes" << endl;
            continue;
        }

        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 11016
#define F(a,t) for(a=2*t;a<=n;a+=t)
main(){int i,j,n,s,p[1000000];while(~scanf("%d",&n)){s=n;F(i,1)p[i]=1;F(i,1)F(j,i){s-=p[j];p[j]=0;}printf("%d\n",--s);}}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
#define NIL -1

struct Node {int parent, left, right;};
struct Node T[200000];
int D[200000];

int setDepth(int u,int p){      //根の接点番号をuとする
    D[u] = p;
    if(T[u].right != NIL)
        setDepth(T[u].right,p);
    if(T[u].left != NIL)
        setDepth(T[u].left,p+1);
}

int printChildren(int u){
    int c;
    c = T[u].left;
    cout << "[";
    while(c != NIL){
        cout << c ;
        if(T[c].right != NIL)
        cout << ", ";
        c = T[c].right;
    }
    cout << "]";
}

int printType(int u){
    if(T[u].parent == NIL)cout <<"root";
    else if(T[u].left == NIL)cout << "leaf";
    else cout << "internal node";
}

int main() 
{
    //構造体配列Tの初期化
    rep(i,200000){
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }

    //親、左子、右兄弟の設定
    int n;
    cin >> n;
    rep(i,n){
        int id,k,cl=NIL;
        cin >> id >> k;
        rep(j,k){
            int c;
            cin >> c;
            if(cl != NIL)T[cl].right = c;
            cl = c;
            T[c].parent = id;
            if(j == 0)T[id].left = c;
        }
    }

    //根の接点番号を設定
    int r;
    rep(i,n){
        if(T[i].parent==NIL)r=i;
    }

    //各ノードのDepthを設定
    setDepth(r,0);

    //出力
    rep(i,n){
        cout << "node " << i << ": parent = "<< T[i].parent << ", depth = " << D[i] <<", ";
        printType(i);
        cout << ", ";
        printChildren(i);
        cout << endl;
    }
}


Measured memory_bytes: 8932
import sys
import heapq

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n, m = inm()
a = inl()


def solve():
    g = []
    for i in range(m):
        b, c = inm()
        g.append((c, b))
    g.sort(reverse=True)
    h = []
    for c, b in g:
        if len(h) == n:
            break
        for i in range(b):
            h.append(c)
            if len(h) == n:
                break
    assert len(h) <= n

    heapq.heapify(a)
    for x in h:
        if a[0] >= x:
            break
        heapq.heappush(a, x)
        heapq.heappop(a)
    return sum(a)


print(solve())


Measured memory_bytes: 27164
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> nums(N + 1);
    for(int i = 1; i <= N; i++) {
        for(int j = 1; j * j <= i; j++) {
            if(i % j == 0) {
                if(j != (i / j))
                    nums[i] += 2;
                else
                    nums[i]++;
            }
        }
    }
    int res = 0;
    for(int i = 1; i <= N; i++) {
        res += ((i % 2) && nums[i] == 8);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


vector<int> getFactorization(int x) { 
  vector<int> vc;
  for (int i = 2; i * i <= x; i++) {
    while (x % i == 0) {
      vc.pb(i);
      x /= i;
    }
  }
  if (x != 1) vc.pb(x);
  sort(vc.begin(), vc.end());
  return vc;
} 

int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  vector<int> vc = getFactorization(n);
  map<int, int> mp;
  int ans = 0;
  for (auto i: vc) {
    mp[i]++;
  }
  for (auto i: mp) {
    int p = i.second;
    int c = 1;
    while (p >= c) {
      ans++;
      p -= c;
      c++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

namespace AOJ.Volume3
{
    public class GeometricData
    {
        public static int Main()
        {
            int n = int.Parse(Console.ReadLine());

            int answer = 0;
            var list = new List<string>();
            for(int i = 0; i < n; i++)
            {
                var input = Console.ReadLine().Split(' ');
                Array.Sort(input);
                string tmp = "";
                foreach(var s in input) { tmp += s + " "; }
                tmp = tmp.Trim();

                if (list.Contains(tmp)) { answer++; }
                else { list.Add(tmp); }
            }

            Console.WriteLine(answer);
            return 0;
        }
    }
}

Measured memory_bytes: 10096