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

struct Edge
{
    int nxt, to;
} e[200010];
int head[100010], cnt;
bool viz[100010];

void add_edge(int a, int b)
{
    e[++cnt] = { head[a], b };
    head[a] = cnt;
}

vector <int> ans;

void dfs(int nod)
{
    for (bool modif = 1; modif; ) {
        modif = 0;
        for (int i(head[nod]); i; i = e[i].nxt) {
            if (!viz[e[i].to]) {
                ans.push_back(e[i].to);
                viz[e[i].to] = 1;
                nod = e[i].to;
                modif = 1;
                break;
            }
        }
    }
}

int main()
{
    int n, m, a, b;
    cin >> n >> m;

    while (m--) {
        cin >> a >> b;
        add_edge(a, b);
        add_edge(b, a);
    }

    int root = 1;

    for (int i(1); i <= n; i++)
        if (head[i])
            root = i;

    ans.push_back(root);
    viz[root] = 1;
    dfs(root);
    reverse(ans.begin(), ans.end());
    dfs(root);

    cout << ans.size() << '\n';
    for (auto i : ans)
        cout << i << ' ';
    return 0;
}


Measured memory_bytes: 2604
#include<stdio.h>
int main()
{
	int a,b,c,d;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
		if(c>=b||a>=d)
		printf("0\n");
		else if(c>=a&&d<=b)
		printf("%d\n",d-c);
		else if(a>=c&&b<=d)
		printf("%d\n",b-a);
		else if(c>=a&&c<=b&&b<=d)
		printf("%d\n",b-c);
		else
		printf("%d\n",d-a);
	}
	return 0;
}
	

Measured memory_bytes: 128
n, m = map(int, input().split())
lx = []
ly = []

for i in range(n + m):
    x, y = map(int, input().split())
    lx.append(x)
    ly.append(y)

for i in range(n):
    r = []
    for j in range(n, m + n):
        r.append(abs(lx[i] - lx[j]) + abs(ly[i] - ly[j]))
    print(r.index(min(r)) + 1)


Measured memory_bytes: 9128
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string s;
    cin>>s;
    int l=s.length();
    if(s.at(l-1)=='s'){
        cout<<s+"es"<<"\n";
    }else{
        cout<<s+'s'<<"\n";
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<-1<<endl;return 0;}
//template
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  std::vector<int> w(N+1,0);
  int ans=0;
  for(int i=N-1;i>=0;i--){
    int res=0;
    for(int j=i+1;j<=N;j+=i+1)res+=w[j];
    if(v[i]==res%2)continue;
    w[i+1]++;ans++;
  }
  cout<<ans<<endl;
  bool f=false;
  for(int i=1;i<=N;i++){
    if(w[i]){
      if(f)cout<<" ";cout<<i<<endl;f=true;
    }
  }
}


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


template <class T> T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
int main(){
     int  n;
    cin>>n;
    long long int  count=0;
    for ( int  i = 1; i <= n; i++)
    {
        if(i%3==0 ||i%5==0 ||i%15==0){
            continue;

        }else{
            count+=i;

        }
    }
    cout<< count <<endl;

}

Measured memory_bytes: 3592
//#include <cmath>
//#include <cstdio>
//#include <vector>
//#include <map>
//#include <iostream>
//#include <algorithm>
//#include <set>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vb = vector<bool>;
using pli = pair<ll,int>; 		
#define fi first
#define v vector
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
int INF = 1e9+7;
ll inf = 1e18+7;
int MOD = 1e9+7;

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

void sub_self(auto &a, auto b){
	a -= b;
	if(a < 0)	a += MOD;
}

void max_self(auto &a, auto b){
	if(b > a)	a = b;
}



void topsort(int i, v<vi>& graph, vb& visit, stack<int>& res){
	visit[i] = true;
	
	for(int x : graph[i]){
		if(!visit[x])
		topsort(x,graph,visit,res);
	}
	res.push(i);
}

const int N = 100010;

ll dp[N];

void solve(){
	int n,k;
	scanf("%d%d",&n,&k);
	dp[0] = 1;
	v<ll> prefix(k+1,0);
	
	for(int c = 0; c < n ; ++c){
		int max_candie;
		scanf("%d",&max_candie);
		for(int used = k; used >= 0 ; --used){
			int l = used +1;
			int r = used  + min(max_candie,k-used);
			if(l <= r){
				if(r+1 <= k)
					sub_self(prefix[r+1], dp[used]);
				add_self(prefix[l], dp[used]);
			}
		} 
		ll summ = 0;
		for(int i =0; i <= k; ++i){
			add_self(summ, prefix[i]);
			add_self(dp[i],summ);
			prefix[i] = 0;
		}
		
	}
	printf("%lld\n", dp[k]);			
	
}	



int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t = 1;
	//cin >> t;
	//scanf("%d",&t);
	while(t--){
		solve();
	}
		
			
}


Measured memory_bytes: 4884
ABC = [int(input()) for _ in range(3)]
X = int(input())

A,B,C = ABC[0],ABC[1],ABC[2]

ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if i * 500 + j * 100 + k * 50 == X:
        ans += 1
        
print(ans)
        


Measured memory_bytes: 9180
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

