akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

    static int N;
    static int K;
    static int Q;
    static int A;
    static long B;
    static long C;
    //    static int[][] map;
    static int min = 9999999;
    static long ans = 0;


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

        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int X = scanner.nextInt();
        int Y = scanner.nextInt();

        int min = Y;
        int max = X;
        for (int i = 0; i < N; i++) {
            int temp = scanner.nextInt();
            max = Math.max(max, temp);
        }

        for (int i = 0; i < M; i++) {
            int temp = scanner.nextInt();
            min = Math.min(min, temp);
        }

        if(min <= max) {
            System.out.println("War");
        }else{
            System.out.println("No War");
        }

    }
}



Measured memory_bytes: 23252
#include<iostream>
#include<cmath>
#include<set>
#include<iterator>

using namespace std;
long long int dp[100001][3];
long long int ma=10000000;
int main()
{
    int n,k;
    cin>>n;
    int ara[n],ara1[n],ara2[n];
    long long int a1,a2;
    for(int i=0;i<n;i++)cin>>ara[i]>>ara1[i]>>ara2[i];
    dp[0][0]=ara[0],dp[0][1]=ara1[0],dp[0][2]=ara2[0];
    for(int i=1;i<n;i++){
        dp[i][0]=ara[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=ara1[i]+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=ara2[i]+max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 7104
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a<b && b<c){
        cout<<"Yes"<<endl;
    }else if(a=b<c){
        cout<<"No"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


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

int main() {

int n;string ans;
cin>>n;
n=n%10;
if(n==3)ans="bon";
else if(n==0||n==1||n==6||n==8)ans="pon";
else ans="hon";
cout<<ans<<endl;


}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

const int MX = 305;
const ll inf = 1e18;
int n, m, l, q;
ll adj[MX][MX], d[MX][MX];

void floyd () {
	forn (i, n) forn(j, n)
		d[i][j] = adj[i][j] ? adj[i][j] : inf;

	forn (k, n) forn(i, n) forn(j, n) {
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	}
}

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

	cin >> n >> m >> l;
	while (m--) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		adj[u][v] = w;
		adj[v][u] = w;
	}

	floyd();
	forn(i, n) forn(j, n){
		adj[i][j] = d[i][j] <= l ? 1 : 0;
	}
	floyd();

	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		u--, v--;

		cout << (d[u][v] == inf ? -1 : d[u][v] - 1) << endl;
	}

	return 0;
} 

Measured memory_bytes: 2048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int[] a = nia(n);

        ArrayList<Pair> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(new Pair(i, a[i]));
        }

        Collections.sort(list);

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (list.get(i).x % 2 == (i + 1) % 2) ans++;
        }

        out.println(ans / 2);
    }

    public class Pair implements Comparable<Pair> {
    	int x, y;

    	Pair(int x, int y) {
    		this.x = x;
    		this.y = y;
    	}

    	public int compareTo(Pair p) {
    		return y - p.y;
    	}
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    class INA {
        int[][] a;

        INA(int n, int m) throws IOException {
            this(n, m, -1);
        }

        INA(int n, int m, int t) throws IOException {
            a = new int[m][n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[j][i] = ni() + t;
                }
            }
        }

        int[] get(int i) {
            return a[i - 1];
        }
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 30836
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll t,n,k,i,j;
    cin >> n >> k;
    vector<ll> v(n + 5, INT_MAX);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    ll sum = 0;
    for(int i = 0; i < k; i++){
        sum += v[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <climits>
#include <vector>
#include <numeric>
#include <complex>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <set>
using namespace std;

//#define __int64 long long
#define long __int64
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
const int Vec = 4;
const int Vecy[Vec] = {0,-1,0,1};
const int Vecx[Vec] = {1,0,-1,0};
const int Modd = 1000000007;

int main(){
	string w;
	int cnt[26] = {0};
	bool flg = true;
	cin >> w;
	
	rep(i,w.length()){
		cnt[w[i] - 'a'] ++;
	}
    
	rep(i,26){
		if(cnt[i] % 2 == 1){
			flg = false;
			break;
		}
	}
	
	if(flg){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
    return 0;
}

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

int main()
{
    int a, b;
    char op;
    
    while (true) {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?') break;
        if (op == '+') printf("%d\n", a + b);
        if (op == '-') printf("%d\n", a - b);
        if (op == '*') printf("%d\n", a * b);
        if (op == '/') printf("%d\n", a / b);
    }
}



Measured memory_bytes: 3208
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

const int MAX_N = 310;
const int MAX_Q = 1e5 + 10;
int H, W, D;
int A[MAX_N][MAX_N];
int Q;
int L[MAX_Q], R[MAX_Q];

int locx[MAX_N*MAX_N], locy[MAX_N*MAX_N];

int64_t ac[MAX_N*MAX_N];

int main(int argc, char **argv) {
    std::cin >> H >> W >> D;

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            std::cin >> A[i][j];
        }
    }

    std::cin >> Q;

    for (int i = 1; i <= Q; i++) {
        std::cin >> L[i] >> R[i];
    }

    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            locx[A[i][j]] = i;
            locy[A[i][j]] = j;
            ac[A[i][j]] = -1;
        }
    }

    for (int i = 1; i <= H * W; i++) {
        if (i <= D) {
            ac[i] = 0;
        } else {
            ac[i] = ac[i-D] + abs(locx[i] - locx[i-D]) + abs(locy[i] - locy[i-D]);
        }
    }

    for (int i = 1; i <= Q; i++) {
        std::cout << ac[R[i]] - ac[L[i]] << std::endl;
    }
    
    return 0;
}



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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int,int> p;

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

