akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	
	public static Boolean BinarySearch(int[] Value, int input, int left, int right) {
		int middle = left + (right-left)/2;  // 
		if (right < left) {
			return false;  // This means that the algorithm is not sorted
			}
		else if (Value[middle] > input) {
			return BinarySearch(Value,input,left,middle-1);  
			}
		else if (Value[middle] < input) {
			return BinarySearch(Value,input,middle+1,right); 
			}
		else {  
			return true;
			}
	}
	
	public static int contains(int[] Value, int[] Array) {
		int sum = 0;
		int left = 0;
		int right = Value.length - 1;
		for (int elements : Array) {
			if (BinarySearch(Value, elements, left, right)) {  // iterates through each value in T and searches for it in S
				sum++;
			}
		}
		return sum;
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int array1 = in.nextInt();
		int[] Value = new int[array1];
		for (int i = 0; i < array1; i++) {
			int number = in.nextInt();
			Value[i] = number;
		}
		int array2 = in.nextInt();
		int[] Array = new int[array2];
		for (int i = 0; i < array2; i++) {
			int number = in.nextInt();
			Array[i] = number;
		}
		in.close();
		int value = contains(Value,Array);
		System.out.println(value);
	}

}


Measured memory_bytes: 68696
#include <stdio.h>

int main (void){

	int a,b;
	int d,r;
	double f;

	
	scanf("%d %d",&a,&b);
	d = a/b;
	r = a%b;
	f = (double)a/(double)b;
	
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <queue>
#define ll long long
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define mp make_pair
#define forn(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
    ll a,b;
    scanf("%lld%lld",&a,&b);
    ll gcd=__gcd(a,b);
    printf("%lld\n",a*b/gcd);
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

const int N = 1e9 + 5;
const int MOD = 1e9 + 7;


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    sort(a.begin(), a.end());
    for(int i = 0; i + 2 < n; i++) {
        for(int j = i + 1; j < n + 1; j++) {
            for(int k = j + 1; k < n; k++) {
                if(a[i] != a[j] && a[j] != a[k] && a[i] + a[j] > a[k])
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"


def primeFactors(n):
	count = defaultdict(int)
	while n % 2 == 0: 
		count[2]+=1 
		n = n / 2 
	for i in range(3,int(math.sqrt(n))+1,2): 
		while n % i== 0: 
			count[i]+=1
			n = n / i 
	if n > 2: 
		count[n]+=1
	return count


n = int(input())
c = primeFactors(n)
ans = 0
for k,v in c.items():
	ans += (-1 + (1+8*v)**0.5)//2
print(int(ans))


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

int main(void)
{
    int y, m, d;
    char c1, c2;
    cin >> y >> c1 >> m >> c2 >> d;

    cout << ((m >= 5) ? "TBD":"Heisei") << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

	    String x = a.substring(0, 1);
	    String y = b.substring(0, 1);
	    String z = c.substring(0, 1);

	    x=x.toUpperCase();
	    y=y.toUpperCase();
	    z=z.toUpperCase();
	    System.out.print(x);
	    System.out.print(y);
	    System.out.print(z);

	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define N 101
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;
vector<P> G[N];
int n,m,C;

int dijkstra(){
  vector<vector<int> >D(N,vector<int>(N,INF));
  priority_queue<PP,vector<PP>,greater<PP> > Q;
  Q.push(PP(0,P(0,0)));
  D[0][0] = 0;
  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost = t.first;
    int pos = t.second.first;
    int cnt = t.second.second;
    if(D[pos][cnt]<cost) continue;
    
    for(int i=0;i<G[pos].size();i++){
      int npos = G[pos][i].second;
      int ncost= cost+G[pos][i].first;
      if(D[npos][cnt]>ncost) Q.push(PP(ncost,P(npos,cnt))),D[npos][cnt]=ncost;
      if(cnt+1<N&&D[npos][cnt+1]>cost) Q.push(PP(cost,P(npos,cnt+1))),D[npos][cnt+1]=cost;
    }
  }
  for(int i=0;i<N;i++)if(D[n-1][i]<= C) return i;
}

int main(){
  while(1){
  cin>>n>>m>>C;
  if(!n&&!m&&!C) break;
  for(int i=0;i<N;i++)G[i].clear();
  for(int i=0,a,b,c;i<m;i++)cin>>a>>b>>c,G[a-1].push_back(P(c,b-1));
  cout<<dijkstra()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


const int MAXX = 1e9 + 7;
int abc[1000000][3];
int dp[1000000][3];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        rep(j,3){
            cin >> abc[i][j];
        }
    }
///    rep(j,3) abc[0][j] = 0;

    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(j == k) continue;
                chmax(dp[i+1][j], dp[i][k] + abc[i][j]);
            }
        }
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}


Measured memory_bytes: 5504
<?php

fscanf(STDIN, "%d", $n);
$names = ['M' => 0, 'A' => 0, 'R' => 0, 'C' => 0, 'H' => 0];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%s", $s);
    $tmp = substr($s, 0, 1);
    ++$names[$tmp];
}

$total = 0;
$F = ['M', 'A', 'R', 'C', 'H'];
for ($i = 0; $i < 1<<5; ++$i) {
    $tmp = [];
    for ($j = 0; $j < 5; ++$j) {
        if ($i & 1<<$j) {
            $tmp[] = $j;
        }
    }
    if (count($tmp) != 3) continue;

    $cnt = 1;
    foreach ($tmp as $fi) {
        $cnt *= $names[$F[$fi]];
    }
    $total += $cnt;
}
echo $total, PHP_EOL;


Measured memory_bytes: 16288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(5);
	rep(i,5)cin >> a[i];
	ll m = a[0];
	rep(i,5)m = min(m,a[i]);
	cout<<(1LL)*(n+m-1)/m+4<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        double N = sc.nextDouble();
        double K = sc.nextDouble();
        double Ans= 0.0;
        for(double i=1.0; i<=N;i++){Ans += 1/((i < K) ? Math.pow(2,Math.ceil(Math.log(K/i)/Math.log(2.0))) : 1.0);}
        Ans /= N;
        System.out.println(Ans);
        sc.close();
    }
}

