akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <math.h>

void swap(int * a, int * b)
{
    int t = *a;
    *a = *b;
    *b = t;
}

void print_int(int n)
{
    printf("%d\n",n);
    
}

void sort(int a[], int n)
{
    int h, i, j;

    for(h = 1; h < n / 9; h = h * 3 + 1)
        continue;

    for(; h > 0; h /= 3)
    {
        for(i = h; i < n; i++)
        {
            j = i;
            while(j >= h && a[j] < a[j-h])
            {
                swap(&a[j], &a[j-h]);
                j -= h;
            }
        }
    }
}

void print_list(int a[], int n)
{
    for(int i = 0; i < n; i++)
    {
        printf("%d ", a[i]);
    }
}

void intcpy(int a[], const int b[], int count)
{
    for(int i = 0; i < count; i++)
    {
        a[i] = b[i];
    }
}

int list_sum(int a[], int n)
{
    int sum = 0;

    for(int i = 0; i < n; i++)
    {
        sum += a[i];
    }

    return sum;
}


void permutate(int s[], int count, int n)
{
    if(n == count)
        return;

    for(int i = n; i < count; i++)
    {
        swap(&s[i], &s[n]);

        if(i != n)
        {
            //intcpy(result[j++], s, count);
        }
        
        permutate(s, count, n+1);
        swap(&s[i], &s[n]);
    }
}




int main(void)
{
   char s[50];
   int n,k;
   scanf("%d %d", &n, &k);
   scanf("%s", s);
   if(s[k-1] == 'A')
   {
       s[k-1] = 'a';
   }
   else if(s[k-1] == 'B')
   {
       s[k-1] = 'b';
   }
   else if(s[k-1] == 'C')
   {
       s[k-1] = 'c';
   }
   printf("%s", s);
   

    return 0;
}



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

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    long x[1010], y[1010];
    for(int i=0; i < n; ++i) cin >> x[i] >> y[i];

    // parity check
    bool parity = (abs(x[0]) + abs(y[0])) & 1;
    for(int i = 1; i < n; ++i) {
        bool tmp = (abs(x[i]) + abs(y[i])) & 1;
        if(parity != tmp) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<long> d;
    // length
    for(int i = 30; i >= 0; --i) d.push_back(1L<<i);
    if(!parity) d.push_back(1);

    cout << d.size() << '\n';
    for(int i = 0; i < d.size(); ++i) cout << d[i] << (i == d.size()-1 ? '\n' : ' ');

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < d.size(); ++j) {
            if(abs(x[i]) >= abs(y[i])) {
                if(x[i] < 0) {
                    cout << 'L';
                    x[i] += d[j];
                } else {
                    cout << 'R';
                    x[i] -= d[j];
                }
            } else {
                if(y[i] < 0) {
                    cout << 'D';
                    y[i] += d[j];
                } else {
                    cout << 'U';
                    y[i] -= d[j];
                }
            }
        }
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
		 
		static void solve() {
			Scanner sc = new Scanner(System.in);
			String S = sc.next();
			String T = sc.next();
			int res = 0;
			sc.close();
			for(int  i = 0; i<S.length();i++) {
				if(S.charAt(i)==T.charAt(i)) {
					res++;
				}
			}	
			if(res +1>=T.length()) {
				System.out.print("Yes");
			}
			else {
				System.out.print("No");
		}
	}
	public static void main(String[] args) {
		solve();
	}

}


Measured memory_bytes: 35520
#include<stdio.h>
#include<string.h>
#include<stdlib.h>



int main(){
  int n=0;
  char c[20002];
  int height[20002];//i番目のマスの左の高さは、height[i-1]。右の高さはheight[i]。height[0]=0
  height[0]=0;//基準の高さ
  int flood[20002];//水の体積。1オリジン
  int floodnum=0;//池の数
  int sum=0;

  
  while(1){
    scanf("%c",&c[n+1]);
    if(c[n+1]=='\n') break;
    if(c[n+1]=='\\') height[n+1]=height[n]-1;
    else if(c[n+1]=='/') height[n+1]=height[n]+1;
    else height[n+1]=height[n];
    n+=1;
  }//読み込み。nが文字の数を表す。cは１オリジン。


  int i;//処理中のマスを表す。
  i=1;
  int j,k;//繰り返し用
  int max;//右の壁となるマス目の番号
  while(1){
    if(c[i]=='\\'){
      j=i+1;
      while(j<=n){
        if(height[i-1]==height[j]) break;
        j+=1;
      }
      
      if(j<=n){
        floodnum+=1;
        flood[floodnum]=0;
        for(k=i;k<=j;k++) flood[floodnum]+=height[i-1]-height[k];
        i=j+1;//次に調べるマスの更新
      }//左側の壁のほうが低い池
       
      else{
        max=-1;
        for(j=i+1;j<=n;j++){
          if(c[j]=='/'){
            if(max==-1) max=j;
            else if(height[max]< height[j]) max=j;
          }
        }
        if(max==-1) i=n+1;
        else{
          floodnum+=1;
          flood[floodnum]=0;
          for(j=i;j<=max;j++){
            if(height[max]-height[j]>0) flood[floodnum]+=height[max]-height[j];
          }
          i=max+1;
        }
      }//右側の壁のほうが低い池
    }
    else i+=1;
    if(i>n) break;
  }

  for(i=1;i<=floodnum;i++) sum+=flood[i];  
  printf("%d\n",sum);
  printf("%d",floodnum);
  for(i=1;i<=floodnum;i++) printf(" %d",flood[i]);
  printf("\n");
  return 0;
}



