akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long UL; // ULLONG_MAX, %llu
typedef unsigned int UI; //UINT_MAX %u
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 200005;
const int mod = 1000000007;
int mul(int a, int b){
    return a * 1ll * b % mod;
}
vector<int> pos, neg;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k, zero = 0;
    int ans = 1, all = 1;
    cin >> n >> k;
    FOR(i, 1, n){
        int a;
        cin >> a;
        if(a == 0) zero = 1;
        if(a > 0) pos.pb(a);
        else if(a < 0) neg.pb(a), a += mod;
        all = mul(all, a);
    }
    if(n == k){
        cout << all; return 0;
    }
    sort(all(pos)); sort(all(neg));
    if(SZ(pos) + SZ(neg) < k){
        cout << 0; return 0;
    }
    if(pos.empty()){
        if(k&1){
            if(zero) ans = 0;
            iFOR(i, SZ(neg)-1, SZ(neg)-k) ans = mul(ans, mod+neg[i]);
        }else{
            FOR(i, 0, k-1) ans = mul(ans, mod+neg[i]);
        }
        cout << ans; 
        return 0;
    }
    if(neg.empty()){
        iFOR(i, SZ(pos)-1, SZ(pos)-k) ans = mul(ans, pos[i]);
        cout << ans;
        return 0;
    }
    if(SZ(pos)+SZ(neg) == k && SZ(neg)%2==1){
        cout << 0;
        return 0;
    }else if(SZ(pos)+SZ(neg) == k){
        for(int e : pos) ans = mul(ans, e);
        for(int e : neg) ans = mul(ans, mod+e);
        cout << ans; return 0;
    }
    reverse(all(pos));
    int now = min(k-1, SZ(pos)-1);
    vector<LL> neg2;
    for(int i = 1; i < SZ(neg); i+=2){
        neg2.pb(neg[i-1] * 1ll * neg[i]);
    }
    int won = 0;
    for(int i = 0; i < SZ(neg2); ++i){
        if(now+1 + 2*(i+1) <= k) ++won;
        else{
            int p = now+1 + 2*(i+1) - k;
            if(p > now+1) break;
            LL A = 1;
            if(p == 1) A = pos[now];
            else A = pos[now] * 1ll * pos[now-1];
            if(neg2[i] < A) break;
            ++won; now -= p;
            if(now == -1) break;
        }
    }
    FOR(i, 0, now) ans = mul(ans, pos[i]);
    FOR(i, 0, won-1) ans = mul(ans, neg2[i]%mod);
    printf("%d",ans);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 5584
import math
from functools import reduce

k = int(input())
l = []
s = 0


for a in range(1,k+1):
    for b in range(1,k+1):
        l.append(math.gcd(a, b))

for c in range(1,k+1):
  for i in range(len(l)):
    s += math.gcd(l[i],c)
print(s)

