akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[100010];
bool vis[100010];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i)
        cin>>a[i];
    memset(vis,false,sizeof(vis));
    for(int i=1;i<n;++i){
        if(a[i]>a[i+1]){
            a[i]--;
            vis[i]=true;
            if(a[i]>a[i+1]){
                puts("No");
                return 0;
            }
            int j=i;
            while(j&&a[j]<a[j-1]){
                if(!vis[j-1]){
                    a[j-1]--;
                    vis[j-1]=true;
                    if(a[j]<a[j-1]){
                        puts("No");
                        return 0;
                    }
                    j--;
                }
                else {
                    puts("No");
                    return 0;
                }
            }
        }
    }
    puts("Yes");
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 310;

int n,k,base,C[maxn][maxn],f[maxn][maxn],g[maxn][maxn];

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>k>>base;
    for (int i=0;i<maxn;i++)
        for (int j=i;j<maxn;j++) {
            if (i==0) C[i][j] = 1;
            else C[i][j] = (C[i-1][j-1] + C[i][j-1])%base;
        }
    for (int i=1;i<=n+1;i++) {
        for (int j=0;j<=k;j++) {
            //cout<<i<< " "<<j<<endl;
            if (i==1) {
                f[i][j] = 1;
                continue;
            }
            f[i][j] = 0;
            for (int m = 1;m < i;m++) {
                //cout<<i<< " "<<j<<" "<<m<<endl;
                f[i][j] = (f[i][j] + 1ll * f[i-m][j] * g[m][j+1] %base * C[m-1][i-2] % base)%base;
            }
        }
        g[i][maxn-1] = f[i][maxn-1];
        for (int j = maxn-2;j>=0;j--) g[i][j] = (g[i][j+1] + f[i][j]) % base;
    }
    cout<<f[n+1][0]<<endl;
}


Measured memory_bytes: 1408
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys
input = sys.stdin.readline

def main():
    N, K = map(int, input().split())
    P = list(map(int, input().split()))
    Et = [0]*(N+1)
    for i in range(N):
        Et[i+1] = Et[i] + (1+P[i])/2
    ret = 0
    for i in range(N-K+1):
        ret = max(ret, Et[i+K]-Et[i])
    print(ret)

if __name__ == '__main__':
    main()

Measured memory_bytes: 24404
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int defaultpip[] = new int[6];
		for(int i=0; i<6; i++){
			defaultpip[i] = Integer.parseInt(std.next());
		}

		Dice dc1 = new Dice(defaultpip);
		int answer = 0;

		int ques = Integer.parseInt(std.next());

		//??¬???????????¬???
		String query[] = {"S", "W", "N", "E"};

		for (int i=0; i<ques; i++){
			int top = Integer.parseInt(std.next());
			int front = Integer.parseInt(std.next());
/*
		????????????????????????

			int toppip = Arrays.asList(dc1.pips).indexOf(top);
			int frontpip = Arrays.asList(dc1.pips).indexOf(front);

			//??????
			int answerarray[][] = { {1,2,4,3},{2,0,3,5},{0,1,5,4},{0,4,5,1},{0,2,5,3},{1,3,4,2} };

			System.out.println(toppip +" "+ frontpip);
			int answer = dc1.pips[answerarray[toppip][(frontpip%4)]];
			System.out.println(answer);
		}
*/
			while(dc1.pips[dc1.nowpip] != top || dc1.pips[dc1.spip] != front){
				dc1 = dc1.newnowpips(query[(int)(Math.random()*4)]);
			}
			answer = dc1.pips[dc1.epip];
			System.out.println(answer);
		}
	}
}

class Dice {
	int pips[];
	int nowpip;
	int spip;
	int epip;
	int wpip;
	int npip;
	int rpip;

	public Dice(int pip[]){
		this(pip, 0, 1, 2, 3, 4, 5);
	}

	public Dice(int pip[], int now, int s, int e, int w, int n, int r){
		pips = pip;
		nowpip = now;
		spip = s;
		epip = e;
		wpip = w;
		npip = n;
		rpip = r;
	}

	public Dice newnowpips(String query){
		if(query.equals("N")){
			return new Dice(pips,spip,rpip,epip,wpip,nowpip,npip);
		}else if(query.equals("E")){
			return new Dice(pips,wpip,spip,nowpip,rpip,npip,epip);
		}else if(query.equals("S")){
			return new Dice(pips,npip,nowpip,epip,wpip,rpip,spip);
		}else if(query.equals("W")){
			return new Dice(pips,epip,spip,rpip,nowpip,npip,wpip);
		}else {	//clockwise
			return new Dice(pips,nowpip,epip,npip,wpip,spip,rpip);
		}
	}

