akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//D: 6/2(1+2)
public class Main{

	public static String s;
	public static int index;
	
	public static char c(){
		return s.charAt(index++);
	}
	
	@SuppressWarnings("unchecked")
	public static Set<Integer> calc(List<Set<Integer>> list, List<Character> ope){
		int n = list.size();
		Set<Integer>[][] dp = new Set[n][n];
		for(int i=0;i<n;i++)dp[i][i]=list.get(i);
		for(int w=1;w<n;w++){
			for(int i=0;i+w<n;i++){
				Set<Integer> res = new HashSet<Integer>();
				for(int k=i;k<i+w;k++){
					for(int x : dp[i][k]){
						char ch = ope.get(k);
						for(int y : dp[k+1][i+w]){
							switch(ch){
							case '+': res.add(x+y);break;
							case '-': res.add(x-y);break;
							case '*': res.add(x*y);break;
							case '/': if(y==0)break;else res.add(x/y);break;
							}
						}
					}
				}
				dp[i][i+w] = res;
			}
		}
		return dp[0][n-1];
	}
	
	public static Set<Integer> exp(){
		List<Set<Integer>> list = new ArrayList<Set<Integer>>();
		List<Character> ope = new ArrayList<Character>();
		while(true){
			char ch = c();
			if(Character.isDigit(ch)){
				index--;
				Set<Integer> a = new HashSet<Integer>();
				a.add(num());
				list.add(a);
			}
			else if(ch=='('){
				list.add(kakko());
			}
			else if(ch=='$')break;
			else {
				ope.add(ch);
			}
		}
		return calc(list, ope);
	}
	
	public static Set<Integer> kakko(){
		List<Set<Integer>> list = new ArrayList<Set<Integer>>();
		List<Character> ope = new ArrayList<Character>();
		while(true){
			char ch = c();
			if(ch=='('){
				list.add(kakko());
			}
			else if(Character.isDigit(ch)){
				index--;
				Set<Integer> a = new HashSet<Integer>();
				a.add(num());
				list.add(a);
			}
			else if(ch==')'||ch=='$') break;
			else {
				ope.add(ch);
			}
		}
		return calc(list, ope);
	}
	
	public static int num(){
		char ch = c();
		int ans = ch-'0';
		while(Character.isDigit(ch)){
			ch = c();
			if(!Character.isDigit(ch))break;
			ans *= 10;
			ans += ch-'0';
		}
		index--;
		return ans;
	}
	