Measured memory_bytes: 25300
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);i++)
void solve(int n) {
	stack<int> stk;
	int head = -1;
	rep(i,n){
		int x=0;
		cin>>x;
		if(i%2==0){
			if(head==x){
				int tmp = stk.top();
				stk.pop();stk.push(tmp+1);
			}else{
				stk.push(1);
			}
			head=x;
		}else{
			if (head==-1) {
				head=x;stk.push(1);
			} else if(head==x) {
				int tmp = stk.top();
				stk.pop();stk.push(tmp+1);
			} else {
				//stk.size()!=0
				if (stk.size()==1){
					int tmp = stk.top();
					stk.pop();stk.push(tmp+1);
				} else {
					int tmp = stk.top();stk.pop();
					tmp += stk.top();stk.pop();
					stk.push(tmp+1);
				}
				head=x;
			}
		}
	}
	int ans=0;
	while(!stk.empty()){
		if(head==0){
			ans+=stk.top();
		}
		stk.pop();
		head=(head+1)%2;
	}
	cout<<ans<<endl;
}
int main () {
	int a;
	while(cin>>a&&a){
		solve(a);
	}
}

Measured memory_bytes: 1200
s = input()
length = len(s)
ind = 0
ans = 0
while ind < length:
  j_num = 0
  o_num = 0
  i_num = 0
  while ind < length and s[ind] != "J":
    ind += 1
  while ind < length and s[ind] == "J":
    j_num += 1
    ind += 1
  while ind < length and s[ind] == "O":
    o_num += 1
    ind += 1
  while ind < length and s[ind] == "I":
    i_num += 1
    ind += 1
  if o_num <= i_num and o_num <= j_num:
    ans = max(ans, o_num)
print(ans)


Measured memory_bytes: 7516
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
struct point{
    int x, y;
}w[110];
int n;
double P[210];
const double PI = acos(-1.0);
 
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        cin >> w[i].x >> w[i].y;
    }
    for(int i = 1; i <= n; i++)
    {
        int cnt = 0;
        for(int j = 1; j <= n; j++)
        {
            if(i == j) continue;
            P[cnt++] = atan2(w[j].y - w[i].y, w[j].x - w[i].x);
        }
        sort(P, P+cnt);
        for(int j = 0; j < cnt; j++) P[j + cnt] = P[j]+2* PI;
        double res = 0.0;
        for(int j = 0; j < cnt; j++) {
            res = max(res, PI - P[j + cnt - 1] + P[j]);
        }
        printf("%.10f\n", res/(2*PI));
    }
    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> res(N,0);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    res[a-1]++;
    res[b-1]++;
  }
  for(int i = 0; i < N; i++){
    cout << res.at(i) << endl;
  }
}

