akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll n;
vector<ll> a;

int main() {
    cin >> n;
    a.resize(n + 1);
    rep(i, n + 1) cin >> a[i];

    combination comb(1e5 + 10);

    map<int, int> mp;
    int first_idx = -1, second_idx = -1;
    for (int i = 0; i < n + 1; i++) {
        if (mp.count(a[i])) {
            first_idx = mp[a[i]];
            second_idx = i;
            break;
        }
        mp[a[i]] = i;
    }
    // cout << first_idx << " " << second_idx << endl;
    // return 0;

    for (int i = 1; i <= n + 1; i++) {
        mint ans = comb(n + 1, i);

        // 被ってるやつを引く
        ans -= comb(first_idx + (n + 1) - 1 - second_idx, i - 1);
        // cout << first_idx + n - 1 - second_idx << " " << i - 1 << endl;
        // cout << comb(first_idx + (n + 1) - 1 - second_idx, i - 1) << endl;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	  ios::sync_with_stdio(0);
      cin.tie(0);
      char ar1[4],ar2[4];
      cin>>ar1;
      if(strcmp(ar1,"ARC")==0)
      {
      	cout<<"ABC"<<"\n";
	  }
	  else 
	  {
	  	cout<<"ARC"<<"\n";
	  }
	  return 0;
}

Measured memory_bytes: 3648
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    cnt=10**5
    m=len(format(cnt, 'b'))
    dp=[[-1 for j in range(n)] for i in range(m+1)]
    for j in range(n):
        if s[j]=='L':
            dp[0][j]=j-1
        else:
            dp[0][j]=j+1
    
    for i in range(m):
        for j in range(n):
            dp[i+1][j]=dp[i][dp[i][j]]
    
    after=[]
    for j in range(n):
        i=0
        nn=cnt
        cur_j=j
        while nn>0:
            if ((nn&1)==1):
                cur_j=dp[i][cur_j]
            nn>>=1
            i+=1
        after.append(cur_j)

    ans=[0]*n
    for j in range(n):
        ans[after[j]] += 1
    print(*ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 108488
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int h1 = input.nextInt();
        int m1 = input.nextInt();
        int h2 = input.nextInt();
        int m2 = input.nextInt();
        int k = input.nextInt();
        System.out.println(h2*60+m2-h1*60-m1-k);
    }
}

Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    ll a;
    ll mem = 1, ng = 1;
    REP(i, n) {
        cin >> a;
        if (a == mem) {
            ng = 0;
            mem++;
        }
    }
    if (ng) {
        cout << -1 << endl;
        return 0;
    }
    ll res = n - (mem - 1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
S = int(input())

# x1y2 - x2y1 = S
# (x1, y1) = (1e9, 1)
# 1e9y2 - x2 = S

x0 = 0
y0 = 0
x1 = 10**9
y1 = 1
y2 = (S-1) // x1 + 1
x2 = x1*y2 - S

print(x0, y0, x1, y1, x2, y2)


Measured memory_bytes: 38384
<?php
  	$x = array();
  	fscanf(STDIN, "%d %d %d", $r, $D, $x[2000]);
	for ($i=2000;$i<2010;$i++) {
    	$x[$i+1] = $r * $x[$i] - $D;
    }
	
	for ($i=2001;$i<=2010;$i++) {
    	echo $x[$i] ."\n";
    } 


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

int	main() {
	vector<int> bingo(9);
  	for (int i=0;i<9;i++) cin >> bingo.at(i);
  	int n;
  	cin >> n;
  	vector<int> corres(9);
  	int c = 0;
  	for (int j=0;j<n;j++) {
      int anno;
      cin >> anno;
    	for (int i=0;i<9;i++) {
        	if (bingo.at(i) == anno) {
              corres.at(c) = i;
              c++;    
            }
        }
    }
  	vector<int> corres2(c);
  	for (int i=0;i<c;i++) corres2.at(i) = corres.at(i);
  	int answer = 0;
  
  	if ((find(corres2.begin(), corres2.end(),0)!=corres2.end()) && (find(corres2.begin(), corres2.end(),1)!=corres2.end()) && (find(corres2.begin(), corres2.end(),2)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),3)!=corres2.end()) && (find(corres2.begin(), corres2.end(),4)!=corres2.end()) && (find(corres2.begin(), corres2.end(),5)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),6)!=corres2.end()) && (find(corres2.begin(), corres2.end(),7)!=corres2.end()) && (find(corres2.begin(), corres2.end(),8)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),0)!=corres2.end()) && (find(corres2.begin(), corres2.end(),3)!=corres2.end()) && (find(corres2.begin(), corres2.end(),6)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),1)!=corres2.end()) && (find(corres2.begin(), corres2.end(),4)!=corres2.end()) && (find(corres2.begin(), corres2.end(),7)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),2)!=corres2.end()) && (find(corres2.begin(), corres2.end(),5)!=corres2.end()) && (find(corres2.begin(), corres2.end(),8)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),0)!=corres2.end()) && (find(corres2.begin(), corres2.end(),4)!=corres2.end()) && (find(corres2.begin(), corres2.end(),8)!=corres2.end())) answer = 1;
  	if ((find(corres2.begin(), corres2.end(),2)!=corres2.end()) && (find(corres2.begin(), corres2.end(),4)!=corres2.end()) && (find(corres2.begin(), corres2.end(),6)!=corres2.end())) answer = 1;
  
  	if (answer==0) cout << "No" << endl;
  	else cout << "Yes" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using Int = int64_t;
