akhauriyash/Code-Regression huggingface dataset:
n,m=map(int,input().split())
students=[]
checkpoints=[]
for i in range(n):
  students.append(input().split())
for j in range(m):
  checkpoints.append(input().split())
#print(students,checkpoints)
nearest=m
nearestdistance=2*10**8
distance=0
for s in range(n):
  for c in range(m):
    distance=abs(int(students[s][0])-int(checkpoints[c][0]))+abs(int(students[s][1])-int(checkpoints[c][1]))
    if distance<nearestdistance:
      nearest=c+1
      nearestdistance=distance
      #print('too near')
  print(nearest)
  nearest=m
  nearestdistance=2*10**8

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

class MyComparator implements Comparator{
	public int compare(Object arg0, Object arg1){
		long x = (long)arg0;
		long y = (long)arg1;

		if(x < y){
			return -1;
		}
		else if(x > y){
			return 1;
		}
		else{
			return 0;
		}
	}
}

class Main{
    public static final Comparator Comp = new MyComparator();
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[x];
        long[] b = new long[y];
        long[] c = new long[z];
        for(int i=0;i<x;i++){
        	a[i] = sc.nextLong();
        }
        for(int i=0;i<y;i++){
        	b[i] = sc.nextLong();
        }
        for(int i=0;i<z;i++){
        	c[i] = sc.nextLong();
        }
        PriorityQueue pq = new PriorityQueue(k,Comp);
        for(int i=0;i<x;i++){
        	for(int j=0;j<y;j++){
        		long w = a[i] + b[j];
        		if(pq.size()<k){
        			pq.add(w);
        		}
        		else if(w>(long)pq.peek()){
        			pq.poll();
        			pq.add(w);
        		}
        	}
        }
        ArrayList<Object> list = new ArrayList<Object>();
        int size = pq.size();
        for(int i=0;i<size;i++){
        	list.add(pq.poll());
        }

        pq.clear();
        for(int i=0;i<list.size();i++){
        	for(int j=0;j<z;j++){
        		long w = (long)list.get(i) + c[j];
        		if(pq.size()<k){
        			pq.add(w);
        		}
        		else if(w>(long)pq.peek()){
        			pq.poll();
        			pq.add(w);
        		}
        	}
        }
        list.clear();
        size = pq.size();
        for(int i=0;i<size;i++){
        	list.add(pq.poll());
        }

        for(int i=list.size()-1;i>=0;i--){
        	System.out.println(list.get(i));
        }
    }
}

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

int D;
const int M = 26;
vector<int> C;
vector<vector<int>> S;
vector<int> T;

const int INF = 1<<30;

template<class T> inline bool chmax(T &a, T b)
{
    if(a < b)
    {
        a = b;
        return true;
    }
    return false;
}

int calc_score(int N=D)
{
    assert(N <= D);
    int ans = 0;
    vector<int> last(M, -1);
    for(int i=0; i<N; i++)
    {
        if(T[i] != -1)
        {
            ans += S[i][T[i]];
            last[T[i]] = i;
        }
        for(int j=0; j<M; j++)
        {
            ans -= C[j] * (i - last[j]);
        }
        cout << ans << endl;
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> D;
    C.resize(M);
    for(int i=0; i<M; i++) cin >> C[i];
    S.resize(D);
    for(int i=0; i<D; i++)
    {
        S[i].resize(M);
        for(int j=0; j<M; j++)
        {
            cin >> S[i][j];
        }
    }
    T.resize(D);
    for(int i=0; i<D; i++)
    {
        cin >> T[i];
        T[i]--;
    }

    calc_score();

    return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

int main(void){

int n;
int i,j;
int min;
int max;
int check=1;
int idx;

scanf("%d",&n);
long int h[n];

for(i=0;i<n;i++){
  scanf("%ld",&h[i]);
}
i=n-1;
while(i>0){
  idx==0;
  while(idx==0||idx==1){
    if(h[i]-h[i-1]==-1){
      if(idx==1){
        printf("No");
        return 0;
      }
    idx=1;
    i--;
    }

    else if(h[i]-h[i-1]==0){
        i--;
    }
    else if(h[i]-h[i-1]<-1){
      printf("No");
      return 0;
      }

    else if(h[i]-h[i-1]>0){
      idx=0;
      i--;
    }
    if(i==0)
    break;
  }


}
if(idx==0||idx==1)
printf("Yes");
else
printf("No");



    return 0;
}


Measured memory_bytes: 896
/*
* Author. Silviase(@silviasetitech)
* For AtCoder
*/

import java.util.*;
import java.lang.*;
import java.math.*;


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



        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();
        int counter = 0;
        int ans = Math.max(a, b);
        while (counter != k) {
            if (a % ans == 0 && b % ans == 0) {
                counter++;
            }
            if (counter == k) {
                break;
            }
            ans--;
        }
        System.out.println(ans);

        
        sc.close();
    }


    public static long gcd(Long m, long n) {
        if(m < n) {
            return gcd(n, m);
        }
        if(n == 0){
            return m;
        } 
        return gcd(n, m % n);
    }

    public static long[][] Combination_nCk(long n, long k) {
        n++; k++;
        long[][] ans = new long[(int)n][(int)k];
        for (int i = 0; i < n; i++) {
            ans[i][0] = 1;
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = ans[i][j] + ans[i][j+1];
                }
            }
        }
        return ans;
    }

    public static double[][] Probability_nCk(int n, int k) {
        n++; k++;
        double[][] ans = new double[n][k];
        for (int i = 0; i < n; i++) {
            if (i == 0) {
                ans[i][0] = 1;
            }else{
                ans[i][0] = ans[i-1][0]/2;
            }
        }
        for (int i = 0; i < n-1; i++) {
            for (int j = 0; j < k-1; j++) {
                if (i < j) {
                    ans[i][j] = 0;
                }else{
                    ans[i+1][j+1] = (ans[i][j] + ans[i][j+1])/2;
                }
            }
        }
        return ans;
    }
}

