akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long

//O(VE)

class BipartiteMatching {
private:
  int V;
  vector<int> match;
  vector<vector<int>> G;
  vector<bool> used;

  void add_edge(int u, int v) {
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
      int u = G[v][i], w = match[u];
      if (w < 0 || ((!used[w]) && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return true;
      }
    }
    return false;
  }

  int bipartite_matching() {
    int res = 0;
    fill(match.begin(), match.end(), -1);
    for (int v = 0; v < V; v++) {
      if (match[v] < 0) {
        fill(used.begin(), used.end(), 0);
        if (dfs(v)) res++;
      }
    }
    return res;
  }

public:
  BipartiteMatching(int N) : V(N), G(N, vector<int>()) {
    match.resize(V);
    used.resize(V);
  }

  void addEdge(int u, int v) { return add_edge(u, v); }
  int getNum() { return bipartite_matching(); }
};

signed main() {
  int X, Y, E;
  cin >> X >> Y >> E;

  BipartiteMatching bm(X + Y);

  while (E--) {
    int x, y;
    cin >> x >> y;
    bm.addEdge(x, X + y);
  }

  cout << bm.getNum() << endl;
  return 0;
}



Measured memory_bytes: 3272
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#define mp make_pair
#define pb push_back

using namespace std;

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

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

int main(){
    int n;
    cin >> n;
    string w[n];
    set<string> word_list;
    bool flag = true;
    for(int i=0;i<n;i++){
        string word;
        cin >> word;
        w[i] = word;
        word_list.insert(word);
    }
    //文字の頭文字と末尾が一致しているいるか確認
    for(int i=1;i<n;i++){
        int end = w[i-1].size()-1;
        if(w[i-1][end]!=w[i][0]){
            flag = false;
            break;
        }
    }
    //すでに出た単語かどうか確認
    if(word_list.size()!=n) flag = false;

    //出力
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


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

int main(){
  long long X;
  cin >> X;
  vector<long long> V(1,0);
  
  for(long long i=1;;i++){
    V.push_back(pow(i,5));
    if(V[i]-V[i-1]>=X) break;
  }
  
  long long N = V.size();
  for(int a=0;a<N;a++){
    for(int b=0;b<N;b++){
      if(V[a]-V[b]==X){
        cout << a << " " << b << endl;
        return 0;
      }
      if(V[a]+V[b]==X){
        cout << a << " " << b*(-1) << endl;
        return 0;
      }
    }
  }
  return 0;
}


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


#define ll long long int
#define ld long double
#define mod 1000000007
#define big 1e18+10
#define small -big
#define pb push_back



template <typename T>

void prarr(T a)
{
     cerr << "[ ";
     
     for(auto i : a){
         cerr << i << " ";
     }
     
     cerr << "]" << endl;
}


#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){
    
	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}



void solve() {
            
         string s, t;
         cin >> s;
         cin >> t;
         
         ll sis = s.size();
         ll sit = t.size();
         
         char A[sis + 1];
         char B[sit + 1];
         
         for(ll i = 1; i <= sis; i++) {
                A[i] = s[i - 1];
         }
         
         for(ll i = 1; i <= sit; i++) {
                B[i] = t[i - 1];
         }
         
         ll d = big;
         
         for(ll i = sit; i <= sis; i++) {
                ll c = 0;
                for(ll j = 1; j <= sit; j++) {
                       if(A[i - sit + j] != B[j]) {
                            c++;
                       }
                }
                d = min(d, c);
         }
         
         cout << d << endl;
       
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   

    int t=1;
    //cin >> t;

    for(int i = 1; i <= t; i++) {  
   
         solve();
    }


    return 0;
        
}


Measured memory_bytes: 3540
import numpy as np
def Palace(n , t , a , hli):

    ans = 0
    count = 10**8

    for i in range(n):
        if abs(a - (t - hli[i] * 0.006)) < count:
            ans = i + 1
            count = abs(a - (t - hli[i] * 0.006))

    return ans

def main():
    n = int(input())
    t , a = map(int , input().split())
    hli = list(map(int , input().split()))
    print(Palace(n , t , a , hli))

if __name__ == '__main__':
    main()