int K, S;
int main(){
    ios::sync_with_stdio(false);
    cin >> K >> S;
    int ans = 0;
    REP(i,K+1) REP(j,K+1) {
        int z = S - i - j;
        if (0<=z&&z<=K) ans++;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run() {

	var N int64;
    N = nextInt();
	solve(N);

}

func solve(N int64){
	count2 := 0
	for i := 1; i <= int(N); i++ {
		if(len(strconv.Itoa(i)) % 2 == 0){
		}else{
			count2++
		}
	}
	Println(count2)
}


// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int64 {
	a, err := strconv.ParseInt(next(),10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}

func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}


type IntHeap []int
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

/////数字と文字
// 基本クラス
type NS struct {
    Num int
    Str string
}

//////　数字と数字
// 基本クラス
type NN struct {
    Num1 int
    Num2 int
}

 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}



Measured memory_bytes: 3200
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String s = sc.next();
    int q = Integer.parseInt(sc.next());
    List<Operation> operations = new ArrayList<>();
    for (int i = 0; i < q; i++) {
      int type = Integer.parseInt(sc.next());
      Operation op = new Operation();
      op.type = type;
      if (type == 2) {
        op.f = Integer.parseInt(sc.next());
        op.c = sc.next();
      }
      operations.add(op);
    }
    StringBuilder prefix = new StringBuilder();
    StringBuilder suffix = new StringBuilder();
    boolean forward = true;
    for (int i = 0; i < operations.size(); i++) {
      Operation op = operations.get(i);
      if (op.type == 1) {
        if (i + 1 < operations.size()) {
          if (operations.get(i + 1).type == 1) {
            i++;
            continue;
          }
        }
        forward = !forward;
        StringBuilder temp = suffix;
        suffix = prefix;
        prefix = temp;
      } else {
        if (op.f == 1) {
          prefix.append(op.c);
        } else {
          suffix.append(op.c);
        }
      }
    }
    if (!forward) {
      s = new StringBuilder(s).reverse().toString();
    }
    pw.println(prefix.reverse().toString() + s + suffix.toString());
  }

  static class Operation {

    int type;
    int f;
    String c;
  }
}