	public String showdice(){
		return pips[nowpip] + " " + pips[spip] + " " + pips[epip] + " " + pips[wpip] + " " + pips[npip] + " " + pips[rpip];
	}
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;


int main(){
  int n,t[55];
  int ans = 0;
  string x,s[55];
  cin >> n;
  rep(i,n){
    cin >> s[i] >> t[i];
  }
  cin >> x;
  for(int i=n-1;i>=0;i--){
    if(x==s[i])break;
    ans += t[i];
  }
  cout << ans << endl;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

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

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  int h, w; cin >> h >> w;
  char c[h][w];

  rep(i, h) rep(j, w) cin >> c[i][j];

  queue<pii> que;
  que.em(0, 0);
  int vs[h][w];

  rep(i, h) rep(j, w) vs[i][j] = -1;
  vs[0][0] = 0;

  while (!que.empty()) {
    auto p = que.front(); que.pop();
    int x = p.fi, y = p.se;

    rep(i, 4) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if (vs[ny][nx] != -1 || c[ny][nx] == '#') continue;

      vs[ny][nx] = vs[y][x] + 1;
      que.em(nx, ny);
    }
  }

  if (vs[h-1][w-1] == -1) {
    cout << -1 << endl;
    return (0);
  }

  int sum = vs[h-1][w-1] + 1;
  int ans = 0;

  rep(i, h) rep(j, w) if (c[i][j] == '.') ++ans;
  cout << ans - sum << endl;
}


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

int main(){
  int N,D,X;
  cin >>N;
  cin >> D >> X;
  int res=X;
  for(int i=0;i<N;++i){
    int A;
    cin >>A;
    res+=1+(D-1)/A;
  }
  cout << res<<endl;
}

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

int main() {
    int n, ans = 0;
    cin >> n;
    int a[n+2];
    a[0] = a[n+1] = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n+1; i++) ans += abs(a[i] - a[i-1]);
    for (int i = 1; i <= n; i++) {
        cout << ans - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]) << endl;
    }

    return 0;
}

Measured memory_bytes: 1664
import math

a, b, h, m = map(int, input().split())

deg_val_hr = h*(math.pi/6)

deg_val_min = 11*m*(math.pi/360)

deg_diff = abs(deg_val_hr - deg_val_min);


ans = a*a + b*b
ans = ans - (2*a*b*math.cos(deg_diff))

print(math.sqrt(ans))

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

int main() {
  int h, n;
  cin >> h >> n;
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum += a;
  }
  cout << (h - sum <= 0 ? "Yes" : "No") << endl;
  return 0;
}

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