Measured memory_bytes: 12488
function Main(input) {
  var dataList = input.split("\n");
  dataList.shift();
  dataList.pop();
  var restaurants = dataList.map((data, index) => {
    var tmp = data.split(" ")
    return { index: index + 1, city: tmp[0], score: parseInt(tmp[1]) }
  });
  restaurants.sort(function(a, b) {
    if (a.city > b.city) {
      return 1;
    } else if (a.city === b.city) {
      if (a.score > b.score) {
        return -1;     
      } else {
        return 1;     
      }
    } else {
      return -1;
    }
  });
  restaurants.forEach(restaurant => {
    console.log(restaurant.index);
  });
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
int n,a[101101],ans;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
        if(a[i]==a[i-1])ans++;
    if(ans&1)ans++;
    cout<<n-ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    string a;
    cin>>a;
    if(a=="ABC")
    {
        cout<<"ARC"<<endl;
    }
    else if(a=="ARC")
    {
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define int long long 
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define print_time cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ull unsigned long long
#define debug1(x) cerr << #x << ": " << x <<'\n'
#define debug2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define debug3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
int gcd(int x,int y)
{
   // cout<<x<<' '<<y<<endl;
    if(y==0)
    return x;
    else
    return gcd(y,x%y);
}
int expo(int n,int m,int p)   //modULAR EXPONENTIATION
{
    int r=1;
    n=n%p;
    while(m>0)
    {
    if(m%2)
	r=(r*n)%p;
    n=(n*n)%p;
    m=m/2;
    }
    return r%p;
}
bool isPrime(int n)
{
    // Corner cases
    if (n <= 1)  return false;
    if (n <= 3)  return true;
 
    // This is checked so that we can skip 
    // middle five numbers in below loop
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (int i=5; i*i<=n; i=i+6)
    if (n%i == 0 || n%(i+2) == 0)
       return false;
 
    return true;
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
	z[i] = min (r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
	++z[i];
    if (i + z[i] - 1 > r)
	l = i, r = i + z[i] - 1;
    }
    return z;
}
int n;
int a[3005];
bool vis[3005][3005][2];
int dp[3005][3005][2];
int solve(int i,int j,int p)
{
	if(i>j)
		return 0;
	if(vis[i][j][p])
		return dp[i][j][p];
	int ans;
	if(p==0)
	{
		ans=0;
		ans=a[i]+solve(i+1,j,1);
		ans=max(ans,a[j]+solve(i,j-1,1));
	}
	else
	{
		ans=-a[i]+solve(i+1,j,0);
		ans=min(ans,-a[j]+solve(i,j-1,0));
	}
	vis[i][j][p]=true;
	dp[i][j][p]=ans;
	return ans;
}
int32_t main()
{
   IOS;
   /*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin); 
   freopen("output.txt","w",stdout);
   #endif
   /********************* Code starts here ***********************/
   cin>>n;
   for(int i=0;i<n;i++)
   {
   	cin>>a[i];
   }
   cout<<solve(0,n-1,0)<<endl;
}        


Measured memory_bytes: 158848
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        int n = stdin.nextInt();
        int k = stdin.nextInt();
        for (int i = 1; i <= k; i++) {
            System.out.println(c(k - 1, i - 1).multiply(c(n - k + 1, i)).mod(mod).intValue());
        }
    }

    private static List<BigInteger> fct = new ArrayList<>();
    private static List<BigInteger> inv = new ArrayList<>();
    private static BigInteger mod = BigInteger.valueOf(1000000007);
    private static BigInteger c(int n, int r) {
        if (n < r) {
            return BigInteger.ZERO;
        }

        if (fct.isEmpty()) {
            fct.add(BigInteger.ONE);
            inv.add(fct.get(0).modInverse(mod));
        }

        for (int i = fct.size(); i <= n; i++) {
            fct.add(fct.get(i - 1).multiply(BigInteger.valueOf(i)).mod(mod));
            inv.add(fct.get(i).modInverse(mod));
        }

        return fct.get(n).multiply(inv.get(n - r).multiply(inv.get(r)).mod(mod)).mod(mod);
    }
}


Measured memory_bytes: 28688
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <numeric> //lcm


#define ERROR() cout << "ERROR!!" << endl; return 0;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

inline bool maxch(int& a, int b) { if (a < b) { a = b; return true; } else return false; }

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

	vector<int> as(a), bs(b);
	rep(i, a) {
		cin >> as[i];
	}
	rep(i, b) {
		cin >> bs[i];
	}

	int x,y,c;
	vector<int> ans;
	rep(i, m) {
	  cin >> x >> y >> c;
		x--; y--;

		ans.push_back(as[x]+bs[y]-c);
	}
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
  ans.push_back(as[0] + bs[0]);
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
}




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

int main() {
char C;
cin >> C;
  
string abc;
  abc = "abcdefghijklmnopqrstuvwxyz";

for (int i = 0; i < 25; i++) {
  if (abc.at(i) == C){
    cout << abc.at(i + 1) << endl;
  }
}

}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int n,q,a,v;



