akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	ll a,b;
	ll ans=0LL;
	cin >>a>>b;
	vector<ll>finder;
	if(a==b){
		cout<<a<<endl;
		return 0;
	}
	if(a%2LL==1){
		finder.push_back(a);
	}
	if(b%2LL==0 and a!=b){
		finder.push_back(b);
	}
	ll pairs=(b-a-finder.size()+1)/2LL;
	if(pairs%2==1){
		ans|=(1LL<<0);
	}
	if(finder.size()!=0){
		ans^=finder[0];
		if(finder.size()==2){
			ans^=finder[1];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
  int a,b,i;
  char op;

  for (i = 1; 1; i++){
    scanf("%d %c %d",&a,&op,&b);
    if ( op == '?' )
      break;
    if ( op == '+' )
      printf("%d\n",a+b);
    if ( op == '-' )
      printf("%d\n",a-b);
    if ( op == '*' )
      printf("%d\n",a*b);
    if ( op == '/' )
      printf("%d\n",a/b);
  }

  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 4010
#define MAX_2N 8010

int N;
char C[MAX_N] = {};
int A[MAX_N] = {};

// 1-indexed であることに注意
template<typename T>
class BITree {
    public:
        BITree(int n) : m_N(n + 1) { m_Tree.assign(m_N, 0); }
        // [1, i] の合計値を返す (log m_N)
        // 閉区間であることに注意
        T Sum(int i) {
            if(i < 1 || i >= m_N) { return 0; }
            T s = 0;
            while(i > 0) { s += m_Tree[i]; i -= i & -i; }
            return s;
        }
        // [i, j] の合計値を返す (log m_N)
        // i < j
        // 閉区間であることに注意
        T Sum(int i, int j) {
            if(i > j) { return 0; }
            return Sum(j) - Sum(i-1);
        }
        // i 番目の要素(1-indexed)に x を足して更新 O(log m_N)
        void Add(int i, T x){ while(i < m_N) { m_Tree[i] += x; i += i & -i; } }
    private:
        int m_N;            // 要素数
        vector<T> m_Tree;   // BIT 本体
};

int dp[MAX_N][MAX_N] = {};
int costB[MAX_N][MAX_N] = {};
int costW[MAX_N][MAX_N] = {};
int posB[MAX_2N] = {};      // B の i がある A のインデックス
int posW[MAX_2N] = {};      // W の i がある A のインデックス
BITree<int>* bit_Bs[MAX_2N] = {};
BITree<int>* bit_Ws[MAX_2N] = {};

signed main()
{
    cin >> N;
    REP(i, 2 * N) {
        cin >> C[i] >> A[i];
        if(C[i] == 'W') { posW[A[i]] = i; }
        else { posB[A[i]] = i; }
    }

    ZERO(dp);
    ZERO(costB);
    ZERO(costW);

    REP(i, 2 * N) {
        bit_Bs[i] = new BITree<int>(N);
        bit_Ws[i] = new BITree<int>(N);
        for(int ind = 0; ind < i; ++ind) {
            if(C[ind] == 'B') { bit_Bs[i]->Add(A[ind], 1); }
            else { bit_Ws[i]->Add(A[ind], 1); }
        }
    }

    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j) {
            costB[i][j] += bit_Bs[posB[i+1]]->Sum(i+2, N);
            costB[i][j] += bit_Ws[posB[i+1]]->Sum(j+1, N);
            costW[i][j] += bit_Bs[posW[j+1]]->Sum(i+1, N);
            costW[i][j] += bit_Ws[posW[j+1]]->Sum(j+2, N);
        }
    }

    dp[0][0] = 0;
    for(int i = 0; i <= N; ++i) {
        for(int j = 0; j <= N; ++j) {
            if(i == 0 && j == 0) { continue; }
            int cand1 = INF, cand2 = INF;
            if(i > 0) { cand1 = dp[i-1][j] + costB[i-1][j]; }
            if(j > 0) { cand2 = dp[i][j-1] + costW[i][j-1]; }
            dp[i][j] = min(cand1, cand2);
        }
    }

    printf("%d\n", dp[N][N]);
    return 0;
}


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

using namespace std; 

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef set <int> st;
typedef set <char> stc;
typedef vector<int>::iterator itr;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sq(a) a*a
#define cu(a) (sq(a)*a)


const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int inf = 1e9+9;
const ll INF = 1e18;

