akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(min(b, d) - max(a, c), 0) << endl;
	return 0;
}


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

int main() {
	unsigned long long t1, t2, a1, b1, a2, b2;
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	if (a1*t1+a2*t2 == b1*t1+b2*t2) {
		cout<<"infinity"<<endl;
		return 0;
	}
	if (a1*t1+a2*t2 < b1*t1+b2*t2) {
		swap(a1, b1);
		swap(a2, b2);
	}

	if (a1*t1 > b1*t1) {
		cout<<0<<endl;
		return 0;
	}

	// Then A1<B1 && A2>B2
	unsigned long long delta = a1*t1 + a2*t2 - b1*t1 - b2*t2;
	long long ans = (b1*t1 - a1*t1) / delta;
	ans = ans*2 + 1; // 1 is the first time.
	if ((b1*t1 - a1*t1) % delta == 0)
		ans--;
	cout<<ans<<endl;
	return 0;
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 N, K;
    cin >> N >> K;

    vector< i64 > A(N);
    cin >> A;

    vector< i64 > r_(41);
    auto r = r_.begin() + 1;
    range(i, 0, 40) {
        i64 sum0 = 0, sum1 = 0;
        i64 msk = (1ll << i); 
        range(j, 0, N) {
            i64 a = msk & A[j];
            sum0 += a;
            sum1 += msk ^ a;
        }

        r[i] = r[i - 1] + max(sum1, sum0);
    }

    i64 ans = 0;
    range(j, 0, N) {
        ans += A[j] ^ K;
    }

    range(i, 0, 40) {
        i64 msk = (1ll << i);
        if (!(msk & K)) continue;

        K -= msk;

        i64 sum = 0;
        range(j, 0, N) {
            sum += ((A[j] >> i) << i) ^ K;
        }

        chmax(ans, sum + r[i - 1]);
    }

    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=444,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
inline int qmo(int x){return x+(x>>31?mod:0);}
int n,a[maxn],f[maxn][maxn][2],cnt,rt,ans;
inline int qpow(int a,int b){
	int ans=1;
	for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
int solve(int l,int r){
	if(l>r) return 0;
	int mid=l,now=++cnt;
	FOR(i,l,r) if(a[i]<a[mid]) mid=i;
	int h=a[mid]-max(a[l-1],a[r+1]);
	if(l==r){
		f[now][0][1]=1;
		f[now][1][0]=1;
		f[now][1][1]=mod-1;
	}
	else{
		int ls=solve(l,mid-1),rs=solve(mid+1,r);
		if(!rs) FOR(i,0,mid-l) FOR(x,0,1) f[now][i][x]=f[ls][i][x];
		else if(!ls) FOR(i,0,r-mid) FOR(x,0,1) f[now][i][x]=f[rs][i][x];
		else FOR(i,0,mid-l) FOR(x,0,1) FOR(j,0,r-mid) FOR(y,0,1)
			f[now][i+j][x&y]=(f[now][i+j][x&y]+1ll*f[ls][i][x]*f[rs][j][y])%mod;
		ROF(i,r-l,0){
			f[now][i+1][0]=(f[now][i+1][0]+f[now][i][1])%mod;
			f[now][i+1][1]=(f[now][i+1][1]-f[now][i][1]+mod)%mod;
		}
	}
	FOR(i,0,r-l+1) FOR(x,0,1){
		int tmp=(qpow(2,r-l+1-i)-!x+mod)%mod;
		f[now][i][x]=1ll*f[now][i][x]*qpow(tmp,h)%mod;
	}
	return now;
}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	rt=solve(1,n);
	FOR(i,0,n){
		int pr=(f[rt][i][0]+f[rt][i][1])%mod;
		ans=(ans+pr)%mod;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 5188
#include <stdio.h>

int kakuinowa(int i){
        int dig,sum=0;
        while(i){
                dig = i%10;
                sum = sum + dig;
                i = i / 10;
        }
        return sum;
}

int main(){
        int N,A,B;
        int count=0,field=0;
        scanf("%d %d %d",&N,&A,&B);
        for(int i=1;i<=N;i++){
                field = kakuinowa(i);
                if((A<=field)&&(field<=B)){
                        count = count +i;
                }
        }
        printf("%d\n", count);
        return 0;
}


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

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)
#define deb(x) cout << #x" = " << x << '\n'
#define has(cont, x) ((cont).find((x)) != (cont).end())
#define sz(x) ((int)(x).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

char grid[123][123];

int main() {
//    freopen("input.in", "r", stdin);
	int h, w;
	scanf("%d %d", &h, &w);
	fr(i, 0, h) scanf("%s", grid[i]);
	fr(i, 0, h) {
		puts(grid[i]);
		puts(grid[i]);
	}
	return 0;
}

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

int main(){
    int n,min,ans;
    cin >> n;
    int R[n];
    for ( int i = 0; i < n; i++)cin >> R[i];
    min  = R[0];
    ans = R[1] - R[0];
    for ( int i = 1; i < n; i++){
        if ( min > R[i]){
            min = R[i];
        }else if ( ans < R[i] - min ){
            ans = R[i] - min;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

int main() {
  int t;
  string output = "APPROVED";
  cin >> t;
  
  for (int i = 0; i < t; i++) {
    int num;
    cin >> num;
    if (num % 2 == 0 && (num % 3 != 0 && num % 5 != 0)) {
      output = "DENIED";
      break;
    }
  }
  
  cout << output << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,h,a;
    cin>>h>>a;
    ans=(h/a)+((h%a!=0)?1:0);

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

const long long MOD = 1000000007LL;
const long long INF = 1e18;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

struct chash {
    static uint64_t splitmix64(uint64_t x) {x += 0x8e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf54876d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31);}
    size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM);}
    size_t operator()(pair<uint64_t,uint64_t> x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x.first + FIXED_RANDOM)^(splitmix64(x.second + FIXED_RANDOM) >> 1);}
};

long long n;

long long solve(long long d, bool a, bool b, bool c){
    if(d > n) return 0;
    long long tot = a&&b&&c ? 1 : 0;
    tot += solve(d * 10 + 3, true, b, c);
    tot += solve(d * 10 + 5, a, true, c);
    tot += solve(d * 10 + 7, a, b, true);
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;

    cout << solve(0,false,false,false);

    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <math.h>

const int INF = 1000000, SBMI = 22;

int main(){
	int n;
	while(std::cin >> n, n){
		double bbmi = INF;
		int bn = 0;
		while(n--){
			//Input
			int i;
			double w, h, bmi;
			std::cin >> i >> h >> w;

			//Processing
			bmi = w / ((h / 100) * (h / 100));
			//WÆÌ·ÅxXgBMIðßéD
			if(fabs(bbmi - SBMI) > fabs(bmi - SBMI))bbmi = bmi, bn = i;
		}
		printf("%d\n", bn);
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int n, x, d = 0, i = 1;
    cin >> n >> x;
    while(n--){
        int li;
        cin >> li;
        d += li;
        i += d <= x ? 1 : 0;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

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

const ll maxn = 100010;

ll n;
ll ar[maxn];

void MAIN() {

    cin >> n;
    fori (i, n) cin >> ar[i];
    sort(ar, ar + n);
    fori (i, n - 1) {
        if (ar[i + 1] - ar[i] > 1) {
            cout << "Impossible\n";
            return;
        }
    }
    if ((ar[n - 1] + 1) / 2 == ar[0] && ar[n - 1] == ar[n - 2] && 
        ((ar[n - 1] % 2 == 1) && (ar[0] != ar[2]) || (ar[0] != ar[1]))) {
        cout << "Possible\n";
    } else {
        cout << "Impossible\n";
    }

}

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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
5
4 3 2 3 4
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int a,b;
  cin >>a >> b;
  string s;
  cin >> s;
  
  
  bool isp=true;
  for(int i=0;i<a;i++){
	if (s[i] < '0' || s[i] > '9')isp=false;
  }
  if (s[a] != '-')isp=false;
  
  for(int i=a+1;i<a+b;i++){
	if (s[i] < '0' || s[i] > '9')isp=false;
  }
  
  
    cout << (isp?"Yes" : "No");
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  private final Scanner sc = new Scanner(System.in);

  public void run() {
    int n = sc.nextInt();

    int[][] mat = new int[n][n];

    for (int i = 0; i < n; i++) {
      int u = sc.nextInt() - 1;
      int k = sc.nextInt();

      for (int j = 0; j < n; j++) {
        mat[u][j] = 0;
      }

      for (int j = 0; j < k; j++) {
        mat[u][sc.nextInt() - 1] = 1;
      }
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n - 1; j++) {
        System.out.print(mat[i][j] + " ");
      }
      System.out.println(mat[i][n - 1]);
    }
  }

  public static void main(String[] args) {
    new Main().run();
  }
}

Measured memory_bytes: 23920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {


   public static void main(String args[]) throws IOException{

	 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	 String[] string =  br.readLine().split(" ");
	 String[] formula = new String[ string.length ];


	 Stack stack = new Stack();
     stack.initialize();


     for(int i = 0;i < string.length; i++){


    	 if( string[i].equals("+")  ){
    		 int x = Integer.parseInt(stack.pop() );
    		 int y = Integer.parseInt(stack.pop() );
             int result = x + y;
             stack.push( String.valueOf(result) );
    	 }
    	 else if( string[i].equals("-") ){
    		 int x = Integer.parseInt(stack.pop() );
    		 int y = Integer.parseInt(stack.pop() );
    		 int result = y - x;
             stack.push( String.valueOf(result) );

    	 }
    	 else if( string[i].equals("*") ){
    		 int x = Integer.parseInt(stack.pop() );
    		 int y = Integer.parseInt(stack.pop() );
    		 int result = x * y;
             stack.push( String.valueOf(result) );
    	 }
    	 else{
    		 stack.push( string[i] );
    	 }
     }


     System.out.println(stack.pop());
 }
}

class Stack {
	int top = 0;
    int MAX = 200;
    String[] S = new String[200];


	void initialize(){
       top = 0;
    }

    boolean isEmpty(){
    	return top == 0;
    }


    boolean isFull(){
    	return top >= MAX - 1;
    }

    void push(String x ){

    	if(isFull()){System.out.println("??¨??????");}
    	top++;
        S[top] = x;

    }

    String pop(){
    	if(isEmpty()){System.out.println("??¨??????");}
    	top--;
    	return  S[top+1];
    }



}

Measured memory_bytes: 24408
#include <iostream>
using namespace std;
#include <string>
int main(){
  int X,Y,Z;
  cin >> X >> Y >> Z;
  if (X > Z){
    cout << "NO" <<endl;
  }else{
    if (X +Y >= Z){
      cout << "YES" <<endl;
    }else{
      cout << "NO" <<endl;
    }
  }
 }


Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
MOD = 10 ** 9 + 7

def k(e)
  (1..e).inject{|sum, t| (sum * t) % MOD}
end

if n == m
  p ((k(n) ** 2) * 2) % MOD
elsif n - m == 1
  p ((k(m) ** 2) * n) % MOD
elsif m - n == 1
  p ((k(n) ** 2) * m) % MOD
else
  p 0
end


Measured memory_bytes: 1788
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
const int N=200005;
int n,m,q,brd,mi[N],x,y;
int main()
{
	RI i; for (scanf("%d%d%d",&n,&m,&q),i=1;i<=n;++i) mi[i]=m+1;
	for (i=1;i<=q;++i) scanf("%d%d",&x,&y),mi[x]=min(mi[x],y);
	for (brd=i=1;i<n;++i) if (mi[i+1]<=brd) return printf("%d",i),0;
	else if (brd+1<mi[i+1]) ++brd; return printf("%d",n),0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert

void solve(){
    ll n,m;
    cin>>n>>m;
    ll a[n+1][m+1];
    ll dp[n+1][m+1];
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            char ch;
            cin>>ch;
            a[i][j] = ch=='#'? 1 : 0;
            dp[i][j] = oo;
        }
    }

    dp[0][0] = a[0][0];
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(i+1 < n)
                dp[i+1][j] = min(dp[i+1][j] , dp[i][j] +  (a[i+1][j] and a[i][j]==0));
            if(j+1 < m)
                dp[i][j+1] = min(dp[i][j+1] , dp[i][j] + (a[i][j+1] and a[i][j]==0));
        }
    }
    cout << dp[n-1][m-1];
}

int main() {
   
    IOS;
    int T=1;
    //cin >> T;
    while(T --){
        solve();
    }
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

class sqrt_decomposition{
    public:
    const i64 B=2000;
    int n;
    vector<i64> data,unif,sum; //uni??????????????????????§?????¶?????????????
    sqrt_decomposition(int n,i64 init):n(n),data(n,init),unif((n+B-1)/B),sum((n+B-1)/B){
        rep(i,0,(n+B-1)/B) unif[i]=init;
        rep(i,0,n) sum[i/B]+=init;
    }

    //[s,t)???x??????????????´???[s,t)???????¨??????????
    i64 add(int s,int t,i64 x){
        i64 res=0;
        while(s<t and s%B!=0){
            data[s]+=x;
            sum[s/B]+=x;
            res+=data[s]+unif[s/B];
            ++s;
        }
        while(s<t and t%B!=0){
            --t;
            data[t]+=x;
            sum[t/B]+=x;
            res+=data[t]+unif[t/B];
        }

        while(s<t){
            int i=s/B;
            unif[i]+=x;
            sum[i]+=x*B;
            res+=sum[i];
            s+=B;
        }
        return res;
    }
};

void solve(){
    int n,q;
    cin >> n >> q;
    sqrt_decomposition sd(n,0);

    rep(i,0,q){
        int k;
        cin >> k;
        if(k==0){
            int s,t,x;
            cin >> s >> t >> x;
            --s;
            sd.add(s,t,x);
        }else{
            int s,t;
            cin >> s >> t;
            --s;
            cout << sd.add(s,t,0) << endl;
        }
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
#define ll long long
int main() {
    ll n, sum = 0, time;
    cin >> n;
    ll a[n], diff[n];
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
        if(i) diff[i - 1] = a[i] - a[i - 1];
    }
    diff[n - 1] = a[0] - a[n - 1];
    if(sum % (n * (n + 1) / 2)){
        cout << "NO" << endl;
        return 0;
    }
    time = sum / (n * (n + 1) / 2);
    for(ll i = 0; i < n; i++){
        if(diff[i] > time || (time - diff[i]) % n) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}


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

using ll = long long int;

ll arr[100010] = {};

int main(void){
    
    int n,a,b;
    cin >> n >> a >> b;
    
    ll l = 1,r = 10000000010,ans = 10000000010;
    
    for(int i = 0; i < n ;i++){
        cin >> arr[i];
    }
    
    for(int i = 0; i < 100; i ++){
        ll mid = l+(r-l)/2;
        
        ll res = mid;
        
        for(int i = 0; i < n; i++){
            ll t = arr[i] - mid*b;
            
            if(t > 0){
                res -= (t+(a-b)-1) / (a-b);
            }
            
        }
        
        //cout << mid << " " << l << " " << r << " res:" << res << endl;
        if(res < 0){
            l = mid + 1;
        }else if(res >= 0){
            r = mid;
        }
        
    }
    
    cout <<l<< endl;
    
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long ll;
int readin(){
	int x=0;
	int f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
ll readll(){
	ll x=0;
	ll f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return f*x;
}
int A[201000];
bool t[201000];
int N;
int check(int x){
	for(int i=1;i<=(N<<1)-1;i++)
	t[i]=A[i]>=x?1:0;
	int dis=0x3f3f3f3f;
	bool ret=t[N];
	if(!(N&1))ret=ret^1;
	for(int i=N-1;i>=1;i--)
	if(t[i]==t[i+1]&&N-i<dis){
		dis=N-i;
		ret=t[i];
	}
	for(int i=N+1;i<=(N<<1)-1;i++)
	if(t[i]==t[i-1]&&i-N<dis){
		dis=i-N;
		ret=t[i];
	}
	return ret;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=(N<<1)-1;i++)
	scanf("%d",&A[i]);
	int l=1;
	int r=(N<<1)-1;
	int ans;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else r=mid-1;
	}
	printf("%d",ans);
	return 0; 
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define INF ((int)1e9)

vector< vs32 > d;
vector< vs32 > t;
vs32 leaf;

void dfs(int p, int u, int id)
{
    bool found = false;
    for (auto v : t[u])
    {
        if (v == p) continue;
        found = true;
        d[id][v] = d[id][u] + 1;
        dfs(u, v, id);
    }
    if (id == 1 && !found) leaf.push_back(u);
}

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

    int N, u, v;
    cin >> N >> u >> v;
    --u; --v;

    t.resize(N);
    d.resize(2, vs32(N, INF));
    int a, b;
    rep (i, N - 1)
    {
        cin >> a >> b;
        --a; --b;
        t[a].push_back(b);
        t[b].push_back(a);
    }

    d[0][u] = 0;
    d[1][v] = 0;
    dfs(-1, u, 0);
    dfs(-1, v, 1);

    int ans = 0;
    for (auto l : leaf)
    {
        if (d[0][l] >= d[1][l]) continue;
        ans = MAX(ans, d[1][l] - 1);
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 11768
# -*- coding: utf-8 -*-
import sys

A,B,C,K = list(map(int, input().rstrip().split()))
#-----

sum_num = 0

for num,cnt in [(1,A), (0,B), (-1,C)]:
    if cnt <= K:
        K -= cnt
        sum_num += num*cnt
    else:
        print( sum_num + num*K )
        sys.exit()


print(sum_num)


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    int diff = b - a;
    bool ans = false;
    // cout << diff << endl;
    rep(i, 0, n){
        if(((n - 1 - i) * c - i * d) <= diff && diff <= (- i * c + (n - 1 -i) * d)) ans = true;
        // cout << (n - 1 - i) * c - i * d << " " << - i * c + (n - 1 - i) * d << endl;
    }
    cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 18:46 on 2019-08-26.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, m;
    cin >> n >> m;
    vvl ab(m + 1);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        if (a > m) continue;
        ab[a].eb(b);
    }

    pq<ll> que;
    ll ans = 0;
    for (ll i = 1; i <= m; ++i) {
        each(e, ab[i]) que.push(e);
        if (que.empty()) continue;
        ans += que.top();
        que.pop();
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}



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

int get_each_value(int n) {
  if ( n == 3 ) {
    return 100000;
  }
  else if ( n == 2 ) {
    return 200000;
  }
  else if ( n == 1 ) {
    return 300000;
  }
  return 0;
}

int main() {
  //input
  int X, Y;
  cin >> X >> Y;
  //calc
  int answer = get_each_value(X) + get_each_value(Y);
  if ( X == 1 && Y == 1 ) {
    answer += 400000;
  }
  //output
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

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

  map<char, bool> m;
  for (auto c : "NEWS") {
    m[c] = false;
  }

  rep(i, len(S)) {
    m[S[i]] = true;
  }

  bool ok = true;
  if (m['W'] ^ m['E'])
    ok = false;
  if (m['N'] ^ m['S'])
    ok = false;

  if (ok)
    cout << "Yes\n";
  else
    cout << "No\n";
}

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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;
const D PI = acos(-1);

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

//for vector

inline D dot(P x, P y){return real(conj(x)*y);}

inline D cross(P x, P y){return imag(conj(x)*y);}

//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

inline int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

inline D seg_p_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}

inline D seg_seg_dis(L a,L b){
  D res = 1e10;
  res = min(res,seg_p_dis(a,b.fs));
  res = min(res,seg_p_dis(a,b.sc));
  res = min(res,seg_p_dis(b,a.fs));
  res = min(res,seg_p_dis(b,a.sc));
  return res;
}

int main(){
  int n,m,l;
  while(scanf("%d%d%d",&n,&m,&l), n){
    vector< vector<L> > stars(n);
    for(int i=0;i<n;i++){
      int x,y,a,r;
      scanf("%d%d%d%d",&x,&y,&a,&r);
      P c = P(x,y);

      vector<P> v(5);
      P p = P(0,r);
      for(int j=0;j<5;j++){
	v[j] = c+rotate(p,PI*(a+j*72)/180);
      }
      
      vector<L> l(5);
      for(int j=0;j<5;j++){
	l[j] = L(v[j],v[(j+2)%5]);
      }
      stars[i] = l;
    }

    vector< vector<D> > g(n, vector<D>(n,0));
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	D dis = 1e9;
	for(L a : stars[i]){
	  for(L b : stars[j]){
	    if(is_cp(a,b)){
	      dis = 0;
	      break;
	    }else dis = min(dis, seg_seg_dis(a,b));
	  }
	}
	g[i][j] = g[j][i] = dis;
      }
    }

    for(int k=0;k<n;k++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
	}
      }
    }

    printf("%.9lf\n",g[m-1][l-1]);
  }
}	