int main(){

    int N, M;
    scanf("%d %d",&N, &M);

    int i, a, work = 0;
    for(i = 0; i < M; i++){
        scanf("%d",&a);
        work += a;
    }

    if(work <= N){
        printf("%d",N-work);
    }else{
        printf("-1");
    }

   return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  ll a=0,b=0;
  ll ans=0;
  rep(i,n){
    if(s[i]=='1') a++;
    else b++;
    if(a>0&&b>0){
      ans+=2;
      a--,b--;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
from itertools import permutations
from math import sqrt, factorial

N = int(input())
towns = [tuple([int(i) for i in input().split()]) for _ in range(N)]

total = 0

for root in permutations(towns):
    ri = iter(root)
    pre = next(ri)
    for t in ri:
        total += sqrt(sum((t[i] - pre[i])**2 for i in (0, 1)))
        pre = t

print(total/factorial(N))


Measured memory_bytes: 3060
N, M = list(map(int,input().split()))
in_ = []
for i in range(M):
    a, b = map(int, input().split())
    in_.append([a, b])
    
class UnionFind():
    
    # 要素数を指定して作成 はじめは全ての要素が別グループに属し、親はいない
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    
    # xの根を返す
    def find(self, x):
        if self.parents[x] < 0:  return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    # xとyが属するグループを併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:  return

        if self.parents[x] > self.parents[y]:  x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    # xが属するグループの要素数
    def size(self, x):  return -self.parents[self.find(x)]
    
    # ｘとyが同じグループか否か
    def same(self, x, y):  return self.find(x) == self.find(y)
    
    # xと同じメンバーの要素
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    # 根の一覧
    def roots(self):  return [i for i, x in enumerate(self.parents) if x < 0]
    
    # グループ数
    def group_count(self):  return len(self.roots())
    
    # 可視化 [print(uf)]
    def __str__(self):  return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if i == j:  continue
        uf.union(in_[j][0] - 1, in_[j][1] - 1)
    ans += (uf.group_count() != 1)
print(ans)

Measured memory_bytes: 68340
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, x; cin >> N >> x;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  rep(i, N) {
    x -= a[i];
    if(x >= 0 && i <N-1) ++ans;
    if(x == 0 && i == N-1) ++ ans;
    else if(x < 0) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String result = null;
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(a < b) {
            for(int i = a; i <= b; i++){
                if(i == c) { result = "Yes"; break; }
                else if(i != c){ result = "No"; }
            }
        }

        if(a > b){
            for(int i = a; i >= b; i--){
                if(i == c) { result = "Yes"; break; }
                else{ result = "No"; }
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 23252
N,A,B=map(int,input().split())
v=[int(x)for x in input().split()]
v.sort(reverse=True)
a=sum(v[:A])/A
m=min(v[:A])
k=v.count(m)
l=v.index(m)
ans=0
import math
for i in range(A,B+1):
    if i==A:
        ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
    else:
        if k-i+l>=0 and a==m:
            ans+=(math.factorial(k)//math.factorial(i-l))//math.factorial(k-i+l)
        else:
            break
            
            
print("{:.6f}".format(a))
print(int(ans))  

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

int main(void) {
  int n, i, j, max = 0, ans = 0;
  scanf("%d", &n);
  int t[n];
  std::vector<int> v;
  for(i = 0; i < n; ++i) {
    scanf("%d", &t[i]);
    if(max < t[i]) max = t[i];
  }
  for(i = 1; i <= max; ++i) if(!(max % i)) v.push_back(i);
  for(i = 0; i < n; ++i) {
    for(j = 0;; ++j) {
      if(v[j] >= t[i]) {
        ans += v[j] - t[i];
        break;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll K,N,A=0,B=0,sum=0,max=0,f=0;
    cin >> K>>N;
    REP(i,N){
        cin >> A;
        if(i==0){
            f=A;
        }
        sum+=A-B;
        if(A-B>max){
            max=A-B;
        }
        B=A;
    }
    if(K-A+f>max){
        max=K-A+f;
    }
    cout << sum+(K-A)-max << endl;
    return 0;    
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int s=0,a,x,y;
for(x=0;x<4;x++){
scanf("%d",&a);
s+=a;
}
x=s/60;
y=s%60;
printf("%d\n%d\n",x,y);
return 0;
}

Measured memory_bytes: 3200
n = int(input())
b = list(map(int, input().split(' ')))
a = [b[0]]

for i in range (0,n-2):
  if b[i] < b[i+1]:
    a.append(b[i])
  else:
    a.append(b[i+1])

print(sum(a)+b[n-2])

Measured memory_bytes: 3060
n, m = [int(i) for i in input().split()]
a = [[0, 0] for _ in range(n)]
for i in range(n):
    a[i] = [int(i) for i in input().split()]
a.sort()
_sum = 0
for i in range(len(a)):
    _sum += a[i][0] * min(m, a[i][1])
    m -= min(m, a[i][1])
print(_sum)

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

class dice{
  
public:
  int _1,_2,_3,_4,_5,_6,sus;

  void moveN(){
    sus=_1;
    _1=_2;
    _2=_6;
    _6=_5;
    _5=sus;
  }
  
  void moveE(){
    sus=_1;
    _1=_4;
    _4=_6;
    _6=_3;
    _3=sus;
  }
  
  void moveW(){
    sus=_1;
    _1=_3;
    _3=_6;
    _6=_4;
    _4=sus;
  }
  
  void moveS(){
    sus=_1;
    _1=_5;
    _5=_6;
    _6=_2;
    _2=sus;
  }
  
  void spin(){
    sus=_2;
    _2=_3;
    _3=_5;
    _5=_4;
    _4=sus;
  }

};

int main(){
  
  dice d[100];
  int i,j,k,l,n;  
  
  cin>>n;
  
  for(i=0; i<n; i++)cin>>d[i]._1>>d[i]._2>>d[i]._3>>d[i]._4>>d[i]._5>>d[i]._6;
  
  for(i=0; i<n; i++)for(j=0; j<n; j++){
      if(j==i)continue;  
     
      for(k=0; k<6; k++){

	if(k==4)d[i].moveE();
	if(k==5){
	  d[i].moveE();
	  d[i].moveE();
	}
	
	for(l=0; l<4; l++){
	  d[i].spin();
	  if(d[i]._1==d[j]._1 &&
	     d[i]._2==d[j]._2 &&
	     d[i]._3==d[j]._3 &&
	     d[i]._4==d[j]._4 &&
	     d[i]._5==d[j]._5 &&
	     d[i]._6==d[j]._6){
	    cout<<"No"<<endl;
	    return 0;
	  }
	}

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;

typedef long long ll;

int main(){
	int a,b;

	scanf("%d%d", &a, &b);

	for(int i = 1; i <= 1000000; i++) {
		if((i*8)/100 == a && (i*10)/100 == b) {
			printf("%d\n", i);
			return 0;
		}
	}

	printf("-1\n");

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sb.append('1');
        for (int i=0;i<N-1;i++) {
            sb.append('0');
        }
        boolean[] flag = new boolean[N];
        char[] ans = sb.toString().toCharArray();
        if (N==1 && M==0) {
            System.out.println(0);
            return;
        }
        for (int i=0;i<M;i++) {
            int s = sc.nextInt()-1;
            int c = sc.nextInt();
            if (s==0 && c==0 && N!=1) {
                System.out.println(-1);
                return;
            }
            if (flag[s] && ans[s]!=(char)(c+48)) {
                System.out.println(-1);
                return;
            }
            ans[s] = (char)(c+48);
            flag[s] = true;
        }
        for (int i=0;i<N;i++) {
            System.out.print(ans[i]);
            if (i==N-1) System.out.println("");
        }
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  char a;
  cin>>a;
  if(a>='A'&&a<='Z'){cout<<'A'<<endl;}
  else{cout<<'a'<<endl;}
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
#define Imax 1e9+5
#define LLmax 1e18
#define Imin -1e9-5
#define LLmin -1e18
string day [] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
vector <string> v;
bool sortByFirst(const pair<int,int>&a,const pair<int,int>&b){
    return a.first>b.first;
}
void dfs (string str, string t = "", int cnt = 0) {
    if (cnt == 2) {
        v.push_back (t);
        return;
    } else {
        for (int i = 0; i <str.size (); i ++) {
            dfs (str, t + str [i], cnt + 1);
        }
    }
}
int main () {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int h,n;
    while(cin>>h>>n){
        int a,sum=0;
        for(int i=0;i<n;i++){
            cin>>a;
            sum+=a;
        }
        sum>=h?cout<<"Yes"<<endl:cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  string a,b;
  cin >> a >> b;
  int c = a.size(),d = b.size();
  if(c>d) cout << "GREATER";
  else if(c<d) cout << "LESS";
  else {
    rep(i,c){
      if(a.at(i)>b.at(i)){
        cout << "GREATER";
        return 0;
      }
      else if(a.at(i)<b.at(i)){
        cout << "LESS";
        return 0;
      }
    }
    cout << "EQUAL";
  }
}

Measured memory_bytes: 3588
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();
		int M = nextInt();

		List<List<Integer>> list = new ArrayList<>(M+1);

		for (int i=0;i<=M;i++) {
			list.add(new ArrayList<>());
		}
		for(int i=0;i<N;i++) {
			int a = nextInt();
			int b = nextInt();
			if(a <= M) list.get(a).add(b);
		}

		PriorityQueue<Integer> pq = new PriorityQueue <Integer>((a1,a2)->MyComparator(a1,a2));
		long sum = 0;
		for(int l=1;l<=M;l++) {
			for(Integer p:list.get(l)) {
				pq.add(p);
			}
			if (!pq.isEmpty()) {
				sum += pq.poll();
			}
		}
		out.println(sum);
	}

	private int MyComparator(int a, int b) {
		return b - a;
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}
}

Measured memory_bytes: 67164
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr double DINF = 100000000000000000.0;
constexpr long long INF = 100000000000000000;
const double PI = acos(-1);

vector<int> G[100];
int a[100], b[100];
int n, m;
const int MAX_V = 100;
bool flag[100];
int bfs(int s,int dame1,int dame2) {
	queue<int>que;

	for (int i = 0; i < MAX_V; i++)flag[i] = false;

	que.push(s);
	flag [s] = true;

	while (que.size()) {
		int p = que.front();
		que.pop();

		for (int i = 0; i < G[p].size(); i++) {
			if (flag[G[p][i]] == false&&!(p==dame1&&G[p][i]==dame2)&&!(p == dame2&&G[p][i] == dame1)) {
				que.push(G[p][i]);
				flag[G[p][i]] = true;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (flag[i] == false)return true;
	}
	return false;
}
int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >>a[i] >> b[i];
		a[i]--, b[i]--;
		G[a[i]].emplace_back(b[i]);
		G[b[i]].emplace_back(a[i]);
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (j != a[i]&&j != b[i]) {
				ans+=bfs(j, a[i], b[i]);
				break;
			}
		}
	}
	if (n == 2)ans = 1;
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a//gcd(a, b)*b
    
def inv(x):
    return pow(x, MOD-2, MOD)
    

def factorize(n):
    factors = []
    
    for i in range(2, int(n**0.5)+1):
        cnt = 0
        
        while n%i==0:
            n //= i
            cnt += 1
    
        if cnt>0:
            factors.append((i, cnt))
    
    if n>1:
        factors.append((n, 1))
    
    return factors

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
#N = 10**4
#A = [i for i in range(10**6, 10**6-N, -1)]

L = 1
d = defaultdict(int)

for Ai in A:
    f = factorize(Ai)
    
    for n, c in f:
        d[n] = max(d[n], c)

for v, c in d.items():
    L *= v**c
    L %= MOD
    
ans = 0

for Ai in A:
    ans += L*inv(Ai)
    ans %= MOD

print(ans)

Measured memory_bytes: 46812
N,M = list(map(int,input().split()))
PY = []
DD = [0 for i in range(N+1)]
for i in range(M):
    P,Y = list(map(int,input().split()))
    PY.append((P,Y,i,""))
PY.sort()
DY = []
for i in PY:
    DY.append((i[2],str(i[0]).zfill(6) + str(DD[i[0]]+1).zfill(6)))
    DD[i[0]] = DD[i[0]] + 1
DY.sort()
for i in DY:
    print(i[1])


Measured memory_bytes: 37268
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,y,z,u;
    int a,b,c,d;
    cin >> x >> y >>z >> u;
    cin >>a >> b >> c >>d;
    int S;
    int T;
    S=x+y+z+u;
    T=a+b+c+d;
    if(S==T||S>T)
        cout << S << endl;
    else
        cout << T << endl;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,sum[100],cou=0;
    cin>>n;
    while(n!=0){
        int a[n];
        sum[cou]=0;
        for(int i=0;i<n/4;i++){
            cin>>a[i];
            sum[cou]+=a[i];
        }
        cou++;
        cin>>n;
    }
    for(int i=0;i<cou;i++){
        cout<<sum[i]<<endl;
    }
}
    

Measured memory_bytes: 2980
#include <stdio.h>
int main(int argc, char *argv[])
{
	int a,b,s=0;
	scanf("%d%d",&a,&b);
	s=a+b;
	if(a%3==0||b%3==0||s%3==0)printf("Possible");
	else printf("Impossible");
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
#define N 100005
#define inf 1000000000
using namespace std;
int n;
int a[N], c[N];
int q;
int main(){
    scanf("%d", &n);
    ll sum=0;
    for(int i=1; i<=n; ++i) scanf("%d", &a[i]), ++c[a[i]], sum+=a[i];
    scanf("%d", &q);
    for(int i=1; i<=q; ++i){
    	int x,y;
    	scanf("%d%d", &x, &y);
    	sum+=(ll)c[x]*(y-x);
    	c[y]+=c[x]; c[x]=0;
    	printf("%lld\n", sum);
	}
	return 0;
} 

Measured memory_bytes: 2508
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String w = sc.next();
        String t = null;
        int count = 0;
        while(true){
            t = sc.next();
            if(t.equals("END_OF_TEXT")) {
            	break;
            }
            t =  t.toLowerCase();
            if(t.equals(w)){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())

//変数
ll A, B, K;


//解法
void solve() {

	for (int i = 0; i < K; i++) {

		if (i % 2 == 0) {//A
			if (A % 2 == 1) A--;
			B += A / 2;
			A = A / 2;
		}
		else {//B
			if (B % 2 == 1) B--;
			A += B / 2;
			B = B / 2;
		}

	}

	cout << A << " " << B;

	return;
}

int main() {
	//入力
	cin >> A>>B>>K;

	solve();
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int l, r;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> l >> r;
	vector<int> mult;
	int mn = INT_MAX;
	for(int i = l; i <= min(r, l + 4037); i++) mult.push_back(i % 2019);
	for(int i = 0; i < (int)mult.size(); i++)
		for(int j = i + 1; j < (int)mult.size(); j++)
			mn = min(mn, (mult[i] * mult[j]) % 2019);
	cout << mn << "\n";
	return 0;
}

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

int main(){
    int n,a,b,ans=0;cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
        int k=i;
        int l=0;
        while(k!=0){
            l+=k%10;
            k/=10;
        }
        if(a<=l&&l<=b) ans+=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<bool> flag(8, false);
  int ans = 0;
  int high = 0;
  REP(i,n){
    int rate;
    cin >> rate;
    if(rate<400 && !flag[0]){
      flag[0] = true;
      ans++;
    }else if(400<=rate && rate<800 && !flag[1]){
      flag[1] = true;
      ans++;
    }else if(800<=rate && rate<1200 && !flag[2]){
      flag[2] = true;
      ans++;
    }else if(1200<=rate && rate<1600 && !flag[3]){
      flag[3] = true;
      ans++;
    }else if(1600<=rate && rate<2000 && !flag[4]){
      flag[4] = true;
      ans++;
    }else if(2000<=rate && rate<2400 && !flag[5]){
      flag[5] = true;
      ans++;
    }else if(2400<=rate && rate<2800 && !flag[6]){
      flag[6] = true;
      ans++;
    }else if(2800<=rate && rate<3200 && !flag[7]){
      flag[7] = true;
      ans++;
    }else if(3200<=rate){
      high++;
    }
  }

  cout << (ans>0 ? ans : 1) << " " << ans+high << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll r,g,b;
cin>>r>>g>>b;
if((r*100+g*10+b)%4==0){
    cout<<"YES"<<endl;
}else{
    cout<<"NO"<<endl;
}
}









Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

constexpr int MAX_V = 10010;
int n, k;
int C[10010], R[10010];
struct edge { LL to, cost; };

typedef pair<LL, LL> PP;

LL d[10010]; //?????¢
vector<edge> vec[10010];

int last = 0;

LL dijkstra() {
	for (int i = 0; i < 10010; i++)d[i] = LINF;
	priority_queue<PP, std::vector<PP>, std::greater<PP>> pq;
	d[0] = 0;
	pq.push(make_pair(d[0], 0));//cost,to
	while (!pq.empty()) {
		PP p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			if (e.to == n - 1)last = e.cost;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
	return d[n - 1];
}

vector<int> G[MAX_V];
int start, goal;

int dis[MAX_V]; //???????????¢????±?????????´???


void bfs() {
	queue<int>que;
	//?????????
	for (int i = 0; i < MAX_V; i++)dis[i] = INF;

	que.push(start);
	dis[start] = 0;

	while (que.size()) {
		int p = que.front();
		que.pop();

		//if (p == goal)break;
		for (int i = 0; i < G[p].size(); i++) {
			if (dis[G[p][i]] == INF) {
				que.push(G[p][i]);
				dis[G[p][i]] = dis[p] + 1;
			}
		}
	}
	REP(i, n) {
		if (dis[i] <= R[start]) {
			if (i == start)continue;
			//cout << start+1 << " " << i+1 << endl;
			//vec[i].emplace_back(edge{ start,C[start] });
			vec[start].emplace_back(edge{ i,C[start] });
		}
	}
}

int main() {
	cin >> n >> k;
	int a, b, c;

	REP(i, n) {
		cin >> C[i] >> R[i];
	}

	for (int i = 0; i < k; i++) {
		cin >> a >> b;
		a--, b--;
		//edgedata[a].emplace_back(edge{ b,c });
		//edgedata[b].emplace_back(edge{ a,c });
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		//vec[a].push_back(edge{ b,c });
		//vec[b].push_back(edge{ a,c });
	}
	REP(j, n) {
		start = j;
		bfs();
	}
	cout << dijkstra() << endl;
	//system("pause");
}

Measured memory_bytes: 237340
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;
    std::vector<int> a;
    for (int i = 1; i < n; i++) a.push_back(abs(s[i] - s[i - 1]));

    bool f = std::find(a.begin(), a.end(), 1) != a.end();
    if (f) for (auto &e : a) e &= 1;
    else for (auto &e : a) e >>= 1;

    bool g = false;
    for (int i = 0; i < n - 1; i++) {
        if (a[i] && n - 2 == (i | (n - 2 - i))) g = !g;
    }

    std::cout << (f ? 1 : 2) * (g ? 1 : 0) << std::endl;

    return 0;
}


Measured memory_bytes: 7804
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

H,W = LI()
S = [[] for i in range(H)]
for i in range(H):
    S[i] = list(str(input()))

graph = [[] for i in range(H * W)]
moves = [[0,1], [1,0], [0,-1],[-1,0]]
for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            for move in moves:
                next_h = h + move[0]
                next_w = w + move[1]
                if -1 < next_h < H and -1 < next_w < W:
                    if S[next_h][next_w] == ".":
                        graph[h * W + w].append(next_h*W + next_w)

# print(graph)
N = H*W
dp = [[mod for i in range(N)] for j in range(N)]
for i in range(N):
    dp[i][i] = 0
for i in range(N):
    for edge in graph[i]:
        dp[i][edge] = 1
        dp[edge][i] = 1
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
ans = 0
for i in range(N):
    for j in range(N):
        if dp[i][j] != mod:
            ans = max(ans, dp[i][j])
print(ans)


Measured memory_bytes: 71384
# B
n = int(input())
a = [int(i) for i in input().split()]
count = 0
flag = True
while flag:
    for i in range(len(a)):
        if a[i] % 2 == 0:
            continue
        else:
            flag  = False
            break
    if flag:
        count += 1
        a = list(map(lambda x: x / 2, a))
print(count)

Measured memory_bytes: 3060
def main():
    N, K = map(int, input().split())
    ab = []
    i = 0
    while i < N:
        a, b = map(int, input().split())
        ab.append([a, b])
        i += 1

    ary = sorted(ab)
    j = 0
    for i in ary:
        j += i[1]
        if j >= K:
            print(i[0])
            break

main()


Measured memory_bytes: 20872
#include <iostream>
#include <stack>
#include <algorithm>
#include <math.h>
#include <string.h>

using namespace std;

int H, W;
char a[200][200];
int use_h[200];
int use_w[200];

int main(int argc, char** argv) {
    cin >> H >> W;
    cout << (H - W + 1) << endl;
    return 0;
    for (int i=0; i<H; i++) cin >> a[i];

    for (int i=0; i<H; i++) for (int j=0; j<W; j++) if (a[i][j] == '#') use_h[i] = 1;
    for (int i=0; i<H; i++) for (int j=0; j<W; j++) if (a[i][j] == '#') use_w[j] = 1;
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) {
            if (use_h[i] && use_w[j]) cout << a[i][j];
        }
        if (use_h[i]) cout << endl;
    }
}

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

int main()
{
  int X, Y;
  while (cin >> X >> Y) {
    if ((X|Y) == 0)
      break;

    vector<vector<int> > cource(Y+1, vector<int>(X, 0));
    for (int i = 0; i < Y; ++i) {
      for (int j = 0; j < X; ++j)
	cin >> cource[i][j];
    }

    vector<vector<int> > dp(Y+1, vector<int>(X, 0));
    for (int i = 0; i < X; ++i) {
      if (cource[0][i] == 0)
	dp[0][i] = 1;
    }

    for (int i = 0; i < Y-1; ++i) {
      for (int j = 0; j < X; ++j) {
	if (cource[i][j] == 0) {
	  if (cource[i+1][j] != 1)
	    dp[i+1][j] += dp[i][j];
	  if (j-1 >= 0 && cource[i+1][j-1] == 0)
	    dp[i+1][j-1] += dp[i][j];
	  if (j+1 < X && cource[i+1][j+1] == 0)
	    dp[i+1][j+1]+= dp[i][j];
	} else if (cource[i][j] == 2 && cource[i+2][j] != 1) {
	    dp[i+2][j] += dp[i][j];
	}
      }
    }

    int ans = 0;
    for (int i = 0; i < X; ++i) {
	ans += dp[Y-1][i];
	ans += dp[Y][i];
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdint>
#include <vector>
#include <set>
#include <iostream>

int main() {
  size_t n;
  scanf("%zu", &n);

  size_t p = 1 << n;
  std::vector<int> a(p);
  for (auto& ai: a) scanf("%d", &ai);

  std::vector<bool> rec(p);
  int ans = 0;
  for (size_t i = 0; i < p; ++i) {
    if (a[i] == 1) {
      bool min = true;
      for (size_t j = 0; j < n; ++j) {
        if (!(i >> j & 1)) continue;
        if (a[i ^ (1 << j)] == 1) {
          min = false;
          break;
        }
      }
      if (min) {
        rec[i] = true;
        ans++;
      }
    }
  }

  for(size_t i=0; i<p; i++) {
    if(rec[i] == false) continue;
    for(size_t k=0; k<n; k++) {
      size_t nbit = i | (1 << k);
      if(a[nbit] == 0) {
        ans = -1;
        break;
      }
      else {
        rec[nbit] = true;
      }
    }
  }

  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 7060
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

int main() {
	int k, s; cin >> k >> s;
	int ans = 0;
	if (k < s) {
		for (int i = 0; i <= k; i++) {
			ans += s - i + 1;
			int a = s - i - k;
			//cout <<'A'<< a << endl;
	
			if (a > 0 && k >= (s - i) / 2) {
				ans += -a * 2;
		
		    }
		  	else if(a>0&&k<(s-i)/2) {
				ans += -(s - i + 1);
			}
		
			//cout << ans << endl;

		}
	}
	else {
		for (int i = 0; i <= s; i++) {
			ans += s - i + 1;
		}
	}
	cout << ans << endl;
}


    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int inf =0x3f3f3f3f;
const int MAXN=10005;
struct node
{
    int next, to, d, c;
} G[2000005];
int cur, n;
bool vis[MAXN];
int cost[MAXN];
int dist[MAXN];
int head[MAXN];
void add(int u, int v, int d, int c)
{
    G[cur].to=v;
    G[cur].c=c;
    G[cur].d=d;
    G[cur].next=head[u];
    head[u]=cur++;
}
queue<int>q;
void spfa(int s)
{

    while(!q.empty()) q.pop();
    memset(vis, false, sizeof(vis));
    fill(cost+1,cost+n+1,inf);
    fill(dist+1,dist+n+1,inf);
    q.push(s);
    dist[s]=0;
    cost[s]=0;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(int i=head[u]; ~i; i=G[i].next)
        {
            int v=G[i].to;
            if(dist[v]>dist[u]+G[i].d||(dist[v]==dist[u]+G[i].d&&cost[v]>G[i].c))
            {
                dist[v]=dist[u]+G[i].d;
                cost[v]=G[i].c;
                if(!vis[v])
                {
                    vis[v]=true;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    int m;
    int u, v, d, c;
    while(~scanf("%d %d", &n, &m))
    {
        if(n==0&&m==0)break;
        memset(head, -1, sizeof(head));
        cur=0;
        while(m--)
        {
            scanf("%d %d %d %d", &u, &v, &d, &c);
            add(u, v, d, c);
            add(v, u, d, c);
        }
        spfa(1);
        int ans=0;
        for(int i=1; i<=n; ++i)
            ans+=cost[i];
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3964
import java.util.*;
public class Main{
      public static void main(String[] args){
           Scanner sc=new Scanner(System.in);
           int a=sc.nextInt();
           int b=sc.nextInt();
           int c=sc.nextInt();

          if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5)){
                     System.out.println("YES");
           }else{
                     System.out.println("NO");
           }
       }
}

Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
const int MAXN=100010;
typedef long long ll;
int A[MAXN];
int n;

void init(int n) {
  for (int i=1; i<=n;i++) {
    A[i]=0;
  }
}
void add(int i,int x) {
  while (i<=n) {
    A[i]+=x;
    i+=i&(-i);
  }
}
ll getSum(int s,int t) {
  ll sumt=0;
  while (t) {
    sumt+=A[t];
    t-=t&(-t);
  }
  ll sums=0;
  s-=1;
  while (s) {
    sums+=A[s];
    s-=s&(-s);
  }
  ll sum=sumt-sums;
  return sum;
}
int main() {
  int q;
  cin >> n >> q;
  init(n);
  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com==0) {
      add(x,y);
    } else {
      cout << getSum(x,y) << endl; 
    }
  }
  return 0;
}

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

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

int main() {
    int n, T; cin >> n >> T;
    vector<pair<int, int>> p(n);
    int c, t;
    rep(i, n){
        cin >> c >> t;
        p[i] = make_pair(c, t);
    }
    sort(p.begin(), p.end());
    rep(i, n){
        if(p[i].second <= T){
            cout << p[i].first << endl;
            return 0;
        }
    }
    cout << "TLE" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const int mx = 3e6+1e3; //check the limits, dummy
typedef pair<int, int> pa;
const double PI = acos(-1);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
bool isprime(int n) { if (n <= 1)return 0; for (int i = 2; i * i <= n; i++)if (n % i == 0)return 0; return 1; }
#define swa(a,b) a^=b^=a^=b
#define re(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define rb(i,a,b) for(ll i=(a),_=(b);i>=_;i--)
#define clr(a,b) memset(a, b, sizeof(a))
#define lowbit(x) ((x)&(x-1))
#define mkp make_pair
//inline ll qpow(ll a, ll b) { return b ? ((b & 1) ? a * qpow(a * a % mod, b >> 1) % mod : qpow(a * a % mod, b >> 1)) % mod : 1; }
//inline ll qpow(ll a, ll b, ll c) { return b ? ((b & 1) ? a * qpow(a * a % c, b >> 1) % c : qpow(a * a % c, b >> 1)) % c : 1; }
void ca(int kase, int ans) { cout << "Case #" << kase << ": " << ans << endl; }
void sc(int& x) { scanf("%d", &x); }void sc(int64_t& x) { scanf("%lld", &x); }void sc(double& x) { scanf("%lf", &x); }void sc(char& x) { scanf(" %c", &x); }void sc(char* x) { scanf("%s", x); }
int n, m, t, k;
int a[mx],mp[mx], sum, b,cnt=1,ans[mx],q[mx];
int main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d%d", &n, &t);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	int maxx = -inf, temp = -inf;
	for (int i = n; i >= 1; i--) {
		temp = max(temp, a[i]);//最大的价格
		maxx = max(maxx, temp - a[i]);//最大的贸易差
	}

	temp = -inf;
	int res = 0;
	for (int i = n; i >= 1; i--) {
		temp = max(temp, a[i]);
		if (maxx == temp - a[i])
			res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 2304
/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

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

class A {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {

            int a,b;
            cin>>a>>b;
            if (b%2) {
                cout<<"No";
                return;
            }
            if (b<2*a){
                cout << "No";
                return;
            }
            if (b>4*a){
                cout << "No";
                return;
            }
            cout << "Yes";

	}
};

#undef int
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    A solver;
    solver.solve(in, out);
}


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

int main(){
    int n, d, i, j, k;
    cin >> n >> d;
    int x[n][d];
    for(i = 0; i < n; i++){
        for(j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }
    int c = 0;
    for(i = 0; i < n; i++){
        for(j = i+1; j < n; j++){
            int a = 0;
            for(k = 0; k < d; k++){
                a += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            int t = sqrt(a);
            if(t * t == a)
                c++;
        }
    }
    cout << c << endl;

}

Measured memory_bytes: 256