akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  300005



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    ll swim[n],bugs[n],hw[n];
    swim[0]=a[0],bugs[0]=b[0],hw[0]=c[0];
    for(ll i=1;i<n;i++)
    {
        swim[i] = a[i]+max(bugs[i-1],hw[i-1]);
        bugs[i] = b[i]+max(swim[i-1],hw[i-1]);
        hw[i] = c[i]+max(bugs[i-1],swim[i-1]);
    }
    cout<<max(swim[n-1],max(bugs[n-1],hw[n-1]));
    return 0;
}

Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define y1 xoxo
using namespace std;

const int N=1e3+20,MAX=1e7;

int n,m,x1,y1,x2,y2,dp[N][N];
char a[N][N];
deque <pair <int,int>> dq;
int dx[]={+1,-1, 0, 0};
int dy[]={ 0, 0,+1,-1};
bool vis[N][N];

bool invalid(int x,int y)
{
	return min(x,y)<0 or x>=n or y>=m or a[x][y]=='#' or vis[x][y];
}

void add(int x,int y,int d,int dir)
{
	dp[x][y]=d;
	if(dir==1) dq.push_back({x,y});
	else dq.push_front({x,y});
}

int main()
{
	scanf("%d%d%d%d%d%d",&n,&m,&x1,&y1,&x2,&y2);
	for(int i=0;i<n;i++) scanf(" %s",a[i]);

	x1--,y1--,x2--,y2--;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			dp[i][j]=MAX;

	add(x1,y1,0,0);
	while(not dq.empty())
	{
		auto p=dq.front();
		dq.pop_front();
		vis[p.first][p.second]=true;

		for(int k=0;k<4;k++)
		{
			int x=p.first+dx[k],y=p.second+dy[k];
			if(invalid(x,y)) continue;
			add(x,y,dp[p.first][p.second],0);
		}

		for(int x=p.first-2;x<=p.first+2;x++)
		{
			for(int y=p.second-2;y<=p.second+2;y++)
			{
				if(invalid(x,y)) continue;
				if(dp[x][y]>dp[p.first][p.second]+1) add(x,y,dp[p.first][p.second]+1,1);
			}
		}
	}

	if(not vis[x2][y2]) printf("-1");
	else printf("%d",dp[x2][y2]);
}

Measured memory_bytes: 9724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int n, m;
    cin>>n>>m;
    if(n>m){
        for(int i = 0; i < n; i++)cout<<m;
    }
    else for(int i = 0; i < m; i++)cout<<n;
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m] <- getIntList
    print $ (m*1900 + (n-m)*100) * 2^m

Measured memory_bytes: 380
#include<bits/stdc++.h>
#include<atcoder/dsu>

using namespace std;
using ll = long long;

int main()
{
	int n, q; cin >> n >> q;
	atcoder::dsu tree(n);
	for(int i = 0; i < q; i++) {
		int a, b, c; cin >> a >> b >> c;
		if(a) {
			cout << tree.same(b, c) << endl;
		} else {
			tree.merge(b, c);
		}
	}
}

Measured memory_bytes: 3704
#include<cstdio>
using namespace std;
int main(void){
    int flag[31] = {1};
    for(int i = 0;i < 28;i++){
        int a; scanf("%d",&a);
        flag[a] = 1;
    }
    for(int i = 0; i <= 30;i++){
        if(flag[i] == 0) printf("%d\n",i);
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var VE = ReadLine().Split().Select(int.Parse).ToArray();
        var V = VE[0];
        var E = VE[1];
        var a = new Edge[E];
        for (int i = 0; i < E; i++)
        {
            var l = ReadLine().Split().Select(int.Parse).ToArray();
            a[i] = new Edge { src = l[0], to = l[1], cost = l[2] };
        }
        WriteLine(Kruskal(a, V));

    }

    public static long Kruskal(Edge[] edges, int v)
    {
        var total = 0L;
        var uf = new UnionFind(v);
        foreach (var e in edges.OrderBy(x => x.cost))
        {
            if (uf.Unite(e.src, e.to))
            {
                total += e.cost;
            }
        }
        return total;
    }
}

public struct Edge
{
    public int src;
    public int to;
    public int cost;
}

public class UnionFind
{
    int[] parent;
    int count;
    public int Count => count;

    public UnionFind(int length)
    {
        parent = new int[length];
        for (int i = 0; i < parent.Length; i++)
        {
            parent[i] = -1;
        }
        count = length;
    }

    public int Root(int v) => parent[v] < 0 ? v : parent[v] = Root(parent[v]);

    public bool Same(int l, int r) => Root(l) == Root(r);

    void Swap<T>(ref T l, ref T r)
    {
        var t = l;
        l = r;
        r = t;
    }