ll N;
ll M;
vl H;
vl A;
vl B;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    cin >> M;
    H = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> H[i];
    }
    A = vl(M);
    B = vl(M);
    for(int i = 0; i < M; ++i){
        cin >> A[i];
        cin >> B[i];
    }
    solve();
}

// 2 <= N <= 10^5
// 1 <= M <= 10^5
// 1 <= H_i <= 10^9
// 1 <= A_i,B_i <= N
// A_i != B_i
// 同じ展望台の組を結ぶ道が複数あることもある。
// 入力中の値はすべて整数である。

// ll N, ll M, vl H, vl A, vl B
// 良い展望台の数を出力せよ。
void solve(){
    vvl g(N);
    rep(i,M){
        g[A[i]-1].push_back(B[i]-1);
        g[B[i]-1].push_back(A[i]-1);
    }

    ll ans=0;
    rep(i,N){
        bool ok=true;
        for(ll to:g[i]){
            if(H[i]<=H[to])ok=false;
        }
        if(ok)++ans;
    }
    cout<<ans<<endl;
}


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

int k, x;

int main() {
  cin >> k >> x;
  int cnt = 1;
  int start = x - k + 1;
  while (cnt < 2 * k) {
    if (cnt != 2 * k - 1) cout << start << " ";
    else cout << start << endl;
    
    cnt++; start++;
  }
  
  return 0;
}

Measured memory_bytes: 256
m,n = map(int,input().split())
A = [[0 for i in range(n)] for j in range(m)]
for i in range(m):
    s = input().strip().split()
    for j in range(n):
        A[i][j] = s[j]

B = [[0 for i in range(n)]]
for i in range(n):
    b = int(input())
    B[0][i] = b


for i in range(m):
    sum = 0
    for j in range(n):
        sum = sum + int(A[i][j]) * B[0][j]
    print(sum)


Measured memory_bytes: 6164
/*input
7 9 20
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<=n;++i){
		for(int j=0;j<=m;++j){
			if(i*m+j*n-2*i*j==k)
				return cout<<"Yes",0;
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  int res = k*pow((k-1),(n-1));
  cout << res << "\n";
  return 0;
}


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

int main()
{
    int r, g, b;
    cin >> r >> g >> b;

    if (((100*r + 10*g + b) % 4) == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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



int main() {

  int64_t n;
  cin>>n;

  //全ての組み合わせ　10^n
  int64_t out_10 = 1;
  for(int i=0;i<n;i++){
    out_10*=10;
    out_10%=1000000007;
  }

  //1を含まない組み合わせ( 9を含まない組み合わせ　)　9^n
  int64_t out_9=1;
  for(int i=0;i<n;i++){
    out_9*=9;
    out_9%=1000000007;
  }

  //1も9も含まない組み合わせ 8^n
  int64_t out_8=1;
  for(int i=0;i<n;i++){
    out_8*=8;
    out_8%=1000000007;
  }

  int64_t out_wk =  (( out_10%1000000007 - out_9%1000000007 - out_9%1000000007 + out_8%1000000007 )%1000000007);
  if(out_wk<0)
    cout<<(out_wk+1000000007)<<endl;
  else
    cout<<out_wk<<endl;
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
 int A,B,C;
 cin>>A>>B>>C;
 if((3*max({A,B,C})-(A+B+C))%2==0){cout<<(3*max({A,B,C})-(A+B+C))/2<<endl;}
 else{cout<<(3*(max({A,B,C})+1)-(A+B+C))/2<<endl;}
 return 0;}

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

int main() {
    int n, nums[8];
    cin >> n;
    if (n == 3) {
        auto list = {2, 5, 63};
        copy(begin(list), end(list), nums);
    } else if (n % 2 == 0) {
        auto list = {2, 10, 3, 9, 4, 8, 6, 12};
        copy(begin(list), end(list), nums);
    } else {
        auto list = {6, 2, 10, 3, 9, 4, 8, 12};
        copy(begin(list), end(list), nums);
    }
    for (int i = 0; i < n; i++) {
        cout << nums[i % 8] + i / 8 * 12 << ' ';
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

using namespace std;

unsigned long long gcd( unsigned long long a, unsigned long long b)
{
	if( b == 0 ) return a;
	else return gcd( b, a % b );
}
int main(int argc, char const* argv[])
{
	unsigned long long a,b,c;

	while( cin >> a >> b ){
		c = gcd(a,b);
		a /= c;
		a *= b;
		cout << c << " " << a << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################
 

N = I()
x,y = LIR(N,2)

max1 = -float('inf')
min1 = float('inf')
for i in range(N):
    max1 = max(max1,x[i]-y[i])
    min1 = min(min1,x[i]-y[i])

max2 = -float('inf')
min2 = float('inf')
for i in range(N):
    max2 = max(max2,x[i]+y[i])
    min2 = min(min2,x[i]+y[i])

print(max(max1-min1,max2-min2))

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

int n, base(-2);
string s;

int main(){
  cin >> n;
  if (n == 0) cout << "0";
  while (n != 0){
    int r = n % base;
    r += (r < 0? 2 : 0);
    s += (n % base == 0 ? "0" : "1");
    n = (n - r) / base;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}


Measured memory_bytes: 256
# 出現回数が最大の文字に統一することが最小値とは限らないので全ての文字列でシミュレーションする

S = input()

ans = 100
for s in S:
    s_split = S.split(s)
    max_len = 0
    for i in range(len(s_split)):
        max_len = max(max_len, len(s_split[i]))
    ans = min(ans, max_len)
print(ans)


Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
typedef int64_t Weight;
Weight INF = 1000000000000000000ll;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
  g[dest].push_back((Edge){dest, src, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int main() {
  int64_t n,m,s,t;
  cin>>n>>m>>s>>t;
  --s;--t;
  Graph g1(n), g2(n);
  REP(i,m) {
    int64_t u,v,a,b;
    cin>>u>>v>>a>>b;
    --u;--v;
    add_edge(g1, u, v, a);
    add_edge(g2, u, v, b);
  }
  Array dist1, dist2;
  dijkstra(g1, dist1, s);
  dijkstra(g2, dist2, t);
  vector<int64_t> res;
  int64_t mn = 0;
  for(int i =n-1; i >= 0; --i) {
    int64_t ncost = dist1[i] + dist2[i];
    int64_t money = 1000000000000000 - ncost;
    mn = max(mn, money);
    res.push_back(mn);
  }
  reverse(ALL(res));
  for (int64_t r : res) {
    cout << r << endl;
  }
  return 0;
}


Measured memory_bytes: 19964
n=int(input())
x=list(map(int,input().split()))

import fractions as frc

y=[0]*n
z=[0]*n

cd=x[0]
for i in range(n):
	cd=frc.gcd(cd,x[i])
	y[i]=cd

#print(y)

cd=x[n-1]
for i in range(n-1,-1,-1):
	cd=frc.gcd(cd,x[i])
	z[i]=cd

#print(z)

res=[0]*n
for i in range(n):
	if i==0:
		res[0]=z[1]
	else:
		if i==n-1:
			res[n-1]=y[n-2]
		else:
			res[i]=frc.gcd(y[i-1],z[i+1])

#print(res)

print(max(res))

Measured memory_bytes: 14080
#include <stdio.h>

int main()
{
  int a, b;
  int max;
  
  scanf("%d %d",&a,&b);
  
  max=a+b;
  
  if(a-b>max)
    max=a-b;
  
  if(a*b>max)
    max=a*b;
  
  printf("%d\n",max);
  
  return 0;
}

Measured memory_bytes: 1724
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = a%10;
    if (b==3){
      System.out.println("bon");
    } else if (b==0 || b==1 || b==6 || b==8) {
      System.out.println("pon");
    } else {
      System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35760
def main():
  n = int(input())
  hs = tuple(map(int, input().split()))

  a, b = 0, abs(hs[1] - hs[0])

  for i in range(2, n):
    d1 = a + abs(hs[i] - hs[i-2])
    d2 = b + abs(hs[i] - hs[i-1])
    a, b = b, min(d1, d2)

  print(b)

if __name__ == "__main__":
  main()


Measured memory_bytes: 14184
#include<stdio.h>
#include<stdlib.h>

#define MAX 500001
#define INFTY 2000000000

int count =0; 
void marge (int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int L[MAX/2+1],R[MAX/2+1];
  
  n1 = mid - left;
  n2 = right - mid;
  
  for(i=0; i<n1; i++) L[i]= A[left+i];
  for(i=0; i<n2; i++) R[i]= A[mid+i];

  /* printf("確認\n");
  for(i=0; i<n1; i++)printf("%d ",L[i]);
  printf("\n");
  for(i=0; i<n2; i++)printf("%d ",R[i]);
  printf("\n");
  printf("確認終了\n");
  */
    
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = j = 0;
  
  for(k=left; k < right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }
}