int main(){
    
        
    while(cin >> n >> q){
        int wakasagi[1000001]={0};
        int outnum=1;
        int outwakasagi=0;

        for(int i=0; i<q; i++){
            cin>>a>>v;
            wakasagi[a]+=v;
            
            if(v<0&&a==outnum){
                outwakasagi+=v;
                for(int i=1; i<=n; i++){
                    if(outwakasagi<wakasagi[i]){
                        outwakasagi=wakasagi[i];
                        outnum=i;
                    }else if(outwakasagi==wakasagi[i]&&outnum>i){
                        outwakasagi=wakasagi[i];
                        outnum=i;
                    }
                }
            }else if(wakasagi[a]>outwakasagi){
                outnum=a;
                outwakasagi=wakasagi[a];
            }else if(wakasagi[a]==outwakasagi&&a<outnum){
                outnum=a;
            }
            cout<<outnum<<" "<<outwakasagi<<endl;
        }
    }
            
}

Measured memory_bytes: 5076
#include <stdio.h>


int main(){
    int N;
    scanf("%d", &N);

    char S[N + 1];
    scanf("%s", S);
    if(N % 2 == 1){
        puts("No");
    }
    else{
        int flag = 1;
        for(int i = 0; i < N / 2; i ++){
            if(S[i] != S[i + N/2]){
                flag = 0;
            }
        }
        if(flag){
            puts("Yes");
        }
        else{
            puts("No");
        }
    }

    return 0;
}

Measured memory_bytes: 1644
import java.util.*;
import static java.lang.System.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();
		int cnt = 0;
	    for(int i = 1; i < n; i++) {
	    	if (str[i] == 'E') cnt++;
	    }
	    int min = cnt;
	    for(int i = 1; i < n; i++) {
	    	if(str[i - 1] == 'W')
	    		cnt++;
	    	if(str[i] == 'E')
	    		cnt--;
	    	if(cnt < 0)
	    		cnt = 0;
	    	if (min > cnt) min = cnt;
	    }
	    out.println(min);
		
		out.close();
	}
	  private static long gcd(long m, long n) {
		    if(m < n) return gcd(n, m);
		    if(n == 0) return m;
		    return gcd(n, m % n);
		}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

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

int main(){
  long long int n;
  cin >> n;
  long long int a[n];
  long long int count[100000];
  for(long long int i=0;i<100000;i++)count[i]=0;
  for(long long int i=0;i<n;i++){
    cin >> a[i];
    count[a[i]]++;
  }
  long long int ans=0;
  for(long long int i=0;i<99998;i++)ans=max(ans,count[i]+count[i+1]+count[i+2]);
  cout <<ans <<endl;
}

Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val k = sc.nextInt()
    val ab = (0 until m).map { sc.next().toInt() to sc.next().toInt() }
    val cd = (0 until k).map { sc.next().toInt() to sc.next().toInt() }
    println(problem157d(n, m, k, ab, cd))
}

fun problem157d(
    n: Int,
    m: Int,
    k: Int,
    ab: List<Pair<Int, Int>>,
    cd: List<Pair<Int, Int>>
): String {
    class UnionFind(n: Int) {
        val parent = IntArray(n) { -1 }

        fun root(x: Int): Int {
            if (parent[x] < 0) return x
            parent[x] = root(parent[x])
            return parent[x]
        }

        fun isSameRoot(x: Int, y: Int) = root(x) == root(y)

        fun merge(x: Int, y: Int) {
            var xRoot = root(x)
            var yRoot = root(y)
            if (xRoot == yRoot) return
            if (parent[xRoot] > parent[yRoot]){
                val tmp = xRoot
                xRoot = yRoot
                yRoot = tmp
            }
            parent[xRoot] += parent[yRoot]
            parent[yRoot] = xRoot
        }

        fun groupSize(x: Int) = -parent[root(x)]

        override fun toString(): String {
            return parent.toString()
        }
    }

    val dame = Array<MutableSet<Int>>(n + 1) { mutableSetOf() }
    val uf = UnionFind(n + 1)
    for (i in 0 until m) {
        val (a, b) = ab[i]
        dame[a].add(b)
        dame[b].add(a)
        uf.merge(a, b)
    }
    for (i in 0 until k) {
        val (c, d) = cd[i]
        if (!uf.isSameRoot(c, d)) continue
        dame[c].add(d)
        dame[d].add(c)
    }
    val ans = mutableListOf<Int>()
    for (i in 1..n) {
        val mem = uf.groupSize(i) - 1
        ans.add(mem - dame[i].size)
    }
    return ans.joinToString(" ")
}

Measured memory_bytes: 127716
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); //for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}
ll t[800001][2];
int lazy[800001][2];
 
void push(ll id,ll l,ll r,int ty){
  if(lazy[id][ty]!=1e9){
    t[id][ty]=min(lazy[id][ty],t[id][ty]);
    if(l!=r){
      lazy[id<<1][ty]=min(lazy[id<<1][ty],lazy[id][ty]);
      lazy[id<<1|1][ty]=min(lazy[id<<1|1][ty],lazy[id][ty]);
    }
    lazy[id][ty]=1e9;
  }
}
void update(ll id,ll l,ll r,ll lq,ll rq,int val,int ty){
  push(id,l,r,ty);
  if(l>r||lq>r||l>rq)return;
  if(lq<=l&&r<=rq){
    lazy[id][ty]=min(lazy[id][ty],val);
    push(id,l,r,ty);
    return;
  }
  ll mid=(l+r)>>1;
  update(id<<1,l,mid,lq,rq,val,ty);
  update(id<<1|1,mid+1,r,lq,rq,val,ty);
  t[id][ty]=min(t[id<<1][ty],t[id<<1|1][ty]);
}
 