    public bool Unite(int l, int r)
    {
        l = Root(l);
        r = Root(r);
        if (l == r) return false;
        count--;
        if (parent[l] > parent[r]) Swap(ref l, ref r);
        parent[l] += parent[r];
        parent[r] = l;
        return true;
    }

    public int Size(int v) => -parent[Root(v)];
}



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

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for(int j=0;j<n;j++){
    cin >> x[j];
    y[j] = x[j];
  }

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

  int med_1 = y[(n/2) - 1];
  int med_2 = y[(n/2)];

  for(int i=0;i<n;i++){
    if(x[i] <= med_1){
      cout << med_2 << endl;
    }
    else{
      cout << med_1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3712
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int h = Integer.parseInt(scanner.nextLine());
        int w = Integer.parseInt(scanner.nextLine());

        System.out.println((n - h + 1) * (n - w + 1));
    }
}


Measured memory_bytes: 23124
#include<iostream>
using namespace std;
long long f(long long A) {
  bool even = false;
  long long i = A + 1;
  if (!(A % 2)) {
    i = A;
    even = true;
  }
  if (i % 4) i = 1;
  else i = 0;
  if (even) return A + i;
  return i;
}
long long XOR(long long p, long long k) {
  long long ans = 0;
  int bi[100];
  int i = 0;
  while(p || k) {
    int l = p % 2;
    int m = k % 2;
    bi[i] = (l + m) % 2;
    i ++;
    p /= 2;
    k /= 2;
  }
  for (int n = i - 1; n >= 0; n --){
    //cout << bi[n] << ' ';
    ans *= 2;
    ans += bi[n];
  }
  cout << endl;
  return ans;
}
int main () {
  long long A, B;
  cin >> A >> B;
  long long j = f(A - 1);
  long long k = f(B);
  //cout << j << ' ' << k << endl;
  cout << XOR(j, k) << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {


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

        int n = scan.nextInt();

        long[] non = new long[n];
        long[] one = new long[n];
        long[] nine = new long[n];
        long[] both = new long[n];
        long mod = 1000000007;


        for (int i=0; i<n; i++) {

            if (i==0) {
                non[i] = 8;
                one[i] = 1;
                nine[i] = 1;
                both[i] = 0;
            } else {
                non[i] = non[i-1] * 8 % mod;
                one[i] = (non[i-1] + one[i-1] * 9) % mod;
                nine[i] = (non[i-1] + nine[i-1] * 9) % mod;
                both[i] = (one[i-1] + nine[i-1] + both[i-1] * 10) % mod;
            }
        }

        System.out.println(both[n-1]);


    }
}

Measured memory_bytes: 76280
import sys
input()
rl = sys.stdin.readlines()
d = {}

for i in rl:
    c, s = i.split()
    #if i[0] == 'i':
    if c[0] == 'i':
        #d[i[7:]] = 0
        d[s] = 0
    else:
        #if i[5:] in d:
        if s in d:
            print('yes')
        else:
            print('no')

Measured memory_bytes: 112100
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <math.h>
using namespace std;

int main() {
    string s;
    cin>>s;
    if(s[0]=='R'){
        if(s[0]==s[1]){
            if(s[1]==s[2])cout<<3<<endl;
            else cout<<2<<endl;
        }
        else cout<<1<<endl;
    }
    else{
        if(s[1]=='R'){
            if(s[1]==s[2])cout<<2<<endl;
            else cout<<1<<endl;
        }
        else{
            if(s[2]=='R')cout<<1<<endl;
            else cout<<0<<endl;
        }
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int D; cin >> D;
    vector C(26, 0);
    rep(i,26) cin >> C.at(i);
    vector S(D, vector(26, 0));
    vector MA(D,0);
    rep(i, D) {
        int ma = 0;
        int maj = 0;
        rep(j, 26) {
            cin >> S[i][j];
            if (ma < S[i][j]) {
                ma = S[i][j];
                maj = j;
            }
        }
        MA[i] = maj;
    }
    vector last(26, 0);
    rep(d,D) {
        int j = MA[d];
            int sat = 0;
            last[j] = d + 1;
            rep(i,26) sat -= (d + 1 - last[i]) * C[i];
            sat += S[d][j];
        cout << j+1 << endl;
    }
}

Measured memory_bytes: 3672
# coding: utf-8
# 自分の得意な言語で
# Let's チャレンジ！！

A = int(input())
B = int(input())
C = int(input())
X = int(input())
correct_count = 0
for A_i in range (A+1):
    for B_i in range(B+1):
        for C_i in range(C+1):
            if X == 500*A_i+100*B_i+50*C_i:
                correct_count = correct_count + 1
print(correct_count)    

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  vector<int> m(n);
  int i;
  int cnt = 0;
  for(i=0;i<n;i++) cin >> m[i];
  sort(m.begin(),m.end());
  for(i=n-1;i>=1;i--) {
    x -= m[i];
    cnt++;
  }
  cnt += x/m[0];
  cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 3600
use std::collections::HashSet;

use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let k: usize = parse_line().unwrap();

    let mut a = 0;
    let mut ret = 0;
    let mut appeared: HashSet<usize> = HashSet::new();
    loop {
        a = (10 * a + 7) % k;
        ret += 1;

        if a == 0 {
            println!("{}", ret);
            break;
        }
        if appeared.contains(&a) {
            println!("-1");
            break;
        }
        appeared.insert(a);
    }
}