void margeSort(int A[],int left,int right){
  int mid;
  // printf("mragrSort\n");
  if (left+1 < right){
    mid = (left + right)/2;
    margeSort(A,left,mid);
    margeSort(A,mid,right);
    marge(A,left,mid,right);
  }
}

int main(){
  int i,j,n;
  int A[MAX];
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  //  printf("マージソート開始\n");
  margeSort(A,0,n);
  
  for(i=0; i<n; i++){
    if(i>=1)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5592
#include <iostream>
#include <string>

int main()
{
	std::string s;
	for (;;) {
		std::cin >> s;
		if (s[0] == '0') break;
		int sum {};
		for (int i=0; s[i]; ++i)
			sum += s[i] - '0';
		std::cout << sum << '\n';
	}
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << "\n";
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        while(true){
            String tmp = br.readLine();
             
            if(tmp == null){
                break;
            }
 
            String[] tmpArray = tmp.split(" ");
            int a = Integer.parseInt(tmpArray[0]);
            int b = Integer.parseInt(tmpArray[1]);
             
            System.out.println(GCD(a,b) + " "+ LCM(a,b));
        }
    }
    
    static long GCD (long a, long b){
	    long candidate = a;
	    while (b % a != 0) {
	      candidate = b % a;
	      b = a;
	      a = candidate;
	    }
	    return candidate;
	}
    
    static long LCM (long a, long b){
		long GCD = GCD(a, b);
		//System.out.println("GCD("+a+","+b+") is "+GCD);
		return GCD * (a/GCD) * (b/GCD);
	}
 
}

Measured memory_bytes: 23956
#C
#入力
N,M=map(int,input().split())
X=[list(map(int,input().split())) for i in range(M)]

#諸関数
def pront(X):
    #デバッグ用プリント
    #環境変数としてdebugを確保して、それが1なら内容を出力
    if debug==1:
        print(X)

#デバッグ用
debug=0#0:本番,1:デバッグ中
#処理
t=0
Y=[-1 for i in range(N)]

for i in X:
    if Y[i[0]-1]==-1:
        Y[i[0]-1]=i[1]
    elif Y[i[0]-1]!=i[1]:
        t=1
        break

pront(Y)
if t==1:
    pront("a")
    print("-1")
elif N==1:
    if Y[0]==-1:
        pront("b1")
        print("0")
    else:
        pront("b2")
        print(Y[0])
elif M==0:
    pront("e")
    print(10**(N-1))
elif Y[0]==0:
    pront("c")
    print("-1")
else:
    pront("d")
    for i in range(N):
        if i==0:
            if Y[0]==-1:
                sa="1"
            else:
                sa=str(Y[0])
        elif Y[i]==-1:
            sa=sa+"0"
        else:
            sa=sa+str(Y[i])
    print(sa)


Measured memory_bytes: 3064
import sys
from copy import deepcopy as copy

def main():
    input = sys.stdin.readline
    n = int(input())
    a = [None]*n
    for i in range(n):
        a[i] = [int(x)-1 for x in input().split()]
    
    index = [0]*n
    search = [int(x) for x in range(n)]
    ans = 0
    while True:
        already = set()
        judge = True
        sub = []
        for key in search:
            if index[key] == n-1:
                continue
            key2 = a[key][index[key]]
            if index[key2] == n-1:
                continue
            if key != a[key2][index[key2]]:
                continue
            if key in already or key2 in already:
                continue
            already.add(key)
            already.add(key2)
            index[key] += 1
            index[key2] += 1
            sub.append(key)
            sub.append(key2)
            judge = False
        if judge:
            break
        ans += 1
        search = copy(sub)
        
    for value in index:
        if value != n-1:
            print(-1)
            sys.exit()
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 81244
/* --- author: dxm --- */
#include<bits/stdc++.h>
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
inline void Fail(){printf("0");exit(0);}

const int maxn=200005;
const int maxm=30;
int n,ans;
int a[maxn],b[maxn];
vector<int>v[maxm][2];

int main(){
	scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n){
		scanf("%d",&b[i]);
		rep(j,29)v[j][b[i]&(1<<j)?1:0].pb(b[i]&((1<<j)-1));
	}
	rep(i,29)rep(j,2)sort(v[i][j].begin(),v[i][j].end());
	rep(j,29){
		int cur=0;
		rep(i,n){
			int ori=cur;
			int now=a[i]&((1<<j)-1);
			if(a[i]&(1<<j)){
				cur+=upper_bound(v[j][0].begin(),v[j][0].end(),(1<<j)-now-1)-v[j][0].begin();
				cur+=v[j][1].size()-(upper_bound(v[j][1].begin(),v[j][1].end(),(1<<j)-now-1)-v[j][1].begin());
			}
			else{
				cur+=upper_bound(v[j][1].begin(),v[j][1].end(),(1<<j)-now-1)-v[j][1].begin();
				cur+=v[j][0].size()-(upper_bound(v[j][0].begin(),v[j][0].end(),(1<<j)-now-1)-v[j][0].begin());
			}
//			cout<<j<<" "<<cur-ori<<endl;
			cur&=1; 
		}
		if(cur&1)ans+=(1<<j);
	}
	printf("%d",ans);
	return 0;
}