int main() {
    Int N, ans = 10;
    cin >> N;
    for (Int i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            auto t = max(to_string(i).size(), to_string(N / i).size());
            if (t < ans) ans = t;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MAXSIZE 10000000;

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  else{
      return a.second > b.second;
  }
}

int Dx[6] = { 0, 0, 1, 1,-1,-1};
int Dy[6] = { 1,-1, 1, 0, 0,-1};

//priority_queue<long long int,vector<long long int>, greater<long long int>> PQ;
//priority_queue<long long int> PQ1;
int main(){
    long long int W,H,x,y;
    long long int ans1,ans2,flg = 0;

    cin >>W>>H>>x>>y;


    cout <<((double(H)*double(W))/2)<<' '<<(2*x == W && 2*y == H)<<endl;
    return 0;
}

/*Syakutori
while(cin >>b && b)){
      ll t = 1;
      long long int ansS = 1,ansT=0;
      long long int sum = 0;

      for(ll s = 1;s < 50000000;s++){

        while(t <  50000000 && sum+Rsum[t] < b){
          sum += Rsum[t];
          t++;
        }
        if(b == sum+Rsum[t]){
          if(ansT - ansS < t-s){
            ansS = s;
            ansT = t;
          }
          cout <<ansS<<" "<<ansT-ansS + 1<<endl;
          break;
        }
        if(t == s)++t;
        else sum -= Rsum[s];
        }
    }

*/

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n;cin>>n;
    ll suma=0,sumb=0;
    ll needa=0,needb=0;
    vector<ll>a(n),b(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];suma+=a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >>b[i];sumb+=b[i];
    }
    for (int j = 0; j < n; ++j) {
        ll d=a[j]-b[j];
        if(d>0)needb+=d;
        ll id=-d;
        if(id>0){
            needa+=(id-1)/2+1;
        }
    }
    bool flg=true;//yesorno
    ll opt=sumb-suma;
    if(opt<max(needa,needb))flg=false;
    if(flg)puts("Yes");
    else puts("No");
   // cout <<suma<<" "<<sumb<<" "<<opt<<" "<<needa<<" "<<needb<<" "<<endl;
    return 0;
}

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