Measured memory_bytes: 22228
using System;
using System.Linq;

namespace ABC081_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NK[0];
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var l = new int[N + 1];
            for (int i = 0; i < N; i++)
                l[A[i]]++;

            Array.Sort(l);
            var d = l.Where(x => x != 0).Count();
            Console.WriteLine(l.Where(x => x!= 0).Take(d - NK[1]).Sum());
        }
    }
}


Measured memory_bytes: 35804
#include <bits/stdc++.h>
#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 pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	int N;
	cin>>N;
	if(N==3){
		puts("2 5 63");
		return 0;
	}
	vector<int> v;
	rep1(i,30000){
		if(i%2==0 || i%3==0) v.pb(i);
	}
	while(true){
		random_shuffle(all(v));
		int S = 0;
		int g = 0;
		rep(i,N){
			S += v[i];
			g = gcd(g,v[i]);
		}
		if(S%6==0 && g==1){
			rep(i,N) cout<<v[i]<<" ";
			puts("");
			break;
		}
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
#define int long long 
using namespace std;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MAX(x) *max_element(ALL(x)) //最小値を求める
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define PB push_back //vectorヘの挿入

signed main(){
    int A ,B,C,D ;
    cin >> A>>B>>C>>D ;

    while(1){
        C -= B ;
        if(C<=0){
            cout << "Yes" <<endl ;
            break;
        }
        A -= D ;
        if(A<=0){
            cout <<"No"<<endl;
            break;
        }
     }

    return 0;
}

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

int main() {
    int n,q;cin>>n>>q;
    priority_queue<int > a[n];
    while(q--){
        int i;cin>>i;
        if(i==0){
            int t,x;cin>>t>>x;
            a[t].push(x);
        }
        if(i==1){
            int t;cin>>t;
            if(a[t].empty()){
                continue;
            }
            cout<<a[t].top()<<endl;
        }
        if(i==2){
            int t;cin>>t;
            if(a[t].empty()){
                continue;
            }
            a[t].pop();
        }
    }
    return 0;
}



Measured memory_bytes: 4056
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  console.log(' ' + buildMaxHeap(lines.shift().split(' ').map(Number)).join(' '));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  const maxHeapify = (i) => {
    let left, right, largest = i;
    left = 2 * i + 1;
    right = 2 * i + 2;
    // if (left >= n && right >= n) return;
    if (left < n && arr[left] > arr[largest]) largest = left;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
  return arr;
}



Measured memory_bytes: 110724
ans = 0
b=[]
for i in range(5):
  a = int(input())
  if a%10 != 0:
    ans += ((a//10)*10 + 10)
    b.append(a%10)
  else:
    ans += a
if sum(b) == 0:
  print(ans)
else:
  print(ans+min(b)-10)

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

bool f(Int t, Int x, Int y) {
    if (x + y > t) return false;
    return (t - (x + y)) % 2 == 0;
}

int main() {
    Int n;
    cin >> n;
    vector<Int> t(n + 1, 0), x(n + 1, 0), y(n + 1, 0);
    for (Int i = 0; i < n; i++) {
        cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
    }
    for (Int i = 0; i < n; i++) {
        if (not f(t[i + 1] - t[i], abs(x[i + 1] - x[i]), abs(y[i + 1] - y[i]))) {
            dump("No");
            return 0;
        }
    }
    dump("Yes");
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    ll n;
    cin >> n;
    ll r = 0;
    bool res = false;
    for(int i = 0;i < n;i++){
        ll a,b;
        cin >> a >> b;
        if(a == b)r++;
        else r = 0;
        if(r >= 3)res = true;
    }
    if(res)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3632
from collections import defaultdict

INF = 10 ** 10
def main():
    N, M = map(int, input().split())

    dp = [[INF] * N for _ in range(N)]
    edges = []
    for i in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        dp[a][b] = c
        dp[b][a] = c
        edges.append((a, b, c))

    for i in range(N):
        dp[i][i] = 0

    for m in range(N):
        for s in range(N):
            for e in range(N):
                if dp[s][m] != INF and dp[m][e] != INF:
                    dp[s][e] = min(dp[s][e], dp[s][m] + dp[m][e])

    ans = 0
    for a, b, c in edges:
        for s in range(N):
            if dp[s][a] + c == dp[s][b]:
                break
        else:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  if(n/1000==n/100-(n/1000)*10 && n/100-(n/1000)*10 == (n%100-n%10)/10) cout << "Yes" << endl;
  else if (n/100-(n/1000)*10 == (n%100-n%10)/10 && (n%100-n%10)/10==n%10) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
n=int(input())
 
x,y,h=[],[],[]
for i in range(n):
  a,b,c=map(int,input().split())
  x.append(a)
  y.append(b)
  h.append(c)
 
for i in range(n):
  if h[i]!=0:
      s=i
      break
 
for cx in range(101):
  for cy in range(101):
    H=h[s]+abs(x[s]-cx)+abs(y[s]-cy)
    for i in range(n):
      if h[i]!=max(0,H-abs(x[i]-cx)-abs(y[i]-cy)):break
      if i==n-1:print(cx,cy,H);exit()


Measured memory_bytes: 3064
from sys import stdin
n, *a = map(int, stdin.read().split())
c2, c4 = 0, 0
for i in a:
    if i % 2 == 0: 
        if i % 4 == 0:
            c4 += 1
        else:
            c2 += 1

if c4 >= len(a) // 2: ans = "Yes"
elif (len(a) - c4 * 2) == c2: ans = "Yes"
else: ans = "No"

print(ans)

Measured memory_bytes: 14052
#include <stdio.h>

int main(){
    double a,b,c,d,e,f;
    double x,y;
    while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
        y=(c*d-a*f)/(b*d-a*e);
        x=(c-b*y)/a;

        printf("%0.3f %0.3f\n",x,y);
    }
    return 0;
}

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

//ユークリッドの互除法
ll gcd(ll x,ll y){
    if(x > y) swap(x,y);
    if(x == 0) return y;
    return gcd(x,y%x);
};

int main(){
    int x;
    cin >> x;
    if(gcd(360,x) == 1) cout << 360 << endl;
    else cout << 360/gcd(360,x) << endl; 
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() { 
  ll n;
  cin >> n;

  std::vector<pair<ll,ll>> ba(n);

  rep(i,n) {
    ll tmpa,tmpb;
    cin >> tmpa >> tmpb;

    ba.at(i).first = tmpb;
    ba.at(i).second = tmpa;
  }

  sort(ba.begin(), ba.end());

  ll sumtime = 0;

  rep(i,n) {
    sumtime += ba.at(i).second;
    if(sumtime > ba.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 6448
#include <iostream>
#define MOD 1000000007
#define M_OD2 2000000014
using namespace std;

int main() {
  long long N; cin >> N;
  long long A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  
  long long sum = 0;
  for (int i = 0; i < N; i++){
    sum = (sum + A[i]) % M_OD2;
  }
  long long sum_ = 0;
  for (int i = 0; i < N; i++){
    sum_ = (A[i] * A[i] + sum_) % M_OD2;
  }
  long long ans;
  ans = ((sum * sum - sum_) % M_OD2 + M_OD2) % M_OD2;
  if (ans % 2 == 0) cout << ans / 2 << endl;
  if (ans % 2 == 1) cout << (ans + MOD) / 2 << endl;
}

Measured memory_bytes: 5196
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  h=pM(split(readline()))
  dp=[0 for i=1:n]
  dp[2]=abs(h[1]-h[2])
  for i=3:n
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
  end
  println(dp[end])
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

Measured memory_bytes: 168984
import sys

# import bisect
# import numpy as np
from collections import deque
# map(int, sys.stdin.read().split())
# import heapq
#import bisect
#import math

from collections import Counter


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


def main():
    N,K,Q =map(int,input().split())
    A =[]
    for i in range(Q):
        A.append(int(input()))
    c = Counter(A)
    for i in range(N):
        if K-Q+c[i+1] >0:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 16880
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int a = x1-x2, b=y1-y2;
    cout << x2+b << " " << y2-a << " " << x1+b << " " << y1-a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if (b / a >= c)
    {
        printf("%d\n", c);
    }
    else
    {
        printf("%d\n", b / a);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define N 100
#define MAX 100000000



void dijks();

int n,G[N][N];

int main(){
  int i,j,u,k,c,v;

  scanf("%d",&n);

  for(i = 0; i< n; i++){
    for(j = 0; j < n; j++){
      G[i][j] = MAX;
    }
  }

  for(i = 0; i< n; i++){
    scanf("%d %d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d %d",&v,&c);
      G[u][v] = c;
    }
  }

  dijks();
  return 0;

}

void dijks(){

  int minv,i,u,v;
  int d[N],color[N];

  for(i = 0; i < n; i++){
    d[i] = MAX;
    color[i] = 0;
  }

  d[0] = 0;
  color[0] = 1;

  while(1){
    minv =MAX;
    u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != 2){
        u  = i;
        minv = d[i];
      }
    }

    if(u == -1)break;
    color[u] = 2;

    for(v = 0; v < n; v++){
      if(color[v] != 2 && G[u][v] != MAX){
        if(d[v] > d[u] + G[u][v]){
          d[v] = d[u] + G[u][v];

color[v] = 1;
        }
      }
    }
  }

  for(i = 0; i < n; i++){
    printf("%d ",i);
    if(d[i] == MAX)printf("-1");
    else printf("%d\n",d[i]);
  }
}

Measured memory_bytes: 636
#include <stdio.h>
  int main(){
	   int a,b;
	  scanf("%d%d",&a,&b);
while(1){
int i,sum=0;
for(i=a;i<=b;i++){
if(i%400==0){
printf("%d\n",i); sum++;
}else if(i%100==0){
continue;
}else if(i%4==0){
printf("%d\n",i);sum++;
}}
if(sum==0) printf("NA\n");
sum=0;
scanf("%d%d",&a,&b);
if(a==0 && b==0) break;
printf("\n");
}
return 0;
}

Measured memory_bytes: 1044
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

struct UnionFind {
    vector<int> par;

    UnionFind(int n): par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }

    int issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;

        // merge by size
        // force size of x to be bigger than that of y
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;

        return true;
    }

    ll size(int x) {
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

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

    UnionFind uf(n);

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        uf.merge(a, b);
    }

    int ans = 0;
    vector<bool> used(n, false);

    REP(i, n) {
        int par = uf.root(i);

        if (par < 0) par = i;

        if (!used[par]) {
            ans++;
            used[par] = true;
        }
    }

    print(ans - 1);
}


Measured memory_bytes: 3732
#include <iostream>
#include <list>
#include <vector>
#include <cassert>
// #include <string>
// #include <algorithm>
// #include <numeric>
// #include <queue>
// #include <cmath>
// #include <set>
// #include <map>
// #include <iomanip>

#define MOD 1000000007
// #define INF 1000000001
#define S 100001

using namespace std;
typedef unsigned long long ull;
// typedef long long ll;

void p_() {
    cout << "\n";
}
template<class Head, class... Body>
void p_(Head head, Body... body) {
    cout << head << ",";
    p_(body...);
}


int main(int argc, char const *argv[]) {
    int A, B;
    cin >> A >> B;
    if (A % 3 == 0 || B % 3 == 0 || (A+B) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin,stdout
from math import sqrt
n,d=map(int,stdin.readline().split());c=0
d=float(d)
for _ in range(n):
    #v=int(stdin.readline())
    x,y=map(int,stdin.readline().split())
    if sqrt(x*x+y*y)<=d:c+=1
print(c)

Measured memory_bytes: 9180
N=int(input())
total=1
A=list(map(int,input().split()))
flag=True
high=1*(10**18)+1
if A.count(0)>=1:
  total=0
else:
  for i in range(N):
    total*=A[i]
    if high<=total:
      flag=False
      break

if not flag:
  print("-1")
else:
  print(total)

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

int main() {
    int N;
    cin >> N;
    pair<pair<string, int>,int> a[N];
    for (int i = 0; i < N; i++) {
        string S;
        int P;
        cin >> S >> P;
        a[i] = make_pair(make_pair(S, -1*P), i);
    }
    sort(a, a+N);
    for (int i = 0; i < N; i++)
        cout << a[i].second + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }

signed main() {
    int a, b, ans = 0;
    cin >> a >> b;
    if (b >= a) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
int main(){
	int N, K; cin >> N >> K;
	vector<int> v(200001);
	REP(i, N){
	    int tmp; cin >> tmp;
	    ++v[tmp];

	}

	priority_queue<int, vector<int>, greater<int>> que;
	FOR(i, 1, 200001){
	    if(v[i] != 0) que.push(v[i]);
	}

	int sum = 0;
	cerr << endl << que.size() << endl;
    while(que.size() > K) sum += que.top(), que.pop();

    cout << sum << endl;

}


Measured memory_bytes: 2168
N = int(input())
P = list(map(int, input().split()))
# ans = False
ans = 0
for i in range(N):
    if P[i] != i+1:
        ans += 1
# for i in range(N):
#     for j in range(i+1, N):
#         P[i], P[j] = P[j], P[i]
#         for k in range(1, N):
#             if P[k] < P[k-1]:
#                 break
#             if k == N-1:
#                 ans = True
#         if ans:
#             break
#         P[i], P[j] = P[j], P[i]
#     if ans:
#         break

if ans > 2:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(ll itr=mp.begin();itr!=mp.end();itr -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

//union find
struct UnionFind {
    vector<ll> parent;
    vector<ll> usize;
 
    UnionFind(int n) : parent(n), usize(n, 1LL){
        rep(i, n)parent[i]=i;
    }
    
    int root(int x){
        if(parent[x] == x) return x;
        else return parent[x] = root(parent[x]);
    }
    
    bool issame(int x, int y){
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
 
        if(x == y)return false;
 
        if(parent[x] > parent[y]) swap(x, y);

        usize[x] += usize[y];
        parent[y] = x;
 
        return true;
    }
    
    int size(int x) {
        return usize[root(x)];
    }
};

int main(){
    ll n, m;
    cin >> n >> m;

    ll a[m], b[m];
    rep(i, m){
        cin >> a[m-i-1] >> b[m-i-1]; 
        a[m-i-1]--, b[m-i-1]--;
    }

    UnionFind uf(n);
    ll cnt[m];
    rep(i, m){
        if(!uf.issame(a[i], b[i])){
            cnt[i] = uf.size(a[i]) * uf.size(b[i]);
            uf.merge(a[i], b[i]);
        }
        else {
            cnt[i] = 0;
        }
    }

    ll ans = 0;
    rep(i, m){
        ans += cnt[m-i-1];
        cout << ans << endl;
    }
}

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

int main(void)
{
    int n;
    cin >> n;

    vector<int> a(n);

    for (size_t i = 0; i < n  ; ++i)
    {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int mid = a[n / 2];
    int count = 0;
    if(a[n / 2 - 1] == a[n / 2]){
        cout << count << endl;
        return 0;
    }
    cout << (a[n / 2] - a[n / 2 - 1]) << endl;
    return 0;   
}

Measured memory_bytes: 640
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vvi root(n);
  rep(i, m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    root[a].push_back(b);
    root[b].push_back(a);
  }
  queue<int> que;
  que.push(0);
  vi checked(n, -1);
  checked[0] = 0;
  while(!que.empty()){
    int pos = que.front();
    que.pop();
    for(int a : root[pos]){
      if(checked[a] == -1){
        que.push(a);
        checked[a] = pos;
      }
    }
  }
  cout << "Yes" << endl;
  rep(i, n - 1) cout << checked[i + 1] + 1 << endl;
}

Measured memory_bytes: 10080
#include <stdio.h>

int main()
{
    int a, b, c, t;
    int sa, sb, sc;
 
    sa = sb = sc = 0;
    while (1) {
        scanf("%d%d%d", &a, &b, &c);
        if (a + b <= c || b + c <= a || c + a <= b) break;
        if (c < a) t = c, c = a, a = t;
        if (c < b) t = c, c = b, b = t;
        t = a*a + b*b;
        if      (c*c == t) sa++;
        else if (c*c <  t) sb++;
        else               sc++;
    }
    printf("%d %d %d %d\n", sa+sb+sc, sa, sb, sc);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> T(N);
    rep(i, N) {
        cin >> T.at(i);
    }
    int M;
    cin >> M;
    vector<int> P(M);
    vector<int> X(M);
    rep(i, M) {
        cin >> P.at(i) >> X.at(i);
    }

    rep(i, M) {
        int total = 0;
        rep(j, N) {
            if (j == P.at(i) - 1) {
                total += X.at(i);
            } else {
                total += T.at(j);
            }
        }
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <set>
#include <cassert>
#include <map>
#include <algorithm>
#include <sstream>
using namespace std;

long long a[2010];
int mn[4010][4010];
int main(){
	long long N,x;
	cin >> N >> x;
	for(int i = 0 ; i < N ; i++)
		cin >> a[i];
	reverse(a,a+N);

	for(int i = 0 ; i < 4010 ; i++)
		for(int j = 0 ; j < 4010 ; j++)
			mn[i][j] = 2e9;

	for(int i = 0 ;i < N ; i++) cin >> a[i], mn[i][i] = a[i], mn[i+N][i+N] = a[i];
	for(int i = 0 ; i < 2*N ; i++){
		for(int j = i+1 ; j < 2*N ; j++){
			mn[i][j] = min(mn[i][j],min(mn[j][j],mn[i][j-1]));
		}
	}
	long long ans = 1e18;
	//cout << mn[0][0] << endl;
	for(int s = 0 ; s <= N ; s++){	
		long long sub = 0;
		for(int k = 0 ; k < N ; k++){
			sub += mn[k][k+s];
		}
		//cout << s << " " << sub << endl;
		ans = min(ans,sub+s*x);
	}
	cout << ans << endl;
}

Measured memory_bytes: 63104
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,x,kaisuu,min;
    cin >> N;
    min = 9999999999; //minは２で割れた回数の最小値、後で値を更新
  
    for (int i=0; i<N; i++) {
      cin >> x;
      kaisuu=0;
      
      while (x % 2 == 0) {
        x /= 2;
        kaisuu ++;
      }
      
      if (kaisuu < min) {
        min = kaisuu;
      }
    }     
    cout << min << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

bool dpx[8030][20002] = {},dpy[8030][20002] = {};

signed main(){
	IOS;
	ll x, y;
	string s;
	cin >> s >> x >> y;
	ll n = s.size();
	vec<ll> vx,vy;
	ll c = 0;
	bool isx = true;
	REP(i,n){
		if(s[i] == 'T'){
			if(isx && c != 0){
				vx.push_back(c);
				c = 0;
			}
			else if(c != 0){
				vy.push_back(c);
				c = 0;
			}
			isx = !isx;
		}
		else c++;
	}
	if(isx){
		vx.push_back(c);
	}
	else{
		vy.push_back(c);
	}
	const ll cnt = 10000;
	ll tx = vx.size();
	ll ty = vy.size();
	dpx[0][cnt] = true;
	dpy[0][cnt] = true;
	for(int i = 0;i < tx;i++){
		for(int j = 0;j <= 20000;j++){
			if(i == 0 && s[0] == 'F'){
				if(j - vx[i] >= 0)dpx[i + 1][j] = dpx[i][j - vx[i]];
			}
			else {
				if(j - vx[i] >= 0)dpx[i + 1][j] = dpx[i][j - vx[i]];
				if(j + vx[i] < 20000)dpx[i + 1][j] |= dpx[i][j + vx[i]];
			}
		}
	}
	for(int i = 0;i < ty;i++){
		for(int j = 0;j <= 20000;j++){
			if(j - vy[i] >= 0)dpy[i + 1][j] = dpy[i][j - vy[i]];
			if(j + vy[i] < 20000)dpy[i + 1][j] |= dpy[i][j + vy[i]];
		}
	}
	if(dpx[tx][x + cnt] && dpy[ty][y + cnt])dump("Yes");
	else dump("No");
}

Measured memory_bytes: 82176
N = int(input())
heights = [int(n) for n in input().split()]

total_step = 0
for i in range(N):
    if i == 0:
        prev_max_height = heights[i]
        continue
    height = heights[i]
    if height > prev_max_height:
        prev_max_height = height
    else:
        total_step += prev_max_height - height

print(total_step)


Measured memory_bytes: 94268
n,d=map(int,input().split())
x=[]
y=[]
a=0
for i in range(n):
	q,w=map(int,input().split())
	x.append(q)
	y.append(w)
for i in range(n):
	ii=x[i]**2+y[i]**2
	t=pow(ii,0.5)
	if t<=d:
		a+=1
print(a)

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


int main(){
    int n;
    cin >> n;
    vector<int> f(n + 1, 0);
    f[0] = 1;
    int ans = -1;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        f[x] = f[x-1];
        if (f[x]) ans = max(ans, x);
    }

    if (ans != -1) ans = n - ans;
    cout << ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n ; i++)



int main() {
  int n; cin >> n;
  float m = (float)n;
  float a[n];float sum = 0; int result;
  rep(i,n){
    cin >> a[i];
    sum += a[i];
  }
  int av = round(sum / m);
  rep(i,n){
     result += pow(av - a[i],2);
  }
  cout << result << endl;

}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n + 1);
  for (int i = 1; i < n; i++)
  {
    cin >> a[i];
    b[a[i]]++;
  }
  for (int i = 1; i < n + 1; i++)
    cout << b[i] << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <math.h>
using namespace std;
int gcd(int a1, int b1) {
    if(a1 == 0 || b1 == 0) {
        return 0;
    }
    if(a1 >= b1) {
        if(a1 % b1 == 0) {
            return b1;
        } else {
            return gcd(b1, a1 % b1);
        }
    } else {
        if(b1 % a1 == 0) {
            return a1;
        } else {
            return gcd(a1, b1 % a1);
        }
    }
}

int main(void){
    // Here your code !
    int n, k, p=0;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) {
        k = 0;
        cin >> a[i];
        if(a[i] == 2) {
            p++;
            continue;
        } else if(a[i] % 2 == 0) {
            continue;
        }
        for(int j=0;j<floor(sqrt(a[i]));j++) {
            if(a[i] % (j+1) == 0) {
                k++;
            }
        }
        if(k == 1) {
            p++;
        }
    }
    cout << p << endl;
}

Measured memory_bytes: 3080
n = int(input())
x = list(map(int, input().split()))
sum = 0
for i in range(n):
  sum += x[i]
  
ave = sum//n
sum = 0
for i in range(n):
  sum += (x[i] - ave)**2
min = sum
sum = 0
for i in range(n):
  sum += (x[i] - ave - 1)**2
max = sum 
 
if min > max:
  print(max)
else:
  print(min)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<stack>
#include<deque>
#include <sstream>
#include <string.h>
#include<fstream>

typedef long long ll ;

#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
#define debug(x) cout<<#x<<" = { "<<x<<" }\n"490
void fo (){fflush(stdout);}
using namespace std;
map <int,int> a , b;
int main ()
{
  int n ;
  scanf ("%d" , &n );
  for (int i =0 ,t , turn = 0 ;i  < n ;i++ , turn = !turn )
  {
    scanf ("%d" ,&t );
    if (turn)
    {
      a[t]++;
    }else
    {
      b[t]++;
    }
  }
  int ans = 0 ;
  if (SZ(a) == SZ(b) && SZ(a) == 1 )
  {
    if (*a.begin() == *b.begin())
    ans = n/2;
  }else
  {
    pair <int,int> m1 , m2 , m11 , m22 ;
    m1.f = m2.f = m11.f = m22.f = -1 ;
    set<pair<int,int>> a1 , b1 ;
    for (auto i : a)
    {
      a1.insert({i.s,i.f});
    }
    for (auto i : b )
    {
      b1.insert({i.s,i.f});
    }
    for (auto i : a1)
    {
      if (m1.f == -1 )
      {
        m1.f = i.s ;
        m1.s = i.f ;
      }else
      {

        m11 = m1 ;
        m1.f = i.s ;
        m1.s = i.f ;
      }
    }
    for (auto i : b1 )
    {
      if (m2.f == -1 )
      {
        m2.f = i.s ;
        m2.s = i.f ;
      }else
      {
        m22 = m2 ;
        m2.f = i.s ;
        m2.s = i.f ;
      }
    }
    if (m1.f != m2.f )
    {
      ans = n - m1.s - m2.s ;
    }else
    {
      if (m11.f != -1 && m22.f != -1 )
      {
        ans = min (n-m1.s-m22.s , n - m11.s - m2.s );
      }else if (m11.f != -1 )
      {
        ans = min (n - m11.s - m2.s , n - m1.s );
      }else
      {
        ans = min (n-m22.s - m1.s , n - m2.s );
      }
    }
  }
  printf ("%d\n" ,ans );

      return 0;
}


Measured memory_bytes: 9600
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {

  ll a,b,c,k;
  cin >> a>>b>>c>>k;
  
  ll ans;

  if(k<=a) ans=k;
  else if(k<=a+b) ans=a;
  else ans=a-(k-a-b);
  
  cout << ans << endl;

}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,k;
int cnt[100010];

void solve(){
    cin >> n >> k;
    rep(i,k){
        int d;cin >> d;
        rep(j,d){
            int a;cin >> a;a--;
            cnt[a]+=1;
        }
    }
    int ans=0;
    rep(i,n){
        if(cnt[i]==0) ans+=1;
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;

const ll INF = (1LL<<60);

int main(){

    ll n; cin >> n;

    ll sum = 0;
    rep2(i, 1, n) sum += i;

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c;
    cin >> a >> b >> c;
    if (a>b) swap(a, b);
    string ans = "Yes";
    if (c<a || c>b) ans = "No";
    
    pr(ans);
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5+5;
int n, m;
struct Tree {
    int ls, rs; ll val; // 左右儿子的编号, 和维护的一个值.
}tre[maxn*80];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}
int update(int pre, int l, int r, int pos, ll v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}
ll query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}
int a[maxn], vis[maxn];
void solve() {
    scanf("%d%d", &n,&m);
    for (int i = 1 ; i <= n ; i ++) {
        scanf("%d", &a[i]);
    }
    root[0] = build(1, n);  
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; scanf("%d%d", &l, &r);
        ll tmp = query(root[r], 1, n, l);
        printf("%lld\n", tmp);
    }
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 334664
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto it = v.begin(); it != v.end(); it++) {
    os << *it << " ";
  }
  return os;
}

int main(int argc, char*argv[])
{
  int m;
  vector<int> xs, ys;
  cin >> m;
  for(int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    xs.push_back(x);
    ys.push_back(y);
  }
    /*
      | x1 y1 1 |
      | x2 y2 1 |
      | x3 y3 1 |
     */
  auto area = [](int x1, int y1, int x2, int y2, int x3, int y3) {
    return x1 * y2 + x2 * y3 + x3 * y1 - (x1 * y3 + x2 * y1 + x3 * y2) ;
  };
  // 1-2 and 3-4
  auto isPara = [&xs,&ys,&area](int p1, int p2, int p3, int p4) {
    int dx = xs[p1] - xs[p3];
    int dy = ys[p1] - ys[p3];
    return 0 == area(xs[p1], ys[p1], xs[p2], ys[p2], xs[p4] + dx, ys[p4] + dy);
  };
  int memo[256][256];
  for(int i = 0; i < m; i++) {
    for(int j = 0; j < m; j++) {
      for(int k = 0; k < m; k++) {
        for(int l = 0; l < m; l++) {
          memo[(i<<4)+j][(k<<4)+l] = isPara(i,j,k,l) ? 1 : 0;
        }
      }
    }
  }
  vector<bool> vss(m);  // choice of sources
  for(int i = 0; i < m/2; i++) {
    vss[i] = false;
    vss[i+m/2] = true;
  }
  int mx = 0;
  do {
    //cout << vss << endl;
    vector<int> ts, ss;
    for(int i = 0; i < m; i++) {
      if(!vss[i]) ts.push_back(i);
      else ss.push_back(i);
    }
    do {
      // check if ts[i] > ss[i]
      bool skip = false;
      for(int i = 0; i < m/2; i++) {
        if(ss[i] < ts[i]) {
          skip = true;
          break;
        }
      }
      if(!skip) {
        int pp = 0;
        for(int i = 0; i < m/2; i++) {
          const int *mm = memo[(ss[i]<<4)+ts[i]];
          for(int j = i+1; j < m/2; j++) {
            pp += mm[(ss[j]<<4)+ts[j]];
          }
        }
        if(pp > mx) mx = pp;
      }
    } while(next_permutation(ts.begin(), ts.end()));
  } while(next_permutation(vss.begin(), vss.end()));
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 3396
from collections import deque
import copy

N, K, C = map(int,input().split())
S = input().split()[0]
TW = 0
q = []

for s in range(len(S)):
    if S[s] == 'o':
        q.append(s+1)

WD = []
LD = 0

for s in q:
    if len(WD) > K:
        break
    if LD == 0:
        WD.append(s)
        LD = s
    elif s-LD <= C:
        continue
    else:
        WD.append(s)
        LD = s


WDR = []
LD = 0
q.reverse()

for s in q:
    if len(WDR) > K:
        break
    if LD == 0:
        WDR.append(s)
        LD = s
    elif LD - s <= C:
        continue
    else:
        WDR.append(s)
        LD = s


for d in range(len(WD)):
    if WD[d] == WDR[len(WD)-d-1]:
        print(WD[d])



Measured memory_bytes: 20988
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = Reader.NextUInt;
        int last = 0;
        int cur = 0;
        int max = 0;
        for (int i = 0; i < n; i++)
        {
            var h = Reader.NextUInt;
            if (last >= h) max = Max(max, ++cur);
            else cur = 0;
            last = h;
        }
        Console.WriteLine(max);
    }
}

static class Reader
{
    const int BUF_SIZE = 1 << 14;
    static Stream Stream;
    static byte[] buffer = new byte[BUF_SIZE];
    static int ptr = 0;
    static Reader() { Stream = Console.OpenStandardInput(); }

    private static void Read()
    {
        Stream.Read(buffer, 0, BUF_SIZE);
    }

    private static byte Next { get { if (ptr == buffer.Length) { Read(); ptr = 0; } return buffer[ptr++]; } }

    public static int NextUInt
    {
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        get
        {
            int res = 0; byte next;
            do { next = Next; } while (next < 48);
            do { res = res * 10 + next - 48; next = Next; } while (48 <= next);
            return res;
        }
    }
}


Measured memory_bytes: 13140