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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int h,w,n,sr,sc;
string s,t;
bool check(char pos,int cur){
	if(pos=='U') return cur<=0;
	if(pos=='D') return cur>h;
	if(pos=='R') return cur>w;
	if(pos=='L') return cur<=0;
	return 0;
}
bool go(int cur,char pos,char neg){
	rep(i,0,n){
		if(s[i]==pos) cur+=(pos=='D' or pos=='R')-(pos=='U' or pos=='L');
		if(check(pos,cur)) return 1;
		if(t[i]==neg) cur+=(neg=='D' or neg=='R')-(neg=='U' or neg=='L');
		if(pos=='U' or pos=='D') cur=min(h,max(cur,1));
		else cur=min(w,max(cur,1));
	}
	return check(pos,cur);
}
void solve(){
	cin>>h>>w>>n;
	cin>>sr>>sc;
	cin>>s>>t;
	if(go(sr,'U','D') or go(sr,'D','U') or go(sc,'L','R') or go(sc,'R','L')) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        string str = cin.next();

        if (str == "ABC")
        {
            WriteLine("ARC");
        }
        else
        {
            WriteLine("ABC");
        }
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int main() {
  int n;
  long ans = 0;

  cin >> n;

  vector<int> a;

  for (int i = 0; i < n * 3; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

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

  int it = (int)a.size() - 2;

  for (int i = 0; i < n; i++) {
    ans += a.at(it);
    it -= 2;
  }

  cout << ans;

  return 0;
}

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

long long gcd(long long a,long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
  int n,k;
  cin>>n>>k;
  int a[n],Max=0;
  for(int i=0;i<n;i++){
      cin>>a[i];
      Max=max(Max,a[i]);
  }
  long long g=a[0];
  for(int i=1;i<n;i++){
      g=gcd(g,a[i]);
  }
  if(Max>=k&&k%g==0){
      cout<<"POSSIBLE"<<endl;
  }
  else cout<<"IMPOSSIBLE"<<endl;
}

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

int dp[110][10010];
int main(void){
    int n,W,i,j,k;
    cin >> n >> W;
    vector<int> v(n+1,0),w(n+1,0);
    for(i=1;i<=n;i++){
        cin >> v[i] >> w[i];
    }
    for(i=1;i<=n;i++){
        for(j=1;j<=W;j++){
            if(j-w[i]>=0)dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            else dp[i][j]=dp[i-1][j];
        }
    }
    int ret=0;
    for(i=0;i<=W;i++)ret=max(dp[n][i],ret);
    cout << ret << endl;
}



Measured memory_bytes: 7024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	bool InRange(int t, int l, int r){ return l <= t && t < r; }
	public void Solve(){
		
		int[][] min = new int[H][];
		for(int i=0;i<H;i++){
			min[i] = new int[W];
			for(int j=0;j<W;j++) min[i][j] = -1;
		}
		var q = new Queue<int>();
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(S[i][j] == '#'){
					min[i][j] = 0;
					q.Enqueue(i * W + j);
				}
			}
		}
		int[] dx = {0, 1, 0, -1};
		int[] dy = {1, 0, -1, 0};
		while(q.Count > 0){
			var now = q.Dequeue();
			for(int t=0;t<4;t++){
				var ny = now / W + dy[t];
				int nx = now % W + dx[t];
				if(!InRange(nx, 0, W) || !InRange(ny,0,H)) continue;
				if(min[ny][nx] == -1){
					min[ny][nx] = min[now / W][now % W] + 1;
					q.Enqueue(ny * W + nx);
				}
			}
		}
		Console.WriteLine(min.Select(a => a.Max()).Max());
		
		
	}
	int H,W;
	String[] S;
	public Sol(){
		var d = ria();
		H = d[0]; W = d[1];
		S = new String[H];
		for(int i=0;i<H;i++) S[i] = rs();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 30296
using System;
using System.Linq;
using System.Collections.Generic;
public class c
{
  public static void Main()
  {
     int N = int.Parse(Console.ReadLine());
      char[] RorB=Console.ReadLine().ToCharArray();
     int Rcount=0;
    for(int i=0;i<N;i++)if(RorB[i]=='R')Rcount++;
     if(Rcount>N-Rcount)Console.WriteLine("Yes");
     else Console.WriteLine("No");
  }
}

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

int abs(int x,int y){int res; if(x>y) res=x-y; else res=y-x; return res;}
int main(void){
    int num[3];
    cin>>num[0]>>num[1]>>num[2];
    int sum,a,b,c,max;
    a=abs(num[0],num[1]);
    b=abs(num[1],num[2]);
    c=abs(num[2],num[0]);
    if(a>b) {if(a>c) max=a; else max=c;}
    else if(b>c) {max=b;} else max=c;
    
    sum=a+b+c-max;
    cout<<max;
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll y,x;
  cin>>x>>y;
  bool ans=0;
  for (int i = 0; i <= x; ++i)
  {
    ll yo=i*2;
    ll ko=(x-i)*4;
    if(yo+ko==y)ans=1;
  }
  if(ans)cout<<"Yes";
  else cout<<"No";
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++ )
typedef pair<int,int> mypair;
int main(){
	int w,n;
	int casen = 1;
	while(1){
		cin>>w;
		if(w==0)break;
		cin>>n;
	vector<int> v(n),we(n);
	rep(i,n)scanf("%d,%d",&v[i],&we[i]);
	vector<vector<int> > dp(n+1,vector<int> ( w+1,0) );
	rep(i,n)rep(j,w+1){
	if(j<we[i])dp[i+1][j]=dp[i][j];
	else dp[i+1][j] = max(dp[i][j],dp[i][j-we[i]]+v[i]);
	}
	mypair ans = mypair(0,0);
	rep(i,w+1)ans = max(ans,mypair(dp[n][i],-i));
	cout<<"Case "<<casen<<":"<<endl;
	cout<<ans.first<<endl<<-ans.second<<endl;
		casen++;
	}


	return 0;
}



Measured memory_bytes: 6836
import Control.Monad

ok' bit s p = ( length $ [] ++ [　() | si <- s, bit !! (si-1) ] ) `mod` 2 == p
ok bit s p m = ( length $ [] ++ [ () | i <- [0..m - 1], ok' bit (s !! i) (p !! i) ] ) == m

main = do
        [n, m] <- fmap (map read . words) getLine
        s <- replicateM m $ fmap (tail . map read . words) getLine
        p <- fmap(map read . words) getLine
        let bits = sequence $ replicate n [False, True]
        print.length $ [ () | bit <- bits, ok bit s p m ]

Measured memory_bytes: 4516
#include<bits/stdc++.h>
#define pii pair<int, int>
#define LL long long
#define mp make_pair
using namespace std;
const int maxn = 53;
string s[maxn];
bool done[maxn][23][2];
int n, c[maxn];

struct Node{
	LL dis;
	int i, j, k;
	//k=0->prefix, k=1->suffix
	Node (int i, int j, int k, LL dis) {
		this->i = i; this->j = j;
		this->k = k; this->dis = dis;
	}
	bool operator < (const Node &A) const {
		return dis > A.dis;
	}
};
priority_queue<Node> q;
LL ans = 1ll << 60;

void check(int li, int ls, int lt, int ri, int rs, int rt, LL val) {
//	cout << li << " " << ls << " " << lt << " " << ri << " " << rs << " " << rt << " " << val << endl;
	while (lt >= ls && rs <= rt) {
		if (s[li][lt] != s[ri][rs])
			return ;
		--lt; ++rs;
	}
	if (lt < ls && rs > rt) {
		ans = min(ans, val);
	} else if (lt < ls) {
		q.push(Node(ri, rt - rs + 1, 1, val));
	} else {
		q.push(Node(li, lt - ls + 1, 0, val)); 
	}
}

int main() {
	#ifdef DEBUG
	freopen("text.in", "r", stdin);
	freopen("wa.out", "w", stdout);
	#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		cin >> s[i] >> c[i];
		if (s[i].size() == 1) {
			ans = min(ans, (LL) c[i]);
			continue;
		}
		q.push( Node(i, s[i].size(), 0, c[i]) );
		q.push( Node(i, s[i].size(), 1, c[i]) );
		q.push( Node(i, s[i].size() - 1, 1, c[i]) );
		for (int j = 1; j < s[i].size(); ++j) {
			check(i, 0, j - 1, i, j + 1, s[i].size() - 1, c[i]);
			check(i, 0, j - 1, i, j, s[i].size() - 1, c[i]);
		}
	}
	while (!q.empty()) {
		auto u = q.top(); q.pop();
		if (done[u.i][u.j][u.k]) continue;
		done[u.i][u.j][u.k] = true;
		if (u.k) {
			for (int i = 1; i <= n; ++i)
				check(i, 0, s[i].size() - 1, u.i, s[u.i].size() - u.j, s[u.i].size() - 1, u.dis + c[i]);
		} else {
			for (int i = 1; i <= n; ++i)
				check(u.i, 0, u.j - 1, i, 0, s[i].size() - 1, u.dis + c[i]);
		}
	}
	if (ans == (1ll << 60)) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3796
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] x = new int[M];
		int[] y = new int[M];
		for (int i = 0; i < M; i++) {
			x[i] = sc.nextInt() - 1;
			y[i] = sc.nextInt() - 1;
		}

		int[] count = new int[N];
		Arrays.fill(count, 1);

		boolean[] red = new boolean[N];
		red[0] = true;

		for (int i = 0; i < M; i++) {
			if (red[x[i]]) {
				red[y[i]] = true;
			}

			count[x[i]]--;
			count[y[i]]++;

			if (count[x[i]] == 0) {
				red[x[i]] = false;
			}

			if (false) {
				System.err.println(Arrays.toString(count));
				System.err.println(Arrays.toString(red));
			}
		}

		int sum = 0;
		for (int i = 0; i < red.length; i++) {
			if (red[i]) {
				sum++;
			}
		}

		System.out.println(sum);
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

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

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 10196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// dp[i][j] := i番目までの商品から価値がv以上になるように選んだ時の重さの最小値
ll dp[110][100001];

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

  repi(i, 0, n + 1) repi(j, 0, 100001) dp[i][j] = INF;
  dp[0][0] = 0;

  int w[n + 1], v[n + 1];
  repi(i, 1, n + 1) { cin >> w[i] >> v[i]; }

  repi(i, 1, n + 1) {
    repi(j, 0, 100001) {
      if (j - v[i] >= 0) {
        // i番目の商品を選べる
        chmin(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
        chmin(dp[i][j], dp[i - 1][j]);
      } else {
        // i番目の商品を選べない
        chmin(dp[i][j], dp[i - 1][j]);
      }
    }
  }

  ll ans = 100000;
  while (dp[n][ans] > w_limit)
    ans--;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 80128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<char,int> mci;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vii;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define in insert
#define sz(v) v.size()
#define mina(a,b) (a)=min((a),(b));
#define maxa(a,b) (a)=max((a),(b));
const ll INF = 1e18 + 5;

ll gcd(ll a, ll b){ 
    if (a == 0) return b;  
    return gcd(b % a, a);  
} 
void solve(){
    ll a, b, c, d;  
    cin>>a>>b>>c>>d;
    ll cc=b/c-a/c;
    if(a%c==0) cc++;
    ll dd=b/d-a/d;
    if(a%d==0) dd++;
    ll g=(c*d)/gcd(c,d);
    ll cd=b/(g)-a/(g);
    if(a%(g)==0) cd++;
    ll r=cc+dd-cd;
    cout<<b-a+1-r;
}
int main(){
    int T=1;        //! COMMENT IF THERE IS NO TEST CASES
    //cin>>T;
    for(int i = 0; i < T; i++) solve(); 
}

Measured memory_bytes: 256
#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(void){
  	int a, b, c, k;
	cin >> a >> b >> c >> k;
  	if(a >= k) cout << k;
  	else if(b >= k-a) cout << a;
  	else cout << a-(k-a-b);
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

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

    if (n <= 2)
    {
        cout << 0 << endl;
        return 0;
    }
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    // sort(l.begin(), l.end());
    // l.erase(unique(l.begin(), l.end()), l.end());

    int s = l.size();
    int c = 0;
    for (int i = 0; i <= s - 3; i++)
    {
        for (int j = i + 1; j <= s - 2; j++)
        {
            for (int k = j + 1; k <= s - 1; k++)
            {
                if (l[i]!=l[j]&&l[j]!=l[k]&&l[k]!=l[i]&&abs(l[i]-l[j]) < l[k] && l[k] < l[i] + l[j])
                {
                    c++;
                }
            }
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int ans = 0;
	int c = 1;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (a == c)
		{
			c++;
			}
		else
		{
			ans++;
		}
	}
	if (c == 1)
	{
		cout << -1 << endl;
	}
	else
	{
		cout << ans << endl;
	}
}



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

using Pi = pair < int , int >;

int main()
{
        int min_cost[3][100005];
        int N, M;
        int S, T;
        vector < int > G[100005];
        
        cin >> N >> M;
        
        while ( M-- ) {
                int a, b;
                cin >> a >> b;
                G[a-1].push_back(b-1);
        }
        
        cin >> S >> T; --S, --T;

        queue < Pi > que;

        fill_n(*min_cost, 3 * 100005, -3);
        min_cost[0][S] = 0;
        que.emplace(S, 0);

        while ( !que.empty() ) {
                Pi dat = que.front(); que.pop();
                int u = dat.first, c = dat.second;
                for ( int &v : G[u] ) {
                        if ( min_cost[(c + 1) % 3][v] == -3 ) {
                                min_cost[(c + 1) % 3][v] = c + 1;
                                que.emplace(v, c + 1);
                        }
                }
        }

        cout << min_cost[0][T] / 3 << endl;

        return ( 0 );
}


Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<string> S(N);
    vector<int> T(N);
    rep(i, 0, N) {
        cin >> S[i] >> T[i];
    }
    string X;
    cin >> X;
    rep(i, 0, N) {
        if (S[i] == X) {
            int ans = 0;
            rep(j, i + 1, N) {
                ans += T[j];
            }
            cout << ans << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
const ll mod=1e9 + 7;
ll power(ll a,ll n)
{
        ll ans=1;
        a=a%mod;
        while(n>0)
        {
                if(n%2==1)
                {
                        ans=(ans*a)%mod;
                }
                n=n/2;
                a=(a*a)%mod;
        }
        return ans;
}

int main()
{
    fast;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll t=ceil((ld)a/(ld)c);
    ll h=floor((ld)b/(ld)c);
    ll r=(h-t+1);
    t=ceil((ld)a/(ld)d);
    h=floor((ld)b/(ld)d);
    r=r+(h-t+1);
    ll k=(c*d)/__gcd(c,d);
    t=ceil((ld)a/(ld)k);
    h=floor((ld)b/(ld)k);
    ll g=(h-t+1);
    //cout<<g<<endl;
    r=r-g;
    cout<<(b-a+1)-r;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int INF = 1e9;

int main() {
    int N, K, Q;
    ll ma = 0;
    cin >> N >> K >> Q;
    vector<ll> point(N);
    for(int i = 0; i < Q; ++i) {
        int A;
        cin >> A;
        --A;
        ++point[A];
    }
    for(int i = 0; i < N; ++i) {
        if(point[i] - Q + K > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 5;

ll a [MAX_N], b [MAX_N];

ll cfrac (ll p, ll q) {
  return (p + q - 1) / q;
}

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

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

  ll cur = 0;
  for (int i = n - 1; i >= 0; i--) {
    ll k = cfrac(a[i] + cur, b[i]);
    cur = k * b[i] - a[i];
  }
  cout << cur << endl;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,i,j;
	scanf("%d",&n);
	ll tot = 0;
	for(i=1;i<=n;i++){
		tot += ((ll)i * (ll)(i+1)) / 2LL;
	}
	// printf("tot: %lld\n",tot);

	for(i=0;i<n-1;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		if(a > b){swap(a,b);}
		ll kanan = n - b + 1;
		ll kiri = a;
		tot -= (kanan * kiri);
	}
	printf("%lld\n",tot);
	
	return 0;
};

Measured memory_bytes: 3828
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#define FOR(i,j,k) for(int i=j;i<=k;i++)
using namespace std;
#define MAXN (1000)
char map[MAXN][MAXN];
bool vis[MAXN][MAXN],mark[MAXN];
int maxx[MAXN];
bool mvis[MAXN][MAXN];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
typedef pair<int,int> pr;
int n,m;
void bfs(){
	FOR(i,0,n+1)FOR(j,0,m+1)mvis[i][j]=true;
	FOR(i,1,n)FOR(j,1,m)mvis[i][j]=false;
	queue<pr> q;
	q.push(pr(1,1));
	mvis[1][1]=true;
	while (!q.empty()){
		pr now=q.front();q.pop();
		int x=now.first;
		int y=now.second;
		FOR(i,0,3){
			int tx=x+dx[i];
			int ty=y+dy[i];
			if (!mvis[tx][ty] && (!vis[tx][ty] || map[tx][ty]=='#')){
				mvis[tx][ty]=true;
				q.push(pr(tx,ty));
			}
		}	
	}
}
int main (int argc, char *argv[])
{
	std::ios::sync_with_stdio(false);
	cin>>n>>m;
	FOR(i,1,n){
		string temp;cin>>temp;
		FOR(k,0,m-1){
			map[i][k+1]=temp[k];
		}
	}
	
	
	FOR(i,1,n){
		FOR(j,1,m){
			if (j==1)	{cout<<".";continue;}
			if (j==m)	{cout<<"#";continue;}
			if (map[i][j]=='#')	cout<<"#";
			else{
				if (i&1)	cout<<"#";
				else cout<<".";
			}
		}cout<<endl;
	}cout<<endl;
	FOR(i,1,n){
		FOR(j,1,m){
			if (i==1 && j==1)	{cout<<".";continue;}
			if (j==1)	{cout<<"#";continue;}
			if (j==m)	{cout<<".";continue;}
			if (map[i][j]=='#')	cout<<"#";
			else{
				if (i&1)	cout<<".";
				else cout<<"#";
			}
		}cout<<endl;
	}
	return 0;
}


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

int main(){
  int n,k;
  cin >>n >>k;
  int cnt = 0;
  rep(i,n){
    int h;
    cin >> h;
    if(h>=k) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
using namespace std;
typedef long long ll;

int main() {
	ll i, j;
	int M, D;
	cin >> M >> D;
	int ans = 0;
	for (i = 1; i <= M; i++)
	{
		for (j = 10; j <= D; j++)
		{
			if ((j % 10) <= 1)
				continue;
			if ((j / 10) <= 1)
				continue;
			if (i == ((j % 10) * (j / 10)))
				ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <numeric>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
clock_t __my_start_clock = clock();
#else
#define eprintf(...)
#endif

#define TIMESTAMP(x) eprintf("["#x"] Time : %.3lf s.\n", (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)
#define TIMESTAMPf(x,...) eprintf("[" x "] Time : %.3lf s.\n", __VA_ARGS__, (clock() - __my_start_clock)*1.0/CLOCKS_PER_SEC)

using namespace std;

#ifdef LOCAL
static struct __timestamper {
  string what;
  __timestamper(const char* what) : what(what){};
  __timestamper(const string& what) : what(what){};
  ~__timestamper(){
    TIMESTAMPf("%s", what.data());
	}
} __TIMESTAMPER("end");
#else 
struct __timestamper {};
#endif

typedef long long ll;
typedef long double ld;

int main() {
#ifdef LOCAL
  freopen("a.in", "r", stdin);
  freopen("a.out", "w", stdout);
#endif

  int w, h, a, b;
  while (scanf("%d%d%d%d", &h, &w, &a, &b) == 4) {
    vector<int> rs, cs;
    for (int i = 0; i <= h && rs.empty(); i++) {
      for (int j = 0; j <= w; j++) {
        if (i * a + (h - i) * (w - a) == j * b + (w - j) * (h - b)) {
          rs.resize(h);
          for (int k = 0; k < h; k++) {
            rs[k] = (k < i) ? a : w - a;
          }
          cs.resize(w);
          for (int k = 0; k < w; k++) {
            cs[k] = (k < j) ? b : h - b;
          }
          assert(accumulate(cs.begin(), cs.end(), 0) == accumulate(rs.begin(), rs.end(), 0));
          break;
        }
      }
    }
    if (rs.empty()) {
      printf("-1\n");
      continue;
    }
    vector<int> v(w);
    for (int i = 0; i < w; i++) {
      v[i] = i;
    }
    for (int i = 0; i < h; i++) {
      sort(v.begin(), v.end(), [&](int a, int b) { return cs[a] > cs[b];});
      string s(w, '0');
      for (int j = 0; j < rs[i]; j++) {
        s[v[j]] = '1';
        cs[v[j]]--;
      }
      printf("%s\n", s.data());
    }
  }

  return 0;
}


Measured memory_bytes: 1280
import sys


def insertion_sort(a):
    print(' '.join(map(str, a)))
    for i in range(1, len(a)):
        v = a[i]
        j = i - 1
        while j >= 0 and a[j] > v:
            a[j + 1] = a[j]
            j -= 1
        a[j + 1] = v
        print(' '.join(map(str, a)))


n = int(sys.stdin.readline())
a = [int(v) for v in sys.stdin.readline().strip().split()]
insertion_sort(a)



Measured memory_bytes: 5612
s = input()
p = input()
Ans = False
cnt = 0

for i in range(len(s)):
    for j in range(len(p)):
        if i + j >= len(s):
            i = -j
        if s[i + j] != p[j]:
            break
        cnt += 1
    if cnt == len(p):
        Ans = True
        break
    cnt = 0

if Ans:
    print('Yes')
else:
    print('No')

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

int main() {
    int mp[100][100];
    int w, h, n; scanf("%d%d%d", &w, &h, &n);
    for (int y = 0; y < h; y++) for (int x = 0; x < w; x++) mp[y][x] = 1;
    for (int i = 0 ; i < n; i++) {
        int xi, yi, ai; scanf("%d%d%d", &xi, &yi, &ai);
        switch (ai) {
        case 1:
            for (int y = 0; y < h; y++) {
                for (int x = 0; x < xi; x++) {
                    mp[y][x] = 0;
                }
            }
            break;
        case 2:
            for (int y = 0; y < h; y++) {
                for (int x = xi; x < w; x++) {
                    mp[y][x] = 0;
                }
            }
            break;
        case 3:
            for (int y = 0; y < yi; y++) {
                for (int x = 0; x < w; x++) {
                    mp[y][x] = 0;
                }
            }
            break;
        case 4:
            for (int y = yi; y < h; y++) {
                for (int x = 0; x < w; x++) {
                    mp[y][x] = 0;
                }
            }
            break;
        default:
            break;
        }
    }
    int res = 0;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            res += mp[y][x];
        }
    }
    printf("%d\n", res);
}


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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

ll MOD = (ll) 10939;
const ll MAXN = (ll) 3e2 + 10;
const ll INF = (ll) 1e17;
const ll LOG = 20;

ll dis[MAXN][MAXN];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> dis[i][j];
	ll mn, ans = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			mn = INF;
			for(int k = 1; k <= n; k++){
				if(k == i || k == j) continue;
				mn = min(mn, dis[i][k] + dis[k][j]);
			}
			if(dis[i][j] > mn) return cout << -1, 0;
			if(dis[i][j] < mn) ans += dis[i][j];
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll a, b, c, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
bool flag = false;

/*--------------------template--------------------*/

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

    cin >> a >> b>>c>>k;
	if(a>=k){cout<<k;return 0;}
	if(a+b>=k){cout<<a;return 0;}
	else{k-=(a+b);cout<<a-k;return 0;}
}


Measured memory_bytes: 3636
const MOD: usize = 1_000_000_007;

fn solve(src: &str) -> String {
    let mut sw = src.split_whitespace();
    let n: usize = sw.next().unwrap().parse().ok().unwrap();
    let m: usize = sw.next().unwrap().parse().ok().unwrap();

    let mut ftl = vec![1];
    for i in 1..n+100 {
        let pre = ftl[i-1];
        ftl.push(i * pre % MOD);
    }
    let pat = |n, r| ftl[n+r-1] * inv(ftl[r]) % MOD * inv(ftl[n-1]) % MOD;
    
    let fct = factorize(m);
    let mut ans = 1;
    for &(_, e) in &fct {
        ans *= pat(n, e);
        ans %= MOD;
    }
    format!("{}\n", ans)
}
#[test]
fn test_solve() {
   assert_eq!(solve("2 6\n"), "4\n");
   assert_eq!(solve("3 12\n"), "18\n");
   assert_eq!(solve("100000 1000000000\n"), "957870001\n");
}
fn inv(n: usize) -> usize {
    let mut ret = 1;
    let mut sqt = vec![n; 31];
    for i in 1..31 {
        sqt[i] = sqt[i-1] * sqt[i-1] % MOD;
    }
    let exp = MOD-2;
    for i in 0..31 {
        if 1<<i & exp != 0 {
            ret *= sqt[i];
            ret %= MOD;
        }
    }
    ret
}
fn factorize(n: usize) -> Vec<(usize, usize)> {
    let mut ret = Vec::new();
    let mut n = n;
    let nsr = (n as f64).sqrt() as usize;
    for &p in &primes(nsr+1) {
        let mut c = 0;
        while n % p == 0 {
            c += 1;
            n /= p;
        }
        if c > 0 {
            ret.push((p, c));
        }
    }
    if n > 1 {
        ret.push((n, 1));
    }
    ret
}
fn primes(n: usize) -> Vec<usize> {
    let mut ret = Vec::new();
    let mut ipm = vec![true; n+1];
    let nsr = (n as f64).sqrt() as usize;
    for p in 2..nsr+1 {
        if ipm[p] {
            let mut mpp = 2*p;
            while mpp <= n {
                ipm[mpp] = false;
                mpp += p;
            }
        }
    }
    for p in 2..n+1 {
        if ipm[p] {
            ret.push(p);
        }
    }
    ret
}
fn main() {
    use std::io::{Read, Write};
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}

Measured memory_bytes: 4352
n, m = map(int, input().split())

xy = [i for i in range(n + 1)]


def root(x):
    i = x
    while i != xy[i]:
        i = xy[i]
    xy[x] = i
    return i


for _ in range(m):
    x, y = map(int, input().split()[:2])
    xy[root(x)] = root(y)

ans = sum(i == v for i, v in enumerate(xy)) - 1

print(ans)


Measured memory_bytes: 7088
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<iostream>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

//累乗だってさ
ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}
//逆元だってさ
ll modinv(ll a,ll mod1) {
    return modpow(a, mod1 - 2, mod1);
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,sum=0;
    cin>>n;
    vec<ll> a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll ara=0,snu=sum;
    ll mini=10000000000;
    rep(i,n-1){
        ara+=a[i];
        snu-=a[i];
        mini=min(mini,abs(snu-ara));
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define IT set<node>::iterator
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef long long ll;
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 1e9;
    for(int i = 0; i < s.size() - t.size() + 1; i++) {
        int cnt = 0;
        for(int j = 0, k = i; j < t.size(); j++, k++) {
            if(s[k] == t[j]) cnt++;
        }
        ans = min(ans, int(t.size() - cnt));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

ll n, a[10010], b[10010], ca, cb, cnta, cntb;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ca += a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		cb += b[i];
		if (a[i] - b[i] > 0)cnta += a[i] - b[i];
		else cntb += (b[i] - a[i] + 1) / 2;
	}
	cout << ((cb-ca>=cnta&&cb-ca>=cntb) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.range;
import std.array;
import std.algorithm;
import std.string;
import std.conv;
import std.typecons;
import std.math;
import std.numeric;

void main(){
    int n = readln().chomp().to!int;
    int[] inputs = readln().chomp().split().map!(to!int).array();
    solve(n, inputs).writeln();
}

int solve(int n, int[] inputs){
    return inputs.sum - n;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') a++;
        if (s[i] == 'G') b++;
        if (s[i] == 'B') c++;
    }
    long long ans = a *1ll* b * c;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int k = j + j - i;
            if (k < n && s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) ans--;
        }
    }
    cout << ans << endl;
}


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

int main() {
    int x1,x2,x3,x4,x5;
    rep(i,5){
        cin>>x1;
        if(x1==0){
            cout<<i+1<<endl;
        }
    }
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>
#include<math.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpChar(const void *a,const void *b){
    return (*((char*)a))-(*((char*)b));
};

int main(){
    char str[100];

    my_gets(str,100,stdin);
    qsort(str,strlen(str),sizeof(char),CmpChar);
    if(str[0]==str[1] && str[2]==str[3] && str[1]!=str[2]){
        puts("Yes");
    }
    else{
        puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 128
from heapq import heappush, heappop
N = int(input())
S = []
for i in range(N):
    l, r = map(int, input().split())
    S.append((l, r))

if all(l <= 0 <= r for l, r in S):
    print(0)
    exit(0)

P = sorted(r for l, r in S)
Q = sorted(l for l, r in S)
L = R = 0
ans = 0
for i in range(N):
    if not i < N-1-i:
        break
    L += P[i]
    R += Q[N-1-i]
    ans = max(ans, abs(R - L)*2)
    if i+1 < N-1-i:
        ans = max(ans, abs(R - L - P[i+1])*2)
    if i < N-1-i-1:
        ans = max(ans, abs(R + Q[N-1-i-1] - L)*2)
print(ans)


Measured memory_bytes: 18976
import java.util.*;
public class Main {
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if((a|b|c) == 0) break;
			boolean flg = false;
			int ansx = -1, ansy = -1, ans = Integer.MAX_VALUE;
			for(int i = 0; ; i++){
				for(int j = 0; j <= i; j++){
					int x = j;
					int y = i - j;
					if(a * x + b * y == c){
						flg = true;
						if(ans > a * x + b * y){
							ans = a * x + b * y;
							ansx = x;
							ansy = y;
						}
					}
					else if(a * x == b * y + c){
						flg = true;
						if(ans > a * x + b * y){
							ans = a * x + b * y;
							ansx = x;
							ansy = y;
						}
					}
					else if(b * y == a * x + c){
						flg = true;
						if(ans > a * x + b * y){
							ans = a * x + b * y;
							ansx = x;
							ansy = y;
						}
					}
				}
				if(flg) break;
			}
			System.out.println(ansx + " " + ansy);
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <cstdio>
using namespace std;

int N;
char a[12];
char ans[12];
int main(void)
{
	int i;
	int cursor = 0;
	
	scanf("%s", a);
	for (i = 0; a[i]; i++)
	{
		if (a[i] == '0') ans[cursor++] = '0';
		else if (a[i] == '1') ans[cursor++] = '1';
		else if (a[i] == 'B' && cursor) ans[--cursor] = '\0';
	}

	printf("%s\n", ans);


	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100000;
int n;
string s;

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> s;

    int ans = 0;
    int i = 0;
    while(i < n) {
        int len = 1;
        while(i+len < n && s[i+len] == s[i]) len++;
        ans++;
        i += len;
    }

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
     #include <iomanip> 
    using namespace std;
     
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       long long int a,s;
      long double b;
        cin>>a>>b;
      // cout<<a<<" "<<b<<endl;
        s=a*b;
        cout<<s<<endl;
        
        return 0;
    }

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int mod =1e9 +7;
int main()
{
  long long int n,k,ans=0;
  cin>>n>>k;
  for(int i=k; i<=n+1; i++)
  {
    long long int low,high;
    low=i*(i-1);
    low/=2;
    high=low+i*(n+1-i);
    ans+=high-low+1;
    ans%=mod;
  }
    cout<<ans;
}

Measured memory_bytes: 3640
class UnionFindNode:
    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value = value
        self.rank_ = 1
        self.member_num_ = 1

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                n_root, child = root, unite_root
            else:
                n_root, child = unite_root, root
            child.parent_ = n_root
            n_root.rank_ = max(n_root.rank_, child.rank_ + 1)
            n_root.member_num_ = n_root.member_num_ + child.member_num_


if __name__ == "__main__":
    N,M=[int(i) for i in input().strip().split()]
    nodes = [UnionFindNode(i) for i in range(N)]
    import sys
    qs = []
    for _ in range(M):
        x, y = map(int, input().split())
        x, y = x-1, y-1
        qs.append((x, y))
    qs = qs[::-1]
    ff = N*(N-1)//2
    rs = []
    for a, b in qs:
        rs.append(ff)
        if nodes[a].root().group_id_ == nodes[b].root().group_id_:
            continue
        ff -= nodes[a].root().member_num_ * nodes[b].root().member_num_
        nodes[a].unite(nodes[b])
    for r in rs[::-1]:
        print(r)


Measured memory_bytes: 91296
#include<iostream>
#include <string>

using namespace std;

int main()
{
	cin.tie(0);ios::sync_with_stdio(false);
	/* ====================================== */
	int N, K;
	cin >> N >> K;
	string n = "NO";
	string y = "YES";

	if((N+1)/2 >= K){
	cout << y;

	}else{
	cout << n;

	}

	/* ====================================== */
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//小数点以下　cout << fixed << setprecision(10) << num << endl;

int main(){
    int n;  cin >> n;
    ll a[n];
    ll sum[n];
    sum[0]=0;
    rep(i,n){
        cin >> a[i];
        sum[i+1]=sum[i]+a[i];
    }
    int j=n;
    ll ans = 0;
    rep(i,n){
        if(sum[n]/2 <= sum[i]){
            j = i;
                break;
        }
    }
    ans = sum[j]*2-sum[n];
    if(j>0) ans = min(ans,sum[n]-sum[j-1]*2);
    cout << ans << endl;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
#ifdef DBG
#define dbg(...) {cerr<<"\033[96;1m";ostream& cout=cerr;__VA_ARGS__;\
(void)(cout);cerr<<"\033[0m";}
#else
#define dbg(...)
#endif
#define st first
#define nd second
#define flg(...) __LINE__, __PRETTY_FUNCTION__
#define mkp(...) make_pair(__VA_ARGS__)
#define prt(...) print(cout, __VA_ARGS__)
#define dprt(...) dbg(prt(__VA_ARGS__))
#define dmp(...) prt(#__VA_ARGS__, __VA_ARGS__)
#define ddmp(...) dbg(dmp(__VA_ARGS__))
#define all(...) begin(__VA_ARGS__), end(__VA_ARGS__)
using namespace std; using ll = long long;
template<typename... t>using V=vector<t...>;
template<typename t>void print(ostream& os, const t& a){os<<a<<'\n';}
template<typename t, typename... v>void print(ostream& os, const t& a,
v&&... b){os<<a<<' ';print(os, b...);}
template<typename t>void inp(t& a){cin >> a;}
template<typename t, typename... v>void inp(t& a, v&... b){cin >> a;inp(b...);}



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, res = 1e9; string s;
    inp(n, s);
    int su = 0;
    for (char c : s)
        su += (c == 'E');
    for (char c : s)
    {
        su -= (c == 'E');
        res = min(res, su);
        su += (c == 'W');
    }
    prt(res);
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<string> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  int M;
  cin >> M;
  string b;
  for(int i = 0; i < M; i++) {
    cin >> b;
    data.push_back(b);
  }
  string a;
  int ans = 0, count = 0;
  for(int i = 0; i < N; i++) {
    a = data.at(i);
    count = 1;
    for(int j = 0; j < N - i - 1; j++) {
      if(a == data.at(j + i + 1)) count++;
    }
    for(int j = 0; j < M; j++) {
      if(a == data.at(N + j)) count--;
    }
    if (count > ans) ans = count;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256