//  \を出力、入力したい場合は\\で表す





Measured memory_bytes: 2080
#include <cstdio>  
#include <algorithm>
using namespace std;  
int main() { 	
	int a,b,c;
	int d;
	scanf("%d/%d/%d", &a,&b,&c);
	if(a>2019){
		printf("TBD");
	}
	if(a<2019){
		printf("Heisei");
	}
	if(a==2019){
		if(b>4){
			printf("TBD");
		}
		if(b<4){
			printf("Heisei");
		}
		if(b==4){
			if(c<=30){
				printf("Heisei");
			}
			if(c>30){
				printf("TBD");
			}
		}
	}

	
	
}






Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      int e = sc.nextInt();
      int k = sc.nextInt();
      if(e-a <= k)System.out.println("Yay!");
      else System.out.println(":(");
    }
}


Measured memory_bytes: 21844
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b>>c;
	cout<<(c/a)*b;
	return 0;
}

Measured memory_bytes: 384
from collections import defaultdict

def f(x):
    a = x%10
    b = 0
    while x:
        b = x
        x //= 10
    return (a,b)

N = int(input())
freq = defaultdict(int)
for i in range(N):
    p = f(i+1)
    freq[p] += 1
ans = 0
for i in range(N):
    p = f(i+1)
    q = (p[1], p[0])
    ans += freq[q]
print(ans)


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

using namespace std;

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

  set<set<int> > ssi;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    set<int> si;
    int a;
    for (int j = 0; j < 3; j++) {
      cin >> a;
      si.insert(a);
    }

    if (ssi.find(si) != ssi.end()) {
      ans++;
    }
    ssi.insert(si);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            int X = in.nextInt();
            int A = in.nextInt();
            int B = in.nextInt();
            int rem = X - A;
            out.println(rem % B);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 21460
// %%
import java.util.*;
import java.io.PrintWriter;

// %%
public class Main {

    private static int N;
    private static int K;
    private static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        load();
        solve();
        pw.flush();
    }

    private static void load() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        K = sc.nextInt();
    }

    private static void solve() {
        if (K > (N - 1) * (N - 2) / 2) {
            pw.println(-1);
            return;
        }

        int cnt = N - 1 + (N - 1) * (N - 2) / 2 - K;
        pw.println(cnt);

        for (int v = 1; v <= N; v += 1) {
            for (int w = v + 1; w <= N; w += 1) {
                pw.println(String.format("%d %d", v, w));
                cnt -= 1;
                if (cnt == 0) {
                    return;
                }
            }
        }
    }

}


Measured memory_bytes: 30292
;;; Utils (quoted from https://competitive12.blogspot.com/2020/03/common-lisp.html)


;; Read fixnum

(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (declare (inline read-byte)
           #-swank (sb-kernel:ansi-stream in))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (read-byte in nil 0))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setq minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (the (integer 0 #.(floor most-positive-fixnum 10)) (* result 10))))
              (return (if minus (- result) result))))))))

;; fast read-line

