akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

type Graph = Vec<Vec<usize>>;

fn crcl(v:usize,org:usize,g:&Graph,mut used:&mut Vec<bool>,mut vs:&mut Vec<usize>){
    // eprintln!("{}",v);
    used[v] = true;
    for &to in &g[v] {
        if to==org {
            vs.push(v);
            return;
        }
        if used[to] {
            continue;
        }
        crcl(to,org,&g,&mut used,&mut vs);
        if !vs.is_empty() {
            vs.push(v);
            return;
        }
    }
}

fn main() {
    let (n,g) = {
        input!{
            n:usize,
            m:usize,
            ab:[(usize,usize);m]
        };
        let mut g = vec![Vec::new();n];
        for (a,b) in ab {
            g[a-1].push(b-1);
        }
        (n,g)
    };

    for i in 0..n {
        // eprintln!("# {}",i);
        let mut vs = Vec::new();
        let mut used = vec![false;n];
        crcl(i,i,&g,&mut used,&mut vs);
        if vs.len()>0 {
            vs = vs.into_iter().rev().collect();
            for _ in 0..n {
                let mut newvs:Vec<usize> = Vec::new();
                let mut flag = vec![None;n];
                for i in 0..vs.len() {
                    flag[vs[i]] = Some(i);
                }
                'outer: 
                for i in 0..vs.len() {
                    let v = vs[i];
                    for &to in &g[v] {
                        if let Some(id) = flag[to] {
                            if i!=vs.len()-1 && id<i || 0<id && id<i {
                                for i in id..(i+1) {
                                    newvs.push(vs[i]);
                                }
                                break 'outer;
                            }
                            if i+1<id {
                                for j in 0..(i+1){
                                    newvs.push(vs[j]);
                                }
                                for j in id..vs.len() {
                                    newvs.push(vs[j]);
                                }
                                break 'outer;
                            }
                        }
                    }
                }
                if !newvs.is_empty() {
                    vs = newvs;
                }
            }
            println!("{}",vs.len());
            let ans = vs.into_iter().map(|x|(x+1).to_string()).collect::<Vec<_>>().join("\n");
            println!("{}",ans);
            return;
        }
    }
    println!("-1");
}

Measured memory_bytes: 2364
#include<iostream>

using namespace std;

int main(){
    int N,M;
    cin >>N>>M;
    int K[N],A[N][M];
    int ansv = 0;
    int ans = 0;
    for(int i = 0; i < N;i++){
        cin >>K[i];
        for(int j = 0; j < K[i]; j++){
            cin >> A[i][j];
        }
    }

    for(int h = 0; h < K[0]; h++){
        ansv = 0;

        for(int i = 0; i < N;i++){
            for(int j = 0; j < K[i]; j++){
                if(A[0][h] == A[i][j]){
                    ansv++;
                }
            }

        }
        if(ansv == N){
            ans++;
        }

    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 100010
char s[MAXN];
int n,ls=1,nw=1,r;
int fa[MAXN];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	if(s[1]=='0'||s[n]=='1')
	{
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<n-i;i++)
		if(s[i]!=s[n-i])
		{
			printf("-1\n");
			return 0;
		}
	for(int i=1;i<n;i++)
		if(s[i]=='1')
		{
			fa[nw]=i+1;nw=i+1;
		}
		else fa[i+1]=nw;
	for(int i=1;i<=n;i++)
		if(fa[i])
			printf("%d %d\n",i,fa[i]);
}

Measured memory_bytes: 1792
#include<stdio.h>

main(){

  int n,q,i,j,c = 0;
  int s[10000],t[500];

  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%d",&s[i]);
  }
  
  scanf("%d",&q);
  
  for(i = 0;i < q;i++){
    scanf("%d",&t[i]);
  }
  
  for(j = 0;j < q;j++){
    for(i = 0;i < n;i++){
      if(s[i]==t[j]){
	c++;
	break;
      }
    }
  }

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

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	char s[5];

	scanf("%s",s);

	if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])
		puts("Yes");
	else if(s[0]==s[2]&&s[1]!=s[2]&&s[1]==s[3])
		puts("Yes");
	else if(s[0]==s[3]&&s[1]!=s[3]&&s[1]==s[2])
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 1660
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        //PQの先頭要素は最小
        PriorityQueue<Long> left=new PriorityQueue<>();
        PriorityQueue<Long> right=new PriorityQueue<>(Comparator.reverseOrder());
        int n=sc.nextInt();
        long[] a=new long[1+n*3];
        for (int i = 1; i <= 3*n; i++) {
            a[i]=sc.nextLong();
        }
        long[] tL=new long[3*n+1];
        long[] tR=new long[3*n+2];
        for (int i = 1; i <=2*n ; i++) {
            left.add(a[i]);
            if(i<=n)tL[i]+=a[i]+tL[i-1];
            else {
                long y=left.poll();
                tL[i]+=tL[i-1]+a[i]-y;
                //out.println("取り出されたのは"+y);
            }
        }
        for (int i = 3*n; i > n; i--) {
            right.add(a[i]);
            if(i>=2*n+1)tR[i]+=a[i]+tR[i+1];
            else {
                long y=right.poll();
                tR[i]+=tR[i+1]+a[i]-y;
                //out.println("取り出されたのは"+y);
            }
        }
        long ans=Long.MIN_VALUE;
        for (int i = n; i <=n*2 ; i++) {
            ans=max(tL[i]-tR[i+1],ans);
        }
        out.println(ans);
        //out.println();
        //for (long j:tL)out.println(j);
        //out.println();
        //for (long j:tR)out.println(j);
    }
}