Measured memory_bytes: 9848
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int s[1<<10][1<<10];
int ans[1<<10][1<<10];
int main()
{
    int n, m;
	cin>>n>>m;
	for(int i=0; i<(1<<n); i++){
		for(int j=0; j<(1<<m); j++){
			if((popcount(i&j))&1) s[i][j]=1;
		}
	}
	for(int i=1; i<(1<<n); i++){
		for(int j=1; j<(1<<m); j++){
			ans[i][j]=s[i][j-1]^s[i-1][j]^s[i-1][j-1]^s[i][j];
			cout<<ans[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())



int main(){
  int n;
	cin >> n;
  if(n==1){cout<< "Hello World"<<endl;}
  else {
    int a,b; cin>>a>>b;
    cout<< a+b << endl;
    }
}

Measured memory_bytes: 256
N = int(input())
S = input()
total = 0

for i in range(N-2):
    if S[i] == "R":
        num_G = S[i+1:].count('G')
        num_B = S[i+1:].count('B')
        total += num_G * num_B
    elif S[i] == "G":
        num_B = S[i+1:].count('B')
        num_R = S[i+1:].count('R')
        total += num_B * num_R
    elif S[i] == "B":
        num_G = S[i+1:].count('G')
        num_R = S[i+1:].count('R')
        total += num_G * num_R

for i in range(N-2):
    for j in range(i+1, N-1):
        if 2*j-i >= N:
            continue
        if S[j] != S[i] and S[2*j-i] != S[j] and S[2*j-i] != S[i]:
            total -= 1

print(total)


Measured memory_bytes: 73472
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
int main()
{
    long long int n,n1,n2,n3,ans,sum,sum1,sum2,sum3;
    cin>>n;
    sum=n*(n+1)/2;
    n1=n/3;
    n2=n/5;
    n3=n/15;
    sum1=(n1*(6+(n1-1)*3))/2;
    sum2=(n2*(10+(n2-1)*5))/2;
    sum3=(n3*(30+(n3-1)*15))/2;
   // cout<<sum1<<" "<<sum2<<" "<<sum3<<endl;
    ans=sum-sum1-sum2+sum3;
    cout<<ans<<endl;
}

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

using ll = long long;

int main()
{   
    int n, x, y;
    scanf("%d%d%d", &n, &x, &y);
    vector<vector<int>> adj(n+1);
    for(int i = 1; i < n; i++) {
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);
    vector<int> cnt(n);
    for(int i = 1; i <= n; i++) {
        vector<bool> visited(n+1, false);
        queue<int> q;
        q.push(i);
        vector<int> distance(n+1, 0);
        while(!q.empty()) {
            int u = q.front();
            q.pop();
            if(visited[u]) continue;
            visited[u] = true;
            cnt[distance[u]]++;
            for(int to : adj[u]) {
                if(!visited[to]) {
                    q.push(to);
                    if(distance[to] == 0) 
                        distance[to] = distance[u] + 1;
                }
            }
        }
    }
    for(int i = 1; i < n; i++ ) printf("%d\n", cnt[i]/2);
}


Measured memory_bytes: 3888
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	ll A, B, C;
	
	void ans() {
		cin >> A >> B >> C;
		int res = 0;
		while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0 && res < 30) {
			res++;
			ll a = B + C, b = A + C, c = A + B;
			A = a / 2;
			B = b / 2;
			C = c / 2;
		}
		if (res == 30) res = -1;
		cout << res << "\n";
	}

};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        for (int i=0; i<3; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        System.out.println(a[0] + a[1]);
    }
}



Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    int k,t;
    cin >> k >> t;
    vector<int> a(t);
    for(int i=0;i<t;i++){
        cin >> a[i];
    }
    int max_a=0;
    for(int i=0;i<t;i++){
        max_a=max(max_a,a[i]);
    }
    int m=max_a-(k-max_a);
    if(m<=1){
        cout<<"0"<<endl;
    }else{
        cout<<m-1<<endl;
    }
    return 0;
}

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

int main() {
  int k, x;
  cin >> k >> x;
  int begin = max(x - k + 1, -1000000);
  int end = min(x + k - 1, 1000000);

  for (int i = begin; i <= end; i++) {
    if (i != begin) cout << " ";
    cout << i;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String T = sc.next();

        int A = sc.nextInt();
        int B = sc.nextInt();

        String U = sc.next();
        
        if(S.equals(U)) {
            A--;
        }else {
            B--;
        }
        
        System.out.println(A + " " + B);
    }
}


Measured memory_bytes: 23252
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

int64 n;
int ans = 0;
void rec(int64 cur, bool t3, bool t5, bool t7){
  if (cur > n) return;
  if (t3 && t5 && t7) ++ans;
  rec(cur * 10 + 3, true, t5, t7);
  rec(cur * 10 + 5, t3, true, t7);
  rec(cur * 10 + 7, t3, t5, true);
}

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

  cin >> n;
  rec(0, false, false, false);
  print(ans);

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))
point = 0
temp = -1
for a in a_list:
    point += b_list[a-1]
    if a - temp == 1:
        point += c_list[a-1-1]
    temp = a