ll query(ll id,ll l,ll r,ll lq,ll rq,int ty){
  push(id,l,r,ty);
  if(l>r||lq>r||l>rq)return 1e9;
  if(lq<=l&&r<=rq){
    return t[id][ty];
  }
  ll mid=(l+r)>>1;
  return min(query(id<<1,l,mid,lq,rq,ty),query(id<<1|1,mid+1,r,lq,rq,ty));
}
int32_t main()
{
    IOS
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif    
 	
	int n,q;
	cin>>n>>q;
	int ans=(n-2)*(n-2);
	for(int i=1;i<=800000;i++)
		t[i][0]=t[i][1]=n,lazy[i][0]=1e9,lazy[i][1]=1e9;

	while(q--)
	{
		int ty;
		cin>>ty;
		int val;
		cin>>val;
		if(ty==1)
		{
			int f=query(1,1,n,val,val,0);
			ans-=(f-2);
			update(1,1,n,1,f,val,1);
		}
		else
		{
			int f=query(1,1,n,val,val,1);
			ans-=(f-2);
			update(1,1,n,1,f,val,0);
		}
		//cout<<ans<<endl;
	}
	cout<<ans;

}    


Measured memory_bytes: 28616
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr int N = 1 << 18;
ll t[N << 1];
int h[N], a[N];

int n;
ll query(int l, int r) {
	ll res = 0;
	for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
		if (l & 1) ckmax(res, t[l++]);
		if (r & 1) ckmax(res, t[--r]);
	}
	return res;
}
void modify(int p, ll v) {
	for (t[p += n] = v; p > 1; p >>= 1) t[p >> 1] = max(t[p], t[p ^ 1]);
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	rep(i, 0, n) cin >> h[i], --h[i];
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, n) modify(h[i], query(0, h[i]) + a[i]);
	cout << query(0, n) << '\n';
}

Measured memory_bytes: 6016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int X, A; cin >> X >> A;
	if (X < A) cout << 0 << endl;
	else cout << 10 << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
ANS = 0
SUM = 0
def dfs(arr, l):
    global SUM, ANS
    # print(arr)
    if l == N:
        for i in range(Q):
            # print(arr[A[i][1]-1]-arr[A[i][0]-1])

            if arr[A[i][1]-1]-arr[A[i][0]-1] == A[i][2]:
                SUM += A[i][3]
            ANS = max(SUM, ANS)
        SUM = 0
        return
    else:
        for i in range(arr[l-1], M+1):
            arr.append(i)
            l = len(arr)
            # print(arr)
            dfs(arr,l)
            arr.pop()

    return ANS

if __name__ == '__main__':
    N, M ,Q = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(Q)]
    ARR = deque([1])
    dfs(ARR,1)
    print(ANS)

Measured memory_bytes: 9392
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

newtype FixF f = InF { outF :: f (FixF f) }