	public static void main(String[] args) {
		boolean debug = true;
		if(!debug){
			try {
				System.setOut(new PrintStream(new File("./src/icpc/D.txt")));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		Scanner sc = new Scanner(System.in);
		while(true){
			s = sc.next();
			if(s.equals("#"))break;
			s = s+"$";
			index = 0;
			System.out.println(exp().size());
		}
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

int main(){
  
  long long X, K, D, kh1, kh2, sh;
  cin>>X>>K>>D;
   
  X=abs(X);
  sh=X/D;
  kh1=X%D;
  kh2=D-kh1;
  
  if(sh>=K){
    cout<<X-K*D<<endl;
    return 0;
  }
  
  if((K-sh)%2==0){
    cout<<kh1<<endl;
  }else{
    cout<<kh2<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define um unordered_map
#define fi first
#define se second

int main()
{   
   fast;
    
    ll n; cin>>n;
    
    vector<ll> dp(3);
    
    for(ll i=0; i<n; i++)
    {
        vector<ll> curr(3, 0);
        vector<ll> arr(3);
        
        for(ll j=0; j<3; j++)
        cin>>arr[j];
        
        for(ll j=0; j<3; j++)
        {
            for(ll k=0; k<3; k++)
            {
                if(j!=k){
                    curr[k]=max(curr[k], dp[j] + arr[k]);
                }
            }
        }

        dp=curr;
    }
    cout<<max(dp[0], max(dp[1], dp[2]))<<endl;
    return 0;
}
/*
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define um unordered_map
#define fi first
#define se second

int main()
{   
   fast;
    
    ll n; cin>>n;
    vector<ll> dp(3);
    
    for(ll day=0; day<n; day++)
    {
        vector<ll> curr(3,0);
        vector<ll> arr(3);
        for(ll i=0; i<3; i++)
            cin>>arr[i];
        
        for(ll i=0; i<3; i++)
        {
            for(ll j=0; j<3; j++)
            {
                if(i!=j)
                {
                    curr[j] = max(curr[j], dp[i] + arr[j]);
                }
            }
        }
        dp=curr;
    }
    
    cout<<max(dp[0], max(dp[1], dp[2]))<<endl;
    
    return 0;
} */



Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define all(x) x.begin(), x.end()
#define watch(x) cout<<#x<<" : "<<x<<endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define testCases int tt;cin>>tt; while(tt--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef vector<string> vs;

int main() {
    fastio;
    int n,x,t;
    cin >> n >> x >> t;
    if (n%x) {
        cout << ((n/x)+1)*t << endl;
    } else {
        cout << (n*t)/x << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define N 10
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
#define Mod(x) (((x) % mod + mod) % mod)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (998244353);
char c[maxn][maxn];
int main(){
    int h,w,k;scanf("%d%d%d",&h,&w,&k);
    for(int i = 1;i <= h;i++){
        scanf("%s",c[i] + 1);
    }
    int tth = (1<<h),ttw = (1<<w);
    int ans = 0;
    for(int si = 0;si < tth;si++){
        for(int wi = 0;wi < ttw;wi++){
            int cnt = 0;
            for(int i = 1;i <= h;i++){
                if((1<<(i - 1)) & si)continue;
                for(int j = 1;j <= w;j++){
                    if((1<<(j - 1) & wi))continue;
                    cnt += (c[i][j] == '#');
                }
            }
            if(cnt == k)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

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

int main()
{
  int P,Q,R;
  cin >> P >> Q >> R;
  int x,y,z;
  x = P+Q;
  y = Q+R;
  z = R+P;
  cout << min(min(x,y),min(y,z)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mood = 1e9 + 7;
long long arr[maxn];
bool cmp(long long i, long long j)
{
	return abs(i) > abs(j);
}
inline long long pp(long long x)
{
	return (x + mood) % mood;
}
long long cl()
{
	int n, kk, tot = 0;
	long long ans = 1LL;
	scanf("%d%d", &n, &kk);
	for(int i = 1; i <= n; i ++)
	{
		scanf("%lld", &arr[i]);
	}
	
	sort(arr + 1, arr + 1 + n, cmp);
	int cnt = 0; 
	for(int i = 1; i <= kk; i ++){
		if(arr[i] < 0){
			cnt ++;
		}
	}
	
	if(cnt % 2 == 0)
	{
		for(int i = 1; i <= kk; i ++)
		{
			ans *= (arr[i] + mood);
			ans %= mood;
		}
		return ans;
	}
	else
	{
		long long negbef, negaft, posbef, posaft;
		int wzngbef=-1, wzngaft=-1, wzpsbef=-1, wzpsaft=-1;
		for(int i = kk; i >= 1; i --){
			if(arr[i] < 0){
				negbef = arr[i]; wzngbef = i; break;
			}
		} 
		for(int i = kk; i >= 1; i --){
			if(arr[i] > 0){
				posbef = arr[i]; wzpsbef = i; break;
			}
		} 
		for(int i = kk+ 1; i <= n; i ++){
			if(arr[i] < 0){
				negaft = arr[i]; wzngaft = i; break;
			}
		}
		for(int i = kk+ 1; i <= n; i ++){
			if(arr[i] > 0){
				posaft = arr[i]; wzpsaft = i; break;
			}
		}
		if(wzngbef !=-1 && wzngaft !=-1 && wzpsbef !=-1 && wzpsaft!=-1)
		{
			if(negbef * negaft > posbef * posaft){
				arr[wzpsbef] = arr[wzngaft];
//				ans *= (negbef * negaft % mood);
//				ans %= mood;
			}
			else{
				arr[wzngbef] = arr[wzpsaft];
//				ans *= (posbef * posaft % mood);
//				ans %= mood;
			}
			
			for(int i = 1; i <= kk; i ++){
					ans *= pp(arr[i]);
					ans %= mood;
			}
			return ans;
		}
		if((wzngbef != -1 && wzpsaft != -1) || (wzpsbef != -1 && wzngaft != -1)){
			if((wzngbef != -1 && wzpsaft != -1) ){
				arr[wzngbef] = arr[wzpsaft];
			}
			else if((wzpsbef != -1 && wzngaft != -1)) {
				arr[wzpsbef] = arr[wzngaft];
			}
			
			for(int i = 1; i <= kk; i ++){
					ans *= pp(arr[i]);
					ans %= mood;
			}
			return ans;
		}
				//cout << posbef <<" "<<posit(negaft)<<"\n";
//		cout <<ans<<" "<< wzngbef<<" "<<wzngaft<<" "<<wzpsbef<<" "<<wzpsaft<<endl;
		for(int i = n - kk + 1; i <= n; i ++){
			ans *= (arr[i] + mood);
			ans %= mood;
		}
		return ans;
	}
	
	
}
int main()
{
	printf("%lld\n", cl());
	return 0;
} 

/*5 3
9 -4 8 -2 -5

5 3
9 8 -5 -4 -2
6 4
-1000000000 -1000000000 -1000000000 999999999 999999999 9999999999
6 3
6 5 -4 -3 -2 -1
*/

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int k,a,b;cin>>k>>a>>b;
    for(int i=a;i<=b;++i){
        if(i%k==0){
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X, Y, A, B, C, ans = 0;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> r, g, v;
    priority_queue<ll, vector<ll>, greater<ll>> que;
    for(ll i = 0; i < A; i++) {
        ll tmp;
        cin >> tmp;
        r.push_back(tmp);
    }
    for(ll i = 0; i < B; i++) {
        ll tmp;
        cin >> tmp;
        g.push_back(tmp);
    }
    for(ll i = 0; i < C; i++) {
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(RALL(r));
    sort(RALL(g));
    sort(RALL(v));
    for(ll i = 0; i < X; i++) {
        que.push(r[i]);
    }
    for(ll i = 0; i < Y; i++) {
        que.push(g[i]);
    }
    for(ll i = 0; i < C; i++) {
        if(que.top() < v[i]) {
            que.pop();
            que.push(v[i]);
        }
    }
    while(que.size()) {
        ans += que.top(), que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 4852
import java.util.Scanner;

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

        int sum = 0;
        for (int i = 0; i < attackNumber; i++) {
            sum += scanner.nextInt();
        }
        if (sum >= health) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 49180
#include <stdio.h>
#include <memory.h>
typedef struct T{
    char team;
    int win;
    int lose;
}T;
int main(void){
    int num,i,o,n;
    T t[10],temp;
    for(;memset(t,0,sizeof(t)),scanf("%d",&num),num;){
        for(i=0;i<num;i++){
            scanf("\n%c",&t[i].team);
            for(o=0;o<num-1;o++){
                scanf("%d",&n);
                if(n == 0)
                    t[i].win++;
                else if(n == 1)
                    t[i].lose++;
            }
        }
        for(i=1;i<num;i++){
            o=i;
            temp=t[i];
            while(o>0){
                if(temp.win > t[o-1].win){
                    t[o]=t[o-1];
                    o--;
                }
                else if(temp.win == t[o-1].win && temp.lose < t[o-1].lose){
                    t[o]=t[o-1];
                    o--;
                }
                else
                    break;
            }
            t[o]=temp;
        }
        for(i=0;i<num;i++)
            printf("%c\n",t[i].team);
    }
    return 0;
}
            


                    

Measured memory_bytes: 600
N = gets.to_i
A = gets.split.map(&:strip).map(&:to_i)

@m = 1000
@k = 0
p = A[0]
s = 'buy'

def buy(i)
  @k += @m / A[i]
  @m -= @k * A[i]
end

def sell(i)
  @m += @k * A[i]
  @k = 0
end

N.times do |i|
  begin
    if s == 'buy'
      if A[i] <= p
        next
      else
        buy(i-1)
        s = 'sell'
      end
    else
      if A[i] >= p
        next
      else
        sell(i-1)
        s = 'buy'
      end
    end
  ensure
    p = A[i]
    if i == N - 1
      sell(i)
    end
  end
end

puts "#{@m}"


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

namespace ConsoleApplication1
{
    class NQueens
    {
        readonly int n;

        List<KeyValuePair<int, int>> qPos;
        int[] row;
        bool[] col, dpos, dneg;

        public NQueens(int N)
        {
            n = N;

            qPos = new List<KeyValuePair<int, int>>();
            row = new int[n];
            col = new bool[n];
            dpos = new bool[2 * n - 1];
            dneg = new bool[2 * n - 1];
        }

        public void SetQueen(int i, int j)
        {
            qPos.Add(new KeyValuePair<int, int>(i, j));
        }

        public void Solve(int i)
        {
            if (i == n)
            {
                PrintBoard();
                return;
            }

            for (int j = 0; j < n; j++)
            {
                if (IsValid(i, j)) continue;

                ChangeBoard(i, j, true);
                Solve(i + 1);
                ChangeBoard(i, j, false);
            }
        }

        private void ChangeBoard(int i, int j, bool isSet)
        {
            row[i] = isSet ? j : -1;
            col[j] = isSet;
            dpos[i + j] = isSet;
            dneg[i - j + n - 1] = isSet;
        }

        private bool IsValid(int i, int j)
        {
            if (col[j]) return true;
            if (dpos[i + j]) return true;
            if (dneg[i - j + n - 1]) return true;
            return false;
        }

        public void PrintBoard()
        {
            bool isCorrect = true;
            int m = qPos.Count;

            for (int i = 0; i < m; i++)
            {
                int index = qPos[i].Key;
                if (row[index] != qPos[i].Value) isCorrect = false;
            }

            if (!isCorrect) return;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    sb.Append(row[i] == j ? "Q" : ".");
                }
                sb.AppendLine();
            }
            Console.Write(sb);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            NQueens Q = new NQueens(8);

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int h = int.Parse(input[0]);
                int w = int.Parse(input[1]);

                Q.SetQueen(h, w);
            }

            Q.Solve(0);
        }
    }
}

Measured memory_bytes: 9060
N, M = map(int, input().split())
X = [int(i) for i in input().split()]
X.sort()
if N>=M:
    print(0)
else:
    dst = [0]*(M-1)
    for i in range(M-1):
        dst[i] = X[i+1]-X[i]
    dst.sort(reverse=True)
    ans = X[M-1]-X[0]-sum(dst[:N-1])
    print(ans)

Measured memory_bytes: 13840
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	typedef pair<int, pint> E;
	priority_queue<E> q;
	int N = in();
	rep(y,N)rep(x,N) {
		int A = in();
		if (A && y < x) q.push(mp(-A, mp(y, x)));
	}
	
	int dist[310][310];
	rep(i,310)rep(k,310)dist[i][k] = INF;
	rep(i,310)dist[i][i] = 0;
	ll ans = 0;
	while (! q.empty()) {
		E e = q.top();
		q.pop();
		int c = -e.first;
		int u = e.second.first;
		int v = e.second.second;
		
		int sp = INF;
		rep(i,N) sp = min(sp, dist[u][i] + dist[i][v]);
		if (sp < c) goto NG;
		dist[u][v] = dist[v][u] = c;
		if (sp == c) continue;
		ans += c;
		rep(i,N) {
			dist[u][i] = min(dist[u][i], dist[u][v] + dist[v][i]);
			dist[i][u] = dist[u][i];
			dist[v][i] = min(dist[v][i], dist[v][u] + dist[u][i]);
			dist[i][v] = dist[v][i];
		}
	}
	
	cout << ans << endl;
	return 0;
	
	NG:;
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

string s;
ll solve(string s) {

}

int main() {
	cin >> s;
	ll ans = 0;
	rep(i, (1 << (s.size() - 1))) {
		ll num = 0;
		rep(j, s.size()) {
			num += (s[j] - '0');
			if (i & (1 << j)) {
				num *= 10;
			}
			else {
				ans += num;
				num = 0;
			}
			//cout << ans << " " << num << endl;
		}
		//cout << ans << " " << num << endl;
		ans += num;
	}
	cout << ans << endl;
}

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

#define fi first
#define se second

const int K = 100100;

using namespace std;

int solve(vector < pair < int, int > > v)
{
        int n = v.size();
        vector < pair < int, int > > l(n), r(n);
        l[0] = v[0];
        r[n - 1] = v[n - 1];
        for(int i = 1; i < n; i++){
                l[i].fi = max(l[i - 1].fi, v[i].fi);
                l[i].se = min(l[i - 1].se, v[i].se);
        }
        int res = 0;
        for(int i = n - 2; i >= 0; i--){
                r[i].fi = max(r[i + 1].fi, v[i].fi);
                r[i].se = min(r[i + 1].se, v[i].se);
                res = max(res, max(0, l[i].se - l[i].fi + 1) + max(0, r[i + 1].se - r[i + 1].fi + 1));
        }
        for(int i = 1; i < n - 1; i++){
                pair < int, int > p = l[i - 1];
                p.fi = max(p.fi, r[i + 1].fi);
                p.se = min(p.se, r[i + 1].se);

                res = max(res, v[i].se - v[i].fi + 1 + max(0, p.se - p.fi + 1));
        }
        return res;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        int n;
        cin >> n;
        vector < pair < int, int > > a(n);
        for(int i = 0; i < n; i++){
                cin >> a[i].fi >> a[i].se;
        }
        sort(a.begin(), a.end());
        int res = solve(a);
        sort(a.begin(), a.end(), [](pair < int, int > x, pair < int, int > y){
             return x.se < y.se;
             });
        cout << max(res, solve(a)) << "\n";
}


Measured memory_bytes: 3456
n = int(input())
s = [input() for _ in range(n)]

res = {'AC': s.count('AC'),
       'WA': s.count('WA'),
       'TLE': s.count('TLE'),
       'RE': s.count('RE')
       }

for k in res:
    print(f'{k} x {res[k]}')



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


signed main(){
    string S;
    cin>>S;
    bool ok=true;
    map<char,int>memo;
    REP(i,S.size()){
        memo[S[i]]++;
    }
    for(auto it=memo.begin();it!=memo.end();it++){
        if(it->second%2==1)ok=false;
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

int main()
{
	string S;
	cin >> S;

	string ans = "No";
	int c = 0;
	for( int i = 0; i < S.size(); i++ ) {
		if( c ) {
			if( S[i] == 'F' ) {
				ans = "Yes";
			}
		}
		else {
			if( S[i] == 'C' ) {
				c = 1;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

lin n,a[100000];

lin lcm(lin x, lin y)
{
    if(x < y)
        return lcm(y,x);

    lin z = x % y;
    if(z == 0)
        return y;

    return lcm(y,z);
}

int main(void)
{
    cin >> n;
    rep(i,n)
    {
        cin >> a[i];
    }

    lin res = a[n-1];

    rep(i,n-1)
    {
        res = lcm(a[i], res);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
local s = io.read()
local a = {}
for i = 1, 4 do
  a[i] = tonumber(s:sub(i, i))
end
for i = 0, 7 do
  local sum = a[1]
  local ti = i
  sum = sum + a[2] * (2 * (ti % 2) - 1)
  ti = ti // 2
  sum = sum + a[3] * (2 * (ti % 2) - 1)
  ti = ti // 2
  sum = sum + a[4] * (2 * (ti % 2) - 1)
  if sum == 7 then
    io.write(a[1])
    local z = i
    for k = 2, 4 do
      io.write(z % 2 == 0 and "-" or "+")
      io.write(a[k])
      z = z // 2
    end
    io.write("=7\n")
    break
  end
end


Measured memory_bytes: 760
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
ll r=1;
a=a%m;
while(b>0)
{
if(b&1)
r=(r*a)%m;
b=b/2;
a=(a*a)%m;
}
return r%m;
}

vi bit;//1-based indexing

void bit_update(ll x,ll n,ll val)
{
    while(x<n)
    {
        bit[x]+=val;
        x+=(x&(~x+1));
    }
}

ll bit_sum(ll x)
{
    ll sum=0;
    while(x>0)
    {
        sum+=bit[x];
        x-=(x&(~x+1));
    }
    return sum;
}



int main(){
    IOS
    string s,t;
    cin>>s>>t;
    int c=0;
    rep(i,0,3)
    {
        if(s[i]==t[i])c++;
    }
    cout<<c;




    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
for i in range(n-1):
  if a[i]>=2:
    ans += a[i]//2
    a[i] = a[i]%2
  if a[i]==1:
    if a[i+1]>=1:
      ans += 1
      a[i] -= 1
      a[i+1] -=1
ans = ans +a[n-1]//2
print(ans)
     

Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(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; }

int main () {
  string s, t;
  cin >> s >> t;
  int S = sz(s);
  int T = sz(t);

  auto match = [&](int k) {
    // 0 <= k <= S-T
    rep(i,T) {
      if (t[i] != s[i+k] && s[i+k] != '?') return false;
    }
    return true;
  };

  auto construct = [&](int k) {
    string ans = s;
    rep(i,T) ans[k+i] = t[i];
    rep(i,S) {
      if (ans[i] == '?') ans[i] = 'a';
    }
    return ans;
  };

  int k = -1;
  rep(i,S-T+1) {
    if (match(i)) k = i;
    //break; // 前の方の'?'ほど'a'にした方がよい
  }

  if (k == -1) cout << "UNRESTORABLE" << endl;
  else cout << construct(k) << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect

def solve(N: int, M: int, P: "List[int]", Y: "List[int]"):
    # もとの値
    val = [[] for i in range(N+1)]
    for pi, yi in [[P[i], Y[i]] for i in range(M)]:
        val[pi].append(yi)

    for i in val:
        i.sort()


    a = sorted([[P[i], Y[i]] for i in range(M)], key=lambda x:(x[0],x[1]))

    for p, y in [[P[i], Y[i]] for i in range(M)]:
        c_id = bisect.bisect_left(val[p], y)
        print(str(p).zfill(6)+str(c_id+1).zfill(6))
    
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [int()] * (M)  # type: "List[int]" 
    Y = [int()] * (M)  # type: "List[int]" 
    for i in range(M):
        P[i] = int(next(tokens))
        Y[i] = int(next(tokens))
    solve(N, M, P, Y)

if __name__ == '__main__':
    main()


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

int main() {
    int k, a, b;
    cin >> k >> a >> b;
    if(a <= b/k*k) cout << "OK" << endl;
    else cout << "NG" << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll n,k;

ll pow_mod(ll a,ll b){
  if(b==1){
    return a;
  }
  else if(b%2==1){
    return (a*pow_mod(a,b-1))%MOD;
  }
  else{
    ll t=pow_mod(a,b/2);
    return t*t%MOD;
  }
}

vl memo(100005,-1);
ll cnt_gcd(ll i){
  if(memo[i]==-1){
    ll a=pow_mod(k/i,n);
    ll j=1;
    while(i+i*j<=k){
      a-=cnt_gcd(i+i*j);
      a=(a+MOD)%MOD;
      j++;
    }
    memo[i]=a;
    return a;
  }
  else
    return memo[i];
}

int main() {
  cin >> n >> k;
  ll ans=0;
  for(int i=k;i>=1;i--){
    ans=(ans+i*cnt_gcd(i))%MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3884
def main():
    s = input()
    cond = s[2] == s[3] and s[4] == s[5]
    print('Yes' if cond else 'No')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 2940
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
    let [N, x] = lines[0].split(" ").map(v=>v-0);
    const list = lines[1].split(" ").map(v=>v-0).sort((a,b)=>a-b);
    let ans = 0;
    for(let i=0;i<N;i++){
        if(x<=0){break;}
        x -= list[i];
        if(x>=0) ans++;
    }
    if(x>0) {ans--;}
    console.log(Math.max(0,ans));
    
});


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

using namespace std;
int main(void){
    int n;
    cin >> n;
    string cmd;
    int cn;
    int lp=0;
    vector<int> vec;
    for(int i=0;i<n;i++){
        cin >> cmd;
        if(cmd=="insert" or cmd=="delete") cin >> cn;
        //cout << cmd << " " << cn << endl;
        
        if(cmd=="insert") vec.push_back(cn);
        if(cmd=="deleteFirst") vec.pop_back();
        if(cmd=="deleteLast") lp++;
        if(cmd=="delete"){
            for(int j=vec.size()-1;j>=lp;j--){
                if(vec[j]==cn){
                    vec.erase(vec.begin() + j);
                    break;
                }
            }
        }        

        /*for(int j=vec.size()-1;j>lp;j--){
            cout << vec[j] << " ";
        }
        cout <<vec[lp]<< endl;*/
    }

        for(int j=vec.size()-1;j>lp;j--) cout << vec[j] << " ";
        cout <<vec[lp]<< endl;    
}



Measured memory_bytes: 7064
use proconio::input;

const MOD : i64 = 998244353;

fn solve(a: usize, b: usize, c: usize, d: usize) -> i64 {
    let mut dp = vec![vec![[0; 2]; d + 1]; c + 1];
    dp[a][b][1] = 1;
    for i in a..=c {
        for j in b..=d {
            if i+1 <= c {
                dp[i+1][j][1] = (dp[i+1][j][1] + dp[i][j][1] * j as i64) % MOD;
                dp[i+1][j][1] = (dp[i+1][j][1] + dp[i][j][0]) % MOD;
            }
            if j+1 <= d {
                dp[i][j+1][0] = (dp[i][j+1][0] + (dp[i][j][0] + dp[i][j][1]) * i as i64) % MOD;
            }
        }
    }
    (dp[c][d][0] + dp[c][d][1]) % MOD
}

fn main() {
    input! {
        a : usize,
        b : usize,
        c : usize,
        d : usize
    };
    println!("{}", solve(a, b, c, d));
}


Measured memory_bytes: 142676
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int a[100000000];
	
int main(){
	long n;
	scanf(" %ld", &n);
	for(long i=0; i<n; ++i) scanf(" %d", &a[i]);
	sort(a, a+n);
	
	long p[300];
	int now=0;
	int limit=15;
	
	if(limit>n) limit=n;
	
	for(int i=0; i<limit; ++i){
		for(int j=0; j<limit; ++j){
			if(i==j) continue;
			stringstream tmp;
			tmp<<a[i];
			tmp<<a[j];
			//cout<<tmp.str()<<endl;
			tmp>>p[now++];		
		}
	}
	
	sort(p, p+now);
	
	printf("%ld\n", p[2]);
}

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

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny") cout << "Cloudy" << endl;
    else if (s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import numpy as np
    import sys
    input = sys.stdin.readline
    N, K = map(int,input().split())
    A = np.sort(list(map(int,input().split())))
    F = np.sort(list(map(int,input().split())))[::-1]

    if K >= np.sum(A)*N:
        print(0)
        exit()
    ma = A[-1]*F[0]
    mi = 0
    A = A*F
    while ma != mi:
        tgt = (ma + mi)//2
        tmp = np.ceil((A-tgt)/F)
        if np.sum(tmp[tmp>0]) <= K:
            ma = (ma + mi)//2
        else:
            mi = (ma + mi)//2+1
    print(ma)
if __name__ == '__main__':
    main()


Measured memory_bytes: 37484
n = int(input())
list_h = list(map(int, input().split()))

# 右から左へ走査する
for i in reversed(range(1, n)):
    l, r = list_h[i-1], list_h[i]

    #左が小さい場合
    if l <= r:
        continue

    #一個だけ左が大きい場合
    elif l - 1 == r:
        list_h[i-1] = list_h[i-1] -1
        continue

    #あかんパターン
    else:
        print("No")
        exit()

print("Yes")

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


using namespace std;


#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search  >
#define lower(arr,n,fixed) lower_bound(arr,arr+n,fixed)-arr  //Lower value search  >=
#define FOR(i,a,n) for(int i=a; i<(int)n; i++)
#define FORI(i,a,n) for(int i=a; i>=(int)n; i--)
#define pii pair<int,int>
#define vpii vector<pii>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define all(a) a.begin(), a.end()
#define MEMSET(p,i) memset(p,i,sizeof(p))





int main(void)
{
	fastIO();

	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int ans = a+b+c;
	int maior = max(a,max(b,c));
	ans -= maior;

	FOR(i,0,k)
	{
		maior *= 2;
		
	}

	ans += maior;

	cout << ans << endl;

	

	return 0;
}


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


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

ll gcd(ll a, ll b) {
	ll c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

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

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

const ll mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0):x(x%mod){}
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
};

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	int n,m;
	cin >> n>>m;
	vector<int> ab(n+1,true);
	rep(i, m) {
		int a; cin >> a;
		ab[a] = false;
	}
	vector<ll> dp(n + 1);
	dp[0] = 1;
	rep(i, n) {
		for (int j = i + 1; j <= min(n, i + 2); j++) {
			if (ab[j]) {
				dp[j] += dp[i];
				dp[j] %= mod;
			}
		}
	}
	cout << dp[n];
	return 0;
}










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

int main(){
    long N; cin>>N;

    long count = 0;
    long p[N];
    rep(i, N) cin>>p[i];

    rep(i, N){
        if(p[i] == i+1){
            count++;
            if(i < N-1 && p[i+1] == i+2) i++;
        }
    }

    cout << count << endl;
}


Measured memory_bytes: 4392
MOD = 10**9 + 7

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  # 重複組合せ: x_1 + ... + x_n = r
        return self.ncr(n + r - 1, n - 1)

N, K = map(int, input().split())
A = list(map(int, input().split()))
comb = Combination(N + 100)
A.sort()

ans = 0
for i, a in enumerate(A):
    ans += a * comb.ncr(i, K - 1)
    ans -= a * comb.ncr(N - i - 1, K - 1)
    ans %= MOD
print(ans)


Measured memory_bytes: 25496
#include<stdio.h>
int main(){
  int H,W,i,j;
  for(;;){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)break;
    for(j=0;j<H;j++){
      for(i=0;i<W;i++){
      printf("#");
    }printf("\n");
    } printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
from itertools import *

n = list(map(int,input().split()))
mm =[]
list1 = []
kei  = []

for x in range(n[2]):
    m = list(map(int,input().split()))
    mm.append(m)

for x in range(n[1]):
    list1.append(x+1)

a = list(combinations_with_replacement(list1,n[0]))

for x in range(len(a)):
    count = 0
    for l in range(n[2]):
        if a[x][int(mm[l][1]-1)] - a[x][int(mm[l][0]-1)] == int(mm[l][2]):
            count += int(mm[l][3])
    kei.append(count)

print(max(kei))

Measured memory_bytes: 86236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	class Node {
		int parent;
		public Node(int x) {
			this.parent = x;
		}
	}
	
	class DisjointSet {
		Node[] p;
		int[] rank;
		
		public DisjointSet(int size) {
			p = new Node[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = new Node(x);
			rank[x] = 0;
		}
		
		private int findSet(int x) {
			while (x != p[x].parent) {
				x = p[x].parent;
			}
			return x;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y].parent = x;
			} else {
				p[x].parent = y;
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x = Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 61692
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] a = new long[n+1];
      for(int i = 1;i <= n;i++)a[i]=sc.nextInt();
      Arrays.sort(a);
      long[] sum = new long[n+1];
      int cnt = 1;
      for(int i = 1;i <= n;i++)sum[i]=sum[i-1]+a[i];
      for(int i = n;i>=2;i--){
      	if(a[i]<=sum[i-1]*2)cnt++;
        else break;
      }
      System.out.println(cnt);
    }
}


Measured memory_bytes: 61420
#include <stdio.h>
#include <string.h>
int main (void){
    char s[100] = {0};
    int i;
    int n;
    scanf("%s",s);
    n = strlen(s);
    for(i=0;i<n-8;i++){
        printf("%c",s[i]);
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
const int val[]={0,2,5,63,20,30};

int N,a[20005];
LL sum;

int main()
{
    scanf("%d",&N);
    if(N<=5)
    {
        for(int i=1;i<=N;i++)printf("%d ",val[i]);
        return 0;
    }
    for(int i=0;i<5000;i++)
        a[i*4+1]=i*6+2,a[i*4+2]=i*6+3,a[i*4+3]=i*6+4,a[i*4+4]=i*6+6;
    for(int i=1;i<=N;i++)sum+=a[i];
    switch(sum%6)
    {
        case 2:
            a[5]=30000;
            break;
        case 3:
            a[6]=30000;
            break;
        case 5:
            a[6]=29998;
            break;
    }
    for(int i=1;i<=N;i++)printf("%d ",a[i]);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define mod 1000000007
#define PI 3.1415926535
using namespace std;
ll power(ll x, ll y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return power(x, y / 2) * power(x, y / 2);
	else
		return x * power(x, y / 2) * power(x, y / 2);
}
ll modExpo(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modExpo((x*x)%mod,n/2);
    else                            
        return (x*modExpo((x*x)%mod,(n-1)/2))%mod;

}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	auto start_time = clock();
	cerr << setprecision(3) << fixed;
#endif
	ll n;
	cin>>n;
	ll i,a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	ll dp[n];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;
#ifdef LOCAL
	auto end_time = clock();
	cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}


Measured memory_bytes: 1792
//Deep Godhani
//DAIICT

#include<bits/stdc++.h>
using namespace std;

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

map<pair<ll,ll>,ll> check;
map<pair<ll,ll>,ll> dp;

ll func(vector<pair<ll,ll>> &r, vector<pair<ll,ll>> &c,ll rstart,ll cstart)
{
  ll rowCount = r[rstart].first;
  ll colCount = c[cstart].first;

  ll x = r[rstart].second;
  ll y = c[cstart].second;
  ll m = 0;

  if(dp[{rstart,cstart}] != 0)
  {
    return dp[{rstart,cstart}];
  }
  if(check[{x,y}] == 1)
  {
    if(rstart+1 < (ll)r.size())
      m = max(m,dp[{rstart+1,cstart}] = func(r,c,rstart+1,cstart));
    if(cstart+1 < (ll)c.size())
      m = max(m,dp[{rstart,cstart+1}] = func(r,c,rstart,cstart+1));
  }
  else
  {
    return dp[{rstart,cstart}] = rowCount + colCount;
  }

  return dp[{rstart,cstart}] = max(rowCount+colCount-1, m);
}

void solve()
{
  ll h,w,m;
  cin >> h >> w >> m;

  vector<pair<ll,ll>> v;
  check.clear();
  dp.clear();
  for(int i=0;i<m;i++)
  {
    ll x,y;
    cin >> x >> y;
    v.push_back({x,y});
    check[{x,y}] = 1;
  }

  map<ll,ll> row,col;
  for(int i=0;i<(ll)v.size();i++)
  {
    row[v[i].first]++;
    col[v[i].second]++;
  }

  vector<pair<ll,ll>> r,c;
  for(auto it=row.begin();it!=row.end();it++)
  {
    r.push_back({it->second,it->first});
  }

  for(auto it=col.begin();it!=col.end();it++)
  {
    c.push_back({it->second,it->first});
  }

  sort(r.begin(),r.end(),greater<pair<ll,ll>>());
  sort(c.begin(),c.end(),greater<pair<ll,ll>>());

  ll ans = func(r,c,0,0);
  cout << ans << endl;
}

int main()
{
    FAST;
    ll t=1;
    //cin >> t;
    while(t--)
    {
			solve();
    }
		return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, h, w);
  int H = h + 2, W = w + 2;

  vector<string> s(H);
  s[0] = s[H - 1] = string(W, '#');
  rep(i, h) {
    in(string, row);
    s[i + 1] = '#' + row + '#';
  }

  function<int(int, int, int, int, vector<vector<int>>&)> rec =
      [&](int dr, int dc, int r, int c, vector<vector<int>>& m) {
        if (s[r][c] == '#') {
          return 0;
        }
        if (m[r][c] == -1) {
          m[r][c] = rec(dr, dc, r + dr, c + dc, m) + 1;
        }
        return m[r][c];
      };
  vector<vector<vector<int>>> memo(4, vector(H, vector(W, -1)));
  int ans = 0;
  int dr[] = {1, -1, 0, 0};
  int dc[] = {0, 0, 1, -1};
  rep(r, H) rep(c, W) if (s[r][c] == '.') {
    int res = -3;
    rep(i, 4) res += rec(dr[i], dc[i], r, c, memo[i]);
    ans = max(ans, res);
  }
  out(ans);
}


Measured memory_bytes: 89728