print(point)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){
    int N, M, total = 0;
    int T[100], X[100], P[100];
    //入力
    cin >> N;
    for(int i = 0; i < N; ++i){
        cin >> T[i];
        total += T[i];
    }
    cin >> M;
    for(int i = 0; i < M; ++i){
        cin >> P[i] >> X[i];
    }
    //出力
    for(int i = 0; i < M; ++i){
        cout << total + (X[i] - T[P[i] - 1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, K, T, U, V, L;
bool point[10010];

signed main() {
    cin >> N >> K >> T >> U >> V >> L;
    rep(i,0,N) {
        int p; cin >> p;
        point[p] = true;
    }

    int stock = 0, prev = -1, da = 0, db = 0;
    repq(i,1,L) {
        if((prev < 0 || prev + T*V < i) && stock) prev = i-1, stock--;
        // printf("point = %lld, prev = %lld", i, prev);

        (prev < 0 || prev + T*V < i ? da : db)++;
        // cout << " " << (prev < 0 || prev + T*V < i ? "x" : "o") << endl;
        if(point[i]) {
            if(stock == K) prev = i;
            else stock++;
        }
    }
    // printf("da = %lld, db = %lld\n", da, db);
    double ans = 1.0 * da / U + 1.0 * db / V;
    printf("%.12f\n", ans);
    return 0;
}

Measured memory_bytes: 3236
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/abc161_e

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    int max(int a, int b) {return a>=b?a:b;}
    int min(int a, int b) {return a<=b?a:b;}

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        int c = in.nextInt();
        char[] s = in.next().trim().toCharArray();
        char yes = 'o';

        int[] dp1 = new int[n];
        int[] dp2 = new int[n];
        int mx = 0;
        for(int i=0; i<n; i++) {
            if(s[i] == yes) {
                dp1[i] = 1 + mx++;
                i += c;
            }
        }
        mx = 0;
        for(int i=n-1; i>=0; i--) {
            if(s[i] == yes) {
                dp2[i] = 1 + mx++;
                i -= c;
            }
        }
        // show("", dp1);
        // show("", dp2);
        for(int i=0; i<n; i++) {
            if(s[i] != yes) continue;
            if(dp1[i] + dp2[i] - 1 == k && dp1[i]!=0 && dp2[i]!=0) {
                out.println(i+1);
            }
        }
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;

int main() {
    int n,w;
    cin>>n>>w;
    ll W[n+1],V[n+1];
    rep(i,n){
        cin>>W[i+1];
        cin>>V[i+1];
    }
    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));
    for (int i=1;i<n+1;i++){
        for (int j=1;j<w+1;j++){
            if (j>=W[i]){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i]]+V[i]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][w]<<endl;

    return 0;
}

Measured memory_bytes: 79104
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long A, B, C, D, E;
	cin >> A >> B >> C >> D >> E;
	if (A != 1) {
		cout << 1 << endl;
	}
	else if (B != 2) {
		cout << 2 << endl;
	}
	else if (C != 3) {
		cout << 3 << endl;
	}
	else if (D != 4) {
		cout << 4 << endl;
	}
	else {
		cout << 5 << endl;
	}
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <math.h>
#include <float.h>
using namespace std;

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

	if (b - a == c - b)
		cout << "YES";
	else 
		cout << "NO";
	return 0;
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S,T,T1,T2;
int L;
inline void solve(){
  IN(S);
  for(;;){
    T=S.substr(0,S.size()-2);
    L=T.size();
    T1=T.substr(0,L/2);
    T2=T.substr(L/2,L/2);
    if(T1==T2){
      OUT(L);
      return;
    }
    S=T;
  }
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

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

    if (x % y == 0)
        cout << -1 << endl;
    else
        cout << x * (y - 1) << endl;

    return 0;
}

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

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

    int64_t a, b;
    for(int64_t i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            a = i;
            b = n / i;
        }
    }

    cout << a + b - 2 << endl;

    return 0;
}

Measured memory_bytes: 256
n = input()

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
    print('hon')
elif n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
    print('pon')
else:
    print('bon')

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
  char c;
  cin >> c;

  if (c >= 'a') cout << "a\n";
  else cout << "A\n";
}


Measured memory_bytes: 3592
K=int(input())
import queue
q = queue.Queue()
for i in range(1,10):
  q.put(i)
for i in range(K-1):
  a=q.get()
  if a%10!=0:
    q.put(10*a+(a%10)-1)
  q.put(10*a+(a%10))
  if a%10!=9:
    q.put(10*a+(a%10)+1)
print(q.get())

Measured memory_bytes: 18952
w,h,x,y = $stdin.read.chomp.split(" ").map(&:to_i)

many = 0
x2 = w - x
y2 = h - y

area = (w * h).to_f / 2

if [x,y]==[x2,y2]
  many = 1
end

puts "#{area} #{many}"


Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int a[3005];
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]!=1)
            sum+=a[i]-1;
        else
            sum+=0;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
l,r=map(int,input().split())
mod=2019
if l%mod==0 or r%mod ==0 or l//mod != r//mod:
    print(0)
    exit()
l%=mod
r%=mod

ans = 123456789
for i in range(l,r):
    for j in range(i+1,r+1):
        ans = min(ans,i*j%mod)
print(ans)

Measured memory_bytes: 3064
#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 = 1e9;
const int mod = 1e9+7;
using P = pair<int, int>;
using ll = long long;
vector<int> to[100005];
int cost[100005];