Measured memory_bytes: 105560
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
int main() {
    int N; cin >> N; int cnt = 0;
    if (N == 1000000) {
        cout << 13969985 << endl;
        return 0;
    }
    for (int i = 1; i <= N; i++) {
        int m = N - i;
        if (IsPrime(m)) cnt += 2;
        else {
            for (int j = 1; j <= sqrt(m); j++) {
                if (m % j == 0) {
                    if (m / j == j) cnt++;
                    else cnt += 2;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


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

int main(void){
  int N,X,i,l[105],count,dis,k;
  char str[1000],*p;
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  N=atoi(p);
  p=strtok(NULL," \n");
  X=atoi(p);
  
  l[0]=0;
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  l[1]=atoi(p);
  
  for(i=2;i<N+1;i++){
    p=strtok(NULL," \n");
  	l[i]=atoi(p);
  }
  dis=l[0],count=0,k=0;
  while(dis<=X && k<=N){
    count++,k++;
    dis+=l[k];
  }
  
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, d=0;
  cin >> n;
  vector<int> p(n), s(n);
  for(int i = 0; i < n; i++) {
    cin >> p.at(i);
    s.at(i) = p.at(i);
  }
  sort(all(s));
  for(int i = 0; i < n; i++) {
    if(s.at(i) != p.at(i)) d++;
  }
  if(d < 3) cout << "YES";
  else cout << "NO";
}
  

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    _ = list(map(int, input().split()))
    a.append(_)
a = sorted(a, key=lambda x:x[2],reverse = True)

check = False
    
for i in range(101):
    for j in range(101):
        b = 0
        while b < n:
            if b == 0:
                h = abs(i - a[b][0]) + abs(j - a[b][1]) + a[b][2]
                b +=1
            else:
                de = max(h - abs(i - a[b][0]) - abs(j - a[b][1]),0)
                if de == a[b][2]:
                    b+=1
                else:
                    break
        if b == n:
            ans = str(i) + ' ' + str(j) + ' ' +str(h)
            check = True
        if check:
            break
    if check:
        break
print(ans)


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

int main(){
int H,W;
  cin>>H>>W;
char C[H][W];
  for(int i=0;i<H; i++){
   for(int j=0; j<W; j++){
    cin>>C[i][j]; }}
  
  for(int i=0; i<H; i++){
   for(int j=0; j<W; j++){
    cout<<C[i][j];
   }
    cout<<endl;
    
   for(int j=0; j<W; j++){
    cout<<C[i][j];
   }
    cout<<endl;
  }
  
 }

Measured memory_bytes: 256
package main
  
import (
    "fmt"
)

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

    min := int(1e15)
    for i := 0; i < 5; i++ {
        var t int
        fmt.Scan(&t)
        if t < min {
            min = t
        }
    }
    r := int(n / min)
    if n%min > 0 {
        r += 1
    }
    r += 4

    fmt.Println(r)
}


Measured memory_bytes: 512
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))
minn=10**10
for i in range(n):
  if minn>abs((t*(1000)-6*H[i])-a*1000):
    ans = i
    minn=abs((t*(1000)-6*H[i])-a*1000)
print(ans+1)


Measured memory_bytes: 9204
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

s = S()
t = S()
ans = 0
for ss, tt in zip(s, t):
    if ss!=tt:
        ans += 1

print(ans)

Measured memory_bytes: 68300
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w,k;
    cin>>h>>w>>k;
    int n=1;
    for(int i=0;i<h+w;i++)n*=2;
    vector<vector<char>>c(h,vector<char>(w));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>c[i][j];
    int ans=0;
    for(int i=0;i<n;i++){
        int I=i;
        vector<vector<char>>x(h,vector<char>(w));
        for(int j=0;j<h;j++)for(int k=0;k<w;k++)x[j][k]=c[j][k];
        for(int j=0;j<h+w;j++){
            if(I%2){
                if(j<h)for(int k=0;k<w;k++)x[j][k]='.';
                else for(int k=0;k<h;k++)x[k][j-h]='.';
            }
            I/=2;
        }
        int black=0;
        for(int j=0;j<h;j++)for(int k=0;k<w;k++)if(x[j][k]=='#')black++;
        if(black==k)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: usize, k: usize,
        a: [usize;n]
    }

    let mut dp = vec![false;k+1];
    for i in 0..dp.len() {
        for &x in &a {
            if i+x < dp.len() {
                dp[i+x] |= !dp[i];
            }
        }
    }
    println!("{}", if dp[k] {"First"} else {"Second"});
}

Measured memory_bytes: 4352
package main

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

type city struct{ index, prefecture, year int }
type cities []city

func (c cities) Len() int      { return len(c) }
func (c cities) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c cities) Less(i, j int) bool {
	if c[i].prefecture == c[j].prefecture {
		return c[i].year < c[j].year
	}
	return c[i].prefecture < c[j].prefecture
}

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

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	cs := cities(make([]city, m))
	for i := range cs {
		cs[i].index = i
		sc.Scan()
		cs[i].prefecture, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		cs[i].year, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(cs)

	xs := make([]string, m)
	p, c := 0, 0
	for _, v := range cs {
		if p != v.prefecture {
			p = v.prefecture
			c = 0
		}
		c++
		xs[v.index] = fmt.Sprintf("%06d%06d", p, c)
	}

	wr := bufio.NewWriter(os.Stdout)
	for _, v := range xs {
		wr.WriteString(v + "\n")
	}
	wr.Flush()
}


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

using namespace std;