cata :: Functor f => (f a -> a) -> FixF f -> a
cata !phi = phi . fmap (cata phi) . outF
{-# INLINE cata #-}

ana :: Functor f => (a -> f a) -> a -> FixF f
ana !psi = InF . fmap (ana psi) . psi
{-# INLINE ana #-}

hylo :: Functor f => (f x -> x) -> (y -> f y) -> (y -> x)
hylo !phi !psi = cata phi . ana psi
{-# INLINE hylo #-}

data Node f a x = Node !a !(f x)
  deriving Show

instance Functor f => Functor (Node f a) where
  fmap f (Node a fx) = Node a (fmap f fx)

newtype Cofree f a = Cofree { runCofree :: FixF (Node f a) }

instance Functor f => Functor (Cofree f) where
  fmap f = Cofree . ana (phi . outF) . runCofree where
    phi (Node a b) = Node (f a) b

extract :: Functor f => Cofree f a -> a
extract !cf = case outF (runCofree cf) of
  Node a _ -> a
{-# INLINE extract #-}

sub :: Functor f => Cofree f a -> f (Cofree f a)
sub !cf = case outF (runCofree cf) of
  Node _ b -> fmap Cofree b
{-# INLINE sub #-}

histo :: Functor f => (f (Cofree f a) -> a) -> FixF f -> a
histo !phi = extract . cata ap
  where ap !a = Cofree $ InF $ Node (phi a) (fmap runCofree a)
{-# INLINE histo #-}

dyna :: Functor f => (f (Cofree f x) -> x) -> (y -> f y) -> (y -> x)
dyna !phi !psi = extract . hylo ap psi
  where ap !a = Cofree $ InF $ Node (phi a) (fmap runCofree a)
{-# INLINE dyna #-}

data DP a = N | P !Int !a
  deriving (Eq, Show)

instance Functor DP where
  fmap f N = N
  fmap f (P n a) = P n (f a)

solve :: Int -> VU.Vector Int16 -> Int
solve !n !hs = dyna phi psi $ (n - 1)
 where
  psi !0 = N
  psi !n = P n (n - 1)

  phi !N         = 0
  phi (P !n !dp) = min f1 f2
   where
    h  = hs VU.! n
    f1 = extract dp + fromIntegral (abs (h - hs VU.! (n - 1)))
    f2 = case sub dp of
      N     -> fromIntegral $ abs $ hs VU.! 1 - hs VU.! 0
      P _ a -> extract a + fromIntegral (abs (h - hs VU.! (n - 2)))

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n hs


Measured memory_bytes: 18940
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<string>
#define pi 3.14159
using namespace std;

int main() {
	double ang = pi / 2;
	double X = 0, Y = 0;
	while(1) {
		int x, y;
		scanf("%d, %d",&x, &y);
		if (x == 0 && y == 0) break;
		X = X + x * cos(ang);
		Y = Y + x * sin(ang);
		ang = ang - y * pi / 180;
	}
	printf("%d\n%d\n", (int)X, (int)Y);

	return 0;
}

Measured memory_bytes: 1192
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Vertex {
  int id;
  int degree;

  Vertex (int id = -1, int degree = -1) {
    this->id = id;
    this->degree = degree;
  }

  bool operator>(const Vertex &v) const {
    return degree > v.degree;
  }
};

struct Edge {
  int a;
  int b;

  Edge (int a = -1, int b = -1) {
    this->a = a;
    this->b = b;
  }
};

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

  priority_queue <int, vector<int>, greater<int>> C;

  vector<int> edges[N + 1];
  vector<Edge> edgeList;
  int degrees[N + 1];
  memset(degrees, 0, sizeof(degrees));

  int a, b;
  for (int i = 0; i < N - 1; ++i) {
    cin >> a >> b;

    edgeList.push_back(Edge(a, b));
    edges[a].push_back(b);
    edges[b].push_back(a);

    ++degrees[a];
    ++degrees[b];
  }

  for (int i = 0; i < N; ++i) {
    int c;
    cin >> c;
    C.push(c);
  }

  priority_queue <Vertex, vector<Vertex>, greater<Vertex>> pque;
  ll sum = 0;
  int ans[N + 1];
  memset(ans, 0, sizeof(ans));

  for (int i = 1; i <= N; ++i) {
    pque.push(Vertex(i, degrees[i]));
  }

  bool checked[N + 1];
  memset(checked, false, sizeof(checked));

  while (!pque.empty()) {
    Vertex v = pque.top();
    pque.pop();

    if (checked[v.id]) continue;
    checked[v.id] = true;

    int val = C.top();
    C.pop();
    ans[v.id] = val;

    for (int i = 0; i < edges[v.id].size(); ++i) {
      int m = edges[v.id][i];
      if (checked[m]) continue;

      --degrees[m];

      pque.push(Vertex(m, degrees[m]));
    }
  }

  for (int i = 0; i < N - 1; ++i) {
    Edge edge = edgeList[i];

    sum += min(ans[edge.a], ans[edge.b]);
  }

  cout << sum << endl;
  for (int i = 1; i <= N; ++i) {
    cout << ans[i];

    if (i != N) {
      cout << " ";
    } else {
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int D; //365
    cin >> D;

    int c[26];
    rep(i, 0, 26) {
        cin >> c[i];
    }

    int s[D][26];
    int t[D] = {};
    rep(i, 0, D) {
        int mx = -1;
        rep(j, 0, 26) {
            cin >> s[i][j];
            if (mx < s[i][j]) {
                mx = s[i][j];
                t[i] = j;
            }
        }
    }

    //日程を乱数で初期化
    srand(time(NULL));
    /*rep(i, 0, D) {
        t[i] = rand() % 26;
    }*/

    ll mx_score = -1e18;
    int cnt = 100000;
    while (cnt--) {
        //d日目のコンテストをqに置き換えてスコアを計算し、改善しなければ元に戻す
        int d = rand() % 365;
        int q = rand() % 26;
        int old = t[d];
        t[d] = q;

        //スコアを計算する
        ll score[D] = {};
        vector<int> last_day(26, -1);
        rep(i, 0, D) {
            if (i != 0) score[i] = score[i - 1];
            //増加分
            score[i] += s[i][t[i]];

            last_day[t[i]] = i;

            //減少分
            ll decrease = 0;
            rep(j, 0, 26) {
                decrease += c[j] * (i - last_day[j]);
            }
            score[i] -= decrease;
        }
        //cout << "score[D - 1]: " << score[D - 1] << endl;
        if (mx_score > score[D - 1]) {
            t[d] = old;
        } else {
            mx_score = score[D - 1];
        }
    }

    rep(i, 0, D) cout << t[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
const int maxn = int(4e4) + 7, P = int(1e9) + 7;
typedef long long ll;
ll fac[maxn], inv[maxn];
ll Pow(ll x,ll y){
    x%=P;
    ll ans=1;
    while(y){
        if (y&1) ans=ans*x%P;
        x=x*x%P;
        y>>=1;
    }
    return ans%P;
}
void init() {
    fac[0] = 1;
    for (int i = 1; i <= maxn - 10; ++i) fac[i] = fac[i - 1] * i % P;
    inv[maxn - 10] = Pow(fac[maxn - 10], P - 2);
    for (int i = maxn - 11; i >= 0; --i) inv[i] = inv[i + 1] * (i + 1) % P;
}

ll C(int x, int y) {
    return fac[x] * inv[y] % P * inv[x - y] % P;
}

int n, a[2000007], b[2000007], dp[4007][4007];

int main() {
//    freopen("in.txt", "r", stdin);
    init();
    scanf("%lld",&n);
    for (ll i=1; i<=n; i++){
        scanf("%lld%lld",&a[i],&b[i]);
        dp[2001-a[i]][2001-b[i]]++;
    }
    for (ll i=1; i<=4001; i++)
        for (ll j=1; j<=4001; j++){
            dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%P;
        }
    ll ans=0;
    for (ll i=1; i<=n; i++)
        ans=(ans+dp[2001+a[i]][2001+b[i]])%P;
    for (ll i=1; i<=n; i++)
        ans=(ans-C(a[i]+a[i]+b[i]+b[i],a[i]+a[i])+P)%P;
    printf("%lld\n",ans*inv[2]%P);
    // printf("%lld\n", ans * Pow(2, P - 2) % P);
    return 0;
}

Measured memory_bytes: 68036
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

const int MAXN = 5e5 + 5;

int dp[MAXN + 5][5];
int Last[MAXN + 5], Next[MAXN + 5];
char s[MAXN + 5];

int N;

void solve_L()
{
	int tot = 0, c = 0;
	s[N + 1] = '0';
	for(int i = 1; i <= N + 1; i++){
		if(s[i] == '0') Next[tot] = i, Last[i] = tot, tot = i;
	}
	for(int i = 1; i <= N; i++){
		if(s[i] == '0'){
			c = i;
			break;
		}
	}
	//printf("%d\n", c);
	dp[c][1] = 0;
	if(c != 0 && s[c - 1] == '1' && s[c + 1] == '1'){
		dp[c][2] = c - 1;
		dp[c][3] = Next[c] - c - 1;
	}
}

int solve_1(int tot)
{
	int Max = 0, c = Last[tot];
	Max = max(Max, dp[c][1]);
	Max = max(Max, dp[c][2]);
	Max = max(Max, dp[c][3]);
	return Max;
}

int solve_2(int tot)
{
	int Max = 0, c = Last[tot];
	if(s[tot - 1] == '1' && s[tot + 1] == '1'){
		Max = max(Max, dp[c][1] + tot - c - 1);
		if(tot - c - 1 >= 2) Max = max(Max, dp[c][2] + tot - c - 2);
	}
	return Max;
}

int solve_3(int tot)
{
	int Max = 0, c = Last[tot];
	if(s[tot - 1] == '1' && s[tot + 1] == '1'){
		Max = max(Max, dp[c][1] + Next[tot] - tot - 1);
		if(tot - c - 1 >= 2){
			Max = max(Max, dp[c][2] + Next[tot] - tot - 1);
		//if(tot == 4) printf("%d\n", Max);
			Max = max(Max, dp[c][3] - 1 + Next[tot] - tot - 1);
		}
	}
	return Max;
}

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf(" %c", &s[i]);
	solve_L();
	bool check = false;
	for(int i = 1; i <= N; i++){
		if(s[i] == '0' && check){
			dp[i][1] = solve_1(i);
			dp[i][2] = solve_2(i);
			dp[i][3] = solve_3(i);
		}
		else if(s[i] == '0') check = true;
	}
	int Max = 0;
	//for(int i = 1; i <= N; i++) printf("%d %d %d\n", dp[i][1], dp[i][2], dp[i][3]);
	//for(int i = 1; i <= N; i++) printf("%d %d\n", Last[i], Next[i]);
	for(int i = 1; i <= N; i++){
		Max = max(Max, dp[i][1]);
		Max = max(Max, dp[i][2]);
		Max = max(Max, dp[i][3]);
	}
	printf("%d\n", Max);
}

Measured memory_bytes: 14336
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
int A, B, C,M;
int main() {
	std::cin >> A >> B >> C;
	M = std::max({ A, B, C });
	M *= 3;
	int sum = A + B + C;
	while ((M - sum) % 2) {
		M += 3;
	}
	std::cout << ((M - sum) / 2) << std::endl;
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    int n = s.size()-2;
    cout << s[0] << n << s[s.size()-1] << endl;
    return 0;
}

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

int main()
{
    int n,ans=0,cnt=0;
    string s;
    cin>>n;
    cin>>s;

    for(int i=0;i<n;i++)
    {
        if(s[i]=='I')
            ++cnt;
        else
            --cnt;
        ans=max(ans,cnt);
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 3600
import java.util.Scanner;

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

        for(int i = 0; i < n; i++)
            ary[i] = stdIn.nextInt();

        int max = ary[0];
        int index_max = 0;
        for(int i = 1; i < n; i++)
            if(max < ary[i]){
                max = ary[i];
                index_max = i;
            }
        
        int center = (max + 1) / 2;

        int index = 0;
        int min = 0;
        int x = 0;
        if(center < ary[0])
            min = ary[0] - center;
        else
            min = center - ary[0];
        for(int i = 1; i < n; i++){
            if(center < ary[i])
                x = ary[i] - center;
            else
                x = center - ary[i];
            if(min >= x && index_max != i){
                min = x;
                index = i;
            }
        }

        System.out.println(max + " " + ary[index]);
    }
}

Measured memory_bytes: 50720
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define endl "\n"
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define cn cin>>
#define co cout<<
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{


long long a,b,c,e,f,g,h;

cin>>a;
string s;
int count=0;
int d=INT_MIN;
for (int i = 0; i < a; ++i)
{
	/* code */
	char s;
	cin>>s;
	if (s=='I')
	{
		/* code */
		count++;
	}
	else{
		count--;
	}
	d=max(d, count);
}
if (d<0)
{
	/* code */
	cout<<"0";
}
else
cout<<d<<endl;
return 0;
}

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

bool	issmall(char c)
{
	return (c >= 'a' && c <= 'z');
}

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

	string	s;
	cin >> s;
	int a;
	a = 0;
	while (1)
	{
		if (s.at(a) == 'A')
			break;
		a++;
	}
	int z;
	z = s.size() - 1;
	while (1)
	{
		if (s.at(z) == 'Z')
			break;
		z--;
	}
	cout << z - a + 1 << endl;
}


Measured memory_bytes: 720
n, k = (int(i) for i in input().split())
balls = (int(i) for i in input().split())
freqs = {}
for ball in balls:
    freqs[ball] = freqs[ball] + 1 if ball in freqs else 1
freq_hist = list(freqs.values())
freq_hist.sort(reverse=True)
print(sum(freq_hist[k:]))


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int K;
	cin >>K;
	vector<int> N(11, 0);
	int hx=0;
	Rep0(i, K) {
		bool Done=false;
		int ix=0;
		while (!Done) {
			N.at(ix)++;
			if (N.at(ix)>9) {
				ix++;
				hx=max(hx, ix);
			} else {
				for (int j=ix-1; j>=0; j--)
					N.at(j)=max(0, N.at(j+1)-1);
				if (ix==hx) {
					Done=true;
				} else if (N.at(ix)<=N.at(ix+1)+1) {
					Done=true;
				} else {
					ix++;
				}
			}
		}
	}
	for (int i=hx; i>=0; i--)
		cout <<N.at(i);
	cout <<endl;
	return 0;
}



Measured memory_bytes: 256
// Author := Abhishek Giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define V(type) vecapital_in_tor<(type)> 
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)
#define el "\n"

/*##################################################################################*/

/*
int prime[1000000] = {0} ;
vecapital_in_tor< int > p ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 1000000 ; i++)
    {
        if(prime[i] == 0)
        {
            p.pb(i);
            for(ll j = i*i ; j <= 1000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

bool isprime(ll n)
{
    for(ll i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

ll fib(int n) 
{ 
  ll a = 0, b = 1, c, i; 
  if( n == 0) 
    return a; 
  for (i = 2; i <= n; i++) 
  { 
    c = (a + b); 
    a = b; 
    b = c; 
  } 
  return b; 
}


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

ll extendedgcd(ll a, ll b, ll& x, ll& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll x1, y1;
    ll d = extendedgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

ll findgrouplcm(vector<int> &arr, int n) 
{ 
    ll ans = arr[0]; 
  
    for (ll i = 1; i < n; i++) 
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));
  
    return ans; 
}


ll powerwithmod(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}


bool comp(const pair<int,int> &a , const pair<int,int> &b){
    return a.first < b.first;
    if(a.first == b.first)  return a.second < b.second;
}

void solve(){
    int x,y;
    cin>>x>>y;
    if( y % 2 == 0 and y >= 2*x and y <= 4*x){
        cout<<"Yes";
    }
    else    cout<<"No";
}

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

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split().Select(long.Parse).ToList();

            long positiveMin = Math.Abs(NK[0] - (NK[0] / NK[1]) * NK[1]);
            long negativeMin = Math.Abs(NK[0] - (NK[0] / NK[1] + 1) * NK[1]);

            Console.WriteLine(Math.Min(positiveMin, negativeMin));
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
using namespace std;

const int MAX = 2100000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int x, y;
    cin >> x >> y;
    if (x < y) swap(x, y);
    COMinit();
    if ((x + y) % 3) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x + y) / 3;
    cout << COM(n, x - n) % MOD << endl;
    return 0;
}


Measured memory_bytes: 49408
#include <stdio.h>
#include <stdlib.h>
 
#define M 500000
#define P 10
#define NIL NULL
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
 
Node root;
 
void insert(int);
void inorder(Node);
void preorder(Node);
 
 
 
int main() {
 
  int m,k,i;
  char s[10];
 
  scanf("%d",&m);
 
  for (i=0 ; i<m ; i++){
    scanf("%s",s);
 
    if(s[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
 
    else {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}
 
void insert(int k){
  Node x = root;
  Node y = NIL;
  Node z;
 
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
 
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
 
  z->parent=y;
 
  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
 
}
 
void inorder(Node r){
  if(r->left!=NIL) inorder(r->left);
  printf(" %d",r->key);
  if(r->right!=NIL)inorder(r->right);
}
 
 
void preorder(Node r){
    printf(" %d",r->key);
    if(r->left!=NIL) preorder(r->left);
    if(r->right!=NIL)preorder(r->right);
}


Measured memory_bytes: 25144
import java.util.Scanner;
public class Main {
	public static void  main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();
		int i,j;
		int ans=0;
		int[][] x = new int[n][d];
		for(i = 0;i<n;i++) {
			for(j=0;j<d;j++) {
				x[i][j] = s.nextInt();
			}
		}
		for(int k=0;k<n;k++) {
			for(i=0;i<n-k-1;i++) {
			double sum =0;
				for(j=0;j<d;j++) {
					sum += Math.pow(x[k][j] - x[n-i-1][j], 2);
				}
				sum = Math.sqrt(sum);
				if(sum - (int)sum == 0) ans++;
			}
		}
		System.out.println(ans);
		s.close();
    }
}

Measured memory_bytes: 21460
n=int(input())
a=input()
b=a[len(a)-1]
word1=[a]
word2=[b]
c=0

for i in range(n-1):
    aa=input()
    bb=aa[0]
    if aa not in word1 and word2[i]==bb:
        word1.append(aa)
        top=aa[len(aa)-1]
        word2.append(top)
    else:
        c=1
        break
        
print("Yes" if c==0 else "No")

Measured memory_bytes: 3064
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N = int(input())

if N%1000 != 0:
    print(1000 - N % 1000)
else:
    print(0)

Measured memory_bytes: 10452
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	vector<pair<int,int>> P(N);
	REP(i,N){
		P[i].first=i;
		P[i].second=in();
	}
	sort(ALL(P),PAIRCOMP(second,<));
	
	REP(i,N-1){
		cout << P[i].first+1 << ' ' ;
	}
	out(P[N-1].first+1);
	return 0;
}


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

using namespace std;

int main(int argc,char* argv[]){
	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
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void){

    ll s;
    cin>>s;

    cout<<"0 0 1000000000 1 ";

    ll x, y;
    //s = 1000000000 * x - y;


    for(ll i = 0;i<=1000000000;i++){
        y = 1000000000 * i - s;
        if(0 <=y && y < 1000000001 ){
            x = i;
            break;
        }
    }

    cout<<y<<" "<<x<<endl;
    

    return 0;
}

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

using namespace std;
const int N=2e5+5;
const int mod=998244353;
int n,m,k,gt[N],igt[N];

int Power(int x,int n)
{
    if(n==0) return 1;
    if(n%2) return Power(x,n-1)*x%mod;
    int tmp=Power(x,n/2);
    return tmp*tmp%mod;
}

int C(int k,int n)
{
    if(k<0||k>n) return 0;
    if(k==0) return 1;
    return gt[n]*igt[n-k]%mod*igt[k]%mod;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>k;
    gt[0]=1;
    for(int i=1;i<=n;i++) gt[i]=gt[i-1]*i%mod;
    igt[n]=Power(gt[n],mod-2);
    for(int i=n-1;i>=0;i--) igt[i]=igt[i+1]*(i+1)%mod;
    int res=0;
    for(int p=n-k;p<=n;p++) res=(res+C(p-1,n-1)*m%mod*Power(m-1,p-1)%mod)%mod;
    cout<<res;
}


Measured memory_bytes: 6668