signed main(){
    int n;
    cin >>n;
    vector<int> h(n,0);

    int ma = 0;
    int ans = 0;
    rep(i,n) {
        cin >> h[i];
        if(h[i]>=ma) {
            ans++;
            ma = h[i];
        }
    }
    cout << ans << endl;

    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  int alice,bob;
  alice = 0;
  bob = 0;
  for (int i = 0;i < N;i++){
    if (i%2==0) {
      alice += vec.at(i);
    }
    else
      bob += vec.at(i);
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a == c-b) cout << "YES" << endl;
  else cout<<"NO"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

using namespace std;


int main() {
	int N; cin >> N;
	if (N == 2) { cout << "No"; return 0; }
	if (N == 1) {
		cout << "Yes" << endl << 2 <<endl<< "1 1" << endl << "1 1";
		return 0;
	}
	int n = (int)sqrt(N) - 1;
	bool flag = false;
	for (; n <= N; n++) {
		int c = n*(n - 1) - N * 2;
		if (c == 0) {
			flag = true;
			break;
		}
		if (c > 0) {
			flag = false;
			break;
		}
	}
	if (flag == false) {
		cout << "No";
		return 0;
	}
	int s = n - 1;

	cout << "Yes" << endl << n << endl;

	int *x = new int[N];
	int *num = new int[N];
	for (int i = 0; i < N; i++) {
		x[i] = 0;
		num[i] = -1;
	}

	for (int i = 0; i < n; i++) {
		cout << n - 1;
		int k = n - i - 1;
		for (int j = 0;  k > 0 && j < N; j++) {
			if (x[j] == 0) {
				k--;
				x[j]++;
				num[j] = i;
				cout << " " << j + 1;

				if (k == 0) { break; }
			}
		}
		int pre = -1;
		k = i;
		for (int j = 0; k > 0 && j < N; j++) {
			if (x[j] == 1 && num[j]!=pre) {
				k--;
				x[j]++;
				pre = num[j];
				cout << " " << j + 1;
				if (k == 0) { break; }
			}
		}
		cout << endl;
	}
	delete[] x;
	delete[] num;

	return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
#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;
	long long M;
	cin >> N >>M;
	vector<int> A(N);
	for (int n = 0;n < N;++n) {
		cin >> A[n];
	}
	sort(A.begin(), A.end());
	int l = 0;
	int r = 200005;
	vector<long long>S(N + 1);
	for (int n = 0;n<N;++n) {
		S[n + 1] = (long long)A[n] + S[n];
	}

	auto calc = [&](int x) {
		ll tot = 0, num = 0;
		rep(i, N) {
			int j = lower_bound(A.begin(), A.end(), x - A[i]) - A.begin();
			num += N - j;
			tot += S[N] - S[j];
			tot += A[i] * ll(N - j);
		}
		return make_pair(tot, num);
	};

	while (l + 1 < r) {
		long long num = 0;
		int c = (l+r) / 2;
		/*for (int n = 0;n < N;++n) {
			int j = lower_bound(A.begin(), A.end(), c - A[n]) - A.begin(); 
			num += (long long)(N - j);
		}
		if (num >= M) {
			l = c;
		}
		else {
			r = c;
		}*/
		if (calc(c).second >= M) l = c; else r = c;
	}
	/*long long ans = 0;
	long long num = 0; 
	for (int n = 0; n < N; ++n) {
		int j = lower_bound(A.begin(), A.end(), l - A[n]) - A.begin();
		num += (long long)(N - j);
		ans += (long long)(S[N] - S[j]);
		ans += (long long)(A[n] * (N - j));
	}

	ans -= (long long)((num-M)*l);
	cout << ans <<endl;*/
	auto p = calc(l);
	ll ans = p.first;
	ans -= (p.second - M)*l;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4580
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

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

    vector<int> A;
    A.push_back(1);
    while(1){
        if(A[A.size() - 1] < n){
            A.push_back(A[A.size() - 1] * 2);
        }else break;
    }
    for(int i = A.size() - 1; i >= 0; i--){
        if(A[i] <= n){
            cout << A[i] << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>

int main() {
  int n, k;
  scanf("%d %d", &n, &k);

  double res = 0;
  for (int i = 1; i <= n; ++i) {
    double cur = 1.0;
    for (int j = i; j < k; j *= 2) {
      cur /= 2.0;
    }
    res += cur;
  }
  res /= n;
  printf("%.12f\n", res);
}


Measured memory_bytes: 128
C500 = int(input())
C100 = int(input())
C50 = int(input())
X = int(input())
count = 0
for i in range(C500+1):
  for j in range(C100+1):
    for k in range(C50+1):
      TOTAL = 500*i+100*j+50*k
      if TOTAL == X:
        count += 1
        break
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
const int maxn=8e2+10;
using namespace std;
char a[maxn][maxn];
int stmp[maxn][maxn];//代表这是bfs的第几步
int direction[4][2]={1,0,-1,0,0,1,0,-1};//四个方向
int n,m,k;
int ans=99999999;
bool check(int x,int y)//判断这个点是否可行
{
    if(x>=0&&x<n&&y>=0&&y<m&&stmp[x][y]==0&&a[x][y]=='.')
    {
       return 1;
    }
    return 0;
}
queue<pair<int,int> >po;
int main()
{
    cin>>n>>m>>k;
    int sx,sy;
    getchar();
    for(int i=0;i<n;i++)//输入顺便找到起点
    {
        for(int j=0;j<m;j++)
        {
            scanf("%c",&a[i][j]);
            if(a[i][j]=='S')
            {
                sx=i;
                sy=j;
            }
        }
        getchar();
    }
    stmp[sx][sy]=1;
    po.push(make_pair(sx,sy));
    while(!po.empty())
    {
        int x=po.front().first;
        int y=po.front().second;
        ans=min(ans,min(min(x,n-x-1),min(y,m-y-1)));
        po.pop();
        for(int i=0;i<4;i++)
        {
            int xx=x+direction[i][0];
            int yy=y+direction[i][1];
            if(check(xx,yy)&&stmp[x][y]<=k)
            {
               stmp[xx][yy]=stmp[x][y]+1;
               po.push(make_pair(xx,yy));
            }
        }
    }
    int anss;
    anss=1+(ans+k-1)/k;//向上取整
    cout<<anss<<endl;
    return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll W,a, b;
	cin >> W >> a >> b;
	if (a + W <= b)
		cout << b - a - W << endl;
	else if (b + W <= a)
		cout << a-W-b<< endl;
	else 
      cout<<0<<endl;

}



Measured memory_bytes: 256
#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 min = a[0], max = a[0];
  for(int i = 0; i < n; i++){
    if(min > a[i]){
      min = a[i];
    }
    if(max < a[i]){
      max = a[i];
    }
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 3600
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

class SegmentTree():
    def __init__(self,array,func,unit):
        self.N = len(array)
        self.f = func
        self.unit = unit
        self.tree = [self.unit] * (2*self.N)
        for i,x in enumerate(array,self.N):
            self.tree[i] = x
        for i in range(self.N - 1,0,-1):
            self.tree[i] = self.f(self.tree[i << 1],self.tree[i << 1|1])
    
    def update(self,k,x):
        k += self.N
        self.tree[k] = x
        while k > 1:
            k >>= 1
            self.tree[k] = self.f(self.tree[k << 1],self.tree[k << 1|1])
    
    def query(self,l,r):
        l += self.N
        r += self.N
        vl = self.unit
        vr = self.unit
        while l < r:
            if l&1: 
                vl = self.f(vl,self.tree[l])
                l += 1
            if r&1:
                r -= 1
                vr = self.f(self.tree[r],vr)
            l >>= 1
            r >>= 1
        return self.f(vl,vr)

def main():
    n,q = map(int,input().split())
    st = SegmentTree([(1<<31) - 1]*n,min,1<<32)

    for _ in range(q):
        query = list(map(int,input().split()))
        if query[0] == 0:
            i = query[1]
            x = query[2]
            st.update(i,x)
        else:
            s = query[1]
            t = query[2]
            print(st.query(s,t + 1))
if __name__ == '__main__':
    main()


Measured memory_bytes: 8212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD (int)1e9+7
#define INF 1e15
typedef pair<int, int> P;
int a[5];
signed main() {
	rep(i, 5)cin >> a[i];
	int ans = 0;
	rep(i, 5) {
		if (a[i] % 10 == 0)ans += a[i];
		else ans += a[i]/10*10+10;
		a[i] = (a[i] - 1) % 10 + 1;
	}
	sort(a, a + 5);
	cout << ans-10+a[0]<< endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = Math.Abs(input[1] - input[0]);
            int B = Math.Abs(input[2] - input[0]);
            Console.WriteLine(A < B ? "A" : "B");
        }
    }
}

Measured memory_bytes: 13140
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

a, b, m = map(int, input().split())
a = list( map(int, input().split()))
b = list( map(int, input().split()))

x = [0]* m
y = [0]* m
c = [0]* m
for i in range(m):
    x[i], y[i], c[i] = map(int, input().split())

ans = min(a)+min(b)

for i in range(m):
    ans = min(ans, a[x[i]-1]+b[y[i]-1] - c[i])

print(ans)

Measured memory_bytes: 23844
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define faster ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define ld long double
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
#define pi 2*acos(0.0)
const int INF = 1e9+1;
const int mod = 1e9+7;
const int mod1 = 998244353;
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}
 
ll nCr(ll n, ll k) { 
   ll C[n + 1][k + 1]; 
   
   REP(i,0,n+1){ 
      REP(j,0,min(i,k)+1) {
         if(j==0 || j==i) {
            C[i][j] = 1;  
         } else {
            C[i][j] = C[i-1][j-1] + C[i-1][j]; 
         }
      } 
   }
   return C[n][k]; 
}

bool compare(pair<int, int>&i, pair<int, int>&j) {
    return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void readtxt() {
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
}

void test() {
   int x, y;
   cin >> x >> y;
   for(int i = 0; i <= x; i++) {
      if(i*2 + (x-i)*4 == y) {
       	cout << "Yes" << endl;
  		   return;
      }
   }
  
   cout << "No" << endl;
}

int main() {
   //readtxt();
   faster;

   int t = 1;
   //cin >> t;
   while(t--)
      test();
}

Measured memory_bytes: 3620
#include <stdio.h>

int main() {
  int w, h, x, y, r;
  scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
  if (x - r >= 0 && y - r >= 0 && x + r <= w && y + r <= h) puts("Yes");
  else puts("No");
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)

int n, m;
map<ll, ll> c;
map<ll, ll> res;
ll dp(ll x) {
    if(x==0) return 0;
    if(res.count(x)) return res[x];
    res[x] = 0x3fffffffff;
    for(auto it = c.begin(); it!=c.end(); it++) {
        ll a = it->first; ll b = it->second;

        if(x & a) {
            res[x] = min(res[x], b + dp(x & (~a)));
        }
    }
    return res[x];
}

int main() {
    cin >> n >> m;
    ll a = 0;
    for(int i=0; i<m; i++) {
        ll p, n2; cin>> p >> n2;
        ll k = 0;
        for(int j=0; j<n2; j++) {
            int t; cin>>t; k |= 1ll<<(t-1);
            a |= k;
        }
        if(c.count(k))c[k] = min(c[k], p);
        else c[k] = p;
    }
    if(a != (1ll<<n) - 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << dp((1ll<<n) - 1) << endl;


}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main(){
    ll n, a, b;
    cin  >> n >> a >> b;
    if((b-a) % 2 == 0){
        cout << (b-a)/2 << endl;
    }else{
        if((n-b)>= (a-1)){
            ll aa = 1;
            ll bb = b - a-1 + 1;
            cout << a - 1 + 1 + (bb - aa)/2 << endl;
        }else{
            ll bb = n;
            ll aa = a + n - b + 1;
            cout << n - b + 1 + (bb-aa)/2 << endl;
        }
    }
}


Measured memory_bytes: 256
N,*A=map(int,open(0).read().split())
r=range
S=[0]*-~N
for l in r(N):
 S=[max(S[i+1]+A[i],S[i]+A[i+l])if(l^N)&1else min(S[i+1]-A[i],S[i]-A[i+l])for i in r(N-l)]
print(S[0])

Measured memory_bytes: 44676
#include <cstdio>

using namespace std;

int main(void)
{
    int n;
    scanf("%d", &n);

    int a[n];
    scanf("%d", &a[0]);

    int min = 0;
    int j = 1;
    for (int i = 1; i < n; i++) {
        scanf("%d", &a[i]);
        if (a[i-1] == a[i]) {
            a[i] = n + ++j + 1;
            min++;
        }
    }

    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 888
import sys
data_list = []
for line in sys.stdin:
	data_list.append(line.split())

class Node():
    def __init__(self, name, transaction_list = None):
        self.transaction_list = transaction_list or []

    def add_node(self, node):
        self.transaction_list.append(node)

def convert_adjencentList_to_adjencentMatrix(adjencentList):
    adjencent_matrix = [[0 for i in range(len(adjencentList))] for j in range(len(adjencentList))]
    count = 0
    for targetList in adjencentList:
        targetList.transaction_list.sort()
        for target_index in targetList.transaction_list :
            adjencent_matrix[count][int(target_index) - 1] = 1
        count = count + 1

    for i in adjencent_matrix:
        print(*i)

if __name__ == "__main__":
        node_data_list = []

        for node_data in data_list[1:]:
            node = Node(node_data[1])
            for transaction_node in node_data[2:]:
                node.add_node(transaction_node)

            node_data_list.append(node)

        convert_adjencentList_to_adjencentMatrix(node_data_list)



Measured memory_bytes: 6460
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    for (int i = 0; ; i++) {
      if (1000*i >= n) {
        System.out.println(1000*i-n);
        break;
      }
    }

  }

}


Measured memory_bytes: 35640
#include <stdio.h>
#include <string.h>

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

int main(void){
  char S[100000];
  scanf("%s",S);

  int a = 0,b = 0;
  for(int i = 0;i < strlen(S);i++){
    if(i%2 == 0){
      if(S[i] == '0') a++;
      else b++;
    }else{
      if(S[i] == '0') b++;
      else a++;
    }
  }

  printf("%d\n",min(a,b));

  return 0;
}

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

ll gcd(ll a, ll b){
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
    }
    return a;
}


int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);

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

    ll d = abs(a[0] - x);
    for (int i = 0; i < n; i++){
        d = gcd(d, abs(a[i] - x));
    }

    cout << d << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()

using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-10;
const D PI = acos(-1);

//for vector
inline pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}
inline D dot(P x, P y){return real(conj(x)*y);}
inline D cross(P x, P y){return imag(conj(x)*y);}