(defmacro buffered-read-line (&optional (buffer-size 30) (in '*standard-input*) (term-char #\Space))
  (let ((buffer (gensym))
        (character (gensym))
        (idx (gensym)))
    `(let* ((,buffer (load-time-value (make-string ,buffer-size :element-type 'base-char))))
       (declare (simple-base-string ,buffer)
                (inline read-byte))
       (loop for ,character of-type base-char =
             ,(if (member :swank *features*)
                  `(read-char ,in nil #\Newline) ; on SLIME
                `(code-char (read-byte ,in nil #.(char-code #\Newline))))
             for ,idx from 0
             until (char= ,character #\Newline)
             do (setf (schar ,buffer ,idx) ,character)
             finally (when (< ,idx ,buffer-size)
                       (setf (schar ,buffer ,idx) ,term-char))
             (return (values ,buffer ,idx))))))


;;; invoke child process

#-swank
(unless (member :child-sbcl *features*)
  (quit
    :unix-status
    (process-exit-code
      (run-program *runtime-pathname*
                   `("--control-stack-size" "128MB"
                     "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                     "--eval" "(push :child-sbcl *features*)"
                     "--script" ,(namestring *load-pathname*))
                                                                 :output t :error t :input t))))



;-------------------
; Write code here
;-------------------



(defun solve (avail-time push-time)
  (cond
    ((null (rest push-time)) avail-time)
    (t
     (+ (min (- (second push-time) (first push-time))
             avail-time)
        (solve avail-time (rest push-time))))))

(defun main ()
  (let* ((n (read))
         (available-time (read))
         (push-time (read-from-string (concatenate 'string "(" (read-line) ")"))))
    (princ (solve available-time push-time))
    (fresh-line)))

(main)


Measured memory_bytes: 66428
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N = int(input())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))

ret = 0
for i in range(N):
  ret += min([An[i]+An[i+1],Bn[i]])
  An[i+1] = max([An[i+1]-max([Bn[i]-An[i],0]),0])
print(ret)

Measured memory_bytes: 82148
n = int(input())
u = [list(map(int, input().split())) for i in range(n)]
z = [u[i][0] + u[i][1] for i in range(n)]
w = [u[i][0] - u[i][1] for i in range(n)]
d = [max(z)-min(z), max(w)-min(w)]

print(max(d))
	


Measured memory_bytes: 61068
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int a[100005];
int zero = 0;

int main()
{
	cin >> n;
	for (int i = 0;i < n;i++) {
		int t;
		cin >> t;

		a[t]++;
		a[t + 1]++;
		if (t == 0) {
			zero++;
		}
		else {
			a[t - 1]++;
		}
	}

	int ma = -1;
	for (int i = 0;i < 100005;i++) {
		ma = std::max(ma, a[i]);
	}

	ma = std::max(ma, zero);

	cout << ma << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

int main(){
  int N,T;
  cin>>N>>T;
  vector<pair<int,int>> AB(N);
  for(int i=0;i<N;i++){
    cin>>AB.at(i).first>>AB.at(i).second;
  }
  sort(AB.begin(),AB.end());

  vector<int> dp(6001,0);
  for(int i=0;i<N;i++){
    for(int j=6000;j>=0;j--){
      if(0<=j-AB.at(i).first&&j-AB.at(i).first<T){
        dp.at(j)=max(dp.at(j),dp.at(j-AB.at(i).first)+AB.at(i).second);
      }
    }
  }
  int ans=0;
  for(int i=0;i<=6000;i++){
    ans=max(ans,dp.at(i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
    def find(self, x):
        if self.par[x] == x:
          return x
        else:
          self.par[x] = self.find(self.par[x])
          return self.find(self.par[x])
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

n, k, l = map(int, input().split())
uf1 = UnionFind(n)
uf2 = UnionFind(n)

for i in range(k):
  x, y = map(int, input().split())
  uf1.union(x-1, y-1)
for i in range(l):
  x, y = map(int, input().split())
  uf2.union(x-1, y-1)

pair = [(uf1.find(i), uf2.find(i)) for i in range(n)]
import collections
c = collections.Counter(pair)
ans = [c[pair[i]] for i in range(n)]

print(" ".join(map(str,ans)))

Measured memory_bytes: 126356
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt=0;

	for(int i=0; i+3<=n; i++) {
		string a=s.substr(i,3);
		//cout<<a<<endl;
		if(a=="ABC") {
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N ;
    bool Arare= false;
  for(int i = 0; i<N; i++) {
     string op;
    cin>>op;
   if (op=="Y") {
     Arare = true;
    break;
    }   
  }
  if (Arare){
    cout << "Four";
  }
  else{
    cout << "Three";
    
  }
    
}


Measured memory_bytes: 256
n = int(input())
c = input()
r=0
w=0
p=0
count = 0
for i in range(len(c)):
    if c[i]=="R":
        r+=1
    else:
        w+=1
white = []

for i in range(len(c)):
    if c[i]=="R":
        r-=1
        
    else:
        white.append(r)
    if r==0:
        break
if len(white)==0:
    print(0)
elif white[0]==0:
    print(0)
else:
    for i in range(len(white)):
        if white[-i-1]>=len(white)-i:
            print(len(white)-i)
            break

Measured memory_bytes: 81264
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
typedef long long LL;
typedef unsigned long long ULL;

int K, T;
int A[101];

int main() {
	cin >> K >> T;
	REP(i, 0, T) {
		cin >> A[i];
	}
	sort(A, A + T, greater<int>());
	cout << max(0, -K - 1 + 2 * A[0]) << endl;
	return 0;
}

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

using namespace std;

int main(void){
  int N;
  cin >> N;
  int i;
  vector<double> v(N);
  for(i=0; i<N; i++)
    cin >> v[i];

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

  for(i=1; i<N; i++)
    v[i] = (v[i-1]+v[i])/2;

  cout << fixed;
  cout << setprecision(8) << v[i-1] << endl;


  return 0;
}


Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// Data :
type Data struct {
	spend, limit int
}

// Datas :
type Datas []Data

func (p Datas) Len() int {
	return len(p)
}

func (p Datas) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Datas) Less(i, j int) bool {
	return p[i].limit < p[j].limit
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	d := make(Datas, N)
	for i := 0; i < N; i++ {
		a, b := getInt(), getInt()
		d[i].limit = b
		d[i].spend = a
	}
	sort.Sort(d)

	// out(d)

	ans := true
	start := 0
	for i := 0; i < N; i++ {
		// out(start, i, "limit", d[i].limit, "time", d[i].spend)
		start += d[i].spend
		// out(start)
		if d[i].limit < start {
			ans = false
			break
		}
	}

	if ans {
		out("Yes")
	} else {
		out("No")
	}

}


Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();
        int sum = 0;

        while (a <= b) {
            if (c % a == 0) {
                sum++;
            }
            a++;
        }

        System.out.println(sum);
    }
}

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

#define int long long

int32_t main()
{
    int n;
    cin>>n;
    
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    
    int dp[n][3]={0};
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
                             
                             

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


int N;
int A[20];
int x[20][20];
int y[20][20];

int dfs(int map[], int level, int n) {
  if (level == N) {
    rep(i, N) {
      if (map[i] == 0) continue;
      rep(j, A[i]) {
        if (map[x[i][j] - 1] != y[i][j]) {
          return 0;
        }
      }
    }
    return n;
  } else {
    map[level] = 0;
    int a1 = dfs(map, level + 1, n);
    map[level] = 1;
    int a2 = dfs(map, level + 1, n + 1);
    return max(a1, a2);
  }
}


void Main() {
  cin >> N;
  rep(i, N) {
    cin >> A[i];
    rep(j, A[i]) {
      cin >> x[i][j] >> y[i][j];
    }
  }

  int map[N];
  rep(i, N) map[i] = 0;
  cout << dfs(map, 0, 0) << endl;
}

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

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] as = new long[n];
		long[] plus = new long[n];
		long[] minus = new long[n];
		for(int i=0; i<n; i++){
			as[i] = sc.nextLong();
			plus[i] = i+1+as[i];
			minus[i] = i+1-as[i];
		}
		Map<Long, Integer> map = new HashMap<>();
		for(long i: minus){
			Integer value = map.get(i);
			if(value == null) map.put(i, 1);
			else map.put(i, value+1);
		}
		long ans = 0;
		for(int i=0; i<plus.length; i++){
			Integer value = map.get(plus[i]);
			if(value != null){
				ans += value;
				int count = map.get(minus[i]);
				map.put(minus[i], count-1);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 63256
from collections import defaultdict

N = int(input())
A = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

d = defaultdict(int)
d[-1] = 3

ret = 1
for a in A :
    ret = ret * d[a-1] % mod
    d[a-1] -= 1
    d[a] += 1
    
print(ret)

Measured memory_bytes: 62124
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<bitset>
#include<vector>
#include<queue>
#include<ext/pb_ds/priority_queue.hpp>
#include<set>
#include<map>
#include<math.h>
#include<set>
#define maxn 500005
#define lson (now<<1)
#define rson ((now<<1)|1)
typedef long long ll;
using namespace std;
using namespace __gnu_pbds; 
char s[maxn],t[maxn];
int main()
{
	scanf("%s%s",s+1,t+1);
	int len=strlen(s+1);
	int ans=0;
	for(int i=1;i<=len;i++)
	if(s[i]!=t[i])
	ans++;
	printf("%d\n",ans);
}

Measured memory_bytes: 4172
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main() {
	int N, a;
	cin >> N;
	map<int, int> count;
	REP(i, N) {
		cin >> a;
		count[a]++;
	}

	map<int, int>::iterator it = count.begin();
	ll ans = 0;
	while (it != count.end()) {
		int diff = (it->second - it->first);
		if (diff < 0) {
			ans += it->second;
		}
		else {
			ans += diff;
		}
		it++;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define Maxn 1007
using namespace std;
int n,m;
char a[Maxn][Maxn];
bool vis[Maxn][Maxn];
int ans=0,dis[Maxn][Maxn];
int dx[4],dy[4];
pair<int,int> que[Maxn*Maxn*2];
int main()
{
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    memset(vis,false,sizeof(vis));
    int lx=0,rx=0;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=m;j++)
            if (a[i][j]=='#')
            {
                vis[i][j]=true;
                dis[i][j]=0;
                que[++rx]=make_pair(i,j);
            }
    dx[0]=0,dy[0]=1;
    dx[1]=0,dy[1]=-1;
    dx[2]=1,dy[2]=0;
    dx[3]=-1,dy[3]=0;
    while (lx<rx)
    {
        ++lx;
        int x=que[lx].first,y=que[lx].second;
        for (int i=0;i<4;i++)
        {
            int xx=x+dx[i];
            int yy=y+dy[i];
            if (xx>=1&&xx<=n&&yy>=1&&yy<=m&&(!vis[xx][yy]))
            {
                vis[xx][yy]=true;
                dis[xx][yy]=dis[x][y]+1;
                ans=max(ans,dis[xx][yy]);
                que[++rx]=make_pair(xx,yy);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 17600
while 1:
    try: a = list(map(int, input().split(',')))
    except: break
    pos = [0]*12
    v1, v2 = a[10], a[11]
    for i in range(10): pos[i+2] = pos[i+1] + a[i]
    L = pos[11]
    pq = (L*v1) // (v1 + v2);
    pr = (L*v1) % (v1 + v2);
    i = 10
    while pq < pos[i]: i -= 1
    if pq == pos[i] and pr == 0: i -= 1
    print(i)


Measured memory_bytes: 5600
import math
from functools import reduce
a,b=input().split()
l=sorted([abs(int(x)-int(b)) for x in input().split()])

def gcd(a,b):
    if a < b:
        a,b = b,a
    if  b==0:
        return a
    c = a % b
    return gcd(b,c)
while len(l)!=1:
    l.append(gcd(l.pop(0),l.pop(-1)))
print(sum(l))



Measured memory_bytes: 14688
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val (d, x) = readLine()!!.split(" ").map(String::toInt)
    val a = mutableListOf(0)
    for (i in 1..n) {
        a.add(readLine()!!.toInt())
    }
    var accum = x
    for (i in 1..n) {
        accum += if (a[i] == 1) {
            d
        } else {
            (d - 1) / a[i] + 1
        }
    }
    println(accum)
}

Measured memory_bytes: 37956
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "b.cpp"

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

  ll ans = 0;
  while (x >= 500) {
    x -= 500;
    ans += 1000;
  }
  while (x >= 5) {
    x -= 5;
    ans += 5;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())

def pne(n):
    print(n,end='')

rem = pow(10,9)+7

#n = ip()                                     #入力整数1つ
#x,y= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a = ["A","C","T","G"]
n =input()
l = a.index(n)
print(a[(l+2)%4])

Measured memory_bytes: 23060
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************

int cnt = 0;
int K;

void rec(int keta, string S){
    if (keta == 1){
        cnt++;
        if (cnt == K) {
            cout << S << endl;
            exit(0);
        }
        return;
    }

    ll x = S[S.size() - 1] - '0';
    FOR(y, max<ll>(x - 1, 0), min<ll>(x + 2, 10)){
        rec(keta-1, S + to_string(y));
    }
}


int main(){

    cin >> K;

    FOR(keta, 1, 100){
        FOR(x, 1, 10) rec(keta, to_string(x));
    }

    return 0;
}


Measured memory_bytes: 256
D,G=map(int,input().split())
table=[(0,0) for i in range(D)]
for i in range(D):
    p,c=map(int,input().split())
    table[i]=(p,c)
ans=10**9

for i in range(1<<D):
    t=G
    s=0
    for j in range(D):
        if i & (1<<j):
            s+=table[j][0]
            t=t-table[j][1]-table[j][0]*(j+1)*100
    if t<=0:
        ans=min(ans,s)
        #print(i,s)
    else:
        j=D-1
        flag=True
        while flag and (j>=0):
            #print(i,j)
            if not (i & (1<<j)):
                for u in range(table[j][0]-1):
                    if t<=0:
                        flag =False
                        break
                    else:
                        s+=1
                        t-=100*(j+1)
            j-=1
        if t<=0:
            ans=min(ans,s)
print(ans)

Measured memory_bytes: 43248
from math import ceil #切り上げ

def inp(): return int(input()) #一個だけ読み取り
def inpm(): return map(int,input().split()) #mapオブジェクトで呼び出し
def inpl(): return list(map(int, input().split())) #数字リストをintで
def inpls(): return list(input().split()) #リストをstrで

str_list = []
for i in range(inp()):
  str_list.append(input())
  
print(len(set(str_list)))


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

using namespace std;

struct UnionFind{
    vector<int>data;
    UnionFind(int size) : data(size, -1){}
    bool unionSet(int x, int y){
        x = root(x);
        y = root(y);
        if(x != y){
            if(data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y){
        return root(x) == root(y);
    }
    int root(int x){
        return data[x] < 0 ? x:data[x] = root(data[x]);
    }
    int size(int x){
        return data[root(x)];
    }
};

int main(){
    int N, M;
    int index[100000];
    int p[100000];
    cin >> N >> M;
    UnionFind UF(N);
    for(int i = 0; i < N ; i++){
        cin >> p[i];
        index[p[i]] = i;
    }
    for(int i = 0; i < M ; i++){
        int x, y;
        cin >> x >> y;
        UF.unionSet(x-1, y-1);
    }
    //cout << "H" << endl;
    int ans = 0;
    for(int i = 0; i < N ; i++){
        if(UF.root(i) == UF.root(index[i+1]) || p[i] == i+1) ans++;
        //cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

LLI test(LLI x1, LLI y1, LLI x2, LLI y2){
  return abs(x1*y2-x2*y1);
}

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

  LLI s;
  while(cin >> s){
    int x1,y1,x2,y2,x3,y3;

    x3 = y3 = 0;

    LLI m = 1e9;

    if(s <= 1e9){
      x1 = s;
      y1 = 0;
      x2 = 0;
      y2 = 1;
    }else{
      x1 = 1e9;
      y2 = (s+m-1)/m;
      x2 = 1;
      y1 = m-s%m;
      if(y1 == m) y1 = 0;
    }

    cerr << test(x1,y1,x2,y2) << endl;

    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
  }
  
  return 0;
}


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

int main() {
    int N,t,x,y,t0=0,x0=0,y0=0;
    cin >> N;
    rep(i,0,N) {
        cin >> t >> x >> y;
        ll dt = t - t0; 
        ll dr = abs(x-x0) + abs(y-y0);
        bool can = (dt >= dr && dt % 2 == dr % 2);
        if(!can){
            cout << "No\n" << endl;
            return 0;
        } 
        t0 = t;x0 = x;y0 = y;
    }
    cout << "Yes\n" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long L = sc.nextLong();
		long R = sc.nextLong();
		long L2019 = L % 2019;
		long R2019 = R % 2019;
		
		if(L/2019 != R/2019 || L2019 == 0) {
			System.out.println(0);
			return;
		}
		
		long ans = Long.MAX_VALUE;
		
		for(long i = L2019; i <= R2019-1; i++) {
			for(long j = i+1; j<= R2019; j++) {
				ans = (ans < (i*j)%2019) ? ans : (i*j)%2019;
			}
		}
		
		System.out.println(ans);
	}

}


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

#define itn int
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

int main() {
	long long n, a, b;
	cin >> n >> a >> b;
	if (a > b) {
		swap(a, b);
	}
	if (a % 2 == b % 2) {
		cout << (b - a) / 2 << "\n";
	} else {
		cout << min((a + b - 1) / 2, (2 * n - a - b + 1) / 2) << "\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ()
{
int n;
cin >> n;
int m = n;
for( ; n > 0 ; n -= 4){
	if(!(n % 7)){
		cout << "Yes";
		return 0;
	}
}
for( ; m > 0 ; m -= 7){
	if(!(m % 4)){
		cout << "Yes";
		return 0;
	}
}
cout << "No";

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(s.compare(u)==0){
        a=a-1;
    }
    else
       b=b-1;
    cout<<a<<' '<<b;

}

Measured memory_bytes: 256
#include<iostream>
main(){int n,c[4],v[4]={10,50,100,500},i,f=0;for(;std::cin>>n,n;){f?puts(""):f=1;for(i=0;i<4;n-=c[i]*v[i++])std::cin>>c[i];for(;i-->0;)for(;n<=-v[i];c[i]--)n+=v[i];for(;i++<4;)c[i]>0&&printf("%d %d\n",v[i],c[i]);}}

Measured memory_bytes: 0
// #1140935 Solution for 0515: School Road by ryogo 
#include<iostream>
using namespace std;
int dp[20][20];
int main(){
	int a, b ,i, j, x, y;
	while(cin>>a>>b){
		if(a == 0 && b == 0) { break; }
		int n;
		cin>>n;
		for(i=1;i<=16;i++)for(j=1;j<=16;j++){dp[i][j]=0;}
		for(i=1;i<=n ;i++){
			cin>>x>>y; dp[y][x]=-1;
		}
		dp[1][1]=1;
		for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				if(i==1 && j==1)continue;
				if(dp[i][j]!=-1){
					dp[i][j]=dp[i][j-1]+dp[i-1][j];
				}
				else dp[i][j]=0;
			}
		}
 
		cout<<dp[b][a]<<endl;
	}
}


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

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

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

    int ans = 0;
    for(int i=0; i+1<n; i++){
        if(a[i] == a[i+1]){
            a[i+1] = -1;
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

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

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
    int x;
    cin >> x;
    
    int res = x / 500 * 1000 + x % 500 / 5 * 5;
    cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
const int INF = 1<<20;
const int N = 101;
int cost[N][N];
int tim[N][N];
using namespace std;
int main()
{
	int n, m, a, b, co, ti,r;
	while (1){
		cin >> n >> m;
		if (n == 0 && m == 0)return 0;
		for (int i = 0; i < N; i++){
			for (int i2 = 0; i2 < N; i2++){
				cost[i][i2] = INF;
				tim[i][i2] = INF;
			}
		}
		for (int i = 0; i < n; i++){
			cin >> a >> b >> co >> ti;
			cost[a][b] = co;
			cost[b][a] = co;
			tim[a][b] = ti;
			tim[b][a] = ti;
		}
		for (int k = 1; k < m+1; ++k)
			for (int i = 1; i < m+1; ++i)
				for (int j = 1; j < m+1; ++j)
				{
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
					tim[i][j] = min(tim[i][j], tim[i][k] + tim[k][j]);
				}
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> a >> b >> r;
			if (r == 0){
				cout << cost[a][b] << endl;
			}
			else
				cout << tim[a][b] << endl;
		}
	}
}

Measured memory_bytes: 1240
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());

        if (S <= W) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }
    }
}

Measured memory_bytes: 27008
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# AtCoder Grand Contest 031
# Problem A: Colorful Subsequence

N = int(input())
S = input()
assert N == len(S)

# 各文字の出現数
numOf = {}
for c in S:
    numOf[c] = 1 if c not in numOf else numOf[c] + 1

# 部分列の数
nSeq = 1
for c in numOf:
    nSeq *= numOf[c] + 1  # いずれか1箇所を選択 or いずれも選ばない
nSeq -= 1  # 空列を除く

print(nSeq % (10 ** 9 + 7))


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

using namespace std;
typedef long long ll;
struct edge{int from, to, cost;
  edge (int f, int t, int c) : from(f),to(t),cost(c) {}
};

int N;
typedef pair<int,int> P;
bool operator < (const edge& a, const edge& b){
  return a.cost < b.cost;
}
vector<P>x,y;
vector<edge> e;
int p[100001];
int Rank[100001];

void init(int N) {
  for(int i = 0; i < N; i++) {
    p[i] = i;
    Rank[i] = 0;
  }
}

int Find(int x) {
  if(x == p[x]) return x;
  return p[x] = Find(p[x]);
}

bool Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return false;

  if(Rank[a] > Rank[b]) p[b] = a;

  else {
    p[a] = b;
    if(Rank[a] == Rank[b]) Rank[a]++;
  }
  return true;
}

  
int main() {
  cin >> N;

  for(int i = 0; i < N; i++) {
    int xx,yy;
    cin >> xx >> yy;
    x.push_back(P(xx,i));
    y.push_back(P(yy,i));
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());

  for(int i = 1; i < N; i++) {
    int xx = x[i].first - x[i-1].first;
    int yy = y[i].first - y[i-1].first;
    e.push_back(edge(x[i].second,x[i-1].second,xx));
    e.push_back(edge(x[i-1].second,x[i].second,xx));
    e.push_back(edge(y[i].second,y[i-1].second,yy));
    e.push_back(edge(y[i-1].second,y[i].second,yy));
  }
  sort(e.begin(),e.end());
  
  init(N);
  
  ll ans = 0;
  
  for(int i = 0; i < e.size(); i++) {
    if(Union(e[i].from,e[i].to))
      ans += e[i].cost;
  }
  cout << ans << endl;
}
    
    


Measured memory_bytes: 10724
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<pair<string, int> > vec(N);
    for(int i=0; i<N; i++){
        string s;int t;
        cin >> s >> t;
        vec[i]=make_pair(s,t);
    }

    string X;
    cin >> X;

    int ans=0;
    int flag=0;
    for(int i=0; i<N; i++){
        if(flag==1){
            ans+=vec[i].second;
        }
        if(vec[i].first==X){
            flag=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef unsigned long long ll;
char buf[1<<20],*p1,*p2;
#define GC (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?0:*p1++)
inline ll R()
{
	char t=GC;
	ll x=0;
	while(!isdigit(t))t=GC;
	while(isdigit(t))x=x*10+t-48,t=GC;
	return x;
}
int n,a[1000005];
inline bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int t=0;
	n=R();
	for(register int i=1; i<=n; i++)
		a[i]=R();
	sort(a+1,a+n+1,cmp);
	for(register int i=1; i<=n; i++)
		if(i+1>a[i+1])
		{
			while(a[t+i+1]==i)
				t++;
			if(((a[i]-i)&1)||(t&1))
				puts("First");
			else
				puts("Second");
			break;
		}
	return 0;
}


Measured memory_bytes: 4976
#include <stdio.h>
 
int main(void) {
  int dice[101][6],subdice[6],i,j,k,l,n,a[6],b[6],subA,subB;
  scanf("%d",&n);
  for(i = 0; i < n; i++)for(j = 0; j < 6; j++)scanf("%d",&dice[i][j]);

  for(i = 0; i < n; i++){
    for(j = i + 1; j < n; j++){
      if(dice[i][0] == dice[j][0]);
      else if(dice[i][0] == dice[j][1] || dice[i][0] == dice[j][4]){
        for(k = 0; k < 6; k++){
          subdice[0] = dice[j][4];
          subdice[4] = dice[j][5];
          subdice[5] = dice[j][1];
          subdice[1] = dice[j][0];
          subdice[2] = dice[j][2];
          subdice[3] = dice[j][3];
          for(l = 0; l < 6; l++)dice[j][l] = subdice[l];
          if(dice[i][0] == dice[j][0])break;
        }
      }
      else if(dice[i][0] == dice[j][2] || dice[i][0] == dice[j][3] || dice[i][0] == dice[j][5]){
        for(k = 0; k < 6; k++){
          subdice[0] = dice[j][2];
          subdice[2] = dice[j][5];
          subdice[5] = dice[j][3];
          subdice[3] = dice[j][0];
          subdice[1] = dice[j][1];
          subdice[4] = dice[j][4];
          for(l = 0; l < 6; l++)dice[j][l] = subdice[l];
          if(dice[i][0] == dice[j][0])break;
        }
      }
      for(k = 0; k < 4; k++){
        subdice[1] = dice[j][2];
        subdice[2] = dice[j][4];
        subdice[4] = dice[j][3];
        subdice[3] = dice[j][1];
        for(l = 1; l < 5; l++)dice[j][l] = subdice[l];
        if(dice[i][1] == dice[j][1]){
          if(dice[i][0] == dice[j][0] && dice[i][2] == dice[j][2] && dice[i][3] == dice[j][3] && dice[i][4] == dice[j][4] && dice[i][5] == dice[j][5]){
            printf("No\n");
            return 0;
          }
        }
      }
    }
  }
  if(i == n && j == n)printf("Yes\n");
  return 0;
}


Measured memory_bytes: 2100
N,x=map(int,input().split())
a=list(map(int,input().split()))

ans=0
for i in range(1,N):
    tmp=a[i-1]+a[i]
    if tmp>x:
        ans+=tmp-x
        if a[i]>=tmp-x:
            a[i]-=tmp-x
        else:
            a[i]=0
    else:
        continue
print(ans)

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

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	final long MOD=(long)1e9+7;

	long pow(long a,long n){
		long ret=1;
		for(;n>0;n>>=1,a=a*a%MOD){
			if(n%2==1)ret=ret*a%MOD;
		}
		return ret;
	}
	
	long inv(long a){
		return pow(a,MOD-2);
	}
	
	long comb(long n,long k){
		long ret=1;
		for(long i=1;i<=n;++i)ret=ret*i%MOD;
		for(long i=1;i<=k;++i)ret=ret*inv(i)%MOD;
		for(long i=1;i<=n-k;++i)ret=ret*inv(i)%MOD;
		return ret;
	}
	
	long fac(long n){
		long ret=1;
		for(long i=1;i<=n;++i)ret=ret*i%MOD;
		return ret;
	}
	
	void run() {
	 	Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		char[] s0=sc.next().toCharArray();
		char[] s1=sc.next().toCharArray();
		int p=0;
		long ans=1;
		int pre=0;
		while(p<N){
			if(s0[p]==s1[p]){
				ans=ans*comb(3-pre,1)%MOD;
				pre=1;
				++p;
			}else{
				if(pre<2){
					ans=ans*comb(3-pre,2)*2%MOD;
				}else{
					ans=ans*3%MOD;
				}
				pre=2;
				++p;++p;
			}
		}
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


Measured memory_bytes: 23764
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>


using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);

int main(){
    int ans, a, b, c;
    while(scanf("%d%d%d", &a, &b, &c)!=EOF){
        ans = MAX(a*10+b+c, MAX(b*10+a+c, c*10+a+b));
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 256