Measured memory_bytes: 1360
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main() {
long long x,y;
cin >> x >> y;
long long ans = 0;
while (x <= y) {
    x *= 2;
    ans++;
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 3000001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_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_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}


int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    map<char, int> m;
    rep (i, n) m[s[i]]++;
    int ans = 1;
    for (auto p : m) ans = mul_mod(ans, p.second + 1);
    cout << mod(ans - 1) << "\n";
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define eps 1e-8
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
using namespace std;
typedef long long ll;
inline int rd()
{
    int x=0,f=1;
    char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}
const int N=200010,mod=1000000007;
int n,a[N],b[N],fac[8010],rfac[8010],ans=0;
int f[4010][4010];

inline int pls(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int mns(int a,int b){return a<b?a-b+mod:a-b;}
inline int mul(int a,int b){return (ll)a*b%mod;}
inline int pwr(int x,int k){int res=1;for(;k;k>>=1,x=mul(x,x))if(k&1)res=mul(res,x);return res;}
inline int _inv(int x){return pwr(x,mod-2);}
inline int C(int n,int m){return n<m?0:mul(fac[n],mul(rfac[m],rfac[n-m]));}

int main()
{
	fac[0]=1;fo(i,1,8001)fac[i]=mul(fac[i-1],i);
	rfac[8001]=_inv(fac[8001]);
	of(i,8001,1)rfac[i-1]=mul(rfac[i],i);
	n=rd();
	fo(i,1,n)a[i]=rd(),b[i]=rd(),f[2000-a[i]][2000-b[i]]=pls(f[2000-a[i]][2000-b[i]],1);
//	f[0][0]=1;
	fo(i,0,4000)fo(j,0,4000){
		if(i)f[i][j]=pls(f[i][j],f[i-1][j]);
		if(j)f[i][j]=pls(f[i][j],f[i][j-1]);
	}
//	cout<<f[3][3]<<endl;
	fo(i,1,n)ans=pls(ans,f[2000+a[i]][2000+b[i]]);
//	fo(i,1,n)cout<<f[2000+a[i]][2000+b[i]]<<' ';cout<<endl;
	fo(i,1,n)ans=mns(ans,C((a[i]+b[i])<<1,a[i]<<1));
	ans=mul(ans,rfac[2]);
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 64640
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define ld long double
int const M=2e5+10,M2=1e7+10,mod=1e9+7,inf=1e18+10;
bool mark[M];
int a[M];
vector<int>adj[M];
vector<int>now;
vector<pii>hlp;
int ans=0,mo=0;
int cnt[M];
void dfs(int v)
{
	now.pb(v);
	mark[v]=1;
	cnt[mo]++;
	for(int i=0;i<adj[v].size();i++)
	{
		//cout<<v<<" "<<adj[v][i]<<" "<<mark[adj[v][i]]<<"*******"<<endl;
		int u=adj[v][i];
		if(!mark[u])dfs(u);
	}
}
int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	if(n==1)return cout<<0,0;
	for(int i=1;i<=n;i++)cin>>a[i],ans+=a[i];
//	if(n==2)return cout<<a[1]+a[2],0;
	for(int i=1;i<=m;i++)
	{
		int aa,b;
		//aa++,b++;
		cin>>aa>>b;
		aa++,b++;
		adj[aa].pb(b);
		adj[b].pb(aa);
	}
	int bad=0,good=0;
	for(int i=1;i<=n;i++)
	{
		if(!mark[i]){
			now.clear();
			++mo,dfs(i);
			if(now.size()==1)bad++;
			else 
			{
				good++;
				for(int j=0;j<now.size();j++)hlp.pb(mp(a[now[j]],mo));
			}
		}
	}
	//cout<<good<<" "<<bad<<" "<<hlp.size()<<endl;
	sort(hlp.begin(),hlp.end());
	reverse(hlp.begin(),hlp.end());
	int res=hlp.size()-(good-1)*2;
	res=res-bad;
	if(mo==1)return cout<<0,0;
	//cout<<hlp.size()<<endl;
	if(res<0)return cout<<"Impossible",0;
	for(int j=0;j<hlp.size();j++)
	{
		int t=hlp[j].S;
	//	cout<<t<<" "<<hlp.size()<<" "<<res<<endl;
		if(!res)break;
		if(cnt[t]==1)continue;
		//cout<<res<<endl;
		cnt[t]--;
		res--;
		ans-=hlp[j].F;
		//cout<<hlp[j].F<<endl;
		//res--;
	}
	cout<<ans;
}

Measured memory_bytes: 12408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  int start = 0;
  int end = 0;
  for (int i = 0; i < S.length(); i++) {
    if(S[i] == 'A') {
      start = i;
      break;
    }
  }
  for (int i = 0; i < S.length(); i++) {
    if(S[i] == 'Z') {
      end = i;
    }
  }
  cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;

string s;


int main(){
    cin>>s;
    int n=s.size();
    s+="#$";
    bool f=true;
    Rep(i,n){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+2<<endl;
            f=false;
            break;
        }
        if(s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            f=false;
            break;
        }
    }
    if(f){
        cout<<-1<<" "<<-1<<endl;
    }

    return 0;
}


Measured memory_bytes: 512
//$g++ -std=c++11 Template.cpp 

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

priority_queue<int> q_descending;
priority_queue<int, vector<int>, greater<int> > q_ascending;

int c[3][3];

int
main(void){  
  ios_base::sync_with_stdio(false);

  REP(i, 3) REP(j, 3) cin >> c[i][j];
  
  int a = 0, b = 0;

  
  for(int a1=c[0][0]; a1>=0; a1--){
    int b1 = c[0][0]-a1;
    int b2 = c[0][1]-a1;
    int b3 = c[0][2]-a1;
    if(b1 < 0 || b2 < 0 || b3 < 0) continue;
    int a2 = c[1][0]-b1;
    int a3 = c[2][0]-b1;
    if(a2 < 0 || a3 < 0) continue;
    if((c[1][1] == a2+b2) && (c[2][1] == a3+b2) && (c[1][2] == a2+b3) && (c[2][2] == a3+b3)) { cout << "Yes" << endl; return 0;}
  }

  cout << "No" << endl;
  
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  //int A, B;
  //cin >> A >> B;

  if (s == "ABC") {
    cout << "ARC" << endl;
  }
  //else if (B - (B % K) != K){
  //else if ((B - (B % K)) >= A && (B - (B % K)) <= B) {
    //cout << "OK" << endl;
  //}
  else {
    cout << "ABC" << endl;
  }

}


Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int,input().split()))
#test
#a = [i for i in range(1,2*10**5+1)]