int main() 
{ 
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    
    int k,n,m;
    
    int a[maxn];
    
    cin >> n;
    bool t = true;
    f0(n){
    	
    	cin >> k;
    	
    	if(k%2 == 0){
    		
    		if((k%3 == 0) || k%5 == 0){
    			
    			
			}else{
				
				t = false;
				
			}
    		
		}
    	
	}
	
	if(t == true) cout << "APPROVED";
	else cout << "DENIED";
    
    return 0; 
    
}






Measured memory_bytes: 256
import sys
import numpy as np

val = np.fromstring(sys.stdin.buffer.read(), np.int64, sep=' ')
n,k = val[:2]
p_list = val[2:]

S = np.zeros(n+1, np.int64)
S[1:] = p_list.cumsum()

KS = S[k:] - S[0:-k]
print((KS.max()+k)/2)

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

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

    int c;

    if(b < 10) c = 10*a+b;
    else if(b < 100) c = 100*a+b;
  	else c = 1000*a+b;
  	

    if((int)sqrt(c)*(int)sqrt(c) == c) cout << "Yes" << endl;
    else cout << "No" << endl;

  	return 0;
}


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

int main() {
  string s;
  cin >> s;
  int front_index = 0, end_index = 0;
  int i;
  for (i = 0; i < s.length(); i++) {
    if (s.at(i) == 'A') {
      front_index = i;
      break;
    }
  }
  for (i = front_index; i < s.length(); i++) {
    if (s.at(i) == 'Z') {
      end_index = i;
    }
  }
  cout << end_index - front_index + 1 << endl;
  return 0;
}


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

using namespace std;
using LL = long long;
const LL LINF = 1e18;
const LL MOD = 1e9+7;



int main(){
    char c;cin >> c;
    if(c == 'A')cout<<"T"<<endl;
    if(c == 'T')cout<<"A"<<endl;
    if(c == 'C')cout<<"G"<<endl;
    if(c == 'G')cout<<"C"<<endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <climits>
#include <vector>

int optimize(int pA, int pB, int pAB, int X, int Y)
{
  int fP = std::min(2*pAB*X + std::max(0, Y-X)*pB, pA*X + pB*Y);
  int sP = std::min(2*pAB*Y + std::max(0, X-Y)*pA, pA*X + pB*Y);
  return std::min(fP, sP);
}

int main()
{
  int pA, pB, pAB, X, Y;
  std::cin >> pA >> pB >> pAB >> X >> Y;
  int ret = optimize(pA, pB, pAB, X, Y);
  std::cout << ret << std::endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int b=scan.nextInt();
			int c[][]=new int[a][b];
			for(int i=0;i<a;i++) {
				for(int j=0;j<b;j++) {
					c[i][j]=scan.nextInt();
				}
			}
			int cnt=0;
			for(int i=0;i<a;i++) {
				for(int j=0;j<a;j++) {
					if(i==j)continue;
					int kazoeru=0;
					for(int k=0;k<b;k++) {
						kazoeru+=(int)Math.pow(c[i][k]-c[j][k],2);
					}
					if(Math.sqrt(kazoeru)==(int)Math.sqrt(kazoeru)) {
						cnt++;
						
					}
				}
			}
			System.out.println(cnt/2);
		}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;


int main()
{
	long long n;
	cin >> n;
	
	vector<long long> h(n);
	vector<long long> hplus(n);
	vector<long long> hminuses;

	long long answer = 0;

	for (long long i = 0; i < n; i++) {
		cin >> h[i];
		hplus[i] = h[i] + i;
		hminuses.push_back(i - h[i]);
	}
	sort(hplus.begin(), hplus.end());
	sort(hminuses.begin(), hminuses.end());


	long long index = 0;
	for (long long i = 0; i < n; ) {
		long long ans = 0;
		for (; index < hminuses.size(); index++) {
			if(hminuses[index] == hplus[i]) ans++;
			if (hplus[i] < hminuses[index]) break;
		}
		while (1) {
			answer += ans;
			i++;
			if (i >= n - 1) break;
			if (hplus[i] != hplus[i - 1]) break;
		}

		if (index > hminuses.size() - 1) break;
	}

	cout << answer << endl;
}

Measured memory_bytes: 8408
h, w = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(h)]
ans = []
for i in range(h):
    for j in range(w):
        if i % 2 == 0:
            if a[i][j] % 2 == 1:
                if j != w - 1:
                    a[i][j + 1] += 1
                    d = [i + 1, j + 1, i + 1, j + 2]
                    ans.append(d)
                elif i != h - 1:
                    a[i + 1][j] += 1
                    d = [i + 1, w, i + 2, w]
                    ans.append(d)
        else:
            if a[i][w - j - 1] % 2 == 1:
                if j != w - 1:
                    a[i][w - j - 2] += 1
                    d = [i + 1, w - j, i + 1, w - j - 1]
                    ans.append(d)
                elif i != h - 1:
                    a[i + 1][0] += 1
                    d = [i + 1, 1, i + 2, 1]
                    ans.append(d)