using namespace std;

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long res = 1;
    res = max(max(a * c, b * c), max(b * d, a * d));
    cout << res << '\n';
    return 0; 
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef pair<int, int> pint;
int main(){
    int n, m;
    while(cin >> n >> m && n){
        priority_queue<pint> pd;
        rep(i, n){
            int d, p; cin >> d >> p;
            pd.push(pint(p, d));
        }
        int ans = 0;
        while(!pd.empty() && m > 0){
            pint now = pd.top(); pd.pop();
            if(m >= now.second){
                m -= now.second;
            }else{
                ans += (now.second - m) * now.first;
                m -= now.second;
            }
        }
        while(!pd.empty()){
            pint k = pd.top(); pd.pop();
            ans += k.first * k.second;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1332
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;

const int  mod = 1e9+7;
string s;

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

  cin >> s;

  int N = s.size();
  int num = 1;
  int pos = 0;
  rep(i, N) {
    if (s.at(i) != '1') {
      pos = i;
      num = s.at(i) - '0';
      break;
    }
  }

  ll K;
  cin >> K;
  
  if (K <= pos) {
    cout << 1 << endl;
  } else {
    cout << num << endl;
  }
}


Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String input = in.readLine();
		
		String[] x = input.split(" ");
		
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		int c = Integer.parseInt(x[2]);
		
		if(b > a && c > b){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}

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

int main() {
  int a,b;
  cin >> a >> b;
  int str1 = 0,str2 = 0;
  
  for (int i=0; i < b; i++) {
    str1 = str1*10 + a;
  }
  for (int i=0; i < a; i++) {
    str2 = str2*10 + b;
  }
  
  if (a >= b) {
    cout << str2 <<endl;
  }
  else {
    cout << str1 <<endl;
  }
  
}


Measured memory_bytes: 256
import java.util.Scanner;

//Social
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int[] b = new int[n+1];
		for(int i=0;i<k;i++){
			int m = sc.nextInt();
			while(m--!=0)b[sc.nextInt()]=i;
		}
		boolean[] bad = new boolean[n+1];
		int r = sc.nextInt();
		while(r--!=0){
			int p = sc.nextInt(), q = sc.nextInt();
			if(b[p]==b[q])bad[p]=bad[q]=true;
		}
		int res = 0;
		for(boolean v:bad)if(v)res++;
		System.out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
using ll =long long;

int main (void) {
  int N;
  cin >>N;
  int a[N+1];
  int count=0;
  int num=1;
  for (int i=1; i<=N; i++) {
    cin >> a[i];
  }
  while (num !=2){
    count+=1;
    num=a[num];
    if (count>N){
      cout << -1;
      return 0;
    }
  }
  cout << count;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<int> vi;

int main() {FIN
  
  int n, m, i, p, ca = 0, pe = 0;
  string s;
  cin >> n >> m;
  vi pr(n + 1), pn(n + 1);
  for (i = 0; i < m; i++) {
    cin >> p >> s;
    if (s == "AC") {
    	if (pr[p] == 0) {
          ca++;
          pr[p] = 1;
        }
    } else {
    	if (pr[p] == 0)
          pn[p]++;
    }
  }
  for (i = 1; i <= n; i++) {
	  if(pr[i] == 1)
		pe += pn[i];
  }
  cout << ca << " " << pe << "\n";
            
  return 0;
}


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

typedef long long ll;
const int MAX_N = 100030;    // Change as necessary
const ll  MODD = 1000000009; //

ll A[MAX_N];
ll B[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;
  for(int i=0;i<n;i++) cin >> A[i];
  sort(A,A+n);
	reverse(A,A+n);

	B[n] = 0;
	for(int i=n-1;i>=0;i--) B[i] = B[i+1] + A[i];

	int ans = n;
	for(int i=1;i<n;i++){
		if(2*B[i] < A[i-1]){
			ans = i;
			break;
		}
	}
	cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char A[8100];
char B[8100];
int sum[8100];
int main(){
	scanf("%s%s",A,B);
	int n=strlen(A);
	bool dame=true;
	for(int i=0;i<3*n;i++){
		A[i+n]=A[i];
		B[i+n]=B[i];
		if(B[i]=='1')dame=false;
	}
	set<int>S;
	for(int i=0;i<n*4;i++){
		if(B[i]=='1')S.insert(i);
		sum[i+1]=sum[i]+B[i]-'0';
	}

	int ret=mod;
	for(int i=0;i<n;i++){
		if(dame){
			bool ok=true;
			for(int j=0;j<n;j++)if(A[i+j]!=B[j])ok=false;
			if(ok)ret=0;
			continue;
		}
		vector<pair<int,int> >v;
		int tmp=0;
		for(int j=0;j<n;j++){
			if(A[i+j]!=B[j]){
				tmp++;
				int L=n+j;
				int R=n+i+j;
				if(sum[R+1]==sum[L]){
					int prev=*(--(S.lower_bound(L)));
					int nx=*(S.lower_bound(R));
					v.push_back(make_pair(prev-L,nx-R));
				}
			}
		}
		std::sort(v.begin(),v.end());
		int cur=mod;
		if(v.size()==0)cur=0;
		int ri=0;
		for(int j=0;j<v.size();j++){
			cur=min(cur,-v[j].first*2+ri*2);
			ri=max(ri,v[j].second);
		}
		cur=min(cur,ri*2);
		ret=min(ret,tmp+i+cur);
	//	printf("%d %d %d\n",tmp,i,cur);
		if(i==0)continue;
		v.clear();
		for(int j=0;j<n;j++){
			if(A[i+j]!=B[j]){
				int R=2*n+j;
				int L=n+i+j;
				if(sum[R+1]==sum[L]){
					int prev=*(--(S.lower_bound(L)));
					int nx=*(S.lower_bound(R));
					v.push_back(make_pair(prev-L,nx-R));
				}
			}
		}
		std::sort(v.begin(),v.end());
		cur=mod;
		if(v.size()==0)cur=0;
		ri=0;
		for(int j=0;j<v.size();j++){
			cur=min(cur,-v[j].first*2+ri*2);
			ri=max(ri,v[j].second);
		}
		cur=min(cur,ri*2);
		ret=min(ret,tmp+n-i+cur);
	//	printf("%d %d %d\n",tmp,n-i,cur);
	}
	if(ret==mod){
		ret=-1;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 640
// これはあってるはずや
#include<stdio.h>

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

    int fourK = 0;
    int twoK = 0;
    for(int i=0; i<n; i++){
        if(a[i]%4 == 0){
            fourK += 1;
        }
        else if(a[i]%2 == 0){
            twoK += 1;
        }
    }

    int ans;
    
    if(2*fourK+1 == n){
        ans = 1;
    }else{
        if(n-(2*fourK) <= twoK){
            ans = 1;
        }else{
            ans = 0;
        }
    }

    if(ans){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=100010,AS=26;
int sum[N][AS],n,mn[AS],tip[AS];
char s[N];
inline void solve(){
	memset(mn,0x3f,sizeof(mn));
	for (int i=1;i<=n;++i){
		for (int j=0;j<AS;++j){
			int val=(sum[i][j]<<1)-i;
			if (val>mn[j]){
				printf("%d %d\n",tip[j],i);
				return;
			}
			val=(sum[i-1][j]<<1)-(i-1);
			if (val<=mn[j]) mn[j]=val,tip[j]=i;
		}
	}
	puts("-1 -1");
	return;
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;++i){
		memcpy(sum[i],sum[i-1],sizeof(sum[i]));
		++sum[i][s[i]-'a'];
	}
	solve();
	return 0;
}

Measured memory_bytes: 10496
#include <stdio.h>
int main(void){
    long int N,M,i,cnt=0;
    long int H[100001];
    long int A[100000];
    long int B[100000];
    long int Nflag[100001];
    
    scanf("%ld",&N);
    scanf("%ld",&M);
    for(i=1;i<=N;i++){
        scanf("%ld",&H[i]);
        Nflag[i]=1;
    }
    
    for(i=0;i<M;i++){
        scanf("%ld",&A[i]);
        scanf("%ld",&B[i]);
        
        if(H[A[i]]<H[B[i]]){
            Nflag[A[i]]=0;
        }else if(H[A[i]]>H[B[i]]){
            Nflag[B[i]]=0;
        }else if(H[A[i]]==H[B[i]]){
            Nflag[A[i]]=0;
            Nflag[B[i]]=0;
        }
        
    }
    
    for(i=1;i<=N;i++){
        if(Nflag[i]==1){
            cnt++;
        }
    }
    
    printf("%ld\n",cnt);
    
    return 0;
}

Measured memory_bytes: 5244
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e3 + 5;
ll f[N][N];
pair<int, int> p[N];
ll cal(int cnt, int l, int r) {
    if(l > r) return 0;
    if(~f[l][r]) return f[l][r];
    ll ans = 1LL * p[cnt].first * abs(p[cnt].second - l) + cal(cnt + 1, l + 1, r);
    ans = max(ans, 1LL * p[cnt].first * abs(p[cnt].second - r) + cal(cnt + 1, l, r - 1));
    return f[l][r] = ans;
}
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        p[i] = {x, i};
    }
    sort(p + 1, p + n + 1,[](pair<int, int> a, pair<int, int> b) {
        return a.first > b.first;
    });
    memset(f, -1, sizeof f);
    printf("%lld\n", cal(1, 1, n));
    return 0;
}

Measured memory_bytes: 35352
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

ans = float("inf")

for i in range(4 ** N):
    temp = i
    mp = -30
    a = 0
    b = 0
    c = 0
    for p in range(N):
        if temp % 4 == 0:
            a += l[p]
            mp += 10
        elif temp % 4 == 1:
            b += l[p]
            mp += 10
        elif temp % 4 == 2:
            c += l[p]
            mp += 10
        
        temp //= 4

    if a == 0 or b == 0 or c == 0:
        continue

    mp += (abs(A - a) + abs(B - b) + abs(C - c))
    if mp < ans:
        ans = mp

print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int a[300010], sum[300010], n;
inline int check(int x) {
    int _min = 0;
    for (int i = 1; i <= n; i += 2) {
        if (sum[i] - _min >= x) {
            _min = min(_min, sum[i + 1]);
            if (i == n) return 1;
        }
    }
    return 0;
}
int main() {
    scanf("%d", &n);
    int sum1 = 0, sum2 = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        if (i % 2 == 0) a[i] = -a[i], sum1 -= a[i];
        else sum2 += a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    if (n % 2 == 0) return printf("%d %d\n", max(sum1, sum2), min(sum1, sum2)), 0;
    int ans, l = -1.5e9, r = 1.5e9;
    while (l <= r) {
        int mid = l + r >> 1;
        if (check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    return printf("%d %d\n", sum1 + ans, sum2 - ans), 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <stdio.h>
#pragma optimize("O3")
#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (a - 1); i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define endl "\n"
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define PLL pair<long long, long long>
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vll vector<long long>
#define mii map<int, int>
#define mll map<long long, long long>
#define MOD 1000000007
#define MAX 1000000007
#define MOD2 1234567891
#define SZ(a) (int) a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define TIE(l, r) Node *l, *r; tie(l, r)
#define EPS 0.00000001
#define PI 3.14159265359
void dout() { cerr << endl; }
#define MAXN 100001

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

/*,--. ,--.
  |  .'   /  ,--,--.  ,---.   ,---.   ,--,--.
  |  .   '  ' ,-.  | | .-. | | .-. | ' ,-.  |
  |  |\   \ \ '-'  | | '-' ' | '-' ' \ '-'  |
  `--' '--'  `--`--' |  |-'  |  |-'   `--`--'
                     `--'    `--'             */



void solve() {
    int n, k;
    cin >> n >> k;
    vi v(n);
    FOR (i, 0, n)
        cin >> v[i];
    sort(all(v));
    int res = 0;
    FOR (i, 0, k)
        res += v[i];
    cout << res;
}

int main() {
    solve();


    cerr << "Time elapsed: " << clock() / (double) CLOCKS_PER_SEC << endl;
    return 0;
}



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

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << (b & 1 || b < a * 2 || b > a * 4 ? "No" : "Yes");
}

Measured memory_bytes: 3688
#include<cstdio>
#include<iostream>
using namespace std;
int cnt[100];
int main()
{
    int n, m;
    cin>>n>>m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin>>a>>b;
        cnt[a]++;
        cnt[b]++;
    }
    for(int i = 1; i <= n; i++)cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
K=int(input())

li=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(li[int(K-1)])

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

struct UnionFind{
  vector<int> par; //親
  vector<int> size; //集合の大きさ

  UnionFind(int n){
    par.resize(n);
    size.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
      size[i] = 1;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(size[x] < size[y]) swap(x,y);
    par[y] = x;
    size[x] += size[y];
  }

};

signed main(){

  int n,k,l; cin >> n >> k >> l;
  UnionFind uf1(n),uf2(n);
  for(int i = 0; i < k; i++){
    int p,q; cin >> p >> q;
    p--,q--;
    uf1.unite(p,q);
  }
  for(int i = 0; i < l; i++){
    int r,s; cin >> r >> s;
    r--,s--;
    uf2.unite(r,s);
  }

  map<pair<int,int>,int> mp;
  for(int i = 0; i < n; i++){
    mp[make_pair(uf1.root(i),uf2.root(i))]++;
  }
  for(int i = 0; i < n; i++){
    cout << mp[make_pair(uf1.root(i),uf2.root(i))] << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 18048
let () =
  let s = read_line () in
  Printf.printf "%d\n" @@
  fst @@
  Array.fold_left (fun (acc, s) c ->
    match s, c with
    | `A n, 'A' -> (acc, `A (n + 1))
    | `AB _, 'A' -> (acc, `A 1)
    | `A n, 'B' -> (acc, `AB n)
    | `AB n, 'C' -> (acc + n, `A n)
    | _ -> (acc, `A 0)) (0, `A 0) @@
  Array.init (String.length s) (String.get s)


Measured memory_bytes: 6400
import itertools
n=int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
count = 0
p_ind = 0
q_ind = 0
for v in itertools.permutations(sorted(p)):
    if p == list(v):
        p_ind = count + 1
    if q == list(v):
        q_ind = count + 1
    count += 1
print(abs(p_ind-q_ind))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
	int key;
	int priority;
	struct node *left;
	struct node *right;
}node;


node * Delete(node **,int);
node * _delete(node **,int);

int find(node *p,int x){

	while(p!=NULL){
		if(p->key == x)return 1;
		else if(p->key > x)p=p->left;
		else p=p->right;
	}
	
	return 0;
	
}

void inorder(node *p){

	if(p->left!=NULL)inorder(p->left);
	
	printf(" %d",p->key);
	
	if(p->right!=NULL)inorder(p->right);
	
	return;
	
}

void preorder(node *p){
	
	printf(" %d",p->key);
	
	if(p->left!=NULL)preorder(p->left);
	
	if(p->right!=NULL)preorder(p->right);
	
	return;
	
}

void print(node *p){

	inorder(p);
	printf("\n");
	
	preorder(p);
	printf("\n");
	
	return;
	
}

node * makenode(int x,int y){
	node *new=malloc(sizeof(node));
	new->key=x;
	new->priority=y;
	new->left=NULL;
	new->right=NULL;
	return new;
}

node *rightRotate(node *p){
	node *q=p->left;
	p->left=q->right;
	q->right=p;
	return q;
}

node *leftRotate(node *p){
	node *q=p->right;
	p->right=q->left;
	q->left=p;
	return q;
}


node* insert(node **t,int key,int priority){
	node *new;
	
	if((*t)==NULL)
		return new=makenode(key,priority);
	if ((*t)->key==key)
		return *t;
	
	if(key < (*t)->key){
		(*t)->left=insert(&(*t)->left,key,priority);
		if((*t)->priority < (*t)->left->priority)
			(*t)=rightRotate((*t));
	}
	else {
		(*t)->right=insert(&(*t)->right,key,priority);
		if((*t)->priority < (*t)->right->priority)
			(*t)=leftRotate((*t));
	}
	
	return *t;
}


node * Delete(node **t,int key){
	if((*t)==NULL)
		return NULL;
		
	if(key < (*t)->key)
		(*t)->left=Delete(&((*t)->left),key);
		
	else if(key > (*t)->key)
		(*t)->right=Delete(&((*t)->right),key);
		
	else return _delete(t,key);
	
	return *t;
}

node * _delete(node **t,int key){
	if((*t)->left==NULL && (*t)->right==NULL)
		return NULL;
	else if((*t)->left==NULL)
		(*t)=leftRotate(*t);
	else if((*t)->right==NULL)
		(*t)=rightRotate(*t);
	else {
		if((*t)->left->priority > (*t)->right->priority)
			(*t)=rightRotate(*t);
		else
			(*t)=leftRotate(*t);
	}
	return Delete(t,key);
}


int main(){
	int n,x,y;
	char com[8];
	node *root=NULL;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%s",com);
		
		switch(com[0]){
		
			case 'i':scanf("%d %d",&x,&y);
					 root=insert(&root,x,y);
					 break;
			
			case 'd':scanf("%d",&x);
					 root=Delete(&root,x);
					 break;
			
			
			case 'f':scanf("%d",&x);
					 if(find(root,x))printf("yes\n");
					 else printf("no\n");
					 break;

			case 'p':print(root);
					 break;
					 
		}
		
	}
	
	return 0;
	
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
		string s1;
		string s2;
		cin >> s1;
		cin >> s2;
		int a = s1.size();
		int b = s2.size();
		vvi dp(a + 1, vi(b + 1, 0));
		for (int i = 0; i <= a; i++)dp[i][0] = i;
		for (int i = 0; i <= b; i++)dp[0][i] = i;
		for (int i = 1; i <= a; i++) {
			for (int j = 1; j <= b; j++) {
				dp[i][j] = min(dp[i - 1][j]+1, min(dp[i-1][j-1]+1,dp[i][j - 1]+1));
				if (i >= 1 && j >= 1 && s1[i - 1] == s2[j - 1]) {
					dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
				}
			}
		}
		/*for (int i = 0; i <= a; i++) {
			for (int j = 0; j <= b; j++) {
				cout << dp[i][j] << " ";
			}
			cout << endl;
		}*/
		cout <<dp[a][b] << endl;
	
	return 0;
}

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

#define N 200123
#define mod 1000000007

int main(){
 ios::sync_with_stdio(false);
 cin.tie(0);
 if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, a[200001], b[200001]; cin >> n;
    for(int i=2;i<=n;i++){
    	cin >> a[i];
    }
    fill(b, b+n+1, 0);
    for(int i=1;i<=n;i++){
    	b[a[i]] += 1;
    }
    for(int i=1;i<=n;i++){
    	cout << b[i] << endl;
    }
 return 0;
}

Measured memory_bytes: 5188
#include "bits/stdc++.h"
using namespace std;
long long ans = 0, i = 0;
vector<long long>A(1000000);
int main() {
	long long N;
	cin >> N;
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.begin() + N);
	while (i < N) {
		long long Number = A.at(i), num = 0;
		while (i < N && A.at(i) == Number) {
			num++, i++;
		}
		if (num % 2 != 0) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    
    
    int a[3];
    for(int i = 0; i < 3; i++) scanf("%d", &a[i]);
    
    sort(a, a + 3);
    
    printf("%d", a[0] + a[1]);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n ;
    cin >> n;
    vector<unsigned long long> a(n);
  
  
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
  }
    sort(a.begin(),a.end());
    
    
  
  unsigned long long s = 1;
   for (int i = 0; i < n; i++){
     if(a.at(i) == 0){
       cout << 0 << endl;
       return 0;
     }
   
    
    
    if(1000000000000000000 /s < a.at(i)){
        cout << -1 <<endl;
      return 0;
    }

    s *= a.at(i) ;
    }
cout << s << endl;
  return 0;

  
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#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)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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;
}

int main() {
  int N;
  cin >> N;
  vector<int> t(N + 1), x(N + 1), y(N + 1);
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  repp(i, 1, N) cin >> t[i] >> x[i] >> y[i];

  rep(i, N) {
    int dt = t[i + 1] - t[i];
    int dx = abs(x[i + 1] - x[i]);
    int dy = abs(y[i + 1] - y[i]);
    int dr = dx + dy;
    if (dt >= dr && (dt - dr) % 2 == 0) {
      continue;
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 1408
n, m = map(int, input().split())
max_l = 0
min_r = 10e6
for i in range(m):
  l, r = map(int, input().split())
  max_l = max(max_l, l)
  min_r = min(min_r, r)
print(max(0, min_r - max_l + 1))

Measured memory_bytes: 3060
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Acum = [0]
for a in A:
    Acum.append(a + Acum[-1])

c = Counter(Acum)
ans = sum(x * (x - 1) // 2 for x in c.values())
print(ans)

Measured memory_bytes: 41728
# B - Guidebook
# https://atcoder.jp/contests/abc128/tasks/abc128_b

import collections

n = int(input())

rest = [list(input().split()) for i in range(n)]
rest_hash = collections.OrderedDict()



for i in range(len(rest)):
    rest[i].append(i+1)


rest.sort(key=lambda x: (x[0], int(x[1])))


for i in range(len(rest)):
    if rest[i][0] in rest_hash:
        rest_hash[rest[i][0]].append(list([rest[i][1], rest[i][2]]))
    else:
        rest_hash[rest[i][0]] = [[rest[i][1], rest[i][2]]]



for n in rest_hash:
    for element in reversed(rest_hash[n]):
        print(element[1])



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

using namespace std;

int main()
{
    int gozen,gogo;
    string ss;
    while(cin>>ss>>gozen>>gogo)
    {
        cout <<ss<<" "<<gozen+gogo<<" " <<gozen*200+gogo*300<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int n;
string k;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n>>k;
	if(k.size()<=n){
		cout<<k;
	}
	else{
		for(int i=0;i<n;i++){
			cout<<k[i];
		}
		cout<<"...";
	}
	return 0;
}


Measured memory_bytes: 3644
def main():
  n=int(input())
  a=list(map(int,input().split()))
  dp=[0,-10**18]
  for i in range(n-1):
    dp2=[max(dp[0]+a[i],dp[1]-a[i]),max(dp[0]-a[i],dp[1]+a[i])]
    dp=dp2
  print(max(dp[0]+a[-1],dp[1]-a[-1]))
main()

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

int main() {
  int n; cin>>n;
  vector<int> a(n);
  rep(i, n-1) {
    int x; cin>>x;
    x--;
    a[x]++;
  }
  rep(i, n) cout<<a[i]<<endl;
}


Measured memory_bytes: 4000
const int N = 400005;
const int LG = 21;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int n, q;
int b[N];
vector<int> r[N];
int dp[N];
int hehe;

int Tree[4 * N];

void Set(int pos, int val, int L = 0, int R = n + 1, int V = 0)
{
    if (L + 1 == R)
    {
        Tree[V] = val;
        return;
    }
    int M = (L + R) / 2;
    if (pos < M) Set(pos, val, L, M, 2 * V + 1);
    else Set(pos, val, M, R, 2 * V + 2);
    Tree[V] = min(Tree[2 * V + 1], Tree[2 * V + 2]);
}

int Get(int l, int r, int L = 0, int R = n + 1, int V = 0)
{
    if (r <= L || R <= l) return INF;
    if (l <= L && R <= r) return Tree[V];
    int M = (L + R) / 2;
    return min(Get(l, r, L, M, 2 * V + 1), Get(l, r, M, R, 2 * V + 2));
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    int tm = (n - m) * 100 + m * 1900;
    cout << tm * (1 << m);
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 12544
package main

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

func abs(i int) int {
	if i < 0 {
		i *= -1
	}
	return i
}

func min(l, r int) int {
	if l > r {
		l = r
	}
	return l
}

func main() {
	var n int
	fmt.Scan(&n)

	h := make([]int, n, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		var e error
		sc.Scan()
		h[i], e = strconv.Atoi(sc.Text())

		if e != nil {
			fmt.Println("ERROR:", e)
			os.Exit(22)
		}
	}

	dp := make([]int, n, n)
	dp[0] = 0
	dp[1] = abs(h[1] - h[0])
	for i := 2; i < n; i++ {
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
	}

	fmt.Println(dp[n-1])
}


Measured memory_bytes: 2688
N = int(input())
As = list(map(int, input().split()))

total = 0
before = 0
for i in range(len(As) - 1):
    if i == 0:
        total = total + As[i] * sum(As[i+1:])
        before = sum(As[i+1:])
    else:
        total = total + ((before - As[i]) * As[i])
        before = before - As[i]

total = total % (10**9 + 7)

print(int(total))

Measured memory_bytes: 31516
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;

int main(){
	char ch;
	while(1){
	scanf("%c",&ch);
	if(ch=='\n')break;
	else if(islower(ch))cout << (char)toupper(ch);
	else if(isupper(ch))cout << (char)tolower(ch);
	else cout << ch;
	}
	cout << "\n";
	return 0;
}

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

int L, sz;
struct Edge {
    int u, v, w;
};
vector<Edge> E;

int main() {
    scanf("%d", &L);
    L--;
    if(L == 1) {
        puts("2 2");
        puts("1 2 1");
        puts("1 2 0");
        return 0;
    }
    while((1 << sz) <= L) sz++;
    int S = 1, T = sz;
    for(int i = 1; i < sz; i++) {
        E.push_back(Edge{i, i + 1, 1 << (sz - i - 1)});
        E.push_back(Edge{i, i + 1, 0});
    }
    int w = 0;
    w = 1 << (sz - 1);
    for(int p = sz - 2, i = 1; p >= 0; p--, i++) {
        if(L >> p & 1) {
            E.push_back(Edge{S, i + 1, w});
            w += 1 << p;
        }
    }
    E.push_back(Edge{S, T, L});
    printf("%d %d\n", sz, (int)E.size());
    for(auto &t : E) printf("%d %d %d\n", t.u, t.v, t.w);
    return 0;
}

/*
*/


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
//#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1<<31)-1;
#define mem(a) (memset(a,0,sizeof(a)))
#define ALL(a)  (a).begin(),(a).end()
struct P{
    int x,y;
}H[200000];
vector<int>G[100005];
int main()
{
    set<int>s;
    int N,M;
    int x,y;
    cin>>N>>M;
    for(int i=1;i<=M;i++){
        cin>>x>>y;
        H[i].x = x;
        H[i].y = y;
        G[x].push_back(y);
        //s.insert(x);
    }
    for(int i=1;i<=N;i++){
        sort(G[i].begin(),G[i].end());
    }


    for(int i=1;i<=M;i++){
        cout<<setw(6)<<setfill('0')<<H[i].x;
        cout<<setw(6)<<setfill('0')<<lower_bound(ALL(G[H[i].x]),H[i].y) - G[H[i].x].begin()+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 7808
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>
#include<iostream>

using namespace std;

int N,W,H,S,T;
int x[507],y[507];
int map[507][507];

int solve(){
  int res=0;
  for(int i=0;i<=W-S+1;i++){
    for(int j=0;j<=H-T+1;j++){

      int tmp=0;
      for(int g=i;g<i+S;g++){
        for(int f=j;f<j+T;f++){
          if(map[g][f]==1) tmp++;
        }
      }

      res=max(res,tmp);

    }
  }
  return res;
}

void init(){
  for(int i=0;i<507;i++){
    x[i]=0;
    y[i]=0;
    for(int j=0;j<507;j++){
      map[i][j]=0;
  }
  }
}

int main(){
  while(1){
    init();
    scanf("%d",&N);
    if(N==0) break;
    scanf("%d%d",&W,&H);
    W--; H--;
    for(int i=0;i<N;i++){
      scanf("%d%d",&x[i],&y[i]);
      map[x[i]-1][y[i]-1]=1;
    }


    scanf("%d%d",&S,&T);

    printf("%d\n",solve());
  }
  return 0;

}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))

const ll inf = (1LL<<62);
const int iinf = (1<<30);
//CLOCKS_PER_SEC

const ld PI = acos(-1);

ld dist(pair <ld, ld> unu, pair<ld, ld> doi){
    return sqrt((unu.fi - doi.fi) * (unu.fi - doi.fi) + (unu.se - doi.se) * (unu.se - doi.se));
}

int main(){
    //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //ifstream cin ("test.in");
    //ofstream cout ("test.out");
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int total_minutes = h * 60 + m;
    
    
    ld angle1 = 1.0 * total_minutes / 2;
    ld angle2 = 1.0 * m * 6;
    
    ld x_1 = 1.0 * a * cos(angle1 * PI / 180);
    ld y_1 = 1.0 * a * sin(angle1 * PI / 180);
    
    ld x_2 = 1.0 * b * cos(angle2 * PI / 180);
    ld y_2 = 1.0 * b * sin(angle2 * PI / 180);
    
    cout << fixed << setprecision(9) << dist({x_1, y_1}, {x_2, y_2});
    return 0;
}


Measured memory_bytes: 4164
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n / 10 != 9 && n % 10 != 9)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    private void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            total += a[i];
        }

        Arrays.sort(a);

        for (int i = 0; i < m; i++) {
            int k = n - 1 - i;
            if (a[k] * 4 * m < total) {
                out.println("No");
                return;
            }
        }
        out.println("Yes");
    }

    private static PrintWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        out = new PrintWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().solve();
        out.close();
    }
}


Measured memory_bytes: 32932
n,x = map(int, input().split())

maisu=[0]*50
pate=[0]*50
maisu[0]=1
pate[0]=1

for i in range(1,50):
    maisu[i]=3+maisu[i-1]*2
    pate[i]=1+pate[i-1]*2

def solve(l,x):
    if l==0:
        return 1
    if x<=1:
        return 0

    if x<=1+maisu[l-1]:
        return solve(l-1,x-1)
    if x==2+maisu[l-1]:
        return pate[l-1] + 1

    return pate[l-1] + 1 + solve(l-1,x-2-maisu[l-1])

print(solve(n,x))

Measured memory_bytes: 80592
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
#define clr0(a) memset(a,0,sizeof(a))
#define clr1(a) memset(a,-1,sizeof(a))
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings mov
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings mov
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights mov
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights mov
main()
{
    long long int life;
    int n, mov, i, j, pos = -1;
    int flag = 0;
    cin>>life>>n;
    int ar[n];

    for(i = 0; i<n; i++)
    {
        scanf("%d", &mov);

        for(j = 0; j<=pos; j++)
        {
            if(mov == ar[j])
            {
                flag = 0;
                break;
            }
        }
        pos++;
        ar[pos] = mov;

        life-=mov;

        if(life<=0)
        {
            flag = 1;
            break;
        }
    }

    if(life<=0 || flag == 1)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#define ll long long
#define out(a) printf("%d",a)
#define ln printf("\n")
const int N=1e5+50;
using namespace std;
int n;
int read()
{
	int s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read();
	if (n==25) puts("Christmas");
	if (n==24) puts("Christmas Eve");
	if (n==23) puts("Christmas Eve Eve");
	if (n==22) puts("Christmas Eve Eve Eve");
	return 0;
}

Measured memory_bytes: 256