Measured memory_bytes: 29612
#include<cstdio>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;
const int M=100007;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,p,q,w;
int s[M];
LL ans;
bool check(LL x){
	LL now=x*q,tot=0;
	int top=n,v;
	while(top){
		if(s[top]<=now) break;
		if((s[top]-now)%w) v=(s[top]-now)/w+1;
		else v=(s[top]-now)/w;
		tot+=v;
		top--; 
	}
	return tot<=x;
}
int main()
{
	n=read(); p=read(); q=read(); w=p-q;
	for(int i=1;i<=n;i++) s[i]=read();
	sort(s+1,s+1+n);
	LL l=0,r=1e9;
	while(l<=r){
		LL mid=(l+r)>>1;
		if(check(mid)) ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(false),cin.tie(0);
void solve(){
  string s;
  cin>>s;
  ll sum=0;
  for(int i=0;i<s.length();i++){
    sum+=(s[i]-'0');
  }
  if(sum%9)cout<<"No";
  else cout<<"Yes";

}
int main(){
 fast;
  int t;
  t=1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3696
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

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

	cout << ((b - a) % 2 == 0 ? "Alice" : "Borys") << endl;
}

Measured memory_bytes: 256
/*
Author : Hocky Yudhiono
5/30/2020 7:01:13 PM

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem
*/

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef vector<int> vi;
typedef pair<LL,LL> PLL;
typedef pair<LL,int> PLI;
typedef pair<int,int> PII;
typedef pair<int,int> pii;
typedef vector<vector<LL>> VVL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

//If the time limit is strict, try not to use long double

//Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
// Do dir^1 to get reverse direction
const char dch[4] = {'R','L','D','U'};
// const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    //Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

LL a,b,c,d,k;

int main(){
    cin >> a >> b >> c >> d >> k;
    LL ret;
    if(a < c){
        ret = (60-b)+((c-a-1)*60);
        ret += d;
    }else{
        ret = d-b;
    }
    // cout << ret << endl;
    cout << max(0LL,ret-k) << endl;
    return 0;
}

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

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

		int[] arr = new int[n];

		int distincts = 0;

		HashMap<Integer, Pair> map = new HashMap<>();
		ArrayList<Pair> li = new ArrayList<>();
		for(int i = 0; i < n; ++i) {
			arr[i] = in.nextInt();

			if(map.get(arr[i]) == null){
				map.put(arr[i], new Pair(arr[i], 1));
				li.add(map.get(arr[i]));
			} else {
				Pair p = map.get(arr[i]);
				p.s++;
			}
		}

		Collections.sort(li);
		if(li.size() <= k) {
			System.out.println(0);
		} else {
			int ans = 0;
			int nn = li.size();
			for(Pair p : li) {
				if(nn <= k) 
					break;

				--nn;
				ans += p.s;
			}

			System.out.println(ans);
		}
	}

	private static class Pair implements Comparable<Pair> {
		int f, s;

		public Pair(int f, int s) {
			this.f = f;
			this.s = s;
		}

		@Override 
		public int compareTo(Pair p) {
			return this.s - p.s;
		}
	}
}


Measured memory_bytes: 110476
n,m=map(int,input().split())
line=list(map(int,input().split()))
if n >= m:
  print(0)
else:
  line.sort()
  stock=0
  distance=[]
  for i in line:
    distance.append(i-stock)
    stock=i
  distance.pop(0)
  distance.sort()
  ans=0
  for i in range(m-n):
    ans+= distance[i]
  print(ans)

Measured memory_bytes: 13968
N,M=map(int,input().split())
k=[0]*M
s=[0]*M
for i in range(M):
    ks=list(map(int,input().split()))
    k[i]=ks[0]
    s[i] = [n-1 for n in ks[1:k[i]+1]]
p=list(map(int,input().split()))
ok=0

#スイッチのon/off
def dfs(A):
    global ok
    # 終端条件 --- N 重ループまで回したら処理して打ち切り
    if len(A) == N:
        ok+=jg(A)
        return
    for v in range(2):
        A.append(v)
        dfs(A)
        A.pop()

#判定
def jg(A):
    for i in range(M):
        ans=0#点灯しているSWの個数カウント
        for j in range(k[i]):
            ans+=A[s[i][j]]
        if ans % 2 != p[i]:
            return 0
    return 1