/*
Input:
-----------------
Output:
*/

Measured memory_bytes: 28628
#include<bits/stdc++.h>
using namespace std;
int main(){
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >>r;
	if(x-r < 0 || y-r < 0 || x+r > w || y+r > h){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

namespace {
    const int max_num = 100000000;
    const int max_check = floor(sqrt(max_num));
}

int main() {
    vector<bool> primes;
    for (int i = 0; i <= max_num; i++) {
        primes.push_back(true);
    }
    for (int i = 2; i <= max_check; i++) {
        if (primes[i]) {
            int j = i * i;
            while (j <= max_num) {
                primes[j] = false;
                j += i;
            }
        }
    }

    int n;
    cin >> n;

    int count = 0;
    for (int i = 0; i < n; i++) {
        int in;
        cin >> in;
        if (primes[in])
            count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 18388
import sys
import math
import collections
from collections import deque
from functools import reduce
import heapq
#x = int(input())
n, k = map(int, sys.stdin.readline().split())
#s = input()
a = list(map(int, sys.stdin.readline().split()))

q = [0 for i in range(n)]
l = [1]
i = 0
while (True):
    if q[a[l[i]-1]-1] == 1:
        p = l.index(a[l[i]-1])
        break
    
    q[a[l[i]-1]-1] = 1
    l.append(a[l[i]-1])
    i += 1

if k < p:
    print(l[k])
else:
    k -= p
    x = k % (len(l)-p)
    print(l[x+p])



Measured memory_bytes: 32116
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
int main() {
	int g[] = {0, 1,3,1,2,1,2,1,1,2,1,2,1 };
	int a, b;
	cin >> a >> b;
	if (g[a] == g[b])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

map<int, vector<int> > mp;

int main() {
    int n;
    input(n);
    vector<int> ns(n + 1);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &ns[i]);

        int h = i + ns[i];
        mp[h].push_back(i);
    }

    llint tot = 0;
    for (int i = 1; i <= n; i++) {
        int h = i - ns[i];
        const auto& v = mp[h];
        auto iter = lower_bound(v.begin(), v.end(), i - 1);
        tot += distance(v.begin(), iter);
    }
    print(tot);
    return 0;
}


Measured memory_bytes: 38284
// author: lkx
// Problem:
// ID:
#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define MP make_pair
#define PH push

const int MOD=1e9+7;

string s;
int ans=0;

int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++) ans+=s[i]-'0';
	for(int i=0;i<s.size();i++)
	{
		int tmp=0;
		for(int j=0;j<i;j++) tmp+=s[j]-'0';
		tmp+=s[i]-'0'-1;
		for(int j=i+1;j<s.size();j++) tmp+=9;
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(void) {
	string S;
	cin >> S;
	int first,second;
	first = atoi(S.substr(0, 2).c_str());
	second = atoi(S.substr(2, 2).c_str());
	// cout << first << " " << second << endl;
	bool yymm = true;
	bool mmyy = true;
	if (first < 1 || 12 < first) {
		mmyy = false;
	}
	if (second < 1 || 12 < second) {
		yymm = false;
	}

	if (yymm && mmyy) {
		printf("AMBIGUOUS\n");
	} else if (yymm && !mmyy) {
		printf("YYMM\n");
	} else if (!yymm && mmyy) {
		printf("MMYY\n");
	} else {
		printf("NA\n");
	}

	return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin>>n;
  for(int i=0;i<3;i++){
    if(n.at(i)=='7'){
      cout<<"Yes"<<endl;
      return 0;
    }
    
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int[] ss = new int[26];
        for (int i = 0; i < s.length; i++) {
            ss[s[i] - 'a']++;
        }
        for (int i = 0; i < ss.length; i++) {
            if(ss[i] == 0) {
                char c = (char) ('a' + i);
                System.out.println(c);
                return;
            }
        }
        System.out.println("None");
    }
}

Measured memory_bytes: 39648
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int INF = 1e9 + 7;
const int MAX_S = 105;
const int MAX_T = 105;
const int MAX_D = 105;
const int MAX_N = 105;
const int MAX_C = 105 * MAX_T;

// 体力 -> 消費カロリー
int dp1[MAX_T][MAX_T][MAX_S];
// 消費カロリー -> 幸福度
int dp2[MAX_C];
// 体力 -> 幸福度
int dp3[MAX_D][MAX_S];

int S, T, U, N, O, D; 
int e[MAX_T], c[MAX_T], h[MAX_N], a[MAX_N];

void make_dp1(){
  memset(dp1, -1, sizeof(dp1));
  dp1[0][0][0] = 0;
  REP(i, T){
    int E = e[i], C = c[i];
    REP(j, U + 1){
      REP(k, S + 1){
        if(dp1[i][j][k] < 0) continue;
        //トレーニングしない
        dp1[i + 1][j][k] = max(dp1[i + 1][j][k], dp1[i][j][k]);
        //する
        //if(k + E <= S && j < U)
        if(k + E <= S)
          dp1[i + 1][j + 1][k + E] = max(dp1[i + 1][j + 1][k + E], dp1[i][j][k] + C);
      }
    }
  }
}

void make_dp2(){
  REP(i, N)
    FOR(j, a[i], MAX_C) dp2[j] = max(dp2[j], dp2[j - a[i]] + h[i]);
}

void make_dp3(){
  memset(dp3, -1, sizeof(dp3));
  //dp3[0][S] = 0;
  dp3[0][0] = 0;
  REP(i, D){
    REP(j, S + 1){
      if(dp3[i][j] < 0) continue;
      //体力kを費やしてトレーニングをする
      for(int k = 0; k + j <= S; ++k){
        int kcal = dp1[T][U][k], ns = max(0, j + k - O);
        if(kcal == -1) continue;
        //cout <<k <<", " <<ns <<", " <<kcal <<", " <<dp2[kcal] <<endl;
        dp3[i + 1][ns] = max(dp3[i + 1][ns], dp3[i][j] + dp2[kcal]);
      }
    }
  }
}

int main() {
  scanf("%d %d %d %d %d %d", &S, &T, &U, &N, &O, &D);
  REP(i, T) scanf("%d %d", &e[i], &c[i]);
  REP(i, N) scanf("%d %d", &h[i], &a[i]);
  make_dp1();
  make_dp2();
  make_dp3();
  int ans = -1;
  REP(i, S + 1) ans = max(ans, dp3[D][i]);
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 5804
import math
a, b, x = [int(x) for x in input().split()]
h = x / (a**2)
if a * h > a * b / 2:
    print(math.degrees(math.atan2(2*(b-h), a)))
else:
    print(math.degrees(math.atan2(b*b,2*a*h)))

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


int main(){
  int n,a[1000]={};
  int mx=1,count=1;
  cin>>n;
  for(int i=1;i<=n;i++){cin>>a[i];}

  for(int i=0;i<n+3;i++){
    if(a[i]==1){count++;}
    if(count>0 && a[i]==0){mx=max(mx,count); count=1;}
  }

  cout<<mx<<endl;
  
  return 0;
}



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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define INF 1000000000000000000LL
#define mod 1000000007LL
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 45
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef pair<i64, i64> pi ;
typedef tree< pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 1005

i64 a[45][700000] , b[1005] ;

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld %lld",&n,&k) ;

    for(i=1; i<=n ; i++)
    {
        scanf("%lld",&b[i]) ;
    }
    m = 0 ;
    for(i=1 ; i<=n ; i++)
    {
        i64 sum = 0LL ;
        for(j=i ; j<=n ; j++ )
        {
            sum += b[j] ;
            a[ 44 ][ ++m ] = sum ;
        }
    }


    for(j=43 ; j>=0 ; j-- )
    {
        n = m ;
        i64 cnt = 0 ;
        for(i=1 ; i<=n ; i++)
        {
            if( (a[j+1][i]&(1LL<<j)) ) cnt++ ;
        }
        if( cnt >= k )
        {
            m = 0 ;
            for(i=1 ; i<=n ; i++)
            {
                if( (a[j+1][i]&(1LL<<j)) ) a[j][++m] = a[j+1][i] ;
            }
        }
        else{
            m =0 ;
            for(i=1 ; i<=n ; i++) a[j][++m] = a[j+1][i] ;
        }
    }

    i64 ans = a[0][1] ;

    for(i=2 ; i<=m ; i++) ans &= a[0][i] ;

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

    return 0 ;
}



Measured memory_bytes: 113152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public void Run()
        {
            var line = Input.ReadIntArray();
            N = line[0];
            K = line[1];
            int ret = N % K == 0 ? 0 : 1;
            Console.WriteLine(ret);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
using namespace std;
int main(void){
    double x, a, b;
    cin >> x;
    cin >> a;
    cin >> b;
    double dist1 = x - a;
    if(dist1 < 0) dist1 *= -1;
    double dist2 = x - b;
    if(dist2 < 0) dist2 *= -1;
    if(dist1 < dist2) cout << 'A';
    else cout << 'B';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

const int maxn = 100000;

int main() {

	int n;
	int df0[maxn], dfn[maxn];
	bool used[maxn];
	vector<vector<int>> v(maxn);
	queue<int> q;

	cin >> n;

	rep(i, n-1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		v[a].push_back(b); v[b].push_back(a);
	}

	fill(used, used + n, false);
	q.push(0); used[0] = true;
	df0[0] = 0;

	while (q.size()) {
		int i = q.front(); q.pop();
		for (int j = 0; j < v[i].size(); j++) {
			if (!used[v[i][j]]) {
				df0[v[i][j]] = df0[i] + 1;
				used[v[i][j]] = true;
				q.push(v[i][j]);
			}
		}
	}
	fill(used, used + n, false);
	dfn[n - 1] = 0;
	q.push(n - 1);
	used[n - 1] = true;
	dfn[n - 1] = 0;

	while (q.size()) {
		int i = q.front(); q.pop();
		for (int j = 0; j < v[i].size(); j++) {
			if (!used[v[i][j]]) {
				dfn[v[i][j]] = dfn[i] + 1;
				used[v[i][j]] = true;
				q.push(v[i][j]);
			}
		}
	}

	int sp = 0;

	for (int i = 0; i < n; i++) {
		if (df0[i] > dfn[i])sp++;
	}

	if (sp < n - sp) {
		cout << "Fennec" << endl;
	}
	else {
		cout << "Snuke" << endl;
	}

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N; 
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        cout << A[i];
        if(i != N - 1) cout << ' ';
        else cout << endl;
    }

    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;
        while( j >= 0 && v < A[j]){
            A[j + 1] = A[j];
            A[j] = v;
            j--;
        }
        rep(j, N){
            cout << A[j];
            if(j != N - 1) cout << ' ';
            else cout << endl;
        }
    }
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int main() {
  
  long long int cost[4], n;
  cin >> cost[0] >> cost[1] >> cost[2] >> cost[3] >> n;

  long long int cospa[4];
  cospa[0] = cost[0] * 8;
  cospa[1] = cost[1] * 4;
  cospa[2] = cost[2] * 2;
  cospa[3] = cost[3] * 1;

  long long int oneli[3];
  oneli[0] = cost[0] * 4;
  oneli[1] = cost[1] * 2;
  oneli[2] = cost[2] * 1;

  long long int most_cospa_index = 0;
  long long int most_cospa = cospa[0];
  for (int i = 0; i < 4; i++) {
    if (most_cospa > cospa[i]) {
      most_cospa = cospa[i];
      most_cospa_index = i;
    }
  }

  long long int second_cospa_index = 0;
  long long int second_cospa = cospa[0];
  for (int i = 0; i < 3; i++) {
    if (second_cospa > cospa[i]) {
      second_cospa = cospa[i];
      second_cospa_index = i;
    }
  }

  if (most_cospa_index == 3) {
    cout << cost[3] * (n / 2) + oneli[second_cospa_index] * (n % 2) << endl;
  } else {
    cout << n * oneli[most_cospa_index] << endl;
  }
  return 0;
}

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

using namespace std;

template< class T >
struct CumulativeSum
{
  vector< T > data;

  CumulativeSum(int sz) : data(sz, 0) {};

  void add(int k, int x)
  {
    data[k] += x;
  }

  void build()
  {
    for(int i = 1; i < data.size(); i++) {
      data[i] += data[i - 1];
    }
  }

  T query(int k)
  {
    if(k < 0) return (0);
    return (data[min(k, (int) data.size() - 1)]);
  }
};

int main()
{

  string S, T;
  int Q;
  cin >> S >> T;
  cin >> Q;

  CumulativeSum< int > sum1(S.size() + 1), sum2(T.size() + 1);

  for(int i = 0; i < S.size(); i++) {
    sum1.add(i + 1, S[i] == 'A');

  }
  for(int i = 0; i < T.size(); i++) {
    sum2.add(i + 1, T[i] == 'A');

  }
  sum1.build();
  sum2.build();


  while(Q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --c;

    int latte = sum1.query(b) - sum1.query(a);
    int malta = (b - a) - latte;

    int beet = sum2.query(d) - sum2.query(c);
    int uku = (d - c) - beet;
    if(((latte - malta) - (beet - uku)) % 3 == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }


    /*
    if((abs(latte - beet) + abs(malta - uku)) % 3 == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
*/
  }


}

Measured memory_bytes: 1664
//#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 1e6+5;
const double eps = 1e-8;

ll v[maxn];
int k[maxn];
map<int,int> mp;
int main()
{
    int n; cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> k[i];
        v[k[i]]++;
    }
    ll sum = 0;
    for(int i = 1; i <= n; i++) {
        if(!mp[k[i]]) {
           sum += v[k[i]]*(v[k[i]]-1)/2;
           mp[k[i]] = 1;
        }
    }
    for(int i = 1; i <= n; i++) {
        sum = sum - v[k[i]]*(v[k[i]]-1)/2 + (v[k[i]]-2)*(v[k[i]]-1)/2;
        cout << sum << endl;
        sum = sum - (v[k[i]]-2)*(v[k[i]]-1)/2 + v[k[i]]*(v[k[i]]-1)/2;
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<ll> Vec;
typedef vector<Vec> DVec;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

#define fi             first
#define se             second
#define pb             push_back
#define INF            LLONG_MAX/3
#define MOD            1000000007
#define bcnt           __builtin_popcount
#define all(x)         (x).begin(),(x).end()
#define uni(x)         x.erase(unique(all(x)),x.end())
#define ub(x,y)        (upper_bound(all(x),y)-x.begin())
#define lb(x,y)        (lower_bound(all(x),y)-x.begin())
#define ssort(x)       sort(all(x))
#define rep(i,n)       repl(i,0,n-1)
#define mkp(x,y)       make_pair(x,y)
#define mmax(x,y)      (x>y?x:y)
#define mmin(x,y)      (x<y?x:y)
#define maxch(x,y)     x=mmax(x,y)
#define minch(x,y)     x=mmin(x,y)
#define exist(x,y)     (find(all(x),y)!=x.end())
#define each(itr,v)    for(auto itr:v)
#define repl(i,a,b)    for(ll i=(ll)(a);i<=(ll)(b);i++)
#define dvec(n1,n2,i)  DVec(n1,Vec(n2,i))

int main(){
  cin.sync_with_stdio(false);
  ll n,k;
  ll ans = 0;
  cin >> n >> k;
  repl(a,k+1,n)repl(b,0,n/a){
    ll nd = a*b;
    ll am = mmin(1+n-nd,a);
    ll rm = mmax(0,am-k);
    ans+=rm;
    if(rm&&b==0&&k==0)ans--;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

N, M, Q = map(int, input().split())
A = [[0]*N for _ in range(N)]

for _ in range(M):
    L, R = map(int, input().split())
    A[L-1][R-1] += 1

acc = [[0]*(N+1) for _ in range(N+1)]

for i in range(N):
    for j in range(N):
        acc[i+1][j+1] = acc[i+1][j]+acc[i][j+1]-acc[i][j]+A[i][j]
    
for _ in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    print(acc[q+1][q+1]-acc[q+1][p]-acc[p][q+1]+acc[p][p])

Measured memory_bytes: 81296
a, b, c = map(int, input().split())
e = 0
for i in range(a):
  d = i + 1
  f = d
  L = []
  for j in range(len(str(d))):
    q, mod = divmod(f, 10)
    f = q
    L.append(mod)
  if b <= sum(L) and sum(L) <= c:
    e = e + d
print(e)

Measured memory_bytes: 9172
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
#include <stack>
#include <queue>

typedef long long ll;
#define ALL(obj) (obj).begin(),(obj).end()
#define MOD 1000000007


using namespace std;

long long GCD(long long x, long long y){
   long long r, tmp;
   if(x < y){
       tmp = x;
       x = y;
       y = tmp;
   }
   while(y!=0){
       r = x%y;
       x = y;
       y = r;
   }
   return x;
}
long long LCM(long long x, long long y){
   long long lcm = (x*y)/GCD(x, y);
   return lcm;
}

int bubblesort(int n){
    vector<int> data(n);
    int num=0;
    for(int end = n-1; end>0; end--){
        for(int j=0; j<end; j++){
            if(data[j+1] < data[j]){
                int temp = data[j];
                data[j] = data[j+1];
                data[j+1] = temp;
                num++;
            }
        }
    }
    return num;
}

int check[3000];
int dfs(int rem){
    if(check[rem]!=(-1)){
        return check[rem]%MOD;
    }
    if(rem<3){
        return check[rem]=0;
    }
    if(rem==1){
        return check[rem]=1;
    }
    check[rem]=1;
    for(int i=rem-3;i>=3;i--){
        check[rem]+=dfs(i);
        check[rem]%=MOD;
    }
    return check[rem];
}

int main(){
    long long n;
    cin >> n;
    fill(check, check+3000, -1);
    dfs(n);
    cout << check[n] << endl;
    return 0;
}


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

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

    int r, c;
    std::cin >> r >> c;
    std::vector<std::vector<int>> a(r+1, std::vector<int>(c+1, 0));
    for(int i=0; i<r; ++i){
        for(int j=0; j<c; ++j){
            std::cin >> a[i][j];
        }
    }
    for(int i=0; i<r; ++i){
        int sum = 0;
        for(int j=0; j<c; ++j){
            sum += a[i][j];
        }
        a[i][c] = sum;
    }
    for(int j=0; j<c; ++j){
        int sum = 0;
        for(int i=0; i<r; ++i){
            sum += a[i][j];
        }
        a[r][j] = sum;
    }
    int sum = 0;
    for(int i=0; i<r; ++i){
        sum += a[i][c];
    }
    a[r][c] = sum;
    for(int i=0; i<r+1; ++i){
        for(int j=0; j<c+1; ++j){
            std::cout << a[i][j] << ((j!=c)?" ":"\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

class UnionFind {
    int n;
    vector<int> par;
    vector<int> rank;

public:
    UnionFind(int a) : n(a), rank(a, 0) {
        par.reserve(n);
        for (int i = 0; i < a; i++) par.push_back(i);
    }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        int x_root = find(x);
        int y_root = find(y);
        if (rank[x_root] > rank[y_root]) {
            par[y_root] = x_root;
        } else if (rank[x_root] < rank[y_root]) {
            par[x_root] = y_root;
        } else if (x_root != y_root) {
            par[y_root] = x_root;
            rank[x_root]++;
        }
    }
    bool same(int x, int y) { return find(x) == find(y); }
};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    UnionFind uf(N);
    vector<int> cnt(N, 0);
    for(int i=0; i<M; i++){
        int x, y;
        cin >> x >> y;
        cnt[x]++;
        cnt[y]++;
        uf.unite(x, y);
    }

    map<int, vector<pair<int, int>>> mp;
    set<int> st;
    for(int i=0; i<N; i++){
        int par = uf.find(i);
        st.insert(par);
        mp[par].push_back(make_pair(a[i], i));
    }
    int K = mp.size();
    if(K == 1){
        cout << 0 << endl;
        return 0;
    }

    long long ans = 0;
    vector<pair<int, int>> vec;
    for(int par : st){
        auto &v = mp[par];
        sort(v.begin(), v.end());
        ans += v[0].first;
        for(int i=1; i<v.size(); i++)
            vec.push_back(v[i]);
    }
    if(vec.size() < K - 2){
        cout << "Impossible" << endl;
        return 0;
    }
    sort(vec.begin(), vec.end());

    for(int i=0; i<K-2; i++){
        ans += vec[i].first;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 17408
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static class Bill implements Comparable<Bill> {
		int p, v;
		double dis;
		Bill(int p,int v, double dis){
			this.p=p;
			this.v=v;
			this.dis=dis;
		}
		public int compareTo(Bill b) {
			if(this.dis-b.dis>0) {
				return 1;
			}
			return -1;
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				int b;
				double INF=1<<29;
				int[] x=new int[n+1];
				int[] y=new int[n+1];
				for(int i=0; i<n; i++) {
					b=sc.nextInt();
					x[b]=sc.nextInt();
					y[b]=sc.nextInt();
				}
				int m=sc.nextInt();
				int s, g;
				PriorityQueue<Bill> pq=new PriorityQueue<>();
				ArrayList<Integer> list=new ArrayList<>();
				while(m-->0) {
					s=sc.nextInt();
					g=sc.nextInt();
					pq.add(new Bill(0, s, 0.0));
					double [] cost=new double[n+1];
					int[] pre=new int[n+1];
					Arrays.fill(cost, INF);
					while(!pq.isEmpty()) {
						Bill bill=pq.poll();
						int now=bill.v;
						double d=bill.dis;
						if(cost[now]<d) continue;
						cost[now]=d;
						pre[now]=bill.p;
						if(now==g) 	break;
						
						for(int i=1; i<=n; i++) {
							if(i==now) continue;
							double r=Math.sqrt((x[now]-x[i])*(x[now]-x[i])+(y[now]-y[i])*(y[now]-y[i]));
							//System.out.println(now+" "+i+" "+r);
							if(r>50) continue;
							if(cost[i]>d+r) {
								pq.add(new Bill(now, i, d+r));
							}
						}
					}
					if(cost[g]==INF) System.out.println("NA");
					else {
						for(int i=g;;i=pre[i]) {
							list.add(i);
							if(i==s) break;
						}
						for(int i=list.size()-1;i>=0; i--) {
							if(i!=list.size()-1) System.out.print(" ");
							System.out.print(list.get(i));
						}
						System.out.println();
					}
					pq.clear();
					list.clear();
				}
				
			}

		}
	}
}


Measured memory_bytes: 28316