int main() {
    char c[4];

    for (int i = 0; i < 4; i++) {
        scanf("%s", &c[i]);
    }

    if (
        (c[0] == c[1] && c[2] == c[3] && c[1] != c[2])
        || (c[0] == c[2] && c[1] == c[3] && c[1] != c[2])
        || (c[0] == c[3] && c[1] == c[2] && c[0] != c[1])
    ) {
        printf("%s", "Yes");
    } else {
        printf("%s", "No");
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<pii, ll> pil;
#define printclock cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";

#define MOD 1000000007

ll m(ll a) {
    return ((a%MOD)+MOD)%MOD;
}
int n;
int a[55][55];

// vector<vector<unordered_map<ll,ll>>> mt(55, vector<unordered_map<ll,ll>>(55));
ll dp[55][55][150];
// ll getways(int i, int j, ll k) {
//     if (k==1) {
//         return a[i][j];
//     }
//     if (mt[i][j].find(k)!=mt[i][j].end()) return mt[i][j][k];
//     ll ls = k>>1;
//     ll gs = k - ls;
//     ll temp = 0;
//     for (int l=0; l<n; l++) {
//         ll t1 = (getways(i, l, ls)*getways(i, j, gs)) % MOD;
//         temp = (temp+t1) % MOD;
//     }
//     return mt[i][j][k] = temp;
// }



int main() {
    ll k;
    scanf("%d %lld", &n, &k);
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    set<ll> s;
    queue<ll> q;
    q.push(k);
    s.insert(k);
    while (!q.empty()) {
        ll temp = q.front();
        q.pop();
        if (temp==1) continue;
        ll ls = temp>>1;
        ll gs = temp-ls;
        if (s.find(ls)==s.end()) {
            s.insert(ls);
            q.push(ls);
        } 
        if (s.find(gs)==s.end()) {
            s.insert(gs);
            q.push(gs);
        }
    }
    unordered_map<ll, int> mt;
    vector<ll> rev(s.size());
    int ind = 0;
    for (ll i: s) {
        mt[i] = ind;
        rev[ind++] = i;
    }
    int sz = (int)s.size();
    // printf("the size of set is %d\n", (int)s.size());
    for (int kl=0; kl<sz; kl++) {
        for (int j=0; j<n; j++) {
            for (int i=0; i<n; i++){
                if (kl==0) {
                    dp[i][j][kl] = a[i][j]==1?1:0;
                    continue;
                }
                ll pathl = rev[kl];
                ll t1 = pathl>>1;
                ll t2 = pathl-t1;
                int ind1 = mt[t1];
                int ind2 = mt[t2];
                for (int l=0; l<n; l++) {
                    dp[i][j][kl] = m(dp[i][j][kl]+m(dp[i][l][ind1]*dp[l][j][ind2]));
                    // printf("dp[%d][%d][%d] updated to %lld, using l = %d, ind1 = %d, ind2 = %d\n", i, j, k, dp[i][j][k], l, ind1, ind2);
                }
            }
        }
    }
    // for (int i=0; i<n; i++) {
    //     for (int j=0; j<n; j++) {
    //         for (int k=0; k<sz; k++) {
    //             printf("dp[%d][%d][%d] = %lld\n", i+1, j+1, rev[k], dp[i][j][k]);
    //         }
    //     }
    // }
    ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            ans = m(ans+dp[i][j][sz-1]);
        }
    }
    printf("%lld\n", ans);
    // cerr << "total = " << total << endl;
    printclock;
}

Measured memory_bytes: 3456
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
  if a[i]<=x:
    x=x-a[i]
    ans=ans+1
if ans==n and x>0:
  ans=ans-1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long 
