akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define pb(n) push_back(n)
#define endl '\n'
#define P(x) cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int ii = 0; ii < (V).size(); ii++) {cin >> (V).at(ii);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(ii,(V).size()){cout << (V)[ii] << " ";} cout<<endl;
#define VOUT2(V) REP(jj,(V).size()){VOUT(V[jj])}
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi > vvi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(n);
  ll d,x;
  IN2(d,x);
  vi a(n);
  VIN(a);

  FOR(i,1,d+1) {
    FOR(j,0,n) {
      FOR(k,0,1000) {
        if (i == 1 + a[j] * k) {
          ans++;
          break;
        }
      }
    }
  }
  OUT(ans + x);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  Main() {
    sc = new Scanner( System.in );
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void run() {
    for(;;) {
      int N=ni();
      if(N==0)break;

      int n = 1;
      int min = 1;
      int max = 1;
      int cnt = 0;
      while(true) {
        if(max > N)break;

        if(n==N){
          ++cnt;
          n += ++max;
        } else if (n < N) {
          n += ++max;
        } else {
          n -= min++;
        }
      }

      System.out.println(cnt-1);
    }
  }

  int ni() {
    return sc.nextInt();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

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

int main()
{
	int N, M, X;
	cin >> N >> M >> X;
	int c1 = 0, c2 = 0;
	for (int i = 0; i < M; i++) {
		int A;
		cin >> A;
		(A < X ? c1 : c2) += 1;
	}
	cout << min(c1, c2) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long int ll;


int main(){
    int h,w;
    cin>>h>>w;
    int a[505][505];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            a[i][j]%=2;
        }
    }
    int y[300000],x[300000],y1[300000],x1[300000];
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w-1;j++){
            if(a[i][j]%2!=0){
                
                a[i][j]=0;
                a[i][j+1]+=1;
                a[i][j+1]%=2;
                y[ans]=i+1;
                x[ans]=j+1;
                y1[ans]=i+1;
                x1[ans]=j+2;
                ans++;
                }
        }
    }
    for(int i=0;i<h-1;i++){
        if(a[i][w-1]%2!=0){
            
            a[i][w-1]=0;
            a[i+1][w-1]+=1;
            a[i+1][w-1]%=2;
            y[ans]=i+1;
            x[ans]=w;
            y1[ans]=i+2;
            x1[ans]=w;
            ans++;
            
        }
    }
    /*for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<a[i][j]<<endl;
        }
        }*/
    cout<<ans<<endl;
    for(int i=0;i<ans;i++){
        cout<<y[i]<<" "<<x[i]<<" "<<y1[i]<<" "<<x1[i]<<endl;
    }
    return 0;
}


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

void aruku(int** house,int w,int h,int row,int col){
	if(house[col][row]==0)return;
	house[col][row]=0;
	if(row+1<w)aruku(house,w,h,row+1,col);
	if(row+1<w && col+1<h)aruku(house,w,h,row+1,col+1);
	if(col+1<h)aruku(house,w,h,row,col+1);
	if(row-1>=0 && col+1<h)aruku(house,w,h,row-1,col+1);
	if(row-1>=0)aruku(house,w,h,row-1,col);
	if(row-1>=0 && col-1>=0)aruku(house,w,h,row-1,col-1);
	if(col-1>=0)aruku(house,w,h,row,col-1);
	if(row+1<w && col-1>=0)aruku(house,w,h,row+1,col-1);
return;
}

int tansaku( int** house,int w,int h){
	int row=0;int col=0;int cnt=0;
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++){
		if(house[i][j]==1){row=j;col=i;cnt++;
			aruku(house,w,h,row,col);
		}
	}
	return cnt;
}