Measured memory_bytes: 100592
#include <stdio.h>

int main()
{
    int n,a[2][100];
    int suma[2] = {0};

    int i,j;

    scanf("%d",&n);

    for (i = 0; i < 2; i++)
    {
        for (j = 0; j < n; j++)
        {
            scanf("%d",&a[i][j]);
            suma[i] += a[i][j];
        }
    }


    suma[0] = 0;
    int ans = a[0][0] + suma[1];
    suma[0] += a[0][0];
    for (i = 1; i < n; i++)
    {
        suma[0] += a[0][i];
        suma[1] -= a[1][i - 1];
        if(ans < suma[0] + suma[1])ans = suma[0] + suma[1];
    }
    
    printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair  
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 2e5+7;
const ll inf = 1e9+7;

ll gauss(ll n){
  return (n)*(n+1)/2;
}
int main() {
	fastio;
  ll n,ans=0; 
  cin>>n;
  f(i,1,n+1){
    ans+= gauss(n/i)*i;
  }
  cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q;
string S;

struct Range {
    int len;
    vector<ll> val;
    Range(const vector<ll> &val_, int l, int r) : len(r - l) {
        val.resize(len);
        for (int i = 0; i < len; i++) {
            val[i] = val_[i + l];
        }
    }
};

int main() {
    cin >> N >> K >> Q;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    B = A;
    sort(ALL(B));

    vector<Range> ranges;
    ranges.push_back(Range(A, 0, N));

    ll ans = INF;
    for (int i = 0; i < N; i++) {
        if (i + Q - 1 > N) break;
        ll first = B[i];
        ll qth = B[i + Q - 1];
        //debug(first);
        //debug(qth);
        vector<Range> new_ranges;
        for (auto range : ranges) {
            int r = 0;
            for (int l = 0; l < range.len;) {
                while (r < range.len && range.val[r] >= first) {
                    r++;
                }
                if (l == r) {
                    l++;
                    r++;
                    continue;
                }
                new_ranges.push_back(Range(range.val, l, r));
                r++;
                l = r;
            }
        }
        //debug(new_ranges.size());
        int sum = 0;
        for (auto range : new_ranges) {
            int cnt = 0;
            for (auto v : range.val) {
                if (v <= qth) {
                    cnt++;
                }
            }
            //debug(cnt);
            sum += max(min(range.len - K + 1, cnt), 0);
        }
        //debug(sum);
        if (sum >= Q) {
            chmin(ans, qth - first);
        }
        ranges = new_ranges;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  	typedef long long ll;
    int N,M;
    cin >> N >> M;

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

    ll remain = M,sum = 0;
    for ( ll i = 0 ; i < N ; i++ ){
        if (drink.at(i).second > remain ){
            sum += drink.at(i).first * remain;
            break;
        }
        else{
            sum += drink.at(i).first * drink.at(i).second;
            remain -= drink.at(i).second;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin>> a>>b;

    cout<< max(0, (a-(b*2)))<< endl;

    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7, mx = 200000;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; void chmax(ll& x, ll y) {if (x<y) x=y;}; void chmin(ll& x, ll y) {if (x>y) x=y;};
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
vector<ll> sm(2002), inv(2002);
void sm_build() {
	sm[0]=1;for(ll i=1;i<=2001;i++) sm[i]=sm[i-1]*i%M;
	inv[2001]=mod_pow(sm[2001],M-2);for(ll i=2000;i>=0;i--) inv[i]=inv[i+1]*(i+1)%M;
}

int main() {
  sm_build();
  ll n,a,b,c,d; cin>>n>>a>>b>>c>>d;
  ll dp[n+1]; fill(dp,dp+n+1,0);
  dp[0]=1;
  ll su[n+1];
  for(ll j=a;j<=b;j++) {
    fill(su,su+n+1,0);
    for(ll k=c;k<=d;k++) {
      if (n < j*k) break;
      ll mu = inv[k] * mod_pow(inv[j], k) % M;// j*k個からj個をk個抜く これはk個に区別
      //cout<<j<<" "<<k<<" "<<mu<<endl;
      int p = n-j*k;
      for(int i=p;i>=0;i--) {
        ll lf = n-i;
        ll ad = sm[lf] * inv[lf-j*k] % M;
        ad = ad * mu % M; ad = ad * dp[i] % M;
        int vu = i+j*k;
        add(su[vu],ad);
      }
    }
    for(int i=0;i<=n;i++) {
      add(dp[i],su[i]);
    }
    /*
    for(int i=0;i<=n;i++) {
      cout<<dp[i]<<" ";
    } cout<<endl;*/
  }
  /*
  for(int i=0;i<=n;i++) {
    cout<<dp[i]<<" ";
  } cout<<endl;*/
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);


            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine((p[0] <= 8 && p[1] <= 8) ? "Yay!" : ":(");

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



Measured memory_bytes: 13396
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],R[2<<17];
/*dfs1(u,p,i)
{
	dp1[u]=1;
	for(i=first[u];i;i=next[i])eb[i]-p?dfs1(eb[i],u),dp1[u]=dp1[u]*-~dp1[eb[i]]%M:0;
}*/
dfs1(u,p,i,I)
{
	dp1[u]=1;
	for(i=first[u];I=eb[i];i=next[i])I-p?dfs1(I,u),dp1[u]=dp1[u]*-~dp1[I]%M:0;
}
/*dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p,x);
	for(;i;i=next[i])
	{
		if(eb[i]!=p)dfs2(eb[i],u,L[i]*R[next[i]]%M+1);
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]-p?-~dp1[eb[i]]:1;
		make(x=next[i],p,t%M*x%M);
		R[i]=R[x]*t%M;
	}
}*/
/*
dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;i;i=next[i])eb[i]-p?dfs2(eb[i],u,R[next[i]]*x%M+1),x=x%M*-~dp1[eb[i]]%M:0;
}
*/
/**/
dfs2(u,p,x,i,I)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;I=eb[i];i=next[i])I-p?dfs2(I,u,R[next[i]]*x%M+1,0,0),x=x%M*-~dp1[I]%M:0;
}
/**/
make(i,p)
{
	if(i)
	{
		make(next[i],p);
		R[i]=R[next[i]]*(eb[i]-p?-~dp1[eb[i]]:1)%M;
	}
}
main(u,v)
{
	/*for(scanf("%d%d",&n,&M);~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}*/
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i]=eb[i+1]=u,ea[i+1]=eb[i]=v,i++:(n=u,M=v);
	for(;~scanf("%d%d",&u,&v);i++)i++?ea[i-1]=eb[i]=u,ea[i]=eb[i-1]=v:(n=u,M=v);
	for(;i--;)
	{
		next[i]=first[ea[i]];
		first[ea[i]]=i;
	}
	dfs1(*R=1,0);
	dfs2(1,0,1);
	for(i=1;i<=n;i++)printf("%d\n",dp2[i]);
}


Measured memory_bytes: 11520
import com.sun.corba.se.impl.orbutil.ObjectUtility;

import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    Random rand = new Random();

    void dfs(int v, int lvl) {
        if (lvl > 2) return;
        if (lvl == 2 && v == n - 1) {
            flag = true;
            return;
        }
        if (used[v]) return;
        used[v] = true;
        for(int i : g[v]){
            dfs(i, lvl + 1);
        }
    }

    boolean used[];
    boolean flag;
    int n;
    ArrayList<Integer> g[];

    public void solve() throws IOException {
        n = nextInt();
        used = new boolean[n];
        g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        int m = nextInt();
        for (int i = 0; i < m; i++) {
            int x = nextInt() - 1, y = nextInt() - 1;
            g[x].add(y);
            g[y].add(x);
        }
        dfs(0, 0);
        if(flag){
            out.print("POSSIBLE");
        }else{
            out.print("IMPOSSIBLE");
        }
    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("sum2.in"));
//            out = new PrintWriter(new File("sum2.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
}

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

char s[5001], t[6], c[5];
int k, n;
inline int findstr(const int& begin, const int& tl) {
  for (int i = begin; i <= n - tl;) {
    for (int j = 0; j < tl; ++j) {
      if (s[i + j] != t[j]) goto cont;
    }
    return i;
  cont:
    ++i;
  }
  return -1;
}
int main() {
  scanf("%s", s);
  scanf("%d", &k);
  n = strlen(s);
  for (c[0] = 'a'; c[0] <= 'z'; ++c[0]) {
    t[0] = c[0];
    int l0 = findstr(0, 1);
    if (l0 < 0) continue;
    if (k == 1) {
      printf("%s\n", t);
      return 0;
    }
    --k;
    for (c[1] = 'a'; c[1] <= 'z'; ++c[1]) {
      t[1] = c[1];
      int l1 = findstr(l0, 2);
      if (l1 < 0) continue;
      if (k == 1) {
        printf("%s\n", t);
        return 0;
      }
      --k;
      for (c[2] = 'a'; c[2] <= 'z'; ++c[2]) {
        t[2] = c[2];
        int l2 = findstr(l1, 3);
        if (l2 < 0) continue;
        if (k == 1) {
          printf("%s\n", t);
          return 0;
        }
        --k;
        for (c[3] = 'a'; c[3] <= 'z'; ++c[3]) {
          t[3] = c[3];
          int l3 = findstr(l2, 4);
          if (l3 < 0) continue;
          if (k == 1) {
            printf("%s\n", t);
            return 0;
          }
          --k;
          for (c[4] = 'a'; c[4] <= 'z'; ++c[4]) {
            t[4] = c[4];
            int l4 = findstr(l3, 5);
            if (l4 < 0) continue;
            if (k == 1) {
              printf("%s\n", t);
              return 0;
            }
            --k;
          }
          t[4] = 0;
        }
        t[3] = 0;
      }
      t[2] = 0;
    }
    t[1] = 0;
  }
}


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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        if( H == 0 && W == 0 ) break;
        
        for( int i = 0; i < H; i++){
            for( int j = 0; j < W; j++){
                if( ( i + j ) % 2 == 0 ){
                    cout << "#";
                } else {
                  cout << ".";
                }
            }
            cout << "\n";
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int a,b,c; cin >> a >> b >> c;
    if (b-a == c-b) cout << "YES\n";
    else cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		String S = sc.next();
		S = S.substring(0,K-1)+S.substring(K-1,K).toLowerCase()+S.substring(K);
		System.out.println(S);
	}

}

Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int x[] = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);
		int sa[] = new int[n-1];
		for (int i = 0; i < n-1; i++) {
			sa[i] = x[i+1]-x[i];
		}