print(len(ans))
for d in ans:
    print(" ".join(map(str, d)))

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

int main() {
    string S;
    cin>>S;
    //Aの隣にあるBCの分だけ移動可能
    //AABCBCBCBCBC
    //BC*5, A*2 で10回移動できる
    long long Acnt = 0;
    long long ans = 0;
    REP(i, 0, S.size()){
        if(S[i]=='A'){
            Acnt++;
        }else if(i != S.size()-1 && S[i] =='B' && S[i+1] =='C'){
            ans += Acnt;
            i++;
        }else{
            Acnt = 0; 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
    	FastScanner sc = new FastScanner(System.in);
/*		FastScanner sc = new FastScanner("6 6 \r\n" +
				"..#..#\r\n" +
				"......\r\n" +
				"#..#..\r\n" +
				"......\r\n" +
				".#....\r\n" +
				"....#.");*/
    	//FastScanner sc = new FastScanner("1000000000000");
		long n = Long.parseLong(sc.next());
		//int b = Integer.parseInt(sc.next());
		//int t = Integer.parseInt(sc.next());
		//int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		//char a[][] = new char[n];
		//int atmp[] = new int[h];
		//int max= 0;
		//int blackar[][] = new int[h*w][2];
		//int p=0;
		PrintWriter out = new PrintWriter(System.out);
		//for(long i = 1; i < n; i++)
		//{
		//	if(n/i==n%i)
		//	{
		//		out.println(n + ":" + i + ":" + n/i + ":" + n%i+":"+ (n/(n%i)-1));
		//	}
		//}
		long ans = 0;
		for(long i = 1; i*i < n; i++)
		{
				long p = n/i-1;
				if(n/p == n%p)
				{
					//out.println(p+ ":" + n/p + ":" + n%p);
					ans += p;
				}
		}

//N=(N%M)*M
//a=N%M
//a+Ma=N =1+M=N/a

		out.println(ans);
		out.flush();
	}

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;
        public FastScanner(String in) {
        	StringReader sr = new StringReader(in);
            reader = new BufferedReader(new BufferedReader(sr));
            tokenizer = null;
        }
        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }

}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  int ans;
  ans = N;
  while (ans > 0) {
    ans -= 1000;
  }
  ans *= (-1);
  
  cout << ans;
  return 0;
}

Measured memory_bytes: 3608
N, M = map(int,input().split())
S = list(map(int,input().split()))
T = list(map(int,input().split()))

MOD = 10**9 + 7

# dp[i+1][j+1] : S_iまで，T_jまでで作ることのできる共通部分列の数
dp = [[0] * 2010 for _ in range(2010)]
dp[0][0] = 1

for i in range(N+1):
    for j in range(M+1):
        if i > 0: dp[i][j] += dp[i-1][j]
        if j > 0: dp[i][j] += dp[i][j-1]
        if i > 0 and j > 0:
            dp[i][j] -= dp[i-1][j-1]
            if S[i-1] == T[j-1]: dp[i][j] += dp[i-1][j-1]
        dp[i][j] = (dp[i][j] + MOD) % MOD

print(dp[N][M])

Measured memory_bytes: 100016
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cassert>
#include <utility>
#include <numeric>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define rep(i,n) for (int i=0; i<(n); ++i)