dfs([])
print(ok)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    int a, b, c;
    a = A + B;
    b = A - B;
    c = A * B;
    int maxa = max(a, b);
    int maxb = max(maxa, c);
    cout << maxb << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
*a, = map(int, input().split())

dp = [[1] + [0]*K for _ in range(N)]
for k in range(1, a[0]+1):
    dp[0][k] = 1

for i in range(1, N):
    for k in range(1, K+1):
        if k - a[i] - 1 >= 0:
            dp[i][k] = dp[i][k-1] + dp[i-1][k] - dp[i-1][k-a[i]-1]
        else:
            dp[i][k] = dp[i][k-1] + dp[i-1][k]
        dp[i][k] %= 1e9+7
        
print(int(dp[-1][-1]))

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

int G[3][3]={};
int main(){
    for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> G[i][j];
    bool ok = true;
    for(int i = 0; i < 2; i++){
        int c;
        for(int j = 0; j < 3; j++){
            if(j == 0) c = G[i][j] - G[i + 1][j];
            else if(c != G[i][j] - G[i + 1][j]) ok = false;
        }
    }
    for(int j = 0; j < 2; j++){
        int c;
        for(int i = 0; i < 3; i++){
            if(i == 0) c = G[i][j] - G[i][j + 1];
            else if(c != G[i][j] - G[i][j + 1]) ok = false;
        }
    }
    if(ok) puts("Yes");
    else puts("No");
}


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

using namespace std;

int n, cnt, ans, s, sum, a[1000000];

int main(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i], s += a[i];
    while (sum < s){
        for (int i = 0; i <= n; i++){
            if (a[i] != 0) a[i]--, sum++, cnt++;
            else{
                if (cnt > 0){
                    ans++;
                    cnt = 0;
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int box[45];

void fibo(int a){
  if(a==0 ||a==1)return;
  else box[a]=box[a-1]+box[a-2];
}

int main(){
  int a,i;
  scanf("%d",&a);
  box[0]=box[1]=1;
  for(i=0;i<=a;i++)fibo(i);
  printf("%d\n",box[a]);
}



Measured memory_bytes: 2108
s = input()
n = len(s)+1
a = [0]*n
l = []
c = 0
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    l.append([s[c], c, i-c+1])
    c = i+1
l.append([s[c], c, len(s)-c])

for i in l:
  if i[0] == "<":
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], j)
  else:
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], i[2]-j)
      
print(sum(a))

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