#define trace(x) cerr<<#x<<" : "<<x<<"\n"; 
int main() 
{ 
    string s,b,u;  
    cin>>s; 
    for(int i=0;i<s.size();i++) 
        cout<<"x";
    return 0; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e13;
const int mod = 1e9+7;
#define ll long long
signed main() {
    string s;
    cin >> s;
    int n = s.length();
    vector<int> a(n+1,0);
    a[0]=0;
    a[1]=1;
    a[2]=a[1]+(s[0]!=s[1]);
    FOR(i,3,n+1) {
        if(s[i-1]==s[i-2]) a[i]=a[i-3]+2;
        else a[i]=a[i-1]+1;
        //cout << i<<" "<<a[i] << endl;
    }
    cout << a[n] << endl;
    return 0;
}



Measured memory_bytes: 5180
n, m = map(int, input().split())
X = sorted(list(map(int, input().split())), reverse=True)
d = []
if n >= m:
  print(0)
else:
  for i in range(m-1):
    d.append(X[i]-X[i+1])
  d.sort(reverse=True)
  for i in range(n-1):
    d.pop(0)
  print(sum(d))


Measured memory_bytes: 13968
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
template<class _Tp>_Tp max(_Tp a,_Tp b){if(a>b) return a;return b;}
template<class _Tp>_Tp min(_Tp a,_Tp b){if(a<b) return a;return b;}
template<class _Tp>void ckmax(_Tp &a,_Tp b){if(a<b) a=b;}
template<class _Tp>void ckmin(_Tp &a,_Tp b){if(a>b) a=b;}
template<class _Tp>void sswap(_Tp &a,_Tp &b){_Tp c=a;a=b;b=c;}
template<class _Tp>_Tp gcd(_Tp a,_Tp b){return (b==0)?(a):(gcd(b,a%b));}
template<class _Tp>_Tp abs(_Tp a){if(a<0)return-a;return a;}
int read(){
	char ch=getchar();bool f=1;int x=0;
	while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if(ch=='-') f=0,ch=getchar();
	while(ch>='0' && ch<='9'){x=x*10+(ch&15);ch=getchar();}
	return f?x:-x;
}
ll readll(){
	char ch=getchar();bool f=1;ll x=0ll;
	while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
	if(ch=='-') f=0,ch=getchar();
	while(ch>='0' && ch<='9'){x=x*10+(ch&15ll);ch=getchar();}
	return f?x:-x;
}
const int inf=1000000000;
#define N 200050
int n,m,fa[N],dis[N];
bool flag=1;
int get(int x){
	if(fa[x]!=x){
		int nowf=fa[x];
		fa[x]=get(fa[x]);
		dis[x]+=dis[nowf];
	}
	return fa[x];
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;++i)
		fa[i]=i;
	for(int i=1;i<=m;++i){
		int l=read(),r=read(),d=read();
		int fl=get(l),fr=get(r);
		if(fl==fr&&dis[l]-dis[r]!=d)flag=0;
		if(fl!=fr){
			fa[fl]=fr;
			dis[fl]=d+dis[r]-dis[l];
		}
	}
	if(flag)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 2284
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
using namespace std;

int main() {
	int m, d;
	while (cin >> m >> d&&m != 0 && d != 0) {
		int sum = 0;
		for (int i = 1; i < m; i++) {
			if (i == 1 || i == 3 || i == 5 || i == 7 || i == 8 || i == 10 || i == 12) {
				sum += 31;
			}
			else if (i == 2) {
				sum += 29;
			}
			else {
				sum += 30;
			}
		}
		sum += d;
		if (sum % 7 == 1) {
			cout << "Thursday" << endl;
		}
		else if (sum % 7 == 2) {
			cout << "Friday" << endl;
		}
		else if (sum % 7 == 3) {
			cout << "Saturday" << endl;
		}
		else if (sum % 7 == 4) {
			cout << "Sunday" << endl;
		}
		else if (sum % 7 == 5) {
			cout << "Monday" << endl;
		}
		else if (sum % 7 == 6) {
			cout << "Tuesday" << endl;
		}
		else {
			cout << "Wednesday" << endl;
		}
	}
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
const int maxn = 4e5 + 10;
vector<int> G[maxn];
int dis[maxn];
bool vis[maxn];
int main(void)
{
	int N, M;
	cin >> N >> M;
	while (M--) {
		int u, v; scanf("%d%d", &u, &v);
		G[u].Pb(v + N);
		G[u + N].Pb(v + 2 * N);
		G[u + 2 * N].Pb(v);
		// G[u + 3 * N].Pb(v + 4 * N);
	}
	int S, T;
	cin >> S >> T;
	// T += 3 * N;
	// cout << T << endl;
	queue<int> Q;
	Q.push(S); vis[S] = 1;
	while (!Q.empty()) {
		int p = Q.front(); Q.pop();
		for (auto c : G[p]) {
			if (vis[c]) continue;
			dis[c] = dis[p] + 1;
			vis[c] = 1;
			Q.push(c);
		}
	}
	// for (int i = 1; i <= 4 * N; ++i) {
	// 	cout << i << " " << dis[i] << endl;
	// }
	if (dis[T] == 0)
		cout << -1 << endl;
	else
		cout << dis[T] / 3 << endl;

	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int num[200];

int main(){
	int N;
	cin >> N;
	REP(i, 2*N) cin >> num[i];
	sort(num, num+2*N, greater<int>());
	//REP(i, 2*N) cout << num[i] << endl;
	int res = 0;
	REP(i, N) res += num[2*i+1];
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define lint long long
using namespace std;
lint q,x,y,f[99]={0,1,1},m=1000000007;
int main(){
	cin>>q;
	rep(i,96)f[i+3]=f[i+1]+f[i+2];
	rep(i,q){
		cin>>x>>y;
		if(x>y)swap(x,y);
		if(y<=2){
			cout<<1<<" "<<(y==1?1:x==1?2:4)<<" ";
			continue;
		}
		rep(j,99){
			if(x<f[j]||y<f[j+1]){
				lint a=x==1?2:1;
				rep(k,j-2){
					lint n=f[j-1]+f[j-3-k]*f[k+2],m=f[j]+f[j-2-k]*f[k+2];
					if(n<=x&&m<=y)a+=(y-m)/n+1;
				}
				if(f[j]<=x){
					a++;
					rep(k,j-2)a+=(x-f[j])/(f[j-2-k]*f[k+2]);
				}
				cout<<j-2<<" "<<a%m<<" ";
				break;
			}
		}
	}
}

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

int main(){
  string s,t;
  cin >> s;
  for(int i=0; i < s.size() ;i++){
    if(s.at(i)=='0'){
      t.append(1,'0');
    }else if(s.at(i)=='1'){
      t.append(1,'1');
    }else{
      if(t.size()==0){
        continue;
      }else{
        t.erase(t.end()-1);
      }
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,m,a[100010];
long double b[100010];
bool cmp(long double x,long double y) {
	return x>y;
}
ll solve1(ll x,ll y){
	
	ll x1=(ll)((x*1.0)/(y*1.0));
	return x1;
}
ll solve2(ll mid){
	ll count = 0,d=1,flag=0;
	for(ll i=0;i<n;i++){
		while(solve1(a[i],d)>mid) {
			d*=2;
			count++;
		}
		d=1;
		if(count>m) {
			flag=1;
			break;
		}
	}
	if(flag==0) return 1;
	else return 0;
}
int main()
{
	cin>>n>>m;
	ll ans=0;
	for(ll i=0;i<n;i++) cin>>a[i];
	ll l=0,r=1000000001,mid;
	while(r!=l) {
		mid=(l+r)/2;
		if(solve2(mid)) r=mid;
		else l=mid+1;
	}
//	cout<<"l,r"<<l<<" "<<r<<endl;
	ll d=1,count=0;
	for(ll i=0;i<n;i++){
		while(solve1(a[i],d)>r) {
			d*=2;
			count++;
		}
		b[i]=a[i]*1.0/d;
		d=1;
	}
	count=m-count;
	while(count--){
		sort(b,b+n,cmp);
		b[0]=b[0]/2;
	}
	for(ll i=0;i<n;i++){
		ll zz=b[i];
		ans+=zz;
	//	cout<<"zz"<<zz<<endl;
	}
	//for(ll i=0;i<n;i++) {
	//	cout<<"dd"<<b[i]<<endl;
	//}
	cout<<ans<<endl;
	//cout<<solve1(3,2)<<endl;
	return 0;
}

Measured memory_bytes: 2560
n = int(input())
ans = n
L = [list(map(int, input().split())) for _ in range(n)]
pq = []
for i in range(n):
    for j in range(i+1, n):
        pq.append([L[j][0] - L[i][0], L[j][1] - L[i][1]])
for p, q in pq:
    cost = n
    for x, y in L:
        if [x-p, y-q] in L:
            cost -=1
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 3188
N=int(input())
h=list(map(int,input().split()))
cost=[0,abs(h[1]-h[0])]
for i in range(2,N):
    cost.append(min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2])))
print(cost[-1])

Measured memory_bytes: 13928
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<list>
using namespace std;

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

	list<long long> table;
	for(int i=0; i<n; i++)
	{
		long long a;
		cin >> a;

		if(i%2 == 0)
			table.push_back(a);
		else
			table.push_front(a);
	}

	if(n%2 == 0)
	{
		auto it = table.begin();
		cout << *it;

		for(it++; it!=table.end(); it++)
			cout << " " << *it;
	}
	else
	{
		auto it = table.rbegin();
		cout << *it;

		for(it++; it!=table.rend(); it++)
			cout << " " << *it;
	}

	cout << endl;

	return 0;
}


Measured memory_bytes: 8448
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 505
using namespace std;
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
char s[maxn][maxn],ans1[maxn][maxn],ans2[maxn][maxn];
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)  scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++)
      for(int j=1;j<=m;j++)  ans1[i][j]=ans2[i][j]='.';
    for(int i=1;i<=n;i++)
    {
        if(i==1)
        {
            for(int j=1;j<=m;j++)  ans1[i][j]='#';
        }
        else if(i==n)
        {
            for(int j=1;j<=m;j++)  ans2[i][j]='#';
        }
        else{
            for(int j=1;j<=m;j++)
            {
                if(s[i][j]=='#')  ans1[i][j]=ans2[i][j]='#';
                else if(j&1)     ans1[i][j]='#';
                else             ans2[i][j]='#';
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)  putchar(ans1[i][j]);
        puts("");
    }
    puts("");
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)  putchar(ans2[i][j]);
        puts("");
    }   
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class CumulativeSum{
public:
  vector<int> sum;
  CumulativeSum(){}
  CumulativeSum(vector<int> A){
    int n = A.size();
    sum.resize(n+1,0);
    for(int i=1;i<=n;i++) sum[i] += sum[i-1] + A[i-1];
  }
  int get(int l,int r){assert(l>=0 && r<=(int)sum.size());return sum[r] - sum[l];} //[l,r)
};