Measured memory_bytes: 3592
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}
int N;

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

    //cout << fixed << setprecision(15);

    string s;
    cin >> s;
    ll K;
    cin >> K;
    K--;
    int n = s.size();
    int i;
    for (i = 0; i < n; ++i)
    {

        if (i == K)
        {
            cout << s[i] << endl;
            return 0;
        }
        if (s[i] != '1')
            break;
    }
    cout << s[i] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

#define INF 10000000000LL

using namespace std;

int main()
{
	int n;
	long long int a, b, sum=0, minb=INF, e=0;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%lld %lld", &a, &b);
		sum=sum+a;
		if(a!=b){
			e=1;
		}
		if(a>b && minb>b){
			minb=b;
		}
	}
	if(e==0){
		printf("%d\n", 0);
	}else{
		printf("%lld\n", sum-minb);
	}
	return 0;
}

Measured memory_bytes: 128
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int dp[100001];
int p[11];
vector<char> d;
int main() {
  int n,k;
  cin >> n >> k;
  char tm;
  rep(i,k){
    cin >> tm;
    d.push_back(tm);
  }
  for(int i = n; i <= 100000; i++){
    string s = to_string(i);
    rep(j, s.size()){
      if(find(all(d), s[j]) != d.end()) {
        break;
      }
      if(j == s.size() -1) {
        cout << i << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, m = map(int, input().split())

dp = [float('inf')]*(1<<n)
dp[0] = 0

for i in range(m):
  a, b = map(int, input().split())
  c = 0
  for j in list(map(int, input().split())):
    c += 1<<(j-1)
  
  for k in range(1<<n):
    dp[k|c] = min(dp[k|c], dp[k]+a)
    
if dp[-1] == float('inf'):
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 44124
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.7f\n", ans); 相対誤差

int main() {
  int n;
  cin >> n;
  if (n%2 == 0) {
    printf("0.50000000");
  } else {
    double ans = (n/2 + 1.0) / n;
    printf("%.7f\n", ans);
  }

}


Measured memory_bytes: 256
//ABC080 - C
#include <iostream>
using namespace std;
int N;
int F[100][10];
int Y[10];
int x = 0;
int P[100][11];
int Max = -1000000000;

void chan(int i, int c);

int main() {
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
                cin >> F[i][j];
        }
    }
    for(int i=0;i<100;i++){
        for(int j=0;j<=10;j++) P[i][j] = 0;
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<=10;j++) cin >> P[i][j];
    }
    chan(0,0);
    chan(0,1);
    cout << Max <<"\n";
    return 0;
}

void chan(int i, int c){
    if(i==10){
        x = 0;
        int t = 0;
        for(int k=0;k<10;k++){
            if(Y[k]==1) t++;
        }
        if(t==0) return;
        for(int p=0;p<N;p++){
            int count = 0;
            for(int q=0;q<10;q++){
                if(Y[q]==1 && F[p][q]==1){
                    count++;
                }
            }
            //cout << count <<" " <<P[p][count] <<"\n";
            x += P[p][count];
        }
        if(Max < x) Max = x;
        //cout<< Max <<"\n";
        return;
    }
    Y[i] = c;
    chan(i+1,0);
    chan(i+1,1);
    
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextLine
    val line = sc.nextLine

    val list = line.split(' ').map(_.toLong)
    println(s"${list.min} ${list.max} ${list.sum}")
  }
}

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

using namespace std;