int main(){
  int N;
  cin >> N;
  int max = 0;
  int ans = 1;
  for(int i = 0; i <= N; i++){
    int w = i;
    int cnt = 0;
    while(w){
      w /= 2;
      if(w > 0)cnt++;
    }
    if(cnt > max){
      max = cnt;
      ans = i;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;

const int N = 15, M = 1050;

char s[N][M];

int n, m, k;

inline int lowbit(int x) { return x & (-x); }
int mp[1<<(N+2)];

int sum[N][M];

int main(int argc, char const *argv[]) {
    // code
    for (int i=0; i<N; ++i)
        mp[1<<i] = i;

    scanf("%d%d%d", &n, &m, &k);
    for (int i=1; i<=n; ++i) {
        scanf("%s", s[i]);
        for (int j=0; j<m; ++j)
            sum[i][j] =( s[i][j] == '1') + sum[i-1][j];
    }


    int lim = 1 << (n-1);
    int ans = n * m;
    for (int mask=0; mask<lim; ++mask) {
        vector<int> row;
        row.push_back(0);
        for (int i=mask; i; i-=lowbit(i)) {
            row.push_back(mp[lowbit(i)] + 1);
        }
        row.push_back(n);

        vector<vector<int>> dat;
        int nn = row.size()-1, mm = m;
        dat.resize(nn+1);
        for (int i=1; i<=nn; ++i) {
            dat[i].resize(m);
            for (int j=0; j<m; ++j)
                dat[i][j] = sum[row[i]][j] - sum[row[i-1]][j];
        }
        bool suc = true;
        for (int i=1; i<=nn; ++i) {
            for (int j=0; j<m; ++j) {
                if (dat[i][j] > k) {
                    suc = false;
                    break;
                }
            }
            if (!suc)
                break;
        }
        if (!suc) continue;
        // dbg(mask, nn);
        // for (int i=1; i<=nn; ++i)
        //     for (int j=0; j<m; ++j)
        //         printf("%d%c", dat[i][j], j==m-1? '\n' : ' ');
        // return 0;
        
        int tans = nn-1;
        static int cnt[N];
        memset(cnt, 0, sizeof cnt);
        for (int j=0; j<m; ++j) {
            bool flag = false;
            for (int i=1; i<=nn; ++i) {
                if (cnt[i] + dat[i][j] > k) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                ++tans;
                memset(cnt, 0, sizeof cnt);
            }
            for (int i=1; i<=nn; ++i)
                cnt[i] += dat[i][j];
        }
        ans = min(ans, tans);

    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 384
// 2020/05/18 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[50001];

	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<50001; i++){
		is_prime[i] = true;
	}

	for(int i=2; i*i<50001; i++){
		if(is_prime[i]){
			for(int j=i*i; j<50001; j+=i){
				is_prime[j] = false;
			}
		}
	}

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int cnt = 0;
		for(int i=2; i<=n-i; i++){
			if(is_prime[i]&&is_prime[n-i]){
				cnt++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}



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

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	string s1 = "", s2 = "";
	
	for(int i = 0; i < n / 2; i++)
		s1 = s1 + s[i];
	for(int i = n / 2; i < n; i++)
		s2 = s2 + s[i];
	
	if(s1 == s2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

int calc(int n, int k, vi &w, ll p) {
  int b = 0;
  rep(i, k) {
    ll s = 0;
    while (s + w[b] <= p) {
      s += w[b];
      b++;
      if (b == n) return n;
    }
  } 

  return b;
}

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

  vi w(n);
  rep(i, n) cin >> w[i];
  
  ll left = 0, right = 100000 * 10000, mid;
  while (right > left + 1) {
    mid = (right + left) / 2;
    int b = calc(n, k, w, mid);

    if (b >= n) right = mid;
    else left = mid;
  }

  cout << right << endl;
}



Measured memory_bytes: 3132
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

// disjoin set
public class Main {
    static class UnionFind {

        private int parent[];
        private int rank[];

        public UnionFind(int Num_element) {
            parent = new int[Num_element];
            rank = new int[Num_element];
            for (int i = 0; i < Num_element; i++)
                makeSet(i);
        }
        public void makeSet(int x) {
            parent[x] = x;
            rank[x] = 0;
        }

        public void union(int x, int y) {
            link(findSet(x), findSet(y));
        }

        public int findSet(int x) {
            if (parent[x] != x) {
                parent[x] = findSet(parent[x]);
            }
            return parent[x];
        }


        public void link(int x, int y) {
            if (rank[x] > rank[y]) {
                parent[y] = x;
            } else {
                parent[x] = y;
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }
        public void command(int com, int x, int y){
            if(com == 0){
                //unite
                union(x,y);
            }else{
                //same
                if( findSet(x) == findSet(y))
                    System.out.println("1");
                else
                    System.out.println("0");
            }
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Disjoin set element number
        int Num_element = sc.nextInt();
        //Query times
        int Num_query =  sc.nextInt();
        
        UnionFind Disjoin_set = new UnionFind(Num_element);
        for (int i=0;i<Num_query;i++){
            // '0' denotes unite and '1' denotes same operation.
            int com = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            Disjoin_set.command(com,x,y);
        }

    }
}



Measured memory_bytes: 110520
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n >> s;
	int r = 0, i = n-1, ll = 0, rr = 0;
	while (i >= 0) {
		while (i >= 0 && s[i] == ')') {
			r++;
			i--;
		}
		while (i >= 0 && s[i] == '(') {
			r--;
			i--;
		}
		if (r < 0) {
			rr -= r;
			r = 0;
		}
	}
	if (r > 0) ll += r;
	string tl = "", tr = "";
	FOR(cnt, ll) tl += "(";
	FOR(cnt, rr) tr += ")";
	cout << tl + s + tr << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int n, m, check[101000];
    bool ac[101000];
    fill(check, check+101000, 0);
    fill(ac, ac+101000, false);
    cin >> n >> m;
    int res = 0, res2 = 0;
    for(int i = 0; i < m; i++){
        int p;  string s;
        cin >> p >> s;
        if(s == "AC"){
            if(!ac[p]){
                res += check[p];
                res2++;
                ac[p] = true;
            }
        }
        else{
            if(!ac[p]){
                check[p]++;
            }
        }
    }
    cout << res2 << " " << res << endl;


    return 0;
}


Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define LL long long
int a,b,c,d;

void solve() {
    //cin>>a>>b>>c>>d;
    int n;
    cin>>n;
    set<string>s;
    for(int i=0;i<n;i++){
        string a;
        cin>>a;
        s.insert(a);
    }
    cout<<s.size()<<"\n";
}

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

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

int main(){
  string S;
  cin >> S;
  int A=S.size(),min_distance=1000;
  for(int i=0;i<A-2;i++){
    string T=S.substr(i,3);
    int B=stoi(T);
    min_distance=min(min_distance,abs(B-753));
  }
  cout << min_distance << endl;
}


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

using namespace std;

int main(){
    vector<int> h(5,0),frg(5,0);

    while(1){
        cin >> h[0];
        if(h[0]==0)break;
        for(int i=1;i<5;i++)cin >> h[i];
        for(int i=0;i<5;i++)frg[h[i]-1]++;

        if(frg[0]*frg[1]*frg[2]!=0 || frg[0]==5 || frg[1]==5 || frg[2]==5){
            for(int i=0;i<5;i++)cout << "3" << endl;
        }else if(frg[0]>0){
            if(frg[1]>0){
                for(int i=0;i<5;i++){
                    if(h[i]==1)cout << "1" << endl;
                    else cout << "2" << endl;
                }
            }else{
                for(int i=0;i<5;i++){
                    if(h[i]==3)cout << "1" <<endl;
                    else cout << "2" << endl;
                }
            }
        }else{
            for(int i=0;i<5;i++){
                if(h[i]==2)cout << "1" << endl;
                else cout << "2" << endl;
            }
        }

        for(int i=0;i<5;i++){
            frg[i]=0;
            h[i]=0;
        }
    }


    return 0;


}

Measured memory_bytes: 3004
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            Integer[] D = new Integer[N];
            for (int i = 0; i < N; i++) {
                D[i] = in.nextInt();
            }
            int M = in.nextInt();
            Integer[] T = new Integer[M];
            for (int i = 0; i < M; i++) {
                T[i] = in.nextInt();
            }

            Arrays.sort(D);
            Arrays.sort(T);
            int di = 0;
            for (int i = 0; i < M; i++) {
                while (di < N && D[di] < T[i]) di++;
                if (di == N || D[di] > T[i]) {
                    out.println("NO");
                    return;
                }

                di++;
            }
            out.println("YES");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



Measured memory_bytes: 74296
#include <stdio.h>

int main(void) {
	int i,j,n,u, k, V[200][200],v;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			V[i][j] = 0;
		}
	}
	for (i = 1; i <= n; i++) {
		scanf("%d %d", &u,&k);
		for (j = 1; j <= k;j++) {
			scanf("%d", &v);
			V[i][v] = 1;
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			printf("%d", V[i][j]);
			if (j < n) printf(" ");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2824
S = input()
if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')
else:
    print('F')

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

template<typename T>
T largestRectangle(vector<T> &v) {
	stack<pair<T, int>> st;
	T maxv = 0;
	v.push_back(0);
	for (int i = 0; i < v.size(); i++) {
		int minv = i;
		while (!st.empty() && st.top().first > v[i]) {
			auto dat = st.top(); st.pop();
			maxv = max(maxv, dat.first * (i - dat.second));
			minv = min(minv, dat.second);
		}
		st.emplace(v[i], minv);
	}
	v.pop_back();
	return (maxv);
}

int main() {
	int N; cin >> N;
	vector<long long> H(N);
	for (auto &v : H) cin >> v;
	cout << largestRectangle(H) << endl;
	return (0);
}



Measured memory_bytes: 5384
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

class Main {
    public static void main(String args[]) {
        ArrayList<Integer> heights = new ArrayList<Integer>();

        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            heights.add(sc.nextInt());
        }

        Collections.sort(heights);
        Collections.reverse(heights);

        for (int i = 0; i < 3; i++) {
            System.out.println(heights.get(i));
        }
    }
}

Measured memory_bytes: 26076
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

lint as = pow(10, 9)+1;

// index が条件を満たすかどうか
bool isOK(lint index, vector<lint>H, lint A, lint B) {
	lint ans = 0;
	rep(i, H.size()) {
		H[i] -= B*index;
		H[i] = max(lint(0), H[i]);
		ans += (H[i] / (A - B))+bool(H[i]%(A-B));
	}
	if (ans > index) {
		return false;
	}
	else {
		return true;
	}
}

// 汎用的な二分探索のテンプレ
lint binary_search(vector<lint>H, lint A, lint B) {
	lint ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	lint ok = (lint)as; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		lint mid = (ok + ng) / 2;

		if (isOK(mid,H,A,B)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {
	lint N, A, B;
	cin >> N >> A >> B;
	vector<lint>H(N);
	rep(i, N) {
		cin >> H[i];
	}
	sort(H);

	lint ans = binary_search(H, A, B);
	cout << ans << endl;
}

Measured memory_bytes: 5560
N, M = map(int, input().split())
A_list = sorted(list(map(int, input().split())))

BC_list = [tuple(map(int, input().split())) for _ in range(M)]
BC_list.sort(key=lambda x: x[1], reverse=True)

n_replace = 0
sum_target = 0
is_broken = False
for B, C in BC_list:
    if n_replace + B <= N:
        for A in A_list[n_replace:n_replace+B]:
            if A < C:
                sum_target += C
                n_replace += 1
            else:
                is_broken = True
                break
    else:
        remaining = N - n_replace
        for A in A_list[n_replace:n_replace+remaining]:
            if A < C:
                sum_target += C
                n_replace += 1
            else:
                is_broken = True
                break
    if is_broken is True:
        break
if n_replace < N:
    sum_target += sum(A_list[n_replace:])

# Output sumed A_list
print(sum_target)


Measured memory_bytes: 22476
#include <bits/stdc++.h>
using namespace std;
 
int main() {
     string a,b;
     cin>>a;
     b=a;
     reverse(a.begin(),a.end());
     if(a==b){
       cout<<"Yes"<<endl;
     }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int n, m, q;
  cin >> n >> m >> q;
  vector<vector<ll>> w(n+1, vector<ll>(n+1, 0));  // 2次元累積和

  rep(i, m) {
    int l, r; cin >> l >> r;
    w[l][r]++;
  }

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        w[i][j] += w[i][j-1];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        w[i][j] += w[i-1][j];
    }
  }

  rep(i, q) {
    int l, r; cin >> l >> r;
    ll ans = w[r][r] - w[l-1][r] - w[r][l-1] + w[l-1][l-1];
    cout << ans << endl;
  }

  return 0;
}


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

int main() {
  long N, num[3];
  cin >> N >> num[0] >> num[1] >> num[2];
  string s[N], c[3] = {"AB", "BC", "AC"};
  int ans[N];
  for (int i=0; i<N; i++)
    cin >> s[i];
  if (num[0]+num[1]+num[2] == 0) {
    cout << "No\n";
    return 0;
  }
  if (num[0]+num[1]+num[2] == 1) {
    for (int i=0; i<N; i++) {
      for (int j=0; j<3; j++) {
        if (s[i].compare(c[j]) == 0) {
          if (num[j] == 1) {
            num[j]--;
            num[(j+1)%3]++;
            ans[i] = (j+1)%3;
          } else if (num[(j+1)%3] == 1) {
            num[(j+1)%3]--;
            num[j]++;
            ans[i] = j;
          } else {
            cout << "No\n";
            return 0;
          }
        }
      }
    }
  } else {
    for (int i=0; i<3; i++)
      if (s[0].compare(c[i]) == 0)
        if (num[i]+num[(i+1)%3] == 0) {
          cout << "No\n";
          return 0;
        }
    for (int i=0; i<N; i++) {
      for (int j=0; j<3; j++) {
        if (s[i].compare(c[j]) == 0) {
          if (num[j]==1 && num[(j+1)%3]==1 && i<N-1) {
            if (s[i+1].compare(c[(j+2)%3])==0) {
              num[j]++;
              num[(j+1)%3]--;
              ans[i] = j;
            } else {
              num[(j+1)%3]++;
              num[j]--;
              ans[i] = (j+1)%3;
            }
          } else {
            if (num[j]<num[(j+1)%3]) {
              num[j]++;
              num[(j+1)%3]--;
              ans[i] = j;
            } else {
              num[j]--;
              num[(j+1)%3]++;
              ans[i] = (j+1)%3;
            }
          }
        }
      }
    }
  }
  cout << "Yes\n";
  for (int i=0; i<N; i++) {
    char a = 'A'+ans[i];
    cout << a << endl;
  }
  return 0;
}

Measured memory_bytes: 7152
s = input()
g = set()
for i in s:
    g.add(i)
ans = 10**9
al = [chr(ord('a') + i) for i in range(26)]

for w in al:
    count = 0
    a = s
    flag = 0
    if not w in g:
        continue
    while flag == 0:
        flag = 1
        for i in a:
            if not i == w:
                flag = 0
        if flag:
            ans = min(ans, count)
        b = ""
        for i in range(len(a)-1):
            if a[i] == w or a[i+1] == w:
                b += w
            else:
                b += a[i]
        a = b
        count += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>

#include <complex>
#include <vector>
#include <cmath>
#include <utility>
#include <cassert>
#include <algorithm>

const double EPS=1e-10;

#define equals(a, b) (fabs((a)-(b))<EPS)
#define X real()
#define Y imag()

using namespace std;

typedef complex<double> Point;
typedef complex<double> Vector;

struct Segment {
    Point p1, p2;
};
typedef Segment Line;

struct Circle {
    Point c;
    double r;
    Circle(Point c=Point(), double r=0.0) :
        c(c),r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Vector a,Vector b) {
    return a.X*b.Y - a.Y*b.X;
}

Point project(Segment s, Point p) {
    Vector base = s.p2-s.p1;
    double r=dot(p-s.p1,base) / norm(base);
    return s.p1+base*r;
}

Point reflect(Segment s, Point p) {
    return p+(project(s,p)-p)*2.0;
}

enum CCW {
    COUNTER_CLOCKWISE=1,
    CLOCKWISE=-1,
    ONLINE_BACK=2,
    ONLINE_FRONT=-2,
    ON_SEGMENT=0,
};

int ccw(Point p0, Point p1, Point p2) {
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return CCW::COUNTER_CLOCKWISE;
    if(cross(a,b)<-EPS) return CCW::CLOCKWISE;
    if(dot(a,b)<-EPS) return CCW::ONLINE_BACK;
    if(norm(a)<norm(b)) return CCW::ONLINE_FRONT;

    return CCW::ON_SEGMENT;
}

double getDistance(Point a,Point b) {
    return abs(a-b);
}

double getDistanceLP(Line l, Point p) {
    return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

bool intersect(Point p1,Point p2,Point p3,Point p4) {
    return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2) {
    return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}
bool intersect(Circle c,Line l) {
    double d=getDistanceLP(l,c.c);
    return !(d>c.r);
}

Point getCrossPoint(Segment s1,Segment s2) {
    Vector base=s2.p2-s2.p1;
    double d1=abs(cross(base,s1.p1-s2.p1));
    double d2=abs(cross(base,s1.p2-s2.p1));
    double t=d1/(d1+d2);
    return s1.p1+(s1.p2-s1.p1)*t;
}
pair<Point, Point> getCrossPoints(Circle c, Line l) {
    assert(intersect(c,l));
    Vector pr=project(l,c.c);
    Vector e=(l.p2-l.p1)/abs(l.p2-l.p1);
    double base=sqrt(c.r*c.r-norm(pr-c.c));

    return make_pair(pr+e*base,pr-e*base);

}

int main() {
    double cx,cy,r;
    cin>>cx>>cy>>r;
    Circle circle({Point(cx,cy),r});
    int q; cin>>q;
    while(q-->0) {
        double x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        Line l=Line({Point(x1,y1),Point(x2,y2)});

        auto ans=getCrossPoints(circle,l);
        vector<pair<double,double>> vec;
        vec.push_back(make_pair(ans.first.X,ans.first.Y));
        vec.push_back(make_pair(ans.second.X,ans.second.Y));
        sort(vec.begin(),vec.end());
        printf("%.10f %.10f ",vec[0].first,vec[0].second);
        printf("%.10f %.10f\n",vec[1].first,vec[1].second);
    }
    return 0;
}

Measured memory_bytes: 1256
from collections import defaultdict
class UnionFind:


    def __init__(self,n):
        self.parent = [i for i in range(n)]
        self.rank = [0]*n
        self.n = n
    def find(self,x):
        if self.parent[x] == x:
            return x
        while x != self.parent[x]:
            self.parent[x] = self.parent[self.parent[x]]
            x = self.parent[x]
        return x
    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x == y:return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same(self,x,y):
        return bool(self.find(x)==self.find(y))

from sys import stdin
def main():
    N,K,L = map(int,stdin.readline().split())
    uf = UnionFind(N)
    uf1 = UnionFind(N)

    for _ in range(K):
        p,q = map(int,stdin.readline().split())
        uf.union(p-1,q-1)
    for _ in range(L):
        r,s = map(int,stdin.readline().split())
        uf1.union(r-1,s-1)
    d = defaultdict(int)
    for i in range(N):
        d[(uf.find(i),uf1.find(i))] += 1
    print(*(d[uf.find(i),uf1.find(i)]for i in range(N)))
    #print(l)

if __name__ == "__main__":
    main()

Measured memory_bytes: 56032
import java.io.*;

public class Main{
	
	public static long findGcd(long f1, long f2){
		long gcd = 1;
		long max, min;
		if(f1 > f2){max = f1; min = f2;}
		else{max = f2; min = f1;}
		
		if(max % min == 0){
			return min;
		}
		
		for(long i=1; i<(long)(Math.sqrt(min)+1); i++){
			if((min % i) == 0){
				if((max % i) == 0){
					if(gcd < i)gcd = i;
				}
				long tmp = min/i;
				if((max % tmp) == 0){
					if(gcd < tmp)gcd = tmp;
				}
			}
		}
		return gcd;
	}
	
	
	public static long findlcm(long f1, long f2){
		long lcm = 0;
		long max, min;
		if(f1 > f2){max = f1; min = f2;}
		else{max = f2; min = f1;}
		long i=1;
		while(lcm == 0){
			if((max * i)%min == 0){
				lcm = max * i;
			}
			i++;
		}
		return lcm;
	}
	
	/*
	//最大公約数を求めるメソッド
    static long findGcd(long x, long y){
        if(x%y==0){
            return y;
        }else{
            long m = 1;
            while(m!=0){
                m = y%x;
                y = x;
                x = m;
            }
            return y;
        }
    }
    */
	
	public static void main(String[] argv) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while((line = br.readLine()) != null){
			String[] lineArray = line.split(" ");
			long[] factor = {Long.parseLong(lineArray[0]), Long.parseLong(lineArray[1])};
			long gcd = findGcd(factor[0], factor[1]);
			long lcm = findlcm(factor[0], factor[1]);
			System.out.println(gcd + " " + lcm);
		}
	}
}

Measured memory_bytes: 18492