akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int m1=0,m2=0,d1=0,d2=0;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1==m2&&d1+1==d2)cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
let rec loop _ =
    let a, op, b = Scanf.scanf "%d %s %d " (fun a op b -> a, op, b) in
    if op <> "?" then (
        let res =
            match op with
            | "+" -> a + b
            | "-" -> a - b
            | "/" -> a / b
            | "*" -> a * b
            | _ -> raise Not_found in
        Printf.printf "%d\n" res;
        loop () )

let _ = loop ();
        


Measured memory_bytes: 2356
h,w=map(int,input().split())
n=int(input())
A=list(map(int,input().split()))
C=[[0]*w for _ in range(h)]
prev_h,prev_w=0,-1
for i in range(n):
    j=0
    while j<A[i]:
        if prev_h%2:
            if prev_w:
                C[prev_h][prev_w-1]=i+1
                prev_w-=1
            else:
                C[prev_h+1][prev_w]=i+1
                prev_h+=1
        else:
            if prev_w!=w-1:
                C[prev_h][prev_w+1]=i+1
                prev_w+=1
            else:
                C[prev_h+1][prev_w]=i+1
                prev_h+=1
        j+=1
for i in range(h):
    print(' '.join([str(n) for n in C[i]]))

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

int dp[105][4][2];

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

  string s;
  cin >> s;
  int n = s.size();

  int K;
  cin >> K;

  dp[0][0][0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 2; k++) {
        int nd = s[i] - '0';

        for (int d = 0; d < 10; d++) {
          int ni = i + 1;
          int nj = j;
          int nk = k;
          if (d != 0) nj++;
          if (nj > K) continue;
          if (k == 0) {
            if (d > nd) continue;
            if (d < nd) nk = 1;
          }
          dp[ni][nj][nk] += dp[i][j][k];
        }
      }
    }
  }
  int ans = dp[n][K][0] + dp[n][K][1];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1;