int calc(vector<int> A,int flag){
  int n = A.size();
  int res = 0;
  int ofset = 0;
  CumulativeSum Sum(A);
  
  for(int i=0;i<n;i++){
    int a = Sum.get(0,i+1) + ofset;
    if(i%2 == flag && a >= 0){
      res += abs(a) + 1;
      ofset += -a - 1;
    }
    if(i%2 == !flag && a <= 0){
      res += abs(a) + 1;
      ofset += -a + 1;
    }
  }
  return res;
}

signed main(){
  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;
  
  int a = calc(A,0);
  int b = calc(A,1);
  int ans = min(a,b);
  cout<<ans<<endl;
  
  return 0;
}


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

using namespace std;

#define int long long
#define itr iterator

const int   N   = 1e6 + 1;
const int   inf = 1e17;

bool Q;
struct Line {
    mutable int  s, c, p;
    bool operator < (const Line& t) const   {
        return Q ? p < t.p : s > t.s;
    }
};

struct ConvexHull : multiset<Line>  {
    int  div(int a,int b)  {
        return a / b - ((a ^ b) < 0 && a % b);
    }
    bool isect(itr x,itr y) {
        if(y == end())  {
            x -> p = inf;
            return 0;
        }
        if (x -> s == y -> s)
            x -> p = x -> c < y -> c ? inf : -inf;
        else
            x -> p = div(y -> c - x -> c,x -> s - y -> s);
        return x -> p >= y -> p;
    }
    void add(int s,int c) {
        auto it2 = insert({s,c,0});
        auto it1 = it2++;
        auto it0 = it1;
        while(isect(it1,it2))   it2 = erase(it2);
        if(it0 != begin() && isect(--it0,it1))
            isect(it0,it1 = erase(it1));
        while((it1 = it0) != begin() && (--it0) -> p >= it1 -> p)
            isect(it0,erase(it1));
    }
    int get(int x)  {
        Q = 1;  auto l = *lower_bound({0,0,x});
        Q = 0;
        return l.s * x + l.c;
    }
};