bucket = [0] * (2*10**5+1)
comb_bucket = [0] * (2*10**5+1)
for i in a:
    bucket[i]+=1

for i,v in enumerate(bucket):
    if v==0:
        continue
    comb_bucket[i] = (v * (v-1))//2
total_comb = sum(comb_bucket)
for ai in a:
    bi = bucket[ai]
    if bi == 1:
        print(total_comb)
    elif bi == 2:
        print(total_comb-1)
    else:
        print(total_comb - (bi-1))


Measured memory_bytes: 26140
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int max = arr[n - 1];
		int min = Integer.MAX_VALUE;
		int val = 0;
		for (int i = 0; i < n - 1; i++) {
			int x;
			if (max % 2 == 0) {
				x = Math.abs(max / 2 - arr[i]);
			} else {
				if (max / 2 >= arr[i]) {
					x = max / 2 - arr[i];
				} else {
					x = arr[i] - (max / 2 + 1);
				}
			}
			if (x < min) {
				min = x;
				val = arr[i];
			}
		}
		System.out.println(max + " " + val);
	}
}


Measured memory_bytes: 50820
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	reps(i,9){
		reps(j,9){
			if(i * j == n){
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}


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


using namespace std;

typedef long long ll;


int main() {
	ll x;
	cin >> x;

	ll ans = 2 * (x / 11);
	x -= ans / 2 * 11;
	
	if (x > 0) {
		if (x <= 6) {
			ans += 1;
		}
		else {
			ans += 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    ll a,b,c; cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << endl
#define rep(i,n) for(int i=0; (i)<(n); ++(i))
#define rrep(i,n) for(int i=(n); (i)>=0; --(i))
#define reps(i,s,n) for(int i=(s); (i)<(n); ++(i))
#define maxi(v) distance(v.begin(), max_element(v.begin(), v.end()))
#define mini(v) distance(v.begin(), min_element(v.begin(), v.end()))
#define maxemt(v) *max_element(v.begin(), v.end())
#define minemt(v) *min_element(v.begin(), v.end())
#define lb(v,x) v[lower_bound(v.begin(), v.end(), x) - v.begin()]
#define ub(v,x) v[upper_bound(v.begin(), v.end(), x) - v.begin()]
template<class T> inline bool print(T& x){ cout << x << endl; return true; }
template<class T> inline bool print_(T& x){ cout << x << " "; return true; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
  }
ll lcm(ll x, ll y){
  return x / gcd(x,y) * y;
}
const int INF = 1e9;
const ll llINF = 1LL<<60;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main(){
  int h, n; cin >> h >> n;
  vector<int> a(n); rep(i,n) cin >> a[i];
  if( h <= accumulate(all(a), 0) ) cout << "Yes";
  else cout << "No";
  
return 0;
}


Measured memory_bytes: 640
import math
A, B, H, M = map(int, input().split())
H = math.radians((H*60 + M)/2)
M = math.radians(M*6)

Ax = A*math.cos(H)
Ay = A*math.sin(H)
Bx = B*math.cos(M)
By = B*math.sin(M)

l = math.sqrt((Ax - Bx)**2 + (Ay - By)**2)
print(l)

Measured memory_bytes: 9524
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n){
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	rep(i,n){
		if(i == a[a[i]]) ++ans;
	}
	ans /= 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640