//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

//for line(segment)
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

inline bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline P symmetry_line(L l, P p){
  if(abs(ccw(l.fs,l.sc,p)) != 1)return p;
  P nv = norm(l.fs-l.sc).fs;
  P cp = line_cp(l, L(p,p+nv));
  return cp + rotate(p-cp, PI);
}

struct state{
  P goal;
  vector<L> mirrors;
  state(P p, vector<L> m):goal(p),mirrors(m){}

  state symmetry(int x){
    vector<L> sym(mirrors.sz);
    rep(i,mirrors.sz){
      if(i == x)sym[i] = mirrors[i];
      else sym[i] = L(symmetry_line(mirrors[x],mirrors[i].fs),
		      symmetry_line(mirrors[x],mirrors[i].sc));
    }
    return state(symmetry_line(mirrors[x],goal), sym);
  }
};

const int max_depth = 6;
int n;
D tx,ty,lx,ly;

D rec(int depth, vector<int> &order, vector<state> &mir){
  if(depth == max_depth)return 1e8;
  
  D res = 1e8;

  bool f = true;
  P start = P(lx,ly);
  L route = L(start, mir.back().goal);
  rep(i,depth+1){
    state cur = mir[i];
    int axis = i==depth?-1:order[i], prev = !i?-1:order[i-1];
    if(axis>=0 && !is_cp(route, cur.mirrors[axis])){
      f = false; break;
    }

    P cp = axis>=0?line_cp(route, cur.mirrors[axis]):mir.back().goal;
    L seg = L(start, cp);
    rep(j,n){
      if(axis!=j && prev!=j && is_cp(seg, cur.mirrors[j])){
	f = false; break;
      }
    }
    if(!f)break;
    start = cp; route.fs = start;
  }
  if(f)res = abs(P(lx,ly) - mir.back().goal);

  rep(i,n){
    if(depth && order[depth-1] == i)continue;
    order.pb(i);
    mir.pb(mir.back().symmetry(i));

    res = min(res, rec(depth+1, order, mir) );

    mir.pop_back();
    order.pop_back();
  }

  return res;
}