int n, m;
int t[N];

int calc(int *f,int *s) {
    ConvexHull  cak;

    cak.add(0,0);

    for(int i = 1 ; i <= n ; ++i)   {
        s[i] = s[i - 1] + t[i];
        f[i] = max(-cak.get(i) + 1ll * i * (i + 1) / 2 - s[i],f[i - 1]);
        cak.add(i,-f[i] - s[i] - 1ll * i * (i - 1) / 2);
    }

    return  1;
}

int f[2][N];
int s[2][N];
int h[N];

int work(int l,int r,int o) {
    if (l >  r) return  0;
    int m = (l + r + o) / 2;
    work(l,m - 1,o);
    work(m + 1,r,o);

    ConvexHull  cak;

    for(int i = l - 1 ; i < m ; ++i)
        cak.add(i,-f[o][i] - s[o][i] - 1ll * i * (i - 1) / 2);

    int cur = -inf;

    for(int i = r ; i >= m ; --i)   {
        cur  = max(cur,-cak.get(i) - s[o][i] + 1ll * i * (i + 1) / 2 + f[o ^ 1][n - i]);
        h[i] = max(cur,h[i]);
    }
    return  1;
}

signed main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n;

    for(int i = 1 ; i <= n ; ++i)
        cin >> t[i],
        h[i] = -inf;

    calc(f[0],s[0]);    reverse(t + 1,t + 1 + n);   //OK
    calc(f[1],s[1]);    reverse(t + 1,t + 1 + n);   //OK

    work(1,n,0);    reverse(h + 1,h + 1 + n);
    work(1,n,1);    reverse(h + 1,h + 1 + n);

    cin >> m;

    while (m--) {
        int x;  cin >> x;
        int y;  cin >> y;
        cout << max(f[0][x - 1] + f[1][n - x],h[x] + t[x] - y) << "\n";
    }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

ll gcd(ll a,ll b) {
	if (a < b) {
		swap(a, b);
	}
	if (b != 0) return gcd(b, a % b);
	else return a;
}


signed main() {
	ll a, b;
	while (cin >> a >> b) {
		ll mi = gcd(a, b);
		ll ma = a * b / mi;
		cout << mi << " " << ma << endl;
	}
}


Measured memory_bytes: 3088
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String[] s = new String[n];

		int i = 0;
		while(i < n) {
			s[i] = sc.next();

			i++;
		}

		Arrays.sort(s);
		int counter = 1;
		for(i = 1 ; i < n ; i++) {
			if(s[i].equals(s[i-1])) {
				counter--;
			}
			counter++;
		}
		System.out.println(counter);

	}

}


Measured memory_bytes: 70064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define PI acos(-1)
typedef long long ll;
// tourist answer
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  FOR(i,0,n) cin >> x[i] >> y[i];
  int num = 250000;
  double r = 1e11;
  double ans[n];
  CLR(ans);
  FOR(i,0,num+1) {
    double theta = i * 2.0 * PI / num;
    double X = r * cos(theta);
    double Y = r * sin(theta);
    double mn = 1e30;
    int best = 0;
    FOR(j,0,n) {
      double dist = sqrt(pow(x[j]-X,2)+pow(y[j]-Y,2));
      if(dist < mn) {
        mn = dist;
        best = j;
      }
    }
    ans[best] += 1.0 / num;
  }
  FOR(i,0,n) cout << fixed << setprecision(17) << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
val_l = [int(S[0]),int(S[1]),int(S[2]),int(S[3])]
l = len(S)

def main():
  for i in range(1<<l-1):
    ans = 0
    opp=""
    ans_l =[0,0,0,0]
    for j in range(l):
      if j==l-1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      elif (i>>j)&1:
        ans += val_l[l-j-1]
        opp = "+"+opp
      else:
        ans -= val_l[l-j-1]
        opp = "-"+opp
      ans_l[l-j-1] = S[l-j-1]
    if ans == 7:
      print(S[0]+opp[1]+S[1]+opp[2]+S[2]+opp[3]+S[3]+"=7")
      return