const ll inf = hell ;
bool is(string s){
	string s2=s;
	reverse(all(s2));
	return s==s2;
}
void solve(){
	ld x, y;
	cin>>x;
	y=x/3.0;
	cout<<fixed<<setprecision(6)<<(y*y*y);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    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);
		int n=sc.nextInt();
		int[] team=new int[n];
		int[] tmp=new int[n];
		int teamA,teamB,scoreA,scoreB,cnt;
		for(int i=0;i<n*(n-1)/2;i++){
			teamA=sc.nextInt();
			teamB=sc.nextInt();
			scoreA=sc.nextInt();
			scoreB=sc.nextInt();
			if(scoreA>scoreB){
				team[teamA-1]+=3;
			}
			else if(scoreA<scoreB){
				team[teamB-1]+=3;
			}
			else{
				team[teamA-1]+=1;
				team[teamB-1]+=1;
			}
		}
		tmp=(int[])team.clone();
		java.util.Arrays.sort(tmp);
		for(int i=0;i<n;i++){
			cnt=0;
			for(int j=n-1;j>=0;j--){
				cnt++;
				if(team[i]==tmp[j]){
					System.out.println(cnt);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 41964
n,m = map(int,input().split())
h = list(map(int,input().split()))
c = [1]*n
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        c[b-1] = 0
    elif h[b-1] > h[a-1]:
        c[a-1] = 0
    elif h[a-1] == h[b-1]:
        c[a-1] = c[b-1] =0
    
print(sum(c))

Measured memory_bytes: 19972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解法:2人が最適な戦略を取った時、大きいカードから順に選ぶはず
int main() {
  //入力
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  sort(a.rbegin(),a.rend()); // 大きい順にソートする
  // a.begin(),a.end()だと小さい順になるので注意
  int ans = 0;
  rep(i,n){
    //奇数の時はAlice 偶数の時はBobのターンになる
    if(i%2==0) ans+=a.at(i);
    if(i%2==1) ans-=a.at(i);
  }
  //出力
  cout << ans << endl;
}


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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  ll sum=0;
  rep(i,0,n)sum+=a[i];
  if(n&1){
    ans(sum&1,"First","Second");
  }
  else{
    ll mi=INF;
    rep(i,0,n)chmin(mi,a[i]);
    ans((mi&1)||(sum&1),"First","Second");
  }
  return 0;
}


Measured memory_bytes: 4392
def main():
    n = int(input())
    for _ in range(n):
        a, b = map(int, input().split())
        ref = a * b
        s = int(ref ** 0.5)
        ans = 2 * s - 1
        if s * (s + 1) >= ref:
            ans -= 1
        if s * s == ref and a != b:
            ans -= 1
        print(ans)
if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
const int mod = 1e9 + 7;
const int N = 200001;
const int M = 2001;
int read() {
	int s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int a[N], b[N];
int f[M * 2][M * 2], jc[M * 4], inv[M * 4];

int add(int x, int y) {
	x += y;
	return x >= mod ? x - mod : x;
}

int dec(int x, int y) {
	x -= y;
	return x < 0 ? x + mod : x;
}

int C(int n, int m) {return (LL)jc[n] * inv[m] % mod * inv[n - m] % mod;}

int pow_mod(int a, int k) {
	int ans = 1;
	while(k) {
		if(k & 1) ans = (LL)ans * a % mod;
		a = (LL)a * a % mod; k /= 2;
	} return ans;
}

int main() {
//	freopen("bbq.in", "r", stdin);
//	freopen("bbq.out", "w", stdout);
	int n = read();
	int mx = 0, my = 0;
	for(int i = 1; i <= n; i++) {
		a[i] = read(), b[i] = read();
		f[M - a[i]][M - b[i]]++;
		mx = _max(mx, a[i]), my = _max(my, b[i]);
	} for(int i = 1; i <= M + mx; i++) for(int j = 1; j <= M + my; j++) f[i][j] = add(f[i][j], add(f[i][j - 1], f[i - 1][j]));
	jc[0] = inv[0] = 1; for(int i = 1; i <= (mx + my) * 2; i++) jc[i] = (LL)jc[i - 1] * i % mod;
	inv[(mx + my) * 2] = pow_mod(jc[(mx + my) * 2], mod - 2); for(int i = (mx + my) * 2 - 1; i >= 1; i--) inv[i] = (LL)inv[i + 1] * (i + 1) % mod;
	int ans = 0, zz = pow_mod(2, mod - 2);
	for(int i = 1; i <= n; i++) ans = add(ans, f[M + a[i]][M + b[i]]);
	for(int i = 1; i <= n; i++) ans = dec(ans, C(2 * (a[i] + b[i]), a[i] + a[i]));
	put((LL)ans * zz % mod);
	return 0;
}


Measured memory_bytes: 64384
#include <iostream>
#include <cstdio>
using namespace std;
struct {int n; double t;} p[3][8], x, q[18];
int main()
{
	int i, j, k;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 8; j++)
			cin >> p[i][j].n >> p[i][j].t;
		for (j = 0; j < 8; j++)
			for (k = 0; k < 7; k++)
				if (p[i][k].t > p[i][k+1].t)
				{
					x = p[i][k];
					p[i][k] = p[i][k+1];
					p[i][k+1] = x;
				}
	}
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 2; j++)
			printf("%d %.2f\n", p[i][j].n, p[i][j].t);
		for (j = 2; j < 8; j++)
			q[i*6+j-2] = p[i][j];
	}
	for (i = 0; i < 18; i++)
		for (j = 0; j < 17; j++)
			if (q[j].t > q[j+1].t)
			{
				x = q[j];
				q[j] = q[j+1];
				q[j+1] = x;
			}
	for (i = 0; i < 2; i++)
		printf("%d %.2f\n", q[i].n, q[i].t);
}

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


int main() {
    int a,b,c,k;
    cin >>a>>b>>c>>k;
    int mx =max(a,(max(b,c)));
    int d =mx;
    for(int i=0;i<k;i++)d*=2;
    int ans =d + a+ b+c-mx;
    cout <<ans <<endl;
}

Measured memory_bytes: 256
S=input()+'R'
ans=[0]*(len(S)-1)

Rf=1
Rc,Lc=0,0
for i,s in enumerate(S):
    if s=='R':
        if Rf:
            Rc+=1
        else:
            #print(x,Rc,Lc)
            
            if Rc%2:
                if Lc%2:
                    ans[x]+=(Rc+Lc)//2
                    ans[x+1]+=(Rc+Lc)//2
                else:
                    ans[x]+=(Rc+Lc)//2 + 1
                    ans[x+1]+=(Rc+Lc)//2
            else:
                if Lc%2:
                    ans[x]+=(Rc+Lc)//2
                    ans[x+1]+=(Rc+Lc)//2 + 1         
                else:
                    ans[x]+=(Rc+Lc)//2
                    ans[x+1]+=(Rc+Lc)//2
            
            Rc,Lc=0,0
            Rc+=1
            Rf=1
    else:
        Lc+=1
        if Rf:
            Rf=0
            x=i-1
        else:
            pass

print(' '.join(list(map(str,ans))))
        