int main(void){
int h,w;
	
	do{
	cin>>w;cin>>h;
	int** house=(int**)calloc(h,sizeof(int*));
	for(int i=0;i<h;i++)house[i]=(int*)calloc(w,sizeof(int));

	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){cin>>house[i][j];}
	}
	
	int ret=tansaku(house,w,h);
	if(w!=0 && h!=0)cout<<ret<<endl;
	for(int i=0;i<h;i++)free(house[i]);
	free(house);
	}while(w!=0 && h!=0);
	
	return 0;
}



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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y = x;
    if (z->key < x->key){
      x=x->left;
    }
    else
      x = x->right;
  }
  z->parent = y;

  if(y==NIL){
    root = z;
  }
  else if(z->key < y->key){
      y->left = z;
  }
  else y->right = z;
}
void inorder(Node u){
if (u !=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
}
void preorder(Node u){
    if(u !=NIL){
printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}

Measured memory_bytes: 24040
def f(a, b):
    rslt = []
    for i in a:
      if i in b:
        rslt += i
        b.remove(i)
    return rslt

n = int(input())
s = [sorted(list(input())) for i in range(n)]
for i in range(1,n):
  s[i] = f(s[i], s[i-1])
print("".join(s[-1]))

Measured memory_bytes: 3060
ans' d =
  let s = map sum d
      mx= maximum s
      mn= minimum s
  in
    [mx,mn]

ans ([0]:_) = []
ans ([n]:x) = 
  let d = take n x
      r = drop n x
      a = ans' d
  in
    a:(ans r)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c
      o = ans i
  mapM_ putStrLn $ map unwords $ map (map show) o



Measured memory_bytes: 5368
N = int(input())
b = list(map(int, input().split()))

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)

Measured memory_bytes: 3064
import Data.List
k = [1,1,1,2,1,2,1,5,2,2,1,5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

main = do
    n <- getLine
    print $ head $ reverse $ take (read n) k

Measured memory_bytes: 508
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            
            for(int i = 1 ; i <= H ; i++){
                if(i % 2 == 1){
                    for(int j = 1 ; j <= W ; j++){
                        if(j % 2 == 1){
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                } else {
                    for(int j = 1 ; j <= W ; j++){
                        if(j % 2 == 0){
                            System.out.print("#");
                        } else {
                            System.out.print(".");
                        }
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 33256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B , C;
  cin >> A >> B >> C;

  if (A <= C && C<= B){
    cout << "Yes" << endl;
  }
    else{
      cout << "No" << endl;
    }
}
      
    
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)

//int a[1001][1001] //aise global me hi

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}
//memset can initialize to 0 or -1 ONLY
// memset(a,0,sizeof(a[0][0])*n*n); //2D array
//memset(a, 0, sizeof(a));  //1D array
//memset(str, 't', sizeof(str)); // string
void solve()
{
    int n,x,y;cin>>n>>x>>y;
    int a[n];
    memset(a,0,sizeof(a));

    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=i;j++)
    		{

    			int dist=min(abs(i-j),min(abs(i-x)+1+abs(y-j),abs(i-y)+1+abs(j-x)));

    			a[dist]++;


    		}

    }
f(i,1,n) cout<<a[i]<<endl;
}


int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
 //   cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(s,t) for (int s = 0; s <= t; s++);
using ll = long long;


int main() {
  string s;
  int i,n,ans = 0;

  cin >> n >> s;

  for (int i = 0; i <= n - 3; i++){
    if((s[i] == 'A') && (s[i + 1] == 'B') && (s[i + 2] == 'C')){
      ans++;
    }

    }

  cout << ans << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int cnt = 1;
    int num1 = 0;
    if(s.size() == 1){
        print(k/2);
        return 0;
    }
    REP(i,s.size()-1){
        if(s[i] == s[i+1]){
            cnt++;
        }
        else{
            num1 += cnt/2;
            cnt = 1;
        }
    }
    if(cnt == s.size()){
        int t = s.size() * k;
        print(t/2);
        return 0;
    }
    num1 += cnt/2;
    string s1 = s+s;
    int num2 = 0;
    cnt = 1;
    REP(i,s1.size()-1){
        if(s1[i] == s1[i+1]){
            cnt++;
        }
        else{
            num2 += cnt/2;
            cnt = 1;
        }
    }
    num2 += cnt/2;
    if(num2-num1 == num1){
        print(k*num1);
    }
    else{
        int x = num2 - (num1 * 2);
        print((num1 * k) + (x * (k-1)));
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
using System;
using System.Linq;
class Program
 {
        static void Main(string[] args)
        {
           string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
           int N = int.Parse(str[0]);
           int M = int.Parse(str[1]);

            str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            int[] a = new int[N];
            for(int i = 0 ;i < N;i++)
           {
            a[i] = int.Parse(str[i]);  //数値で受け取りたい場合は変換す
           } 
            
            int count = 0;
          float sum = a.Sum();
          float aa = 4*M;
            for(int i = 0 ;i < N;i++)
            {
                if(a[i] < sum/aa)
                 {
                     count++;

                 }
            }
             if((N-count) >= M)
             {
             　Console.Write("Yes");//改行なし出力
             }
             else
             {
               Console.Write("No");//改行なし出力
             }

        }
 }







Measured memory_bytes: 13268
N,K = list(map(int, input().split()))
R,S,P = list(map(int, input().split()))
T = list(input())
ans = 0

for i in range(N):
    if i >= K and T[i] == T[i-K]:
        T[i] = 'zero'

for l in range(N):
    if T[l] == 'r':
        ans += P
    elif T[l] == 's':
        ans += R
    elif T[l] == 'p':
        ans += S

print(ans)





Measured memory_bytes: 4084
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}

function Main({ int, str, strs, ints }: NormalInput) {
  const N = int();
  const R = int();
  console.log(N>=10?R:R+100*(10-N));
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 7500
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <utility>
#include <set>
  
using namespace std;
 
int main() {

  string str;
  int n;
  cin >> str >> n;
   
  string mode;
  string tmp(str.size(), '0');
  int l, r;
   
  rep (i, n) {
    cin >> mode >> l >> r;
    if (mode == "print") {
      repx (j, l, r + 1) cout << str[j];
      cout << endl;
    }
    else if (mode == "reverse") {
      //repx (j, l, r + 1) tmp[j - l] = str[j];
      //rep (j, r - l + 1) str[r - j] = tmp[j];
      reverse(str.begin() + l, str.begin() + r + 1);
    }
    else if (mode == "replace") {
      cin >> tmp;
      //repx (j, l, r + 1) str[j] = tmp[j - l];
      str.replace(l, r - l + 1, tmp);
    }
    //cout << str << endl;
  }
  return 0;  
}



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

int main(){
    int b;
    int a;
    
    cin >> a >> b;

    if ((a * b) % 2 == 1)
    {
        cout << "Odd" << endl;
    }
    else
    {
        cout << "Even" << endl;
    }
    
    

}

Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>
 
int main(){
  int N;
  scanf("%d", &N);
  int d[N];
  int i;
  for (i = 0; i < N; i++) {
    d[i] = 0;
    scanf("%d", &d[i]);
  }
  int sum = 0;
  for (i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += d[i] * d[j];
    }
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll power(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)

//your code here!

int main(void){
    ll N, ans[100]={0};
    scanf("%lld", &N);
    if(0==N) {
        puts("0");
        return 0;
    }
    ll idx=0;
    while(N!=0) {
        ans[idx] = abs(N%(-2));
        if(N<0 && ans[idx]) N--;
        N /= -2;
        idx++;
    }
    for(ll i=idx-1; i>=0; i--) printf("%lld", ans[i]);
    return 0;
}


Measured memory_bytes: 128
n,m=gets.split.map(&:to_i)
h_list=gets.split.map(&:to_i)
g_list=[1]*n

m.times do
    a,b=gets.split.map(&:to_i)
    if h_list[a-1] > h_list[b-1]
        g_list[b-1]=0
    elsif h_list[a-1] < h_list[b-1]
        g_list[a-1]=0
    else
        g_list[a-1]=0
        g_list[b-1]=0
    end
end

ans=0

g_list.each do |i|
    ans+=1 if i!=0 
end

p ans


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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i,n){
        if(s[i]=='R') a[i]=0;
        if(s[i]=='G') a[i]=1;
        if(s[i]=='B') a[i]=2;
    }
    vector<int> cnt(3,0);
    rep(i,n) cnt[a[i]]++;
    ll ans = 1;
    rep(i,3) ans*= cnt[i];
    for(int j=0;j<n;j++){
        for(int i=0;i<j;i++){
            int k = j+j-i;
            if(k<n){
                if(a[i]!=a[k] and a[i]!=a[j] and a[j]!=a[k]) ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
//#include <fstream>	// require freopen

using namespace std;

struct D{
	int m, a, b;
};

int main()
{
//	cut here before submit 
//	freopen ("testcase.db", "r", stdin );
	int n;

	while (cin >> n && n ) {
		vector<D> d(n);
		int i,j;

		for (i = 0; i < n; ++i ){
			cin >> d[i].m >> d[i].a >> d[i].b;
		} // end for

		bool break_bridge = false;
		
		for (i = 0; i < n; ++i ){
			int sum = d[i].m;
			for (j = 0; j < n; ++j ){
				if (i != j && d[i].a >= d[j].a && d[i].a < d[j].b ){
					sum += d[j].m;
				} // end if
			} // end for
			if (sum > 150 ){
				break_bridge = true;
				break;
			} // end if
		} // end for
		
		cout << (break_bridge ? "NG" : "OK" ) << endl; 
	} // end while
		
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N, M;
    vector<vector<int>> G;
    vector<int> label;

    void input() {
        cin >> N >> M;
        G.resize(N);
        label.resize(N);
        rep(i, 0, M) {
            int a, b, c;
            cin >> a >> b >> c;
            a--, b--;
            G[a].push_back(b);
            G[b].push_back(a);
        }
    }

    void dfs(int v, int p = -1) {
        label[v] = 1;
        for (auto e : G[v]) {
            if (!label[e] && p != e) {
                dfs(e, v);
            }
        }
    }

    void solve() {
        input();
        int ans = 0;
        for (int i = 0; i < N; ++i) {
            if (!label[i]) {
                ans++;
                dfs(i);
            }
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 10752
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 100005

using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
long long int MOD = 1000000007;
int A[110000];
vector<int>g[110000];
bool dame=false;
long long dfs(int a,int b){
	long long rem=A[a];
	if(g[a].size()>1)rem*=2;
	for(int i=0;i<g[a].size();i++){
		if(b==g[a][i])continue;
		long long v=dfs(g[a][i],a);
		if(v>A[a])dame=true;
		rem-=v;
	}
	if(rem>A[a])dame=true;
	if(rem<0)dame=true;
	if(b==-1&&rem)dame=true;
	return rem;
}
int main(){
	int N;cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N-1;i++){
		int p,q;scanf("%d%d",&p,&q);p--;q--;
		g[p].push_back(q);
		g[q].push_back(p);
	}
	if(N==2){
		if(A[0]==A[1])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		return 0;
	}
	int at=-1;
	for(int i=0;i<N;i++){
		if(g[i].size()>1){
			at=i;break;
		}
	}
	if(at==-1)return 1;
	dfs(at,-1);
	if(dame)printf("NO\n");else printf("YES\n");
}


Measured memory_bytes: 13056
#include<stdio.h>
#include<iostream>
using namespace std;

string S;
int main (){
    cin >> S;
    int cnt = 0;
    int ans = 0;
    for(int i=0; i<S.size(); i++) {
        if( S[i] == 'A' || S[i] == 'C' || S[i] == 'G'|| S[i] == 'T') {
            cnt++;
        } else {
            ans = max( ans, cnt);
            cnt = 0;
        }
    }
    ans = max(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    n, m, k = map(int, input().split())
    mod = 998244353
    kai = [None]*n
    m1 = [None]*n
    num = 1
    ki = 1
    for i in range(n):
        m1[i] = num
        num *= m-1
        num %= mod
        kai[i] = ki
        ki *= i+1
        ki %= mod
    
    def comb(a, b):
        return kai[a]*fermat(kai[b]*kai[a-b], mod)
        
    ans = 0
    for i in range(k+1):
        ans += m*m1[n-1-i]*comb(n-1, i)
        ans %= mod
    print(ans)
        
def fermat(x, p):
    """
    1/x (mod p) を返す
        x**(p-1) ≡ 1    [if gcd(x, p) == 1]
        x**(p-2) ≡ 1/x
        繰返し二乗法 
            ex: x**50  = (x**25)**2
                x**25  = (x**12)**2 * x
                x**12  = (x**6)**2
                x**6   = (x**3)**2
    """
    times = []
    mod = p
    p -= 2
    while p > 1:
        times.append(p%2)
        p //= 2
    x %= mod
    out = x
    for i in times[::-1]:
        if i:
            out = (x*pow(out, 2, mod))%mod
        else:
            out = pow(out, 2, mod)
    return out

if __name__ == "__main__":
    main()

Measured memory_bytes: 77632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

int main(){
    ll N;
    cin >> N;
    vll A(N);
    set<ll> s;
    rep(i, N){
        cin >> A[i];
        decltype(s)::iterator it = s.find(A[i]);
        if(it != s.end()){
            s.erase(A[i]);
        }else{
            s.insert(A[i]);
        }
    }
    cout << s.size() << endl;
}

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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed

int H, W;
string S[3300];
int y[3300][3300], x[3300][3300];

signed main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++)cin >> S[i];
    for (int i = 1; i <= H; i++)for (int j = 1; j <= W; j++)y[i][j] = x[i][j] = S[i - 1][j - 1] == '.';
    for (int i = 1; i <= H; i++)
        for (int j = 1; j <= W; j++) {
            if (y[i][j] != 0)y[i][j] += y[i - 1][j];
            if (x[i][j] != 0)x[i][j] += x[i][j - 1];
        };
    for (int i = H; i >= 1; i--)
        for (int j = W; j >= 1; j--) {
            if (y[i][j] != 0)y[i][j] = max(y[i][j], y[i + 1][j]);
            if (x[i][j] != 0)x[i][j] = max(x[i][j], x[i][j + 1]);
        }
    int ans = 0;
    for (int i = 1; i <= H; i++)for (int j = 1; j <= W; j++)ans = max(ans, y[i][j] + x[i][j]);
    cout << ans - 1 << endl;

}

Measured memory_bytes: 110336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    vector<ll> a(3);
    for(int i = 0; i < 3; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    string ans = "No";
    if(a[0] == a[1] && a[1] != a[2]){
        ans = "Yes";
    }
    else if(a[0] != a[1] && a[1] == a[2]){
        ans = "Yes";
    }
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


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

#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef vector<int> vi;
typedef long long int ll;
vector<vector<int>> adj;

class A {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s; in>>s;
		s[3]='8';
		out<<s;

	}
    void inG(int m, istream& in){ int u,v; adj = vector<vi>(200005);f(i, m){ in>>u>>v; adj[u].push_back(v); adj[v].push_back(u); }}
};


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


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAXLEN 20

int main()
{
  static char str[MAXLEN + 1];
  int i;
  scanf("%s", str);
  for (i = strlen(str) - 1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int s,w; cin>>s>>w;
    if (w>=s) {
        cout << "unsafe" << '\n';
    }
    else {
        cout << "safe" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3624
// finish date: 2019/1/26

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;


int main() {
    int H, A;
    cin >> H >> A;
    cout << (H - 1) / A + 1<<endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

// bit演算

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	s := make([][]int, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			sj, _ := strconv.Atoi(sc.Text())
			s[i] = append(s[i], sj)
		}
	}

	p := make([]int, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	var ans int
	for i := 0; i < 1<<n; i++ {
		on := make([]bool, n)
		for j := 0; j < n; j++ {
			// on[j] = (i>>j)%2 == 1
			on[j] = i>>j&1 == 1
		}
		var miss bool
		for j := 0; j < m; j++ {
			var num int
			for _, v := range s[j] {
				if on[v-1] {
					num++
				}
			}
			if num%2 != p[j] {
				miss = true
				break
			}
		}

		if !miss {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1868
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    double X;
    string S;
    cin >> X;
    double cur=100;
    ll cnt=0;
    while(X > cur){
        cnt++;
        cur += cur*0.01;
        cur = double(ll(cur));
    }
    cout << cnt <<endl;
}

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

// requiredstring contains stringlist ?(yes:1,no:0)
template <class T>
bool strcontain(const string stringlist,
                const T& requiredstring) {
  return stringlist.find(requiredstring) != string::npos;
}

string s, p = "ATCG";

int solve();

int main() {
  cin >> s;

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

int solve() {
  int now = -1, ans = 0;
  for(int i = 0; i < s.size(); ++i) {
    if(!strcontain(p, s[i])) now = i;
    ans = max(ans, i - now);
  }

  return ans;
}

Measured memory_bytes: 256
using System;

public class Hello{
    public static void Main(){
        int N=int.Parse(Console.ReadLine());
        int juu=N/10;
        int ichi=N%10;
        if(juu==9||ichi==9){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }
    }
}


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

using namespace std;

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

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

    int Q;
    cin >> Q;
    vector<int> B(Q), C(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> B[i] >> C[i];
    }

    long long sum = 0;
    vector<long long> cnt(100005, 0);
    for (int i = 0; i < N; ++i) {
        cnt[A[i]]++;
        sum += A[i];
    }

    for (int i = 0; i < Q; ++i) {
        long long old_num = cnt[B[i]];
        long long minus = (long long)B[i] * (long long)old_num;
        long long plus = (long long)C[i] * (long long)old_num;
        cnt[B[i]] = 0;
        cnt[C[i]] += (long long)old_num;

        sum = sum - minus + plus;
        cout << sum << endl;
    }

}


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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (B >= C || A + B >= C)
		cout << B + C << endl;
	else
		cout << A + 1 + (B << 1) << endl;
	cin >> ws;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	map<int, int> A;

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

	int ans = 0;
	for (auto p : A) {
		if (p.second % 2 == 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#include <functional>
#include <map>
#include <queue>
using namespace std;
int main()
{
  long long x,y,z;
  cin>>x>>y;
  z=y-x;
  z*=z-1;
  z/=2;
  z-=x;
  cout<<z<<endl;
  //system("pause");
  return 0;
}

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

// #define fi first
// #define se second
#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(v) (v).begin(), (v).end()
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
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 (a>b) { a=b; return 1; } return 0; }

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;

const ll M=1000000007ll;
const ll MOD=1000000007ll;
const ll MAX=100000001ll;
//const ll M = 1000000000+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
   return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(ll n){
  if(n==0) return 1;
  mint ans = f(n/2);
  ans *= ans;
  if(n%2==1) ans*= 2;
  return ans;
}

mint choose(ll n, ll k){
  mint x=1, y=1;
  rep(i,k){
    x *= (n-i);
    y *= (i+1);
  }
  return x / y;
}

struct BIT {
  private:
   vector<ll> bit;
   ll N;
 
  public:
   BIT(ll size) {
     N = size;
     bit.resize(N + 1);
   }
 
   // 一点更新です
   void add(ll a, ll w) {
     for (ll x = a; x <= N; x += x & -x) bit[x] += w;
   }
 
   // 1~Nまでの和を求める。
   int sum(ll a) {
     ll ret = 0;
     for (ll x = a; x > 0; x -= x & -x) ret += bit[x];
     return ret;
   }
 };
 
ll fff(ll n, vector<ll>& v, ll i, ll j, ll rl){
  ll can = 0;
  ll can_i = 0;

  cout << v[0]<<endl;
  
  // right
  if(rl == 0){
    rep(k, n){
      if(v[k]*(j-k)>can){
	can = v[k]*(j-k);
	can_i = k;
      }
      //cout << can<<endl;
    }
    v[can_i] = 0;
    return can;
  }
  // left
  else{
    rep(k, n){
      if(v[k]*(k-i)>can){
	can = v[k]*(k-i);
	can_i = k;
      }
      //cout << can<<endl;

    }
    v[can_i] = 0;
    return can;
  }
  
}

ll ff(ll x){
  return x * (x+1) / 2;
}

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

  string s;
  cin>>s;

  stack<ll> st;
  rep(i, n){
    if(s[i]=='(') st.push(1);
    else{
      if(st.empty()) st.push(2);
      else if(st.top()==1) st.pop();
      else st.push(2);
    }
    //cout<<st.top()<<endl;
  }

  ///cout << 1<<endl;
  ll l=0, r=0;
  while(!st.empty()){
    if(st.top()==1) r++;
    else l++;
    st.pop();
  }

  rep(i, l){
    cout << "(";
  }

  cout<<s;
  
  rep(i, r){
    cout << ")";
  }
  
  
  cout<<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String args[]){
  Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int arr[]=new int[n];
  int dp[]=new int [n];
  for(int i=0;i<arr.length;i++)
    arr[i]=sc.nextInt();
  
  for(int i=1;i<n;i++){
    int min=Integer.MAX_VALUE;
  if((i-1)>=0){
    int a=dp[i-1]+Math.abs(arr[i]-arr[i-1]);
    if(a<min)
      min=a;
  }
    if((i-2)>=0){
     int a=dp[i-2]+Math.abs(arr[i]-arr[i-2]);
      if(a<min)
        min=a;
    }
    dp[i]=min;
  }
  System.out.println(dp[n-1]);
}
}

Measured memory_bytes: 49032
n = int(input())
L = list(map(int,input().split()))
li = []
a = 0
while a <= 101:
    for i in range(len(L)-1,-1,-1):
        if i == L[i]-1:
            li.append(L[i])
            L.pop(i)
            break
    a +=1
    
if len(L) > 0:
    print(-1)
else:        
    li = li[::-1]
    for i in range(len(li)):
        print(li[i])

Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  vector<ll> v;
  ll x[m+1]={};
  for(int i=0;i<m;i++){
    cin>>x[i];
  }
  sort(x,x+m);
  for(int i=1;i<m;i++){
    v.push_back(x[i]-x[i-1]);
  }
  sort(v.begin(),v.end());
  ll ans=0;
  for(int i=0;i<m-n;i++){
    ans+=v[i];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define INF 1000000000000 //10^12

int main(){
    ll n,m;
    cin >>n >>m;
    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

struct UnionFind {
    vector<int> par;
 
    UnionFind(int N) : par(N){
        rep(i,N)par[i]=i;
    }
 
    int root(int x){
        if(par[x]==x)return x;
        return par[x]=root(par[x]);
    }
 
    void unite(int x, int y){
        if(root(x)==root(y))return;
        par[root(x)]=root(y);
    }
 
    bool same(int x, int y){
        return root(x)==root(y);
    }
};

int main(){
    int N,M; cin>>N>>M;
    UnionFind tree(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        tree.unite(a-1,b-1);
    }
    int ROOT[N];
    rep(i,N)ROOT[i]=0;
    rep(i,N){
        int r=tree.root(i);
        ROOT[r]++;
    }
    sort(ROOT,ROOT+N);
    cout<<ROOT[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 10940
#include<stdio.h>
void kansu(int,int);
int main(void)
{
	int r,a;

	while(1)	{
		scanf("%d %d",&r,&a);
		if((r==0) && (a==0)) break;
		kansu(r,a);
	}
	return 0;
}
void kansu(int r,int a)
{
	int t[4],h[4];
	int i,j;
	int hit,blow;
	t[0]=r%10;
	r=r/10;
	t[1]=r%10;
	r=r/10;
	t[2]=r%10;
	t[3]=r/10;
	h[0]=a%10;
	a=a/10;
	h[1]=a%10;
	a=a/10;
	h[2]=a%10;
	h[3]=a/10;
	
	hit=0;
	blow=0;
	for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(h[i]==t[j]){
					if(i==j){
						hit++;
					}
					else{
						blow++;
					}
				}
			}
		}
	printf("%d %d\n",hit,blow);
}


Measured memory_bytes: 2592
///In the name of ALLAH

#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;
 
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mx_int_prime 999999937
 
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007
 
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define sqr(a) ((a) * (a))
 
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int mx = 1e5+123;
int dp[mx], n, h[mx], k;

int solve ( int i )
{
  if ( i == n ) return 0;
  if ( dp[i] != -1 ) return dp[i];

  int ret = inf;
  for ( int j = 1; j <= k; j++ ) {
    if ( i + j <= n ) ret = min ( ret, abs ( h[i] - h[i+j] ) + solve ( i+j ) );
  }

  return dp[i] = ret;
}

int main()
{
  optimize();

  cin >> n >> k;
  for ( int i = 1; i <= n; i++ ) cin >> h[i];

  memset ( dp, -1, sizeof (dp) );
  cout << solve ( 1 ) << endl;


  return 0;
}

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

long long int dp[1002][1002];

int main() {

    string t,b;

    cin >> t >> b;

    int tsize = t.size(), bsize = b.size();

    dp[0][0] = 1;

    for(int i=0;i<=t.size();i++){
        for(int j=0;j<=b.size();j++){
            if(t[i] == b[j]){
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= 1000000007;
            }
            dp[i+1][j] += dp[i][j];
            dp[i+1][j] %= 1000000007;
        }
    }

    cout << dp[tsize][bsize] << endl;

    return 0;
}

Measured memory_bytes: 10852
#define _CRT_SECURE_NO_WARINGS
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <fstream>
#include <map>
#include<cstring>
#include <unordered_map>

using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;

#define andrew ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v) (int)(v.size())
#define all(v) v.begin(), v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i *PI / 180.0)
#define cos(i) (long double)cos(i * PI/ 180.0)

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int dy8[] = { 0, 0, 1, -1, 1, -1, -1, 1 };
int dx8[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int id8[] = { 0, 1, 2, 3, 4, 5, 6, 7 };
struct item
{
    int w;
    ll v;
};
int n, w;
vector<item>v;
ll mem[101][100005];
ll solve(int i, int ww)
{
   
    if (i == n)
        return 0;
   
    if (mem[i][ww] != -1)
        return mem[i][ww];

    mem[i][ww] = solve(i + 1, ww);

    if (ww - v[i].w >= 0)
        mem[i][ww] = max(mem[i][ww], solve(i + 1, ww - v[i].w) + v[i].v);

    return mem[i][ww];
}
int main()
{
    andrew;   

    cin >> n >> w;
    v.resize(n);
    for (auto& it : v)
        cin >> it.w >> it.v;

    memset(mem, -1, sizeof(mem));

    cout << solve(0, w) << endl;



  

}


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

#define REP(i,n) for(ll i=0; i < (n); ++i)
#define REPR(i,n) for(ll i=(n); i >= 0; --i)
#define FOR(i, m, n) for(ll i = (m); i < (n); ++i)

#define INF 1e9

int N;
string s;
vector<vector<int>> patern;
int W = 0, S = 1;


int cmb(int sw, char ox, int t){
  if(sw == W && ox == 'o'){
    return (t+1) % 2;
  }
  else if(sw==W && ox=='x'){
    return t;
  }
  else if(sw == S && ox=='o'){
    return t;
  }
  else{
    return (t+1) % 2;
  }
}

void solve(){
  REP(i, 4){
    REP(j, N-1){
      if(j == 0){
        patern[i][N-1] = cmb(patern[i][0], s[0], patern[i][1]);
      }
      else if(j == N-2){
        if(cmb(patern[i][j], s[j], patern[i][j-1]) == patern[i][N-1] && cmb(patern[i][j+1], s[j+1], patern[i][j]) == patern[i][0]){
          REP(k, N){
            if(patern[i][k] == W){
              cout << 'W';
            }
            else{
              cout << 'S';
            }
          }
          cout << endl;
          return;
        }
      }
      else{
        patern[i][j+1] = cmb(patern[i][j], s[j], patern[i][j-1]);
      }
    }
  }
  cout << -1 << endl;
}

int main(){
  cin >> N >> s;
  patern.resize(4, vector<int>(N));
  patern[0][0] = patern[0][1] = W;
  patern[1][0] = W, patern[1][1] = S;
  patern[2][0] = patern[2][1] = S;
  patern[3][0] = S, patern[3][1] = W;
  solve();

  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N,M; cin >> N >> M;
    int P[M],Y[M];
    vector<vector<int>>V(N);
    rep(i,M){
        cin >> P[i] >> Y[i];
        V[P[i]-1].push_back(Y[i]);
    }
    rep(i,N){
        sort(V[i].begin(),V[i].end());
    }
    rep(i,M){
        auto itr = lower_bound(V[P[i]-1].begin(),V[P[i]-1].end(),Y[i]);
        cout << setfill('0') << right << setw(6) << P[i];
        cout  << setfill('0') << right << setw(6) << itr-V[P[i]-1].begin()+1;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 8576