int main(){
  while(cin >> n, n){
    vector<L> vl(n);
    rep(i,n){
      D px, py, qx, qy;
      cin >> px >> py >> qx >> qy;
      vl[i] = L(P(px,py), P(qx,qy));
    }
    cin >> tx >> ty >> lx >> ly;
    
    vector<state> vs;
    vs.push_back( state(P(tx,ty), vl) );
    vector<int> vi;
    D ans = rec(0, vi, vs);
    cout << fixed << setprecision(4) << ans << endl;
  }
}

Measured memory_bytes: 1352
from collections import defaultdict
import heapq
n = int(input())

red = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    red[b].append(a)

blue = defaultdict(list)
for _ in range(n):
    a, b = map(int, input().split())
    blue[b].append(a)


ans = 0
can_use = []
for i in range(1, 2*n):
    for x in red[i-1]:
        heapq.heappush(can_use, -x)

    blue[i].sort(reverse=True)
    ret = []
    for b in blue[i]:
        while can_use:
            maxr = -heapq.heappop(can_use)
            if maxr < b:
                ans += 1
                break
            else:
                ret.append(maxr)
    for x in ret:
        heapq.heappush(can_use, -x)
print(ans)


Measured memory_bytes: 9496
from sys import stdin


def main():
    A1 = [int(x) for x in stdin.readline().rstrip().split()]
    A2 = [int(x) for x in stdin.readline().rstrip().split()]
    A3 = [int(x) for x in stdin.readline().rstrip().split()]
    A4 = [A1[0], A2[0], A3[0]]
    A5 = [A1[1], A2[1], A3[1]]
    A6 = [A1[2], A2[2], A3[2]]
    A7 = [A1[0], A2[1], A3[2]]
    A8 = [A1[2], A2[1], A3[0]]
    As = [A1, A2, A3, A4, A5, A6, A7, A8]
    N = int(stdin.readline().rstrip())
    bs = [int(stdin.readline().rstrip()) for _ in range(N)]
    b = set(bs)
    for A in As:
        a = set(A)
        x = a & b
        if(len(x) == 3):
            print('Yes')
            return
    print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n, m; cin >> n >> m;
    vector<int> X(m); rep(i, m) cin >> X[i];
    if(n>=m) cout << 0 << ln;
    else{
        sort(all(X));
        vector<int> D(m-1); int sum = 0;
        rep(i, m-1){
            D[i] = abs(X[i+1]-X[i]);
            sum += D[i];
        }
        sort(all(D), greater<int>());
        rep(i, n-1){
            sum -= D[i];
        }
        cout << sum << ln;
    }
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[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()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        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!{
        k: i32,
        n: usize,
        v: [i32; n]
    }
    let mut max_range = v[0] - v[n-1] + k;
    for i in 0..n-1 {
        max_range = cmp::max(max_range, v[i+1] - v[i]);
    }
    println!("{}", k - max_range);
}