using namespace std;
using ll = long long;
int main (){
    string S;
    cin >> S;
    
    if (S.compare("SUN")==0){cout << "7";}
    else if(S.compare("MON")==0){cout << "6";}
    else if(S.compare("TUE")==0){cout << "5";}
    else if(S.compare("WED")==0){cout << "4";}
    else if(S.compare("THU")==0){cout << "3";}
    else if(S.compare("FRI")==0){cout << "2";}
    else if(S.compare("SAT")==0){cout << "1";}
    

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int find(vector<int>& grp, int x) {
    if (grp[x] != x)
        return grp[x] = find(grp, grp[x]);
    return x;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<int> L(m, 0);
    vector<int> R(m, 0);
    vector<int> D(m, 0);
    vector<int> grp(n+1, 0);
    for(int i = 0; i <= n; i++)
        grp[i] = i;
    unordered_map<int, vector<pair<int, int>>> e;
    for(int i = 0; i < m; i++) {
        cin >> L[i] >> R[i] >> D[i];
        e[L[i]].push_back({R[i], D[i]});
        e[R[i]].push_back({L[i], -D[i]});
        int r1 = find(grp, L[i]);
        int r2 = find(grp, R[i]);
        grp[r1] = grp[r2] = min(r1, r2);
    }
    unordered_set<int> grp_root;
    for(int i = 0; i < m; i++) {
        grp_root.insert(find(grp, L[i]));
    }
    vector<int> pos(n+1, INT_MIN);
    for(auto r: grp_root) {
        vector<int> dq = {r};
        pos[r] = 0;
        while(!dq.empty()) {
            vector<int> new_dq;
            for(auto node: dq) {
                // cout << "visit " << node << endl;
                for(auto nxt: e[node]) {
                    if (pos[nxt.first] == INT_MIN) {
                        pos[nxt.first] = pos[node] + nxt.second;
                        new_dq.push_back(nxt.first);
                    } else {
                        //cout << "nxt " << nxt.first << endl;
                        //cout << pos[nxt.first] << " " << pos[node] + nxt.second << endl;
                        if (pos[nxt.first] != pos[node] + nxt.second) {
                            cout << "No" << endl;
                            return 0;
                        }
                    }
                }
            }
            new_dq.swap(dq);
        }
    }
    cout << "Yes" << endl;
    return 0;
}




Measured memory_bytes: 16292
#include<bits/stdc++.h> 
using namespace std;
 
#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

double dp[3001][3001];

int main()
{
    ll t_c; t_c = 1;
    // cin >> t_c;
    for(ll t_i=0; t_i<t_c; ++t_i){
        memset(dp,0,sizeof(dp));
        dp[0][0] = 1;
        ll n; cin >> n;
        for(ll i=1; i<=n; ++i){
            double temp; cin >> temp;
            for(ll j=0; j<=n; ++j){
                dp[i][j+1] += dp[i-1][j]*temp;
                dp[i][j] += dp[i-1][j]*(1-temp);
            }
        }
       
        double ans = 0;
        for(ll i=0; i<=n; ++i){
            ll rem = n-i;
            if(i>rem) ans += dp[n][i];
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 70656
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
//N頂点
$N = $key->A[0];
//M辺
$M = $key->A[1];
//https://book.mynavi.jp/manatee/detail/id=65960
//頂点フラグ
$used = new SplFixedArray($N);
//接続状態を保存する
$connected = new SplFixedArray($N);
//初期化
for($i=0;$i<$N;$i++) {
  $used[$i]=0;
  //接続状態はconnected[頂点数=N][頂点数=N]
  $connected[$i]=new SplFixedArray($N);
  for($j=0;$j<$N;$j++) {
    $connected[$i][$j]=0;
  }
}
//つながっているところを1にする
//頂点1-2がつながっているなら
// connected[0][1]=1
// connected[1][2]=1になるようにする
for($i=0;$i<$M;$i++) {
  $a = $key->X[$i][0]-1;
  $b = $key->X[$i][1]-1;
  $connected[$a][$b] = 1;
  $connected[$b][$a] = 1;
}
printf("%d\n",dfs(0,1));

function dfs($now,$depth) {
  global $used,$connected,$M,$N;
  if ($used[$now]) return 0;
  if ($depth == $N) return 1;
  $used[$now]=1;
  $ans  = 0;
  for($i=0;$i<$N;$i++) {
    if ($connected[$now][$i]) {
      $ans += dfs($i,$depth+1);
    }
  }
  $used[$now]=0;
  return $ans;
}

Measured memory_bytes: 3956
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
cd = [[int(i) for i in input().split()] for _ in range(N)]

ab.sort(key = lambda x: x[1], reverse=True)
cd.sort()

x = 0
for c, d in cd:
    for a, b in ab:
        if a < c and b < d:
            x += 1
            ab.remove([a, b])
            break

print(x)


Measured memory_bytes: 9124
#include <stdio.h>
#define N 100
int main(){
  int i,j,n,a[N],flag=1,count=0;

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

  while(flag!=0){
    flag=0;
    for(j=n-1;j>=i+1;j--){
      if(a[j]<a[j-1]){
        flag=a[j];
	a[j]=a[j-1];
        a[j-1]=flag;
	flag=1;
	count++;
      }
    }
    i++;
  }
  for(i=0;i<n;i++){
    if(i<n-1) printf("%d ",a[i]);
    else printf("%d\n",a[i]);
  }
  printf("%d\n",count);
  return 0;
}

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


void solve(long long X, long long N, std::vector<long long> p){
    long long ans = 0;
    long long minDelta = 999999;
    bool isContain;
    rep(i,300){
        isContain = false;
        for(int j=0; j<N; j++){
            if(i == p[j]){
                isContain = true;
                break;
            }
        }
        if(isContain) continue;
    
        long long d = abs(X - i);
        if(d < minDelta){
            ans = i;
            minDelta = d;
        }
    }

    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    if(N == 0){
        cout << X << endl;
        return 0;
    }
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int N = 200000;



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

    int n;
    cin >> n;
    int x = n % 1000;
    if(n % 1000 == 0){
        cout << 0 << endl;
    }
    else{
        cout << 1000 - x << endl;
    }
    return 0;
}


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

char s[200][200];

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


    int op=1;
    for(int i=1;i<=50;i++){
        for(int j=1;j<=99;j++){
            s[i][j]='#';
        }
    }

    for(int i=1;i<=47&&a>1;i+=2){
        for(int j=1;j<=99&&a>1;j+=2){
            s[i][j]='.';a--;
        }
    }

    for(int i=51;i<=99;i++){
        for(int j=1;j<=99;j++){
            s[i][j]='.';
        }
    }

    for(int i=53;i<=99&&b>1;i+=2){
        for(int j=1;j<=99&&b>1;j+=2){
            s[i][j]='#';b--;
        }
    }

    if(a>1||b>1)puts("-1");

    else
    {
        puts("99 99\n");
        for(int i=1;i<=99;i++){
            for(int j=1;j<=99;j++){
                printf("%c",s[i][j]);
            }puts("");
        }
    }


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
using P = pair<int, int>;
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 998244353;
    int n,m;
    cin>>n>>m;
    vector<vector<int>> edge(n+1);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    vector<int> ans(n+1,-1);
    ans[1]=0;
    queue<int> que;
    que.push(1);
    while(!que.empty()){
        int now=que.front();que.pop();
        rep(i,edge[now].size()){
            if(ans[edge[now][i]]!=-1)continue;
            ans[edge[now][i]]=now;
            que.push(edge[now][i]);
        }
    }
    cout<<"Yes"<<endl;
    rep(i,2,n+1)cout<<ans[i]<<endl;
}


Measured memory_bytes: 12896
N, K = list(map(int, input().split()))
S = input()
ret = 0
for i in range(len(S) - 1):
    if(S[i] == S[i + 1]):
        ret += 1
if(ret + (K * 2) > N - 1):
    ret = N - 1
else:
    ret += (K * 2)
print(ret)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<set>
#include<queue>
using namespace std;

struct UF{
    vector<int> p;
    int n;

    UF(int siz){
        n = siz;
        p.resize(n, 0);
        for(int i = 0; i < n; i++)  p[i] = i;
    }

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

    bool same(int x, int y){
        return parent(x) == parent(y);
    }
    
    void unite(int x, int y){
        x = parent(x), y = parent(y);
        p[x] = y;
    }
};

typedef long long ll;

int main(){
    int n, m;
    cin >> n >> m;
    if((n-1-m)*2 > n){
        cout << "Impossible" << endl;
        return 0;
    }else if(n-1 == m){
        cout << 0 << endl;
        return 0;
    }
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    UF uf(n);
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        uf.unite(x, y);
    }
    multiset<int> s[n];
    for(int i = 0; i < n; i++)  s[uf.parent(i)].insert(a[i]);
    priority_queue<int> pq;
    ll ans = 0;
    int res = (n-1-m)*2;
    for(int i = 0; i < n; i++){
        if(s[i].empty())    continue;
        ans += *s[i].begin();
        res--;
        for(auto it = ++s[i].begin(); it != s[i].end(); it++)   pq.push({-(*it)});
    }
    while(res-- > 0){
        ans += -pq.top();   pq.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11008
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    a = na()

    total_xor = a[0]
    for i in range(1, n):
        total_xor ^= a[i]

    ans = []
    for ai in a:
        ans.append(total_xor ^ ai)

    print(*ans, sep=" ")


if __name__ == '__main__':
    main()


Measured memory_bytes: 33240
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int x, y; cin >> x >> y;

   int ans = INF;
   if (x <= y) {
      chmin(ans, y - x);
   }
   if (-x <= y) {
      chmin(ans, y - (-x) + 1);
   }
   if (x <= -y) {
      chmin(ans, -y - x + 1);
   }
   if (-x <= -y) {
      chmin(ans, -y - (-x) + 2);
   }
   COUT(ans);

   return 0;
}

Measured memory_bytes: 256
N = int(input())
def divisore(n):
    divisors=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort(reverse=True)
    return divisors

ans = 0
for i in range(1,N+1):
    if i % 2 == 0:
        continue
    li = divisore(i)
    if len(li) == 8:
        ans +=1

print(ans)

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  string s, t;
  cin >> s >> t;
  int n = sz(s);
  int m = sz(t);
  if(m > n) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vs ans;
  for(int i = 0; i <= n-m; i++) {
    bool ok = true;
    rep(j,m) {
      if(s[i+j] != t[j] && s[i+j] != '?') ok = false;
    }
    if(ok) {
      string c = s;
      c.replace(i,m,t);
      rep(i,n) {
        if(c[i] == '?') c[i] = 'a';
      }
      ans.push_back(c);
    }
  }
  sort(all(ans));
  if(ans.empty()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  cout << ans[0] << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		int cnt = 0;
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		for(int i = 0;i <= K;i ++) {
			for(int j = 0;j <= K;j ++) {
				int k = S - i - j;
				if(0 <= k && k <= K) cnt ++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        int n = Integer.parseInt(sc.next());
        
        if(h > w){
            if(n%h == 0){
                System.out.println(n/h);
            }else{
                System.out.println(n/h +1);
            }
        }else{
            if(n%w == 0){
                System.out.println(n/w);
            }else{
                System.out.println(n/w +1);
            }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int M1, D1, M2, D2; cin >> M1 >> D1 >> M2 >> D2;

if (M1 < M2) cout << "1\n";
else cout << "0\n";


}

// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var n int

func Pow10(n int) int {
	return int(math.Pow10(n))
}

func f(base, digit int) []int {
	var ret []int
	if v := base + Pow10(digit)*3; v <= n {
		ret = append(ret, v)
		ret = append(ret, f(v, digit+1)...)
	}
	if v := base + Pow10(digit)*5; v <= n {
		ret = append(ret, v)
		ret = append(ret, f(v, digit+1)...)
	}
	if v := base + Pow10(digit)*7; v <= n {
		ret = append(ret, v)
		ret = append(ret, f(v, digit+1)...)
	}
	return ret
}

func check(n int, m map[int]bool) bool {
	m[n%10] = true
	if m[3] && m[5] && m[7] {
		return true
	}
	if n/10 == 0 {
		return false
	}
	return check(n/10, m)
}

func main() {
	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	txt := scanner.Text()
	n, _ = strconv.Atoi(txt)

	cnt := 0
	for _, x := range f(0, 0) {
		if check(x, map[int]bool{}) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 6080
from collections import deque
infinity=10**6

import sys
input = sys.stdin.readline
N,u,v = map(int,input().split())
u -= 1
v -= 1

G=[[] for i in range(N)]
for i in range(N-1):
    A,B = map(int,input().split())
    A -= 1
    B -= 1
    G[A].append(B)
    G[B].append(A)

ends = []
for i in range(N):
    if len(G[i]) == 1:
        ends.append(i)

#幅優先探索
def BFS (s):
    queue = deque()
    d = [infinity]*N
    
    queue.append(s)
    d[s]= 0
    
    while len(queue)!=0:
      u = queue.popleft()
      for v in G[u]:
      	if d[v] == infinity:
        	d[v] = d[u]+1
        	queue.append(v) 	  


  
    return d

d_nigeru = BFS(u)
d_oni = BFS(v)

ans=0
for u in ends:
    if d_nigeru[u] < d_oni[u]:
        ans = max(ans,d_oni[u]-1)

print(ans)

Measured memory_bytes: 61600
/*input
2 3 3
2 2
1 1
1 3
*/
 
 
#include <bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define se second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define INTMAX  2147483647
#define INTMIN  -2147483648
#define LLMAX 9223372036854775807
#define LLMIN -9223372036854775808
#define MOD 1000000007
typedef map<long long int, long long int> mpi;
typedef set<long long int> seti;
typedef multiset<long long int> mseti;
typedef priority_queue<long long int> pq;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define PI 3.1415926535
#define dbg(x) cerr << "\n" << (#x) << " = " << (x) << endl ;
//#define cerr if(false)cerr

// cout<<fixed<<setprecision(10)<<(v1+v2+v3)<<endl;
  
struct node{
    ll val;
};


long long int minimum = 100000000000000;

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

struct ct_s_h {long long int cts, cth, index;};

bool compare(long long int a, long long int b) {
	if(gcd(a,b) < minimum)
		return 1;
	else return 0;
}






int main(){
	ll h,w,m; cin>>h>>w>>m;
	map <ll,ll> row, col;
	map <pair<ll,ll>, ll > presence;
	for(int i=0;i<m;i++){
		ll r, c; cin>>r>>c;
		presence[mp(r,c)] = 1;
		row[r]++;
		col[c]++;
	}
	map <ll,ll> :: iterator ir, ic;
	long long int ans = -1;
	long long int rmax = -1;
	vector<long long int> rownums;
	for(ir = row.begin(); ir!=row.end(); ++ir){
		if(ir->second > rmax){rmax = max(rmax, ir->second);}
	}
	for(ir = row.begin(); ir!=row.end(); ++ir){
		if(ir->second == rmax){rownums.pb(ir->first);}
	}
	long long int cmax = -1;
	vector<long long int> colnums;
	for(ic = col.begin(); ic!=col.end(); ++ic){
		if(ic->second > cmax){cmax = max(cmax, ic->second);}
	}
	for(ic = col.begin(); ic!=col.end(); ++ic){
		if(ic->second == cmax){colnums.pb(ic->first);}
	}

	ans = rmax + cmax -1;
	for(int i=0;i<rownums.size();i++){
		for(int j=0;j<colnums.size();j++){
			if(presence[mp(rownums[i],colnums[j])]!=1){
				ans = rmax + cmax;
				break;
			}
		}
	}
	
	cout<<ans<<endl;
	return 0;	
}















 


Measured memory_bytes: 82916
#include<cstdio>

int n, m;
bool ans[2000][2000];

void f(int x1, int x2, int y1, int y2) {
  if (x1 > x2 || y1 > y2) {
    return;
  }
  int midx = (x1 + x2) / 2;
  int midy = (y1 + y2) / 2;
  f(x1, midx - 1, y1, midy - 1);
  f(x1, midx - 1, midy + 1, y2);
  f(midx + 1, x2, y1, midy - 1);
  f(midx + 1, x2, midy + 1, y2);
  ans[midx][midy] = true;
}

int main() {
  f(1, 1023, 1, 1023);
  scanf("%d %d", &n, &m);
  for (int i = 1; i < (1 << n); i++) {
    for (int j = 1; j < (1 << m); j++) {
      printf("%d", ans[i][j]);
    }
    printf("\n");
  }
}


Measured memory_bytes: 3200
#! env/bin/local python3
# -*- coding:utf-8 -*-

is_first = True
while True:
    try:
        if is_first:
            n, m  = [int(i) for i in input().split()]
            is_first = False
        else:
            arr = [int(i) for i in input().split()]
    except EOFError:
        break

total_vote = sum(arr)
sorted_arr = sorted(arr, reverse=True)

list_up_arr = sorted_arr[: m]

flag = True
for l in list_up_arr:
    if l < 1 / (4 * m) * total_vote:
        flag = False

print('Yes' if flag else 'No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
struct Point{
	int x,y,w;
}a[maxn];
bool cmp(const Point& A,const Point& B){
	return A.w>B.w;
}
int f[maxn],siz[maxn],cnt[maxn];
int find(int x){
	return f[x]==x?x:f[x]=find(f[x]);
}
int main()
{
	int n,h,w;cin>>n>>h>>w;
	for(int i=1;i<=n;i++)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
	sort(a+1,a+1+n,cmp);
	ll ans = 0;
	for(int i=1;i<=h+w;i++)f[i] = i,siz[i] = 1,cnt[i] = 0;
	for(int i=1;i<=n;i++){
		int x = a[i].x,y = a[i].y+h;
		int p = find(x),q = find(y);
		if(p==q){
			if(siz[p]>cnt[p]){
				cnt[p]++;
				ans += a[i].w;
			}
		}
		else{
			if(siz[q]==cnt[q]&&siz[p]==cnt[p])continue;
			f[q] = p;
			siz[p] += siz[q];
			cnt[p] += cnt[q];
			cnt[p]++;
			ans += a[i].w;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5248
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  ll dp[3]= {0};
  rep(i,s.size()) dp[s[i]-'a']++;
  if(abs(dp[0]-dp[1])<=1 && abs(dp[2]-dp[1])<=1 && abs(dp[0]-dp[2])<=1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}

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


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int h, w, a, b; cin >> h >> w >> a >> b;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			bool b00l = (i <= b) ^ (j <= a);
			cout << b00l;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1280
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int sum = 0;
         for(int x: arr)
            sum += x;
         double lim = 1.0/(4*M);
         lim *= sum;
         int cnt = 0;
         for(int x: arr)
            if(x >= lim)
               cnt++;
         if(cnt >= M)
            System.out.println("Yes");
         else
            System.out.println("No");
      }
   }

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

template<class T>
class BinaryIndexedTree {
private:
	vector<T> nodes;
	int p;

public:
	BinaryIndexedTree(int n) : nodes(n + 1), p(1 << (int)log2(n)) {}

	// 0-indexed
	void add(int index, T value) {
		for (int i = index + 1; i < nodes.size(); i += i & -i) {
			nodes[i] += value;
		}
	}

	// 0-indexed [0, index)
	T sum(int index) {
		T s = 0;
		for (int i = index; i > 0; i &= i - 1) {
			s += nodes[i];
		}
		return s;
	}

	// 0-indexed [l, r)
	T sum(int l, int r) {
		return sum(r) - sum(l);
	}

	// min x: sum[0, x)>=k
	int lowerBound(int k) {
		if (k == 0) {
			return 0;
		}
		int v = 0;
		for (int i = p; i > 0; i >>= 1) {
			if (v + i < nodes.size() && nodes[v + i] < k) {
				k -= nodes[v + i];
				v += i;
			}
		}
		return v + 1;
	}
};

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

	BinaryIndexedTree<int> bit(m + 10);
	vector<int> l(n), r(n);
	vector<vector<int>> buk(m + 1);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> l[i] >> r[i];
		r[i]++;
		buk[r[i] - l[i]].push_back(i);
	}
	int len = n;

	for (int i = 1; i <= m; i++) {
		for (int id : buk[i]) {
			bit.add(l[id], 1);
			bit.add(r[id], -1);
			len--;
		}
		int cnt = len;
		for (int j = 0; j <= m; j += i) {
			cnt += bit.sum(j + 1);
		}
		cout << cnt << endl;
	}
}

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

typedef long long ll;

int N, M;
priority_queue<int> Q;

void input_init(void) {
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		Q.push(a);
	}
}

void solve(void) {
	int cnt = M;
	while (cnt > 0) {
		int a = Q.top();
		Q.pop();
		Q.push(a / 2);
		--cnt;
	}
}

ll calcu(void) {
	ll sum = (ll)0;
	while (!Q.empty()) {
		int a = Q.top();
		Q.pop();
		sum += a;
	}
	return sum;
}

int main(void) {
	input_init();
	solve();
	ll ans = calcu();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	_P("%.12lf\n",x*atan(1)*8);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <climits>
#include <unordered_map>
#include <queue>


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

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

int main() {
    vector<ll> num(3);
    cin >> num[0] >> num[1] >> num[2];
    sort(num.begin(), num.end());
    cout << num[0] + num[1] + (num[2]*10) << endl;
    return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, a[100001];
ll mi, ma[100001];
 
int main(int argc, char **argv) {
	cin >> n;
	REP(i, n+1) cin >> a[i];
	mi = ma[n] = a[n];
	FORR(i, 1, n+1) {
		mi = max((ll)1, (mi+1)/2 + a[i-1]);
		ma[i-1] = ma[i] + a[i-1];
	}
	if (mi >= 2) {
		cout << -1 << endl;
		return 0;
	}
	ma[0] = 1;
	ll res = 1;
	REP(i, n) {
		ma[i+1] = min(ma[i+1], (ma[i] - a[i]) * 2);
		if (ma[i+1] <= 0) {
			cout << -1 << endl;
			return 0;
		}
		res += ma[i+1];
	}
	cout << res << endl;
	return 0;
}
 

Measured memory_bytes: 5184
import java.util.*;

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

        int w = sc.nextInt();
        int n = sc.nextInt();

        int[] value = new int[w];
        for(int i=0;i<value.length;i++){
            value[i] = i+1;
        }

        for(int i=0;i<n;i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0])-1;
            int b = Integer.parseInt(ab[1])-1;

            int x = value[a];
            value[a] = value[b];
            value[b] = x;
        }

        for(int i=0;i<value.length;i++){
            System.out.println(value[i]);
        }
    }
}



Measured memory_bytes: 26084