Arrays.sort(sa);
//m-1koryaku

int ans=0;
for (int i = 0; i < n-1-(m-1); i++) {
	ans+=sa[i];
}
System.out.println(ans);
	}}

Measured memory_bytes: 49384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
#include <cmath>
using namespace std;

int main(){
    int W, H;
    cin >> W >> H;
    vector<pair<int, int>> pq;
    for(int i=0; i<W; i++){
        int p;
        cin >> p;
        pq.push_back(make_pair(p, 0));
    }
    for(int i=0; i<H; i++){
        int q;
        cin >> q;
        pq.push_back(make_pair(q, 1));
    }
    int cnt0 = 0;
    int cnt1 = 0;
    sort(pq.begin(), pq.end());
    long long ans = 0;
    for(int i=0; i<pq.size(); i++){
        if(pq[i].second == 0){
            long long tmp = H+1-cnt1;
            if(tmp <= 0) break;
            ans += tmp * pq[i].first;
            cnt0++;
        }else{
            long long tmp = W+1-cnt0;
            if(tmp <= 0) break;
            ans += tmp * pq[i].first;
            cnt1++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2420
def gcd(x,y):
    a=max(x,y)
    b=min(x,y)
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)

def lcm(x,y):
    return (x*y)//gcd(x,y)

N=int(input())
ans=1
for i in range(N):
    ans=lcm(ans,int(input()))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200001;
const int MOD = 2019;

vector<int> pow10(MAX, 1);
void init()
{
  for (int i = 1; i < MAX; i++)
  {
    pow10.at(i) = (pow10.at(i - 1) * 10) % MOD;
  }
}

int main()
{
  init();
  string S;
  cin >> S;
  int n = S.size();
  map<int, int> mp;
  vector<int> T(n + 1, 0);
  mp[T.at(n)]++;
  for (int i = n - 1; i >= 0; i--)
  {
    T.at(i) = (T.at(i + 1) + (S.at(i) - '0') * pow10.at(n - i - 1)) % MOD;
    mp[T.at(i)]++;
  }
  long long ans = 0;
  for (auto p : mp)
  {
    int v = p.second;
    ans += v * (v - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> fi(H);
    REP(i,H) cin >> fi[i];
    vector<vector<int>> ans(H,vector<int>(W));
    vector<int> gyou(H);
    REP(i,H) REP(j,W){
        if(fi[i][j] == '#') gyou[i]++;
    }
    int cnt = 1;
    REP(i,H){
        if(gyou[i] == 0) continue;
        int tmp = 1;
        REP(j,W){
            if(fi[i][j] == '#'){
                if(tmp == 1) tmp++;
                else{
                    cnt++;
                }
            }
            ans[i][j] = cnt;
        }
        cnt++;
    }

    REP(i,H){
        if(gyou[i] > 0) continue;
        if(i == 0) REP(j,W) ans[i][j] = ans[i+1][j];
        else REP(j,W) ans[i][j] = ans[i-1][j];
    }
    for(int i=H-1;i>=0;i--){
        if(gyou[i] > 0) continue;
        if(i == H-1) REP(j,W) ans[i][j] = ans[i-1][j];
        else REP(j,W) ans[i][j] = ans[i+1][j];
    }
    REP(i,H){
        REP(j,W) cout << ans[i][j] << " ";
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision


#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

namespace Problem{
using namespace std;
class Writer{
static ostringstream oss;
public:template<class T> void appendln(const vector<vector<T>> &ans,string spl=" ", string el="\n"){for(int i=0; i<(int)ans.size(); ++i){for(int j=0; j<(int)ans[i].size(); ++j){oss << ans[i][j];oss << (j==(int)ans[i].size()-1?el:spl);}}}
    template<class T> void appendln(const vector<T>& ans, string spl=" "){for(int i=0; i<(int)ans.size(); ++i){oss << ans[i] << (i==(int)ans.size()-1?"\n":spl);}}
    template<class T> void appendln(const T& answer){oss << answer << "\n";}
    template<class T> void append(const T& answer){oss << answer;}
    void appends(const string spl){oss.seekp((int)oss.tellp()-1);oss<<"\n";}
    template<class F, class... R>void appends(const string spl,const F& fi, const R&... rest){oss << fi << spl; appends(spl, rest...);}
    static void write(){cout << oss.str();}
    Writer(){static bool is_single =true;assert(is_single);is_single=false;};
};ostringstream Writer::oss;


class Solver{
public:
    int n;
    vector<int> a;
    Solver(LL n):n(n),a(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        int ans = a[0];
        for(int i=0; i<n-1; ++i){
            if(abs(ans*2-a.back()) > abs(a[i]*2-a.back())){
                ans = a[i];
            }
        }
        cout  <<a.back()  << ' ' << ans << "\n";

    }
};
}

int main(){
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    long long n=0;
    std::cin >> n;
    Problem::Solver sol(n);
    sol.solve();
    Problem::Writer::write();
    return 0;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};
vector<edge> G[MAX_V];

void dijkstra(int s, vector<int> &d){
	priority_queue< pii,vector<pii>,greater<pii> > que;
	rep( i,d.size() )d[i]=INF;
	d[s] = 0;
	que.push( pii(0,s) );
	
	while( que.size() ){
		pii p=que.top();
		que.pop();
		
		int v=p.second;
		if(d[v]<p.first)continue;
		
		rep(i,G[v].size()){
			edge e=G[v][i];
			if(d[e.to]>d[v]+e.cost){
				d[e.to]=d[v]+e.cost;
				que.push(pii(d[e.to],e.to));
			}
		}
	}
}


string replace(string origin,string from,string to){
	string ret = "";
	for(int i=0;i<origin.size();){
		if(i+from.size()<=origin.size()){
			bool isSame = true;
			for(int j=i;j<i+from.size();j++){
				if(origin[j]!=from[j-i])isSame = false;
			}
			if(isSame){
				ret += to;
				i+=from.size();
			}
			else ret += origin[i++];
		}
		else ret += origin [i++];
	}
	return ret;
}



int main(){
	assert( replace("aaxaaa","aa","bca")=="bcaxbcaa" );
	int n;
	while(cin>>n&&n){
		vector<pair<string,string>> vp;
		rep(i,MAX_V)G[i].clear();
		rep(i,n){
			string a,b;
			cin>>a>>b;
			vp.pb(make_pair(a,b));
		}
		
		string s,t;
		cin>>s>>t;
		
		map<string,int> num;
		queue<string> que;
		que.push(s);
		int c=0;
		num[s]=c++;
		
		while(que.size()){
			string q = que.front();
			que.pop();
//			cout<<q<<endl;
			
			rep(i,vp.size()){
				string a =vp[i].first,b=vp[i].second;
				if( q.find(a)!=string::npos ){
					string res = replace(q,a,b);
					if(res.size()>t.size()+1 || num.count(res)!=0)continue;
					que.push(res);
					num[res]=c++;
					G[num[q]].pb(edge{c-1,1});
				}
			}
		}
		assert(c<MAX_V);
		vector<int> d(c);
		dijkstra(num[s],d);
		if(num.count(t)==0)cout<<-1<<endl;
		else cout<<d[num[t]]<<endl;
	}
}

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



int n, m ;
char a[1001][1001];
int b[1001][1001];

int dp[1001][1001] ;

int f(int i, int j) {
	if (dp[i][j] != -1)
		return dp[i][j];

	if (i == n - 1 && j == m - 1) {
		// b[i][j] = 1;
		// for (int ii = 0; ii < n; ii++)
		// 	for (int jj = 0; jj < m; jj++)
		// 		cout >> b[ii][jj];
		return 1;
	}
	if (i >= n || j >= m)
		return 0;
	if (a[i ][j] == '#') return 0;
	int count = 0;
	b[i][j] = 1;
	count += f(i + 1, j);
	count += f(i, j + 1);
	b[i][j] = 0;

	return dp[i][j] = count % 1000000007;
}


int main()
{	

	cin >> n >> m;
	memset(dp, -1, sizeof dp);
	//memset(b, '.', sizeof b);

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	// for (int i = 0; i < n; i++)
	// 	for (int j = 0; j < m; j++)
	// 		b[i][j] = 0;


	cout << f(0, 0);

	//cout << ans;
	return 0;
}

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

int d[55][55],n,m,k,q,ans;
int main() {
  cin >> n >> m >> k >> q;
  for(int i=0,x,y,z;i<q;i++) {
    cin >> x >> y >> z;
    d[y][x]++;
  }
  for(int i=0;i<m;i++) {
    for(int j=0,x;j<n;j++){
      cin >> x;
      ans+=d[i][j]*x;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int arr[100002];
int her[100001];

int main(){
	
		int n;
		cin>>n;
		long long count = 0;
		for(int i=0;i<n+1;i++)
			cin>>arr[i];
		for(int i=0;i<n;i++)
			cin>>her[i];
		for(int i=0;i<n;i++){
			if(arr[i]>her[i]){
				count+=her[i];
			}
			else{
				count+=arr[i];
				her[i]-=arr[i];
				arr[i]=0;
				if(arr[i+1]>her[i]){
					count+=her[i];
					arr[i+1]-=her[i];
				}
				else{
					count+=arr[i+1];
					arr[i+1]=0;
				}
			}
		}
		cout<<count<<endl;
	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }


int main(){
    ll n, m; cin >> n >> m;
    vector<ll> x(m);
    vector<ll> sa(m-1);
    ll ans = 0;

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

    if(n>=m) {
        cout << 0 << endl;
        return 0;
    }

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

    for (int j = 1; j < m; ++j) {
        sa[j-1] = x[j]-x[j-1];
    }

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

    for (int k = 0; k < sa.size() - (n-1); ++k) {
        ans += sa[k];
    }

    cout << ans << endl;
}


Measured memory_bytes: 1792
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[derive(Debug)]
struct UnionFind {
    par: Vec<usize>,
    sizes: Vec<usize>
}
impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let par = (0..n).collect();
        let sizes = vec![1; n];
        UnionFind{par, sizes}
    }
    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] { x } else {
            self.par[x] = self.find(self.par[x]);
            self.par[x]
        }
    }
    fn unite(&mut self, x: usize, y: usize) {
        let mut x = self.find(x);
        let mut y = self.find(y);
        if x == y { return; }
        if self.sizes[x] < self.sizes[y] {
            std::mem::swap(&mut x, &mut y);
        }
        self.par[y] = x;
        self.sizes[x] += self.sizes[y];
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
    fn size(&mut self, x: usize) -> usize {
        let t = self.find(x);
        self.sizes[t]
    }
}
fn main() {
    let (n, q) = {
        let t: Vec<usize> = read_vec();
        (t[0], t[1])
    };
    let mut uf = UnionFind::new(n);
    for _ in 0..q {
        let t: Vec<usize> = read_vec();
        if t[0] == 0 {
            uf.unite(t[1], t[2]);
        }
        else {
            println!("{}", uf.same(t[1], t[2]) as i32);
        }
    }
}


Measured memory_bytes: 4772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = ll(b) - 1; i >= (a); i--)
#define TR(X)                                              \
  ({                                                       \
    if (0) cerr << "TR: " << (#X) << " = " << (X) << endl; \
  })

const ll MAXN = 200100;

ll sequ[MAXN];        // Zahlenfolge (nur dieses Array füllen)
int lis[MAXN];        // Länge der längsten an dieser Position endenden LIS
ll minval[MAXN + 1];  // minimaler in der Zahlenfolge vorkommender Wert, bei dem
// eine LIS dieser Länge endet; das Array ist per Def. aufsteigend sortiert

// Berechnet Länge der LIS (strict increasing, sequ[i1] < sequ[i2)
int LIS(int N) {
  int maxlen = 0;
  minval[0] = LLONG_MIN;  // Falls nur '<=' gelten muss:
  FOR(i, 0, N) {          // lower_bound durch upper_bound ersetzen
    lis[i] = upper_bound(minval, minval + maxlen + 1, sequ[i]) - minval;
    if (lis[i] > maxlen) {
      maxlen = lis[i];
      minval[maxlen] = sequ[i];
    } else if (sequ[i] < minval[lis[i]]) {
      minval[lis[i]] = sequ[i];
    }
  }
  return maxlen;
}

int main() {
  cin.sync_with_stdio(0);
  ll x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  bool reverseX = x1 > x2;
  if (reverseX) {
    swap(x1, x2);
    swap(y1, y2);
  }

  bool reverse = y1 > y2;

  ll miX = min(x1, x2), miY = min(y1, y2), maX = max(x1, x2), maY = max(y1, y2);

  ll N;
  cin >> N;
  vector<pll> points;

  FOR(i, 0, N) {
    ll x, y;
    cin >> x >> y;
    if (x < miX || x > maX || y < miY || y > maY) continue;
    if (reverse) y *= -1;
    points.pb({x, y});
  }

  sort(all(points));
  TR(sz(points));

  TR(y1);
  TR(y2);
  TR(reverse);

  ll j = 0;
  // sequ[j++] = y1;
  FOR(i, 0, sz(points)) sequ[j++] = points[i].yy;
  // sequ[j++] = y2;

  /*
  if (reverse) {
          sequ[0] *= -1;
          sequ[j-1] *= -1;
  }
  */

  FOR(i, 0, j) TR(sequ[i]);

  //LIS(j);
  ll k = 0;
  if (j) k = LIS(j);

  TR(k);

  long double res;
  res = 100 * abs(x1 - x2) + 100 * abs(y1 - y2) -
        4.292036732051033807686783083602485579014153003124470895125l * k;
  TR(res);
  TR(x1);
  TR(x2);
  TR(x1 - x2);
  TR(y1);
  TR(y2);
  TR(y1 - y2);
  if (k == min(abs(x1 - x2), abs(y1 - y2)) + 1) {
    TR("sonderfall");
    res += 4.292036732051033807686783083602485579014153003124470895125l;
    res -= 20;
    res += M_PI * 10;
  }
  cout << fixed << setprecision(20) << res << endl;

}  // cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 8044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  
  if(s<t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long

int n, m, c, a[100][100], b[100], ans, total;
int32_t main() {
	total = 0;
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> c;
	for(int i = 0; i < m; ++i) cin >> b[i];
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < n; ++i) {
		ans = 0;
		for(int j = 0; j < m; ++j) {
			ans += a[i][j]*b[j];
		}
		if (ans+c > 0) ++total;
	}
	cout << total;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int INF = 1000;

int main()
{
    int n;
    cin >> n;
    int ans = INF;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        int a;
        cin >> a;
        while (a % 2 == 0) {
            cnt++;
            a /= 2;
        }
        if (ans > cnt) ans = cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    double n;
    cin >> n;
    
    double ans = (n/3) * (n/3) * (n/3);

    printf("%.10f\n", ans);

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

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    
    double N = sc.nextDouble();
    double a;
    if(N % 2 == 0){
      a = 0.5;
    } else {
      a = ((N - 1)/2 + 1)/N;
    }
    
    System.out.println(a);
  }
}
  

Measured memory_bytes: 24148
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  int o = 1;
  while(o < B){
    o += A - 1;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
PrimeList=[2]
LikeList=[3]
Cumsum=[0]

for i in range(3,320,2):
    j=0
    while(1):
        if j==len(PrimeList):
            PrimeList.append(i)
            break
        elif i%PrimeList[j]==0:
            break
        j+=1
        
for i in range(5,100000,4):
    j=0
    while(1):
        if PrimeList[j]>i**(1/2):
            LikeList.append(i)
            break
        elif i%PrimeList[j]==0 or (i+1)/2%PrimeList[j]==0 :
            break
        j+=1
        
for i in range(1,100001):
    Cumsum.append(Cumsum[i-1]+int(i in LikeList))
    
Q=int(input())

for i in range(Q):
    l,r = list(map(int, input().split()))
    print(Cumsum[r]-Cumsum[l-1])



Measured memory_bytes: 6548
def getinputdata():

    array_result = []    
    array_result.append(input().split(" "))

    flg = True

    try:
        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

n= int(arr_data[0][0])

arr=[int(arr_data[1][x]) for x in range(n)]
arr01 = [x for x in arr if x % 4 ==0] 
arr02 = [x for x in arr if x % 4 !=0 and x % 2==0] 

cnt=0
if len(arr)>0:

    for i in arr01:

        while i % 2==0:

            i//=2
        
            cnt+=1
    
    cnt+=len(arr02)
   
print(cnt)


Measured memory_bytes: 4212
def f(x1, y1, x2, y2):
    return y1 - y2 + x2, -x1 + x2 + y2

def solve(x1, y1, x2, y2):
    x3, y3 = f(x1, y1, x2, y2)
    x4, y4 = f(x2, y2, x3, y3)
    return " ".join(map(str, [x3, y3, x4, y4]))

assert solve(0,0,0,1) == "-1 1 -1 0"
assert solve(2,3,6,6) == "3 10 -1 7"
assert solve(31,-41,-59,26) == "-126 -64 -36 -131"
x1, y1, x2, y2 = map(int, raw_input().split())
print solve(x1, y1, x2, y2)

Measured memory_bytes: 2692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace template
{
    class Program
    {
        static void Main(string[] args)
        {
            int imp = Convert.ToInt32(Console.ReadLine());
            switch (imp) { 
                case 7:
                case 5:
                case 3:
                    Console.WriteLine("YES");
                    break;
                default:
                    Console.WriteLine("NO");
                    break;
            }
        }
    }
}

Measured memory_bytes: 11220
a, b = map(int, input().split())

for t_a in range(1, 1000):
    h_a = sum([t_part for t_part in range(t_a + 1)])
    s_a = h_a - a
    if s_a >= 1:
        t_b = t_a + 1
        h_b = sum([t_part for t_part in range(t_b + 1)])
        s_b = h_b - b
        if s_b >= 1:
            if s_a == s_b:
                print(s_a)
                exit()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define boost ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0)
#define vi vector<int>
#define P push_back
#define F first
#define S second
#define debug(x) cout<<(x)<<" "
#define pi vector<pair<int,int> >
#define FOR(i,x,n) for(int i=x;i<n;i++)
#define all(a) a.begin(),a.end()
using namespace std;
int main(){
    boost; 
    int i,j;
    cin>>i>>j;
    if((int)i/2019<(int)j/2019)cout<<"0";
    else{
        i=i%2019;
        j=j%2019;
        int ans=INT_MAX;
        for(int h=i;h<j;h++){
            for(int g=h+1;g<=j;g++){
                ans=min(ans,(h*g)%2019);
            }
        }
        cout<<ans;
    }



    

    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  int A[N];
  int pos = 0;
  int sum = 0;
  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += abs(pos - A[i]);
    pos = A[i];
  }
  sum += abs(pos);
  REP(i,N) {
    if (i == 0) {
      cout << sum - abs(A[0])+ abs(A[1]) - abs(A[1] - A[0]) << endl;
    } 
    else if (i == N-1) {
      cout << sum - abs(A[N-1])+ abs(A[N-2]) - abs(A[N-1] - A[N-2]) << endl;
    }
    else {
      cout << sum - abs(A[i] - A[i-1]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1])  << endl;
    }
  }
  
}

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

int main(){
	int a[20],max=0,sum1=0,sum2=0,k;
	
	for(int i=0;i<20;i++){
		cin >> a[i];
	}
	for(int j=0;j<3;j++){
		for(int i=0;i<10;i++){
			if(max<a[i]){
				max=a[i];
				k=i;
			}
		}
		sum1+=max;
		max=0;
		a[k]=0;
	}
	for(int j=0;j<3;j++){
		for(int i=10;i<20;i++){
			if(max<a[i]){
				max=a[i];
				k=i;
			}
		}
		sum2+=max;
		max=0;
		a[k]=0;
	}
	cout << sum1 << ' ' << sum2 << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

        while (sc.hasNext()) {
            String s = sc.next();
            boolean prevIsDream = false;
            boolean prevIsErase = false;
            int idx = 0;

            while (idx < s.length()) {
                if (s.startsWith("erase", idx)) {
                    idx += 5;
                    prevIsErase = true;
                    prevIsDream = false;
                } else if (s.startsWith("dream", idx)) {
                    idx += 5;
                    prevIsErase = false;
                    prevIsDream = true;
                } else if (s.startsWith("er", idx) && prevIsDream) {
                    idx += 2;
                    prevIsErase = false;
                    prevIsDream = false;
                } else if (s.startsWith("r", idx) && prevIsErase) {
                    idx++;
                    prevIsErase = false;
                    prevIsDream = false;
                } else {
                    break;
                }
            }

            if (idx == s.length()) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}


Measured memory_bytes: 26832
n, m = map(int,input().split())
SC = [list(map(int, input().split())) for _ in range(m)]

def check(num):
    num = str(num)
    if len(num) != n:
        return False

    for s, c in SC:
        if num[s-1] != str(c):
            return False
    return True


for i in range(1000):
    if check(i):
        print(i)
        exit()
print(-1)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  char b;
  cin >> b;
  
  if(b == 'A') {
    cout << "T" << endl;
  }else if(b == 'T') {
    cout << "A" << endl;
  }else if(b == 'G') {
    cout << "C" << endl;
  }else if(b == 'C') {
    cout << "G" << endl;
  }
}
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  int c = 0;
  for(int i=a; i<=b; i++){
    string str = to_string(i);
    string r_str = str;
    reverse(r_str.begin(), r_str.end());
    if(str==r_str) c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){

	int a,b,d,sum;

	while(scanf("%d %d",&a,&b)!=EOF){
		sum=a+b;
		d=0;
		while(sum!=0){
			sum/=10;
			d++;
		}
		printf("%d\n",d);
	}
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int main(){
int N,K;
int sum=0;
scanf("%d",&N);
scanf("%d",&K);
int x[N];
for (int i = 0; i < N; i++)
{
  scanf("%d",&x[i]);
}

for (int i = 0; i < N; i++)
{
  if(x[i] < (K-x[i])){
    sum += x[i];
  }else{
    sum += (K-x[i]);
  }
}
sum*=2;

printf("%d",sum);

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 100000 + 5;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

char st[maxn];
int main() {
#ifdef Wearry
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    scanf("%s", st);
    int len = strlen(st);

    for(int i = 0; i < len - 8; ++i) printf("%c", st[i]);
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <cstring>
#include <queue>

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MAXN = 405;

int h, w;
vector<string> g;
int ans = 0;
bool visited[MAXN][MAXN];

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

ll bfs(P start) {
  queue<P> q;
  q.push(start);
  visited[start.first][start.second] = true;
  ll b_cnt = 0;
  ll w_cnt = 0;
  while (!q.empty()) {
    P cur = q.front(); q.pop();
    if (g[cur.first][cur.second] == '#') b_cnt++;
    else w_cnt++;
    for (int i = 0; i < 4; ++i) {
      int next_y = cur.first + dy[i];
      int next_x = cur.second + dx[i];
      if (next_x < 0 || next_x >= w || next_y < 0 || next_y >= h || visited[next_y][next_x]) continue;
      if (g[cur.first][cur.second] == g[next_y][next_x]) continue;
      visited[next_y][next_x] = true;
      q.emplace(next_y, next_x);
    }
  }
  return b_cnt * w_cnt;
}

int main(){
  cin >> h >> w;
  g.resize(h);
  for (int i = 0; i < h; ++i) {
    cin >> g[i];
  }

  ll ans = 0;
  memset(&visited[0][0], 0, sizeof(visited));  
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (!visited[i][j]) ans += bfs(make_pair(i, j));
    }
  }

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    i64 n;
    bool a=false;
    cin>>n;
    for(i64 i=0;i<10;i++){
        for(i64 j=0;j<10;j++){
            if(n==i*j) a=true; 
        }
    }
    if(a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256