Measured memory_bytes: 17072
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AShikAndStone solver = new AShikAndStone();
        solver.solve(1, in, out);
        out.close();
    }

    static class AShikAndStone {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int h = in.ints(), w = in.ints();
            String[] a = in.string(h);
            int c = 0;
            for (String row : a) {
                for (char column : row.toCharArray()) {
                    if (column == '#') {
                        c++;
                    }
                }
            }
            if (c == h + w - 1) {
                out.println("Possible");
            } else {
                out.println("Impossible");
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String[] string(int length) {
            return IntStream.range(0, length).mapToObj(x -> string()).toArray(String[]::new);
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



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

public class Main {
 
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        String s = sc.next();
        int n = s.length();
        int[] result = new int[n]; 
        for (int i = 0; i < n; i++) {
            result[i] = 0;
            for (int j = 0; j < n-i; j++) {
                if ((s.charAt(i+j) == 'A' || s.charAt(i+j) == 'C') || (s.charAt(i+j) == 'G' || s.charAt(i+j) == 'T')) {
                    result[i]++;
                } else break;
            }
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, result[i]);
        }
        System.out.println(max);
    }
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    
    public boolean hasNext() { 
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

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

#define ll long long

ll n, a, b; 

int main(){
	scanf("%lld%lld%lld", &n, &a, &b);
	if(n == 1){
		if(a != b) printf("0\n");
		else printf("1\n");
		return 0;
	}
	if(a > b) return printf("0\n"), 0;
	printf("%lld\n", (n - 2) * (b - a) + 1);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int H, W;
    while(cin >> H >> W, H != 0 && W != 0){
        for(int i = 0; i < H; i++){
            for(int j = 0; j <W; j++){
                if((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0)){
                    cout << "#" ;
            }else if((i % 2 == 0 && j % 2 != 0) || (i % 2 != 0 && j % 2 == 0)){
                    cout << ".";
            }
            }
            cout << "" << endl;
        }
        cout << "" << endl;
    }

return 0;
}
    

Measured memory_bytes: 3096
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const char PTTN[9][5][6]={
{
	".....",
	"...|.",
	".....",
	"...|.",
	"..-.."
},{
	"..-..",
	"...|.",
	"..-..",
	".|...",
	"..-.."
},{
	"..-..",
	"...|.",
	"..-..",
	"...|.",
	"..-.."
},{
	".....",
	".|.|.",
	"..-..",
	"...|.",
	"....."
},{
	"..-..",
	".|...",
	"..-..",
	"...|.",
	"..-.."
},{
	"..-..",
	".|...",
	"..-..",
	".|.|.",
	"..-.."
},{
	"..-..",
	"...|.",
	".....",
	"...|.",
	"....."
},{
	"..-..",
	".|.|.",
	"..-..",
	".|.|.",
	"..-.."
},{
	"..-..",
	".|.|.",
	"..-..",
	"...|.",
	"..-.."
}};

void flipLR(char face[5][5]){
	rep(i,5) rep(j,2) swap(face[i][j],face[i][4-j]);
}

void flipUD(char face[5][5]){
	rep(i,2) rep(j,5) swap(face[i][j],face[4-i][j]);
}

void rot90(char face[5][5]){
	static int g[128];
	g['|']='-'; g['-']='|'; g['.']='.';

	char tmp[5][5];
	rep(i,5) rep(j,5) tmp[4-j][i]=g[face[i][j]];

	rep(i,5) rep(j,5) face[i][j]=tmp[i][j];
}

void f(char face[5][5],int k){
	switch(k){
		case 0:
		case 2:
		case 4:
			flipLR(face);
			break;
		case 1:
			flipLR(face);
			rot90(face);
			break;
		case 3:
			flipLR(face);
			rot90(face); rot90(face); rot90(face);
			break;
		case 5:
			flipUD(face);
			flipLR(face);
			break;
	}
}

void parse(const char die[21][28],int num[6]){
	// upper left coordinate
	const int ul[6][2]={{0,7},{7,0},{7,7},{7,14},{7,21},{14,7}};

	rep(k,6){
		int t=ul[k][0]+1,l=ul[k][1]+1;
		rep(d,9){
			char face[2][5][5];
			rep(i,5) rep(j,5) {
				face[0][i][j]=die[i+t][j+l];
				face[1][i][j]=PTTN[d][i][j];
			}
			f(face[1],k);

			bool eq=true;
			rep(i,5) rep(j,5) if(face[0][i][j]!=face[1][i][j]) eq=false;
			if(eq){ num[k]=d+1; break; }
		}
	}
}

int main(){
	while(1){
		char die[2][21][28];
		rep(i,21){
			char s[58]; scanf("%s",s);
			rep(j,28){
				die[0][i][j]=s[j];
				die[1][i][j]=s[j+29];
			}
		}
		if(die[0][0][0]=='0') break;

		int num[2][6];
		rep(k,2) parse(die[k],num[k]);

		int win=0,tot=0;
		rep(i,6) rep(j,6) {
			if(num[0][i]> num[1][j]) win++;
			if(num[0][i]!=num[1][j]) tot++;
		}
		puts(2*win>=tot?"HIGH":"LOW");
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

int main(){
	int n,k;
	cin >> n >> k;
	vector<ll> da(n);
	rip(i,n,0){
		cin >> da[i];
	}
	ll w=0,b=0;
	rip(i,n,0){
		if(da[i]>0){
			w+=da[i];
			b+=da[i];
		}
	}
	rip(i,k,0){
		if(da[i]>0){
			w-=da[i];
		}
		else{
			b+=da[i];
		}
	}
	ll ans=max(b,w);
	rip(i,n,k){
		if(da[i]>0){
			w-=da[i];
		}
		else{
			b+=da[i];
		}
		if(da[i-k]>0){
			w+=da[i-k];
		}
		else{
			b-=da[i-k];
		}
		ans=max(ans,max(b,w));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	int X;
	cin >> X;



	if (N * 500 >= X)cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;

const int N=200005;
const ll inf=1000000000000000ll;

int n,b,a,c,d;
ll ans,mx,mn;
int f[N];
ll s[N];

void pd(int i,int a,int b){
	mx=max(max(s[a],s[i]-s[a]),max(s[b]-s[i],s[n]-s[b]));
	mn=min(min(s[a],s[i]-s[a]),min(s[b]-s[i],s[n]-s[b]));
	ans=min(ans,mx-mn);
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&f[i]),s[i]=s[i-1]+1ll*f[i];
	a=1;
	for (i=1;i<=n;i++)
		if (s[i]<=s[n]-s[i]) b=i;
	ans=inf;
	for (i=2;i<=n-2;i++){
		while (a<i&&s[a+1]<=s[i]-s[a+1]) a++;
		while (b<n&&s[b+1]-s[i]<=s[n]-s[b+1]) b++;
		pd(i,a,b);
		if (a<i) pd(i,a+1,b);
		if (b<n) pd(i,a,b+1);
		if (a<i&&b<n) pd(i,a+1,b+1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2560
#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;
    
    int cnt = 0, tmp, lmt;
    REP(i, n){
        cin >> tmp;
        lmt = sqrt(tmp);
        FOR(j, 2, lmt + 1){
            if(tmp % j == 0){
                cnt++;
                break;
            }
        }
    }
    cout << n - cnt << endl;


    return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <cmath>

#include <stdio.h>

#define PI 3.1415926535

using namespace std;

int main(){

   double a, b, C;

   cin >> a >> b >> C;

   C = C * PI / 180;

   printf("%.8lf\n", (a * b / 2) * sin(C));
   printf("%.8lf\n", a + b + sqrt(a*a + b*b - 2*a*b*cos(C)));
   printf("%.8lf\n", 2 * (a * b / 2) * sin(C) / a);

   return 0;
}


Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define inf ((ll)1e18+5)
#define maxx ((ll)1e6+5)
#define pb push_back
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
/*
bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //usefile;
  //test
  {
    int n;
    cin>>n;
    map<int,int>mp;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
      int temp;
      cin>>temp;
      v[i]=temp;
      mp[temp]++;
    }
    int ans=0;
    for(auto i:mp){
      ans+=i.second*(i.second-1)/2;
    }
    for(int i=0;i<n;i++)
    {
      int res=ans-mp[v[i]]+1;
      cout<<res<<endl;
    }
    
  }
  //time("");
  return 0; }

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int n;

void dfs(string s, char mx) {
    if (s.length() == n) {
        cout << s << endl;
        return;
    }

    for (char c = 'a'; c <= mx+1; ++c) { //今まで使った文字+1までOK
        string t = s;
        t += c;
        dfs(t, max(mx, c)); //今まで使った文字+1ならそれがmaxで入る
    }
};

int main() {

    cin >> n;

    dfs("", 'a'-1);
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	double t1,t2;
	while (cin>>t1>>t2) {
		if (t1 < 35.50 && t2 < 71.00) {
			cout << "AAA" << endl;
		}
		else if (t1 < 37.50 && t2 < 77.00) {
			cout << "AA" << endl;
		}
		else if (t1 < 40.00 && t2 < 83.00) {
			cout << "A" << endl;
		}
		else if (t1 < 43.00 && t2 < 89.00) {
			cout << "B" << endl;
		}
		else if (t1 < 50.00 && t2 < 105.00) {
			cout << "C" << endl;
		}
		else if (t1 < 55.00 && t2 < 116.00) {
			cout << "D" << endl;
		}
		else if (t1 < 70.00 && t2 < 148.00) {
			cout << "E" << endl;
		}
		else  {
			cout << "NA" << endl;
		}
	}

return 0;
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
const int maxn = 4e5 + 33, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n, q, pw[maxn], cnt[maxn];
string s;
void solve2() {
	ll ans = 0, pos=0;
	for(auto i : s) {
		pos++;
		if((i-'0')%2==0) ans += pos;
	}
	cout << ans;
	exit(0);
}
void solve5() {
	ll ans = 0, pos=0;
	for(auto i : s) {
		pos++;
		if((i-'0')%5==0) ans += pos;
	}
	cout << ans;
	exit(0);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q >> s;
	if(q==2) solve2();
	else if(q==5) solve5();
	pw[0] = 1;
	for(int i = 1; i < maxn; i++) pw[i] = (pw[i-1]*10ll)%q;
	ll cur = 0, ans = 0;
	cnt[0]++;
	for(int i = 0; i < n; i++) {
		(cur += pw[n-i-1]*(s[i]-'0'))%=q;
		ans += cnt[cur];
		cnt[cur]++;
	}
	cout << ans;
}



Measured memory_bytes: 4884
import heapq

N, M = map(int, input().split())
A = [-i for i in map(int, input().split())]
heapq.heapify(A)
for i in range(M):
  tmp = -((-heapq.heappop(A))//2)
  heapq.heappush(A, tmp)

print(-sum(A))

Measured memory_bytes: 14180
#include<iostream>
using namespace std;
long ans;
long cnt[55],p[55];
void dfs(long n,long x)
{
	if(n==0)
	{
		if(x>0)ans++;
		return;
	}
	if(x<=1)return;
	else if(x<=1+cnt[n-1])
	{
		dfs(n-1,x-1);
	}
	else if(x==2+cnt[n-1])
	{
		ans+=p[n-1]+1;
		return;
	}
	else if(x<=cnt[n-1]*2+2)
	{
		ans+=p[n-1]+1;
		dfs(n-1,x-cnt[n-1]-2);
		return;
	}
	else
	{
		ans+=p[n-1]*2+1;
		return;
	}
}
main()
{
	long n,x;cin>>n>>x;
	p[0]=cnt[0]=1;
	for(int i=1;i<=50;i++)
	{
		p[i]=p[i-1]*2+1;
		cnt[i]=cnt[i-1]*2+3;
	}
	dfs(n,x);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    n = gets.chomp.to_i

    h = Hash.new(0)
    n.times do |i|
      h[gets.chomp] += 1
    end

    m = gets.chomp.to_i
    m.times do |i|
      h[gets.chomp] -= 1
    end

    max_v = -200
    h.each do |k, v|
      if max_v < v
        max_v = v
      end
    end

    if max_v < 0
      puts 0
    else
      puts max_v
    end

  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 4092
h,w=map(int,input().split())
a=[input() for _ in range(h)]
#print(a)
A=[]
for i in range(h):
    if "#" in a[i]:
        A.append(a[i])
#print(A)
l=[]
for i in range(len(A[0])):
    x=0
    for j in range(len(A)):
        if A[j][i]==".":
            x+=1
    if x==len(A):
        l.append(i)
#print(l)
for i in range(len(A)):
    ans=""
    for j in range(len(A[0])):
        if j in l:
            continue
        else:
            ans+=A[i][j]
    print(ans)

Measured memory_bytes: 3064
import heapq


def func(n, k, td):
    neta = [0 for _ in range(n)]
    td.sort()
    td.reverse()
    _heapq = []
    _sum = 0
    types = 0
    for i in range(k):
        _sum += td[i][0]
        if neta[td[i][1]] == 0:
            types += 1
        if neta[td[i][1]] > 0:  # 被っているものだけ後で削除する可能性あり
            heapq.heappush(_heapq, td[i])
        neta[td[i][1]] += 1
    _max = _sum + types**2
    # print("td:{} heapq:{}".format(td, _heapq))
    for i in range(k, n):
        # neta[td[i][1]] != 0なら,
        # td[i] < td[j](j<i)なのでtd[i]は無視
        if len(_heapq) > 0 and neta[td[i][1]] == 0:  # 種類が増えるとき
            tmp = heapq.heappop(_heapq)
            _sum -= tmp[0]
            _sum += td[i][0]
            neta[tmp[1]] -= 1
            types += 1
            neta[td[i][1]] += 1
        # print("td:{} heapq:{}".format(td, _heapq))
        # print("_sum:{} typed:{}".format(_sum, types))
        _max = max(_max, _sum + types**2)
    return str(_max)


n, k = [int(i) for i in input().split()]
td = [[0, 0] for _ in range(n)]
for i in range(n):
    td[i][1], td[i][0] = [int(i) for i in input().split()]
    td[i][1] -= 1
# print("print(func({},{},{}))".format(n, k, td))
print(func(n, k, td))
"""
print(func(5,3,[[9, 0], [7, 0], [6, 1], [5, 1], [1, 2]]))
print(func(7,4,[[1, 0], [1, 1], [1, 2], [6, 3], [5, 3], [5, 3], [5, 3]]))
print(func(6,5,[[1000000000, 4], [990000000, 1], [980000000, 2], [970000000, 5], [960000000, 5], [950000000, 3]]))
"""


Measured memory_bytes: 21012
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  for (int i = 0; i < N; i++){
    cin >> T[i] >> A[i];
  }
  long long t = T[0], a = A[0];
  for (int i = 1; i < N; i++){
    long long t2 = T[i], a2 = A[i];
    long long M = max((t + t2 - 1) / t2, (a + a2 - 1) / a2);
    t = t2 * M;
    a = a2 * M;
  }
  cout << t + a << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
const ll mod = 1e9 + 7;

const int N = 200000;

int n;

ll a[N], d[N]; // b[i] = a[i] + d[i]
ll asum;

set<PL> neg, pos;
ll possum;

void add_d(int x, ll y) {
  d[x] = y;
  if (x == 0 || x == 2 * n - 1) return;
  if (y >= 0) {
    possum += y;
    pos.insert(PL(y, x));
  } else {
    neg.insert(PL(y, x));
  }
}

void rm_d(int x) {
  ll y = d[x];
  if (x == 0 || x == 2 * n - 1) return;
  if (y >= 0) {
    possum -= y;
    pos.erase(PL(y, x));
  } else {
    neg.erase(PL(y, x));
  }
}

ll solve() {
  ll tot = possum;
  if (pos.size() % 2 == 1) {
    tot += max(-pos.begin()->first, neg.rbegin()->first);
  }
  return tot + asum;
}


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int q;
  cin >> n >> q;
  VL a(2 * n), b(2 * n);
  REP(i, 0, 2 * n) {
    cin >> a[i];
    asum += a[i];
  }
  REP(i, 0, 2 * n) {
    ll b;
    cin >> b;
    add_d(i, b - a[i]);
  }
  REP(i, 0, q) {
    int p, x, y;
    cin >> p >> x >> y;
    p--;
    asum += x - a[p];
    a[p] = x;
    rm_d(p);
    add_d(p, y - x);
    cout << solve() << "\n";
  }
}


Measured memory_bytes: 18944
import math
from collections import deque

H, W = [int(_) for _ in input().split()]

S = [list(input()) for _ in range(H)]


def f(h, w):
    memo = [[-1] * W for _ in range(H)]
    lst = deque()
    lst.append((h, w, 0))
    res = 0
    while lst:
        h, w, c = lst.popleft()
        if memo[h][w] >= c: continue
        memo[h][w] = c
        res = max(c, res)
        for x, y in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            nh = x + h
            nw = y + w
            if nh < 0 or nh >= H: continue
            if nw < 0 or nw >= W: continue
            if memo[nh][nw] > -1: continue
            if S[nh][nw] == '#': continue
            lst.append((nh, nw, c + 1))

    return res

def main():
    ans = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#': continue
            ans = max(ans,f(h,w))
    return ans
print(main())



Measured memory_bytes: 74636
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;

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


int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, x;
	cin >>n >> x;
	ll g = gcd(n,x);
	if(g==1){ cout << 3*(n-1)<<endl; return 0;}
	cout << g*3*(n/g-1)<<endl; return 0;

	//if(x*2==n){cout << n*3/2 << endl; return 0;}
	//if(x*3==n){cout << n*2 << endl; return 0;}

	//cout << 3*(n-1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005,mod=4000007;
int n,father[N];
queue<PI> q;
ll ycl[N];
vector<int> v[N];
struct has_table{
	bool has[mod]; int b[mod];
	ll a[mod],v[mod];
	inline int insert(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]++; return b[i];
			}
		}
	}
	inline void clear(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]=0; return;
			}
		}
	}
	inline int find(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				return b[i];
			}
		}
	}
}Ma,er;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
int main(){
	srand(time(0));
	n=read();
	for(int i=1;i<=n;i++)ycl[i]=(ll)rand()<<32|rand();
    for(int i=1;i<=n*2-2;i++){
        int x=read(),y=read(); 
        v[x].push_back(y); v[y].push_back(x);
        Ma.insert(y,x);
        if(Ma.insert(x,y)==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;i++)father[i]=i;
    while(!q.empty()){
    	int x=q.front().first,y=q.front().second; q.pop();
		x=getfather(x); y=getfather(y); if(x==y){puts("NO"); return 0;}
		if(v[x].size()<v[y].size()) swap(x,y); 
		er.insert(x,y); er.insert(y,x); 
		//cout<<x<<" "<<y<<endl;
        for(unsigned i=0;i<v[y].size();i++){ 
            int to=v[y][i]; if(er.find(y,to)){continue;}
            //if(y!=3||to!=3)cout<<x<<" "<<y<<" "<<to<<" "<<er.find(y,to)<<endl;
            er.insert(to,y); er.insert(y,to); v[to].push_back(x);
            Ma.insert(x,to);
            if(Ma.insert(to,x)==2)q.push(mp(to,x));
            v[x].push_back(to);
        }
        father[y]=x; v[y].clear();
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=father[i]==i;
    if(ans==1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 113024
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

struct UnionFind {
    typedef vector<int> vi;
    int n;
    vi par, rank, cnt;

    UnionFind(int n)
        : n(n), par(n), rank(n, 0), cnt(n, 1) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int find(int a) {
        if (par[a] == a) return a;
        return par[a] = find(par[a]);
    }

    void unite(int a, int b) {
        a = find(a);
        b = find(b);

        if (a == b) return;
        if (rank[a] < rank[b]) {
            par[a] = b;
            cnt[b] += cnt[a];
        } else {
            par[b] = a;
            cnt[a] += cnt[b];
            if (rank[a] == rank[b]) rank[a]++;
        }
    }

    int count(int a) { return cnt[find(a)]; }

    bool same(int a, int b) { return find(a) == find(b); }
};

const int MAX_N = 100000;
int n;
int x[MAX_N];
pii sx[MAX_N];
int y[MAX_N];
pii sy[MAX_N];

struct edge {
    int cost, from, to;
};
vec<edge> edges;

int main() {
    fastio();

    cin >> n;

    forn(i, n) {
        cin >> x[i] >> y[i];
        sx[i] = mp(x[i], i);
        sy[i] = mp(y[i], i);
    }

    sort(sx, sx + n);
    sort(sy, sy + n);

    forn(i, n - 1) {
        edges.push_back((edge) { sx[i + 1].fst - sx[i].fst, sx[i + 1].snd, sx[i].snd });
        edges.push_back((edge) { sy[i + 1].fst - sy[i].fst, sy[i + 1].snd, sy[i].snd });
    }

    sort(edges.begin(), edges.end(), [&](edge e1, edge e2) { return e1.cost < e2.cost; });

    UnionFind mst(n);

    ll ans = 0;
    int i = 0;
    while (mst.count(0) < n) {
        edge e = edges[i];
        i++;

        if (mst.same(e.from, e.to)) continue;

        ans += e.cost;
        mst.unite(e.from, e.to);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 7284
#include<bits/stdc++.h>
typedef  long long int ll;
typedef  long double ld;
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define mod 1000000007
#define F first
#define S second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
//recursions\
#pragma comment(linker, "/stack:200000000")
//loops\
#pragma GCC optimize("unroll-loops")
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
using namespace std;

const int N = 1e6 + 5;
int main()
{
	sync;
	ll a,b , c, d;
	cin >> a  >> b >> c >> d;
	cout << max({a * c, a * d, b * c, b * d});		
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>

using namespace std;

template<typename T> 
void show(T a){
  for(auto i : a){ cout << i << " "; }
  cout << endl;
}


int main(int argc, char *argv[]){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int k, s;
  cin >> k >> s;
  int count = 0;
  for(int i = 0; i <= k; i++){
    for(int j = 0; j <= k; j++){
      int tmp = s - i - j;
      count += tmp <= k && tmp >= 0 ? 1 : 0;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))
m = 0
for i in range(N):
    if i == 0:
        m = (K - A[N-1]) + A[0]
    else:
        m = max([m, A[i] - A[i-1]])
print(K-m)

Measured memory_bytes: 78668
#include<stdio.h>

static const int N = 100;

void insertionSort(int A[], int n){
  int i;
  for(i = 1; i <= n; i++ ){
    if(i > 1) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, v;
  int A[N+1];
  scanf("%d", &n);
  for(i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  insertionSort(A,n);
  for(i = 2; i <= n; i++){
    v = A[i];  //3. v = A[i]
    j = i - 1; //4. j = i - 1
    while(j >= 0 && A[j] > v){ //5. while j >= 0 かつ A[j] > v
      A[j+1] = A[j]; //6. A[j+1] = A[j]
      j--;           //7. j--
      A[j+1] = v;   //8. A[j+1] = v
    }
    insertionSort(A,n);
  }
  return 0;
}



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

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(n);
    vector<pair<ll,ll>> p(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>p[i].second>>p[i].first;
    sort(all(a));
    sort(all(p),greater<pair<ll,ll>>());
    ll nowp=0;
    rep(i,n){
        if(p[nowp].first>a[i]){
            a[i]=p[nowp].first;
            if(p[nowp].second==1) nowp++;
            else p[nowp].second--;
        }
        else break;
    }
    ll sum=0;
    rep(i,n) sum+=a[i];
    cout<<sum<<endl;
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	map<string, int>mp;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int M;
	cin >> M;
	for (int i = 0; i < M; ++i) {
		string s;
		cin >> s;
		mp[s]--;
	}
	int ans = 0;
	for (auto x : mp) {
		ans = max(ans, max(0, x.second));
	}
	cout << ans << endl;
	return 0;
}


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

#define     MAX_LENGTH     255
// #define     __DEBUGING__

using namespace std;

double num_abs_round(const double,const int);

int main(){
#ifdef __DEBUGING__
	double ip;
	int n;

	while(cin >> ip >> n){
		cout << num_abs_round(ip,n) << endl;
		printf("%.3f\n",num_abs_round(ip,n));
	}
#else
	double a,b,c,d,e,f;
	double det;
	double x,y;
	double X,Y;

	while (cin >> a >> b >> c >> d >> e >> f){
		// Det(係数行列) を計算
		det = (a * e) - (b * d);
		// Det(係数行列) ≠ 0 かどうかをチェック
		if(det == 0){
			cerr << "エラー：この連立方程式の解は存在しないか一意に定まらない" << endl;
			return -1;
		}

		// 解を求める
		x = ((e * c) - (b * f)) / det;
		y = ((a * f) - (d * c)) / det;

		// 整形
		X = num_abs_round(x,3) * ((x >= 0) ? 1 : (-1));
		Y = num_abs_round(y,3) * ((y >= 0) ? 1 : (-1));

		// 表示する
		printf("%.3f %.3f\n",X,Y);
	}
#endif

	return 0;
}

double num_abs_round(const double num,const int p){
	char num_str[MAX_LENGTH];
	char rtn_str[MAX_LENGTH];
	int i,j;
	bool flag = false;
	double rtn;

	// rtn_str の初期化
	for(i=0;i < ((int)(MAX_LENGTH));i++){
		rtn_str[i] = '\0';
	}

	// 数値を文字列に変換
	sprintf(num_str,"%f\0",num);

	// 符号の確認
	if(num_str[0] == '-'){
		j = 1;
		rtn_str[0] = '0';
	}else{
		j = 0;
	}

	// 小数点の検索 (num_str[j] に '.' が入っている)
	for(;num_str[j] != '.';j++){
		// 小数点がなければ num をそのまま返す
		if(num_str[j] == '\0'){
			return num;
		}
		// rtn_str に num_str をコピー
		rtn_str[j] = num_str[j];
	}

	// '.'をコピー
	rtn_str[j] = '.';

	// 小数点以下 (p + 1) 桁までをコピー
	for(i=1;i <= (p + 1);i++){
		// num が (p + 1) 桁未満だったら num をそのまま返す
		if(num_str[(j + i)] == '\0'){
			return num;
		}
		// rtn_str に num_str をコピー
		rtn_str[(j + i)] = num_str[(j + i)];
	}

	// 小数点以下 (p + 1) 桁を四捨五入
	if(((rtn_str[(j + p + 1)] - '0') >= 0) && ((rtn_str[(j + p + 1)] - '0') <= 4)){
		rtn_str[(j + p + 1)] = '\0';
	}else if((((int)(rtn_str[(j + p + 1)] - '0')) >= 5) && (((int)(rtn_str[(j + p + 1)] - '0')) <= 9)){
		flag = true;
		rtn_str[(j + p + 1)] = '\0';
	}else{
		return 0;
	}

	// rtn_str を数値に変換
	rtn = atof(rtn_str);

	// 五入の場合の処理
	if(flag == true){
		rtn += pow((double)10,(double)(p * (-1)));
	}

	return rtn;
}

Measured memory_bytes: 1248
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

int main(){
    vector<long long int> vta= {0},vtb = {0};
    long long int ta=0,tb=0;
    int n,m,k;
    int ans=-1;
    cin >> n >> m >> k;
    rep(i,n){
        int a;
        cin >> a;
        ta +=a;
        vta.push_back(ta);
    }
    rep(i,m){
        int a;
        cin >> a;
        tb +=a;
        vtb.push_back(tb);
    }
    int ai=0,bi=0;
    rep(i,n+1){
        if(vta[i] > k){
            break;
        }
        else{ai = i;}
    }
    ans = ai;
    while(ai != -1&& bi!=m+1){
        if(vta[ai]+vtb[bi]<=k){
            ans = max(ans,ai+bi);
            bi++;
        }
        else{
            ai--;
        }
    }
    cout<< ans << endl;
}

Measured memory_bytes: 7504
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  [k, a, b] <- getIntList
  if a >= (b - 2)
    then print $ k + 1
    else do
      let i = a - 1
      if k <= i
        then print $ k + 1
        else do
          let r = k - i
          let gain = b - a
          print $ a + r `div` 2 * gain + r `mod` 2


Measured memory_bytes: 3736
def min(a, b)
  a < b ? a : b
end

L, R = gets.chomp.split.map(&:to_i)

if R - L + 1 >= 2019
  puts 0
  exit
end

min = 0xffffffff
L.upto(R) do |i|
  (i + 1).upto(R) do |j|
    min = min(min, i * j % 2019)
  end
end
puts min

Measured memory_bytes: 1788