int main()
{
    int n,t,i,s,sum=0,m;
    cin >> n >> t;
    for(i=0;i<n;i++)
    {
        cin >> m;
        if(i==0)
        {
            sum+=t;
            s=m;
        }
        else if(m-s>t)
        {
            sum+=t;
            s=m;
        }
        else if(m-s<=t)
        {
            sum+=(m-s);
            s=m;
        }
    }
    cout << sum << endl;
    return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct T {
  int x, y, c;
};

int s[101][101];
char a[101][101];

int main() {
  int h, w;
  cin >> h >> w;
  int ss = 0;
  rep(i, 0, h) rep(j, 0, w) {
    cin >> a[i][j];
    if(a[i][j] == '.') ss++;
    s[i][j] = 1145141919;
  }

  queue<T> q;
  q.push({0, 0, 0});

  while(!q.empty()) {
    T t = q.front();
    q.pop();
    if(t.x == h - 1 && t.y == w - 1) {
      cout << ss - (t.c + 1) << endl;
      return 0;
    }
    if(s[t.x][t.y] <= t.c) continue;
    s[t.x][t.y] = t.c;
    if(t.x > 0 && a[t.x - 1][t.y] == '.' && s[t.x - 1][t.y] > t.c + 1) q.push({t.x - 1, t.y, t.c + 1});
    if(t.x < h - 1 && a[t.x + 1][t.y] == '.' && s[t.x + 1][t.y] > t.c + 1) q.push({t.x + 1, t.y, t.c + 1});
    if(t.y > 0 && a[t.x][t.y - 1] == '.' && s[t.x][t.y - 1] > t.c + 1) q.push({t.x, t.y - 1, t.c + 1});
    if(t.y < w - 1 && a[t.x][t.y + 1] == '.' && s[t.x][t.y + 1] > t.c + 1) q.push({t.x, t.y + 1, t.c + 1});
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
N = int(input())
Nac = 0
Nwa = 0
Ntle = 0
Nre = 0
for i in range(N):
    a = input()
    if a == "AC":
        Nac += 1
    elif a == "WA":
        Nwa += 1
    elif a == "TLE":
        Ntle += 1
    elif a == "RE":
        Nre += 1

print("AC x %d" % Nac)
print("WA x %d" % Nwa)
print("TLE x %d" % Ntle)
print("RE x %d" % Nre)

Measured memory_bytes: 9144
#include <stdio.h>
int main()
{
    int a ;
    scanf("%d",&a);
    
    int b;
    scanf("%d",&b);
    
    int c = a*500;
    
    if( c>=b){
        printf("Yes");

    }
    
    else{
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 1708
s=input()
t=s.replace('x','')
if t!=t[::-1]:
    print(-1)
else:
    l=[]
    k=0
    for c in s:
        if c=='x':
            k+=1
        else:
            l.append(k)
            k=0
    l.append(k)

    ans=0
    for i in range(len(l)//2):
        ans+=abs(l[i]-l[-(i+1)])

    print(ans)

Measured memory_bytes: 46192
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;

int main() {
	//入力;
	int H, W;
	cin >> H >> W;
	vector<string> maze(H);
	REP(i, H) { cin >> maze[i]; }

	//白マス・黒マスのカウント;
	int white=0, black=0;
	REP(i,H){
		REP(j,W){
			if (maze[i][j] == '.') ++white;
			else ++black;
		}
	}

	vector<vector<int>> maze_c(H, vector<int>(W, -1));
	queue<int> que_y, que_x;

	maze_c[0][0] = 0;
	que_y.push(0);
	que_x.push(0);

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


	while (!que_x.empty()) {
		int y, x;
		y = que_y.front();
		x = que_x.front();
		que_y.pop();
		que_x.pop();

		REP(i, 4) {
			int ny = y + dy[i];
			int nx = x + dx[i];

			if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
			if (maze[ny][nx] == '#') continue;
			if (maze_c[ny][nx] != -1)continue;

			maze_c[ny][nx] = maze_c[y][x] + 1;
			que_y.push(ny);
			que_x.push(nx);
		}
	}

	if (maze_c[H - 1][W - 1] == -1) cout << -1 << endl;
	else {
		cout << white - maze_c[H - 1][W - 1] - 1 << endl;

	}


	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int N = in.nextInt(); int K =in.nextInt();
			int[] a = new int[N];
			for (int i = 0; i < N; i++) {
				a[i] = in.nextInt();
			}
			Arrays.sort(a);

			int ans = 0;

			int l = -1, r = N;
			int m = 0;
			while (r - l > 1) {
				m = (r+l)/2;
				boolean[][] dp = new boolean[N+1][K+1];

				dp[0][0] = true;

				for (int j = 0; j < N; j++) {
					for (int k = 0; k <= K; k++) {

						// jがi番目と同じ場合は選ばない
						if (m == j) {
							dp[j+1][k] |= dp[j][k];
						} else {
							// DPの遷移条件
							if (k-a[j] >= 0) {
								dp[j+1][k] |= dp[j][k-a[j]];
							} else {
								dp[j+1][k] |= dp[j][k];
							}
						}
					}
				}

				// 必要かどうか
				boolean ok = false;
				for (int j = Math.max(0, K-a[m]); j < K; j++) {
					ok |= dp[N][j];
				}
				if (ok) {
					r = m;
				} else {
					l = m;
				}
			}

			out.println(r);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

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

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 206032
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
#include <cassert>

using namespace std;
typedef long long ll;

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

    ll q;
    cin >> q;
    ll ans = 0;
    multiset<ll> left, right;
    for(ll i = 0; i < q; ++i){
        ll t, a, b;
        cin >> t;
        if(t == 1){
            cin >> a >> b;
            ans += b;
            if(i == 0){
                left.insert(a);
                right.insert(a);
            }else{
                ll lmax = *left.rbegin();
                ll rmin = *right.begin();
                if(a < lmax){
                    left.insert(a);
                    left.insert(a);

                    ll tmp = *left.rbegin();
                    left.erase(--left.end());
                    right.insert(tmp);

                    ans += tmp - a;
                }else if(a > rmin){
                    right.insert(a);
                    right.insert(a);

                    ll tmp = *right.begin();
                    left.insert(tmp);
                    right.erase(right.begin());

                    ans += a - tmp;
                }else{
                    left.insert(a);
                    right.insert(a);
                }
            }
            assert(left.size() == right.size());
        }else{
            cout << *left.rbegin() << ' ' << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19072
#!/usr/bin/python3
from collections import defaultdict

n, m = map(int, input().split())
br = []
r = defaultdict(list)
for _ in range(m):
    a, b = input().split()
    br.append((a, b))
    r[a].append(b)
    r[b].append(a)

done = {}

def s(node):
    if done[node] == 1:
        return
    done[node] = 1
    for i in r[node]:
        if node in down and i in down:
            continue
        s(i)

def chk():
    for i in r.keys():
        done[i] = 0
    s('1')
    for i in done.keys():
        if done[i] == 0:
            return False
    return True

nbr = 0
for i in br:
    down = i
    if chk() == False:
        nbr += 1

print(nbr)

Measured memory_bytes: 3700
//g++  7.4.0

#include <bits/stdc++.h>

using namespace std ; 

int main()
{
     int n ; 
     cin >> n ; 
     
     string s ; 
     int a = 0 , b = 0 , c = 0, d =0 ; 
     
     while(n--) {
         
         cin >> s ; 
         
         if(s == "AC") a ++ ; 
         else if( s == "WA") b ++ ; 
         else if( s == "TLE") c++ ;
         else d ++ ; 
     }
     
     cout << "AC x " << a <<"\n" ; 
     cout << "WA x " << b << "\n" ; 
     cout << "TLE x " << c <<"\n" ; 
     cout << "RE x " << d <<"\n" ; 
     
}

Measured memory_bytes: 3592
#include<stdio.h>

#define N 100

static const int MAX = 500;
static const int INFTY = (1<<21);


main(){
  int n, i, j, e,v, sum;
  int u = 0,mincost = 0;
  int cost[N];
  int key[N];
  int p[N],M[N][N];
  
  
  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }

 for(i=0;i < n;i++){
   key[i] = INFTY;
   p[i] = -1;
   cost[i] = 0;
 }

 key[0] = 0;

 while(1){
   u = -1;
   mincost = INFTY;

   for(i=0;i < n;i++){
     if(key[i] < mincost && cost[i] == 0){
       mincost = key[i];
       u = i;
     }
   }

   if(u == -1) break;

   cost[u] = 1;

   for(v=0;v <n;v++){
     if(M[u][v] < key[v] && cost[v] ==0){
       p[v] = u;
       key[v] = M[u][v];
     }
   }
 }

  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( p[i] != -1 ) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 636
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj1149().doIt();
    }
    class aoj1149{
    	int dfs(int deep,String str){
    		int result = 0;
    		if (Character.isDigit(str.charAt(0))) {
                return Integer.valueOf(str)/2 + 1;
            }
    		ArrayList<Integer> array = new ArrayList<Integer>();
    		int poss = 0;
    		int num = 0;
    		for(int i = 0;i < str.length();i++){
    			if(str.charAt(i)== '['){
    				poss++;
    			}
    			else if(str.charAt(i) == ']'){
    				poss--;
    			}
    			if(poss == 0){
    				array.add(dfs(deep+1,str.substring(num + 1, i)));
    				num = i + 1;
    			}
    		}
    		Collections.sort(array);
//    		System.out.println(array.toString()+" "+deep);
    		for(int i = 0;i < array.size()/2 + 1;i++){
    			result = result + array.get(i);
    		}
    		return result;
    	}
        void doIt(){
        	int n = sc.nextInt();
        	for(int i = 0;i < n;i++){
        		String str = sc.next();
        		System.out.println(dfs(0,str));
        	}
        }
     }
}

Measured memory_bytes: 39288
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << fixed << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

//----------------------------------------------------------------
const int MAX = 510000;
// fac[n] = n! % MOD, finv[n] = (n!)^-1 % MOD, inv[n] = n^-1 % MOD
ll fac[MAX], finv[MAX], inv[MAX];

// make table for binomial coefficient
void bcinit(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  REP(i,2,MAX){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

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

int main(void) {
  bcinit();
  int n, k;
  cin >> n >> k;

  REP(i,1,k+1){
    int red = n-k-(i-1);

    if(red<0){
      prt(0); continue;
    }

    ll ans = 1;
    ans = (ans * nCr(k-1,i-1)) % MOD;
    ans = (ans * nCr(red+i, red)) % MOD;

    prt(ans);
  }
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100000;

int n, m;

vector<int> conn[N];
ll parent[N], sz[N];

// DSu
void make_set(int v) {
    parent[v] = v;
    sz[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (sz[a] < sz[b])
            swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
    }
}


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    vector<pair<int, int>> edges(m);
    for (auto& i : edges) {
        cin >> i.first >> i.second;
        --i.first, --i.second;
    }
    reverse(edges.begin(), edges.end());

    for (int i = 0; i < n; i++)
        make_set(i);
    
    vector<ll> diff;
    for (auto edge : edges) {
        int fg = find_set(edge.first), sg = find_set(edge.second);
        if (fg != sg) {
            diff.push_back(sz[fg] * sz[sg]);
            union_sets(fg, sg);
        } else {
            diff.push_back(0);
        }
    }

    reverse(diff.begin(), diff.end());
    
    ll ans = 0;
    for (auto i : diff) {
        ans += i;
        cout << ans << '\n';
    }
}


Measured memory_bytes: 6900
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import GHC.ST
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

judge f = length gs == 2 && all (==1) (zipWith (+) p1 p2) && abs (sum $ map ((subtract 1) . (*2)) p1) <= 1
  where
    gs = group $ sort f
    [(p1,l1), (p2,l2)] = map (fnTuple (head, length)) gs

main = do
    [w,h] <- getInts
    cs <- replicateM h getInts
    putStrLn $ cond "yes" "no" $ judge cs


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

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


int main(){
  string s;
  cin >> s;
  s = s+'R';
  char b = 'N';
  ll count_r = 0;
  ll count_l = 0;
  for(ll i = 0; i < s.size(); i++){
    if(b=='L'&&s[i]=='R'){
      rep(j, count_r-1){
        cout << 0 << " ";
      }
      cout << (count_r+1)/2 + (count_l)/2 << " ";
      cout << (count_r)/2 + (count_l+1)/2 << " ";
      rep(j, count_l-1){
        cout << 0 << " ";
      }
      count_r = 0;
      count_l = 0;
    }
    if(s[i]=='R') count_r++;
    if(s[i]=='L') count_l++;
    b = s[i];
  }
  cout << endl;

  return 0;
}

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

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const string YES = "YES";
const string NO = "NO";

void solve(std::string A, std::string B, std::string C){
    bool ans1 = false;
    bool ans2 = false;
    if (A[A.length() - 1] == B[0]) ans1 = true;
    if (B[B.length() - 1] == C[0]) ans2 = true;
    if (ans1 && ans2) print(YES);
    else print(NO);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string A;
    std::cin >> A;
    std::string B;
    std::cin >> B;
    std::string C;
    std::cin >> C;
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.substr(0, 1) == S.substr(1, 1)) {
    cout << "Bad" << endl;
  } else if (S.substr(1, 1) == S.substr(2, 1)) {
    cout << "Bad" << endl;
  } else if (S.substr(2, 1) == S.substr(3, 1)) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }

  return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int n; cin >> n;
    vi p(n);
    rep(i,n) {
        cin >> p[i];
    }

    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        if(p[i] == i+1) {
            swap(p[i], p[i+1]);
            ++cnt;
            ++i;
        }
    }

    cout << cnt << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define inf 100000000000000000
#define ll long long 
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define test ll t ; cin>>t; while(t--)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),
  fast;
	
	ll n ;
	cin>> n ;
	ll cnt=0;
	for(ll i=1;i<=n ;i++){
		ll a=log10(i);
		if(~a&1)cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

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

int main() {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> T(2 * N);
    for (int i = 0;i < 2 * N;i++) cin >> T[i];
    sort(T.begin(), T.end());
    int res = 0;
    for (int i = 0;i < 2 * N;i += 2) res += T[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 764
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

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

template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_mset;

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define F0R(i,a) for(int i = 0; i < a; i++)
#define F0Rd(i,a) for (int i = a - 1; i >=0 ; i--)
#define FORd(i,a,b) for (int i = b - 1; i >= a; i--)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) int((x).size())
#define newl '\n'

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define print(x) cout << x << newl;
#define finish(x) return cout << x << "\n", 0;
#define bug(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _ << " " << 

const int MXN = 2e5 + 5;
//const int MXN = 1e6 + 5;
const ll MOD = 998244353;
const ll INF = 1e9 + 7;



ll X;


int main(){ FAST
	//ifstream cin("/Users/konwoo/input.txt");
	//ofstream cout("/Users/konwoo/output.txt");

    cin >> X;
    ll hp = X/500;
    ll rem = X % 500;
    cout << 1000*hp + 5*(rem/5) << newl;









	return 0;
}


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

using namespace std;

int main()
{
	for (;;)
	{
		string x;
		cin >> x;

		if (x == "0")
		{
			break;
		}

		int sum = 0;
		for (int i = 0; i < x.length(); i++)
		{
			sum += x[i] - '0';
		}

		cout << sum << endl;
	}
}


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

//#include <map>

using namespace std;

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

	vector<int> vData;

	for (int i = 0; i < n; i++)
	{
		int t;
		cin >> t;
		vData.push_back(t);
	}

	reverse(vData.begin(), vData.end());

	for (int i = 0; i < vData.size(); i++)
	{
		cout << vData.at(i);
		if (i == vData.size() - 1)break;
		cout << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

typedef pair<long long int, long long int> P;

int main() {

	long long int n, k;
	cin >> n >> k;

	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	priority_queue<P, vector<P>, greater<P> > pq;

	P p = P(0, 0);

	for (long long int i = 0; i < n; i++) {
		if (p.first == 0) {
			p = P(1, a[i]);
		}
		else {
			if (a[i] == a[i - 1]) {
				p.first++;
			}
			else {
				pq.push(p);
				p = P(1, a[i]);
			}
		}
	}

	pq.push(p);

	long long int sz = pq.size();
	long long int ans = 0;

	while (sz > k) {
		P pp = pq.top();
		pq.pop();
		ans += pp.first;
		sz--;
	}

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

Measured memory_bytes: 7792
#include <iostream>

using namespace std;
const int N=110;
int g[N][N];
int main()
{
    // c[0][0]=1;
    // for(int i=1;i<N;i++)
    // {
    //     for(int j=0;j<=i;j++)
    //     {
    //         c[i][j]=c[i-1][j]+c[i-1][j-1];
    //     }
    // }
    int n,m;
    cin>>n>>m;
    cout<<((n*(n-1))/2+(m*(m-1))/2)<<endl;
}

Measured memory_bytes: 256
import math
N, D = map(int, input().split())

count = 0
for i in range(N):
    X, Y = map(int, input().split())
    if X > D or X < -D or Y > D or Y < -D:
        continue
    if math.sqrt(X * X + Y * Y) <= D:
        count = count + 1

print(count)


Measured memory_bytes: 9172
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
// n total de noites
// k as primeiras noites

int main(){
    int n, k, x, y, eq=0, soma1=0, soma2=0, soma3=0;
    scanf("%d %d %d %d", &n, &k ,&x, &y);

    if(k>n)
    	soma3= n*x;
    else {
		eq= n-k; // o resto das noites
    	soma1= x*k;
    	soma2= y*eq;
    	soma3= soma1+soma2;


    }
    
    printf("%d\n", soma3);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define NUM 100

using namespace std;

int main(void){
    int a, b;
    scanf("%d %d", &a, &b);

    if(13 <= a){
        printf("%d\n", b);
    }else if(6 <= a){
        printf("%d\n", b / 2);
    }else{
        printf("0\n");
    }
}


Measured memory_bytes: 760
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

bool isBigger(vector<int> v1, vector<int> v2)
{
	int cnt1 = accumulate(v1.begin(), v1.end(), 0);
	int cnt2 = accumulate(v2.begin(), v2.end(), 0);
	if(cnt1 > cnt2) return true;
	else if(cnt1 < cnt2) return false;
	else {
		for(int i = 9; i > 0; i--){
			if(v1[i] > v2[i]) return true;
			else if(v1[i] < v2[i]) return false;
		}
	}
	return false;
}

int main()
{
	int n, m;
	cin >> n >> m;
	int matchNum[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
	vector<bool> canuse(10, false);
	for(int i = 0; i < m; i++){
		int a;
		cin >> a;
		canuse[a] = true;
	}
	vector<vector<int> > result(n + 1);
	result[0] = vector<int>(10, 0);
	for(int i = 0; i < n; i++){
		if(result[i].empty()) continue;
		for(int j = 1; j < 10; j++){
			if(!canuse[j] || i + matchNum[j] > n) continue;
			vector<int> tmp = result[i];
			tmp[j]++;
			if(isBigger(tmp, result[i + matchNum[j]])){
				result[i + matchNum[j]] = tmp;
			}
		}
	}
	for(int i = 9; i > 0; i--){
		for(int j = 0; j < result[n][i]; j++){
			cout << i;
		}
	}
	cout << endl;
}

Measured memory_bytes: 896
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

s = input()
t = input()
t2 = t[::-1]
if s == t2:
    print("YES")
else:
    print("NO")
 

Measured memory_bytes: 3316
#include <cstdio>

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

using namespace std;

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

	int ans=0;
	rep(x,k+1) rep(y,k+1) if(0<=s-x-y && s-x-y<=k) ans++;
	printf("%d\n",ans);

	return 0;
}


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

int A, B, C, D;

int main()
{
    cin >> A >> B >> C >> D;

    while(true)
    {
        //T
        C -= B;
        if(C <= 0)
        {
            cout << "Yes" << endl;
            break;
        }
        //A
        A -= D;
        if(A <= 0)
        {
            cout << "No" << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
	int D, N; cin >> D >> N;
 
	int S = 1; S = pow(100,D);
	if (N != 100) {
		cout << S * N << endl;
	}
	else {
		cout << S * 101 << endl;
	}
	return 0;
}

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
	ll n, i, k;
	cin >> n;
	vector<ll>v(n+1),val(n);
	rep(i,0,n){
		cin >> k;
		val[i] = k;
		v[k]++;
	}
	ll ans = 0;
	rep(i,1,n+1){
		ans += (v[i] * (v[i]-1))/2;
	}
	rep(i,1,n+1){
		k = (v[val[i-1]] * (v[val[i-1]]-1))/2;
		ans -= k;
		ans +=  ((v[val[i-1]]-1 ) * (v[val[i-1]]-2))/2;
		cout << ans << nl;
		ans -=  ((v[val[i-1]]-1 ) * (v[val[i-1]]-2))/2;	
		ans += k;
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}



Measured memory_bytes: 6316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int i;
    char S[11],T[12];
    scanf("%s",S);
    scanf("%s",T);
    int S_len = strlen(S);
    int T_len = strlen(T);
    int diff = T_len - S_len;
    if(diff!=1){
        printf("No\n");
        return 0;
    } 

    for(i=0;i<S_len;i++){
        if(S[i]!=T[i]){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1644
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local N = read.nl()
local set = {}
for i=1,N do
    local s = read.l()
    set[s] = true
end
local c = 0
for k,v in pairs(set) do
    c = c + 1
end
print(c)

Measured memory_bytes: 53556