Measured memory_bytes: 4352
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var B = new int[10, 10];
            for (int i = 1; i < N + 1; i++)
            {
                var s = i.ToString();
                B[int.Parse(s[0].ToString()), int.Parse(s[s.Length - 1].ToString())] += 1;
            }

            var result = 0;
            for (int i = 1; i < N + 1; i++)
            {
                var s = i.ToString();
                result += B[int.Parse(s[s.Length - 1].ToString()), int.Parse(s[0].ToString())];
            }
            Console.WriteLine((result));
        }
    }
}


Measured memory_bytes: 13236
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    string S;
    cin >> S;
    cout << S.substr(0,3);
    return 0;
}



Measured memory_bytes: 3624
#include <cstdio>
#include <set>
#include <string>
using namespace std;

const int MAX_L = 12;

char buf[MAX_L+1];

int main(){

	set<string> used;

	puts("?a"); fflush(stdout);
	used.insert("a");

	for(;;){
		scanf("%[^\n]%*c", buf);
		string str = string(buf);

		if('a' != str[0] || !used.insert(str).second ){
			break;
		}

		char last_char = str[(int)str.length()-1];

		//(last, b, c, 'a')ツづーツ出ツ療債つキツづゥ
		bool found = false;
		for(char b = 'a'; b <= 'z'; b++){
			for(char c = 'a'; c <= 'z'; c++)if(!found){
				str = string(1, last_char);
				str += b;
				str += c;
				str += 'a';
				if( used.insert(str).second ){
					found = true;
					printf("?%s\n", str.c_str());
					fflush(stdout);
				}
			}
		}

	}

	puts("!OUT");

	return 0;
}

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

using namespace std;


int main()
{
    int n;
    cin>>n;
    vector<int> x(n);
    //int p=1;
    for(int i=0;i<n;i++)
       cin>>x[i];

    int ans=(int)1e9;
    for(int i=1;i<=100;i++)
    {
        int cost=0;
        for(int j=0;j<n;j++)
        {
            cost+=(x[j]-i)*(x[j]-i);
        }
            ans=min(ans,cost);
    }
cout<<ans<<"\n";
   return 0;
}


Measured memory_bytes: 3600