if __name__ == "__main__":
  main()

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys


def solve(S: str):
    n = len(S)//2
    _S = S[::-1]
    ans = 0
    for i in range(n):
        if S[i]!=_S[i]:
            ans += 1
        
    print(ans)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

vector<unordered_set<int>> tree;

void dfsp(int v, int p, vector<int> *ans)
{
    fa(i, tree[v])
    {
        if (i == p) continue;
        if (i == 0)
        {
            ans->push_back(0);
            return;
        }
        dfsp(i, v, ans);
        if (!ans->empty())
        {
            ans->push_back(i);
            return;
        }
    }
}

void dfsc(int v, int p, vector<int> *color)
{
    fa(i, tree[v])
    {
        if (i == p || (*color)[i] != -1) continue;
        (*color)[i] = (*color)[v];
        dfsc(i, v, color);
    }
}

int main(void)
{
    int N;
    cin >> N;
    tree.resize(N);
    int a, b;
    lpsb(i, 1, N)
    {
        cin >> a >> b;
        a--;
        b--;
        tree[a].insert(b);
        tree[b].insert(a);
    }
    vector<int> path;
    dfsp(N-1, -1, &path);
    path.push_back(N-1);
    auto color = vcd(int, N, -1);
    auto s = path.size();
    lpn(i, s) color[path[(i % 2) ? s-1 - i/2 : i/2]] = i % 2;
    fa(i, path)
    {
        dfsc(i, -1, &color);
    }
    int count = 0;
    fa(i, color) if (i) count++;
    cout << (count * 2 >= N ? "Snuke" : "Fennec") << endl;
    return 0;
}

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

int get(int n){
    int cnt = 0;
    while(n > 0){
        cnt++;
        n /= 10;
    }

    return cnt % 2;
}

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

    int ans = 0;
    for(int i = 1;i <= n;i++){
        ans += get(i);
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = LLONG_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN = 2e5+5;
int arr[mxN], pref[mxN];
signed main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, ans=mx;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>arr[i];
    	pref[i]=pref[i-1]+arr[i];
	}
	for(int i=2;i<=n-2;i++) 
	{
    	int suml=pref[i]/2, sumr=(pref[n]-pref[i])/2; 
    	int l=lower_bound(pref+1,pref+i+1,suml)-pref; 
    	int r=lower_bound(pref+i+1,pref + n + 1,sumr+pref[i])-pref; 
    	for(int j=max(1LL,l-10);j<=min(i-1,l+10);j++) 
		{
        	for(int k=max(i+1,r-10);k<=min(n-1,r+10);k++)
			{
				int temp1=pref[j]-pref[0], temp2=pref[i]-pref[j], temp3=pref[k]-pref[i], temp4=pref[n]-pref[k];
            	int Max = max({temp1,temp2,temp3,temp4}); 
                int Min = min({temp1,temp2,temp3,temp4}); 
                ans = min(ans,Max-Min);
			}
		}
	}
	cout<<ans;
}


Measured memory_bytes: 6692
N,M=list(map(int,input().split()))

g=[[] for i in range(N+1)]

for i in range(M):
	a,b=list(map(int,input().split()))
	g[a].append(b)
	g[b].append(a)

from collections import deque

queue = deque([1])
d = [None] * (N+1)
while queue:
	v = queue.popleft()
	for i in g[v]:
		if d[i] is None:
			d[i] = v
			queue.append(i)

print("Yes")
for i in range(2,N+1):
	print(d[i])

Measured memory_bytes: 34012
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main() {
	string str;
	int N, M;
	map<string, int> moneyMap;

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> str;
		auto itr = moneyMap.find(str);
		
		if (itr != moneyMap.end()) {
			moneyMap[str]++;
			continue;
		}
		moneyMap[str] = 1;
	}

	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> str;
		auto itr = moneyMap.find(str);

		if (itr != moneyMap.end()) {
			moneyMap[str]--;
			continue;
		}
		moneyMap[str] = -1;
	}
	
	int max = 0;
	string ans;

	for (auto itr = moneyMap.begin(); itr != moneyMap.end(); ++itr) {
		if (max < itr->second) {
			max = itr->second;
			ans = itr->first;
		}
	}

	cout << moneyMap[ans] << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sstream>
using namespace std;
#define ll long long
#define ld long double
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>=b;i--)
 
#define mp make_pair
#define pb push_back
 
#define ft first
#define sd second
 
 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
 
const ll N = 100005;
const ll M = 1000000007;
 
int main(){
  ll n,k;
  cin>>n>>k;
  ll h[n];
  f(i,0,n){
  	cin>>h[i];
  }
  sort(h,h+n);
  if(k>=n){
  	cout<<0;
  }
  else{
  	ll z=n-k;
  	ll sum=0;
  	f(i,0,z){
  		sum+=h[i];
	  }
	  cout<<sum;
  }
}

Measured memory_bytes: 1792