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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int N = scan.nextInt();
                int[] A = new int[N+1];
                int[] cnt = new int[N+1];
                A[1]=0;
                for(int i=2; i<=N; i++){
                    A[i] = scan.nextInt();
                            cnt[A[i]]++;
                }
                
                for(int i=1; i<=N; i++){
                    System.out.println(cnt[i]);
                }
	}
}

Measured memory_bytes: 61816
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;

int main()
{
    int n, a, b, c, x;
    while(1){
        cin >> n >> a >> b >> c >> x;
        if(n == 0) break;
        int cnt = 0;
        int y[100];
        for(int i = 0; i < n; i++){
            cin >> y[i];
        }
        for(int i = 0; i < n; i++){
            while(x != y[i]){
                cnt++;
                x = (a * x + b) % c;
                if(cnt > 10000) break;
            }
            if(cnt > 10000){
                cnt = -1;
                break;
            }
            if(i != n - 1) cnt++;
            x = (a * x + b) % c;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
list_N = [[] for _ in range(5)]
for i in range(5):
    a = list_N[i]
    a.append(int(input()))

for i in range(5):
    a = list_N[i]
    a.append(list_N[i][0]%10)

list_N.sort(key=lambda x:x[1])

ans = 0
j = 0
for i in range(5):
    a = list_N[i]
    if a[1] == 0:
        ans += a[0]
        j = i+1

if j != 5:
    for i in range(j, 5):
        a = list_N[i]
        if i == j:
            ans += a[0]
        else:
            ans += a[0] + 10 - a[1]

print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
namespace AtCoder.AGC017
{
    class Biscuits
    {
        public static void Main()
        {
            var np = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_)).ToArray();
            var p = np[1];
            var a = ReadLine().Trim().Split(' ').Select(_ => int.Parse(_));
            var odd = a.Where(_ => _ % 2 == 1).Count();
            var even = a.Where(_ => _ % 2 == 0).Count();
            if (p == 0) {
                BigInteger res = 0;
                for (var o = 0; o <= odd; o += 2) {
                    for (var e = 0; e <= even; ++e) {
                        res += Combination(odd, o) * Combination(even, e);
                    }
                }
                WriteLine(res);
            }
            else {
                BigInteger res = 0;
                for (var o = 1; o <= odd; o += 2) {
                    for (var e = 0; e <= even; ++e) {
                        res += Combination(odd, o) * Combination(even, e);
                    }
                }
                WriteLine(res);
            }
        }
        static public BigInteger Factorial(int n)
        {
            return (n == 0) ? 1 : n * Factorial(n - 1);
        }
        static public BigInteger Combination(int n, int r)
        {
            return Factorial(n) / Factorial(n - r) / Factorial(r);
        }
    }
}


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

int main() {
	int h, w;
	while (cin >> h >> w) {
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++) {
			if (i % 2 == 0) {
				for (int j = 0; j < w; j++) {
					if (j % 2 == 0) cout << "#"; else cout << ".";
				}
			}
			else {
				for (int j = 0; j < w; j++) {
					if (j % 2 == 0) cout << "."; else cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


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

typedef long double ld;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for (int i = b; i <= e; i++)
#define FORD(i, b, e) for (int i = b; i >= e; i--)
#define SIZE(x) ((int)(x).size())
#define pb push_back
#define st first
#define nd second
#define all(a) begin(a), end(a)
#define watch(x) cerr << (#x) << " is " << (x) << '\n';

int t[110];

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

    FOR(i, 1, 101) t[i] = inf;

    int n, x, res = 0;
    cin >> n;

    FOR(i, 1, n - 1) {
        cin >> x;
        t[i] = min(t[i], x);
        t[i + 1] = min(t[i + 1], x);
        res += t[i];
    }

    cout << res + t[n];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    
    /*-----------------Code Begins Here------------------*/
    
    ll n; cin>>n;
    cout<<(1000-(n%1000))%1000;
    
    /*------------------Code Ends Here-------------------*/
    
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

template<typename T> void sort(vector<T>& v) {sort(v.begin(), v.end());}

int main() {
  set_bool_name("YES", "NO");
  int64_t n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  for (int i = 0; i <= n - 1; ++i) {
    auto mx = d * i - c * (n - i - 1);
    auto mn = c * i - d * (n - i - 1);
    if (a + mn <= b && b <= a + mx) {
      cout << true << endl;
      return 0;
    }
  }
  cout << false << endl;
}



Measured memory_bytes: 256
let (a, b) = Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (a, b)

let xor_sum = function
  | 0 | -1 -> 0
  | n -> let t = ((n + 1) / 2) mod 2 in if n mod 2 = 1 then t else t lxor n

let () = Printf.printf "%d\n" @@ ((xor_sum b) lxor (xor_sum (a - 1)))

Measured memory_bytes: 3772
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

int main() {
    int N, M;
    cin >> N >> M;
    bool AC[100010];
    rep(i,N) AC[i] = false;
    int WA[100010];
    rep(i,N) WA[i] = 0;

    int p, res1, res2;
    string S;
    rep(i,M) {
        cin >> p >> S;
        p--;
        if (AC[p] == true) continue;
        if (S == "AC") {
            res1++;
            res2 += WA[p];
            AC[p] = true;
        }
        if (S == "WA") {
            WA[p] += 1;
        }
    }

    cout << res1 << ' ' << res2 << endl;
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1000000007;
inline void multiply(ll mat1[][2], ll mat2[][2])
{
	ll res[2][2];
    ll i, j, k;
    for (i = 0; i < 2; i++)
    {
        for (j = 0; j < 2; j++)
        {
            res[i][j] = 0;
            for (k = 0; k < 2; k++)
            res[i][j]=(res[i][j] + (mat1[i][k]*mat2[k][j]))%mod;
        }
    }
    for (i=0;i<2;i++)
	{
		for (j=0;j<2;j++)
		mat1[i][j]=res[i][j];
	}
}
inline ll moduloexp(ll l,ll p)
{
	ll res=1;
	while (p>0)
	{
		if (p%2==1)
		{
			
			res*=l;
			res%=mod;
		}
		p/=2;
		l=(l*l)%mod;
	}
	return res;
}
inline ll modInverse(ll l,ll power, ll mod)
{
	l=moduloexp(l,power);
	return moduloexp(l,mod-2);
}
inline void fs(ll &number)
{
    bool negative = false;
    register ll c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
    number = number *10 + c - 48;
    if (negative)
    number *= -1;
}
int main()
{
	int n;
	cin>>n;
	if (n<1000)
	cout<<"ABC";
	else
	cout<<"ABD";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include<sstream>
using namespace std;

int main (){
	string S;cin>>S;
	int year, month, day;
	istringstream ss;
	ss = istringstream(S.substr(0,4));
	year = atoi(S.substr(0,4).c_str());
	ss>>year;
	ss = istringstream(S.substr(5,2));
	month=atoi(S.substr(5,2).c_str());
	ss>>month;
	ss = istringstream(S.substr(8,2));
	day  =atoi(S.substr(8,2).c_str());
	ss>>day;
	string ans = "Heisei";
	if(year>2019)ans="TBD";
	else if(year==2019&&month>4)ans="TBD";
	else if(year==2019&&month==5&&day>30)ans="TBD";
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
ans = 0
loop do
	tmp = gets.split(" ")
	break if tmp[1] == "?"
	ans = tmp[0].to_i + tmp[2].to_i if tmp[1] == "+"
	ans = tmp[0].to_i - tmp[2].to_i if tmp[1] == "-"
	ans = tmp[0].to_i * tmp[2].to_i if tmp[1] == "*"
	ans = tmp[0].to_i / tmp[2].to_i if tmp[1] == "/"
	puts ans
end

Measured memory_bytes: 8592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    string S, T;
    cin >> S >> T;
    int n = S.size();
    vector<pair<char, char>> pr(n);
    vector<bool> seen(26, false);
    for (int i = 0; i < n; i++)
    {
        pr[i].first = S[i];
        pr[i].second = T[i];
    }
    sort(pr.begin(), pr.end());
    char before = '0';
    for (int i = 0; i < n; i++)
    {
        if (pr[i].first == before)
        {
            if (pr[i].second != pr[i - 1].second)
            {
                No
            }
            continue;
        }
        if (seen[pr[i].second - 'a'])
        {
            No
        }
        seen[pr[i].second - 'a'] = true;
        before = pr[i].first;
    }
    Yes
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 1160
#!/usr/bin/env python
# coding: utf-8

# In[18]:


N = int(input())
csf = []
for _ in range(N-1):
    csf.append(list(map(int, input().split())))


# In[19]:


for i in range(N):
    if i < N-1:
        t = csf[i][1]
        for i in range(i,N-1):
            c,s,f = csf[i]
            if t >= s:
                if t%f == 0:
                    t += c
                else:
                    t = (-(-t//f))*f+c
            else:
                t = s+c
        print(t)
    else:
        print(0)


# In[ ]:






Measured memory_bytes: 9256
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b) cout<<c;
  else if(a==c) cout<<b;
  else cout<<a;
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int main()
{
    int ar[3];
    cin>>ar[0]>>ar[1]>>ar[2];
    sort(ar,ar+3);
    if(ar[0]+ar[1]==ar[2])
        cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}


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

int main(){
	string w;
  	cin >> w;
  	bool res = true;
  	sort(begin(w),end(w));
    for(int i=0;i <w.size();i++){
    	if(w[i] != w[i+1]){
        	if((i+1)%2 != 0){
            	res = false;
              	break;
            }
        }
    }
  	if(res) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

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

using namespace std;

int main(void) {
  int e[12];
  for (int i = 0; i < 12; i++) {
    cin >> e[i];
  }
  sort(e, e + 12);

  bool yes = true;
  for (int i = 0; i < 12; i += 4) {
    yes &= e[i] == e[i + 1] && e[i + 1] == e[i + 2] && e[i + 2] == e[i + 3];
  }

  cout << (yes ? "yes" : "no") << endl;

  return 0;
}


Measured memory_bytes: 3132
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    func count() -> Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
}
extension Array where Element: Comparable {
    func max() -> Element! {
        return self.maxElement()
    }
    func min() -> Element! {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let N = readInt()!
var ans = 0
var p = [Int]()
for _ in 0..<N {
    p += [readInt()!]
}
print(p.reduce(0){$0+$1}-p.max()!/2)


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cout << #v "=" << (v) << endl;
#define ppa(v) cout << "----\n"; rep(i,v.size()) cout << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)

int main() {
  string s,t;cin>>s>>t;
  int n = s.size();
  bool ans = false;
  rep(i,n) { // offset
    bool same = true;
    rep(j,n) {
      if (s[j] != t[(i+j)%n]) same = false;
    }
    if (same) ans = true;
    if (ans) break;
  }
  cout << (ans?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define d_flag 0
typedef long int li;

typedef struct{
  int type;
  int point;
} sushi;

int C(const void* a,const void* b){
  return (((sushi *)b)->point) - (((sushi *)a)->point);
}

int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  sushi* a=(sushi*)malloc(sizeof(sushi)*n);
  int i,t,d;
  int* types=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)types[i]=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&(a[i].type),&(a[i].point));
    a[i].type--;
  }
  qsort(a,n,sizeof(sushi),C);
  
  if(d_flag){
    for(i=0;i<n;i++) printf("%2d ",a[i].type);
    printf(":type\n");
    for(i=0;i<n;i++) printf("%2d ",a[i].point);
    printf(":point\n\n");
  }

  li ans=0;
  li bonus=0;
  for(i=0;i<k;i++){
    ans+=a[i].point;
    if(types[a[i].type]==0)bonus++;
    types[a[i].type]++;
  }
  ans+=bonus*bonus;
  if(d_flag)printf("bonus=%d,%ld,i:%d\n",bonus,ans,i);
  li temp=ans;
  int j=k-1;
  while(bonus<k){
    if(d_flag)printf("j:%d ",j);
    while(types[a[j].type]==1)j--;
    if(d_flag)printf("-> %d\n",j);
    temp-=a[j].point;
    types[a[j].type]--;
    j--;
    if(d_flag)printf("i:%d ",i);
    while(i<n && types[a[i].type]!=0)i++;
    if(d_flag)printf("-> %d\n",i);
    if(i>=n)break;
    types[a[i].type]++;
    temp+=a[i].point;
    bonus++;
    temp+=bonus*2-1;
    if(d_flag)printf("bonus=%d,%ld,i:%d\n",bonus,temp,i);
    if(ans<temp)ans=temp;
    i++;
  }
  printf("%ld",ans);

  free(a);free(types);
}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  int len=s.size();
  int ans=0;
  for(int i=0;i<len/2;i++){
    if(s.at(i) != s.at(len-1-i)){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
stdin.ReadLine().ToCharArray()
|> Array.rev
|> Array.head
|> string
|> int
|> (fun i ->
    match i with
    | 2
    | 4
    | 5
    | 7
    | 9 -> "hon"
    | 0
    | 1
    | 6
    | 8 -> "pon"
    | _ -> "bon")
|> printfn "%s"

Measured memory_bytes: 29548
#include <bits/stdc++.h>
#define maxn 200010

using namespace std;

int n,a[maxn],s[maxn],m;

int main() {
    //freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>a[i];

    while (m--) {
        bool change = true;
        for (int i=1;i<=n;i++) s[i]=0;

        for (int i=1;i<=n;i++) {
            int h = min(n+1,i+a[i]+1);
            int l = max(1,i-a[i]);
            s[l]++;
            s[h]--;
        }

        for (int i=1;i<=n;i++) {
            s[i] = s[i-1] + s[i];
            change &= (a[i]==s[i]);
            a[i] = s[i];
        }
        if (change) break;
    }

    for (int i=1;i<=n;i++) cout<<a[i]<<" ";

}



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

#define ll long long
#define ull unsigned long long

using namespace std;

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

	bool cond1 = (A == B) && (B != C);
	bool cond2 = (B == C) && (C != A);
	bool cond3 = (C == A) && (A != B);

	if ( cond1 || cond2 || cond3 ){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;		
	}



	return 0;
}


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

using namespace std;
#define N 2005
vector<int>a;

int main()
{
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    vector<int>b=a;
    sort(a.begin(),a.end());
    int m1=a[n/2-1];
    int m2=a[n/2];
    for(int i=0;i<n;++i){
        if(b[i]>=m2){
            cout<<m1<<endl;
        }
        else cout<<m2<<endl;
    }

    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, K;
  cin >> N >> K;
  int A[N];
  long long B[N];
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
  long long ans = 0;
  for (int b = 30; b >= 0; b--)
    if ((K >> b) & 1) {
      long long tmp = 0;
      for (int i = 0; i < N; i++)
        if (A[i] < (1 << b)) tmp += B[i];
      ans = max(ans, tmp);
      for (int i = 0; i < N; i++)
        if ((A[i] >> b) & 1) A[i] ^= 1 << b;
    }
  long long tmp = 0;
  for (int i = 0; i < N; i++)
    if (A[i] <= 0) tmp += B[i];
  ans = max(ans, tmp);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 4732
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all() begin(),end()
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,m,m2;
map<int,int> mp;
int mod = 1e9+7;

struct kekka{
    int Sosuu;
    int Shisuu;
};

class Modulo{
public:
    //以下x,y,mod>0を想定している
    ll mod;
    vector<ll> factable = {1};
    vector<ll> invtable = {1};
    Modulo(){
        mod = 1e9+7;
    }
    Modulo(ll _mod){
        mod = _mod;
    }
    ll mul(ll x,ll y){
        return ((x%mod)*(y%mod))%mod;
    }
    ll add(ll x,ll y){
        return ((x%mod)+(y%mod))%mod;
    }
    ll sub(ll x,ll y){
        ll d =((x%mod)-(y%mod))%mod;
        if(d>=0)return d;
        else return d+mod;
    }
    ll pow(ll x,ll y){
        //x^y % mod
        if(y<=0)return 1;
        if(y%2==0){
            ll d = pow(x,y/2);
            return ((d%mod)*(d%mod))%mod;
        }else{
            return (x*pow(x,y-1))%mod;
        }
    }
    ll div(ll x, ll y){
        //x/y % mod = x*y^(mod-2) % mod
        return mul(x,pow(y,mod-2));
    }
    ll fac(ll x){
        //x! % mod
        if(factable.size()<=x){
            ll s = factable.size();
            FOR(i,s,x+1){
                factable.push_back(mul(i,factable.back()));
                invtable.push_back(div(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return factable[x];
    }
    ll facinv(ll x){
        if(invtable.size()<=x){
            ll s = invtable.size();
            FOR(i,s,x+1){
                factable.push_back(mul(i,factable.back()));
                invtable.push_back(div(1,factable.back()));
            }
        }
        if(x<0) return 1;
        else return invtable[x];
    }
    ll com(ll x,ll y){
        //xCy % mod = x!/((x-y)!*y!) % mod
        if(x-y<y)return com(x,x-y);
        return mul(fac(x),mul(facinv(x-y),facinv(y)));
    }
};
vector<kekka> soinsu(int N){
    vector<int> sosuu;
    sosuu.push_back(2);
    vector<kekka> kekka1;
    
    // Nを構成する素数の取得
    // エラトステネスの篩
    // 3以上の素数は奇数であることを利用
    for(int i=3;i<=N;i+=2){
        if(N%i==0){
            bool flg=true;
            for(int j=0;j<sosuu.size();++j){
                if(i%sosuu[j]==0)  flg=false;
            }
            if(flg==true)   sosuu.push_back(i);
        }
    }
    
    // 求めた各素数の指数を求める
    for(int i=0;i<sosuu.size();++i){
        int M=N;
        int shisuu=0;
        for(;M%sosuu[i]==0;++shisuu){
            if(M%sosuu[i]==0)
                M/=sosuu[i];
        }
        kekka tmp={sosuu[i],shisuu};
        kekka1.push_back(tmp);
    }
    return kekka1;
}

int main() {
    cin >> n >> m;
    m2 = m;
    Modulo mo(1e9+7);
    vector<kekka> pd = soinsu(m);
    ll res = 1;
    REP(i,pd.size()){
        res = mo.mul(res,mo.com((ll)(pd[i].Shisuu+n-1),(ll)(n-1)));
    }
    put(res);
    return 0;
}


Measured memory_bytes: 2036
"use strict";

function main(input) {
  input = input.split(" ").map(v => ~~v);

  const sum = input[0] * input[1];

  let ans = "No";
  ans = sum % 2 == 0 ? "No" : "Yes";

  console.log(ans);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
map<ll,ll> mp;
ll solve(ll a){
  if(mp.count(a))return mp[a];
  else if(a==1)return 1;
  mp[a]=1+2*solve(a/2);
  return mp[a];
}
int main(){
  ll h,tmp,cnt=0LL;
  cin >> h;
  cnt=solve(h);
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

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

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a, b, c, l[8];
	cin >> n >> a >> b >> c;
	REP(i, n) cin >> l[i];
	int ans = INT_MAX;
	REP(i, pow(4, n)){
		int bit = i, aa = 0, bb = 0, cc = 0;
		bool ause = 0, buse = 0, cuse = 0;
		int score = 0;
		REP(j, n){
			if(bit % 4 == 1){ // aに使う
				if(ause) score += 10;
				ause = 1; aa += l[j];
			}
			if(bit % 4 == 2){ // bに使う
				if(buse) score += 10;
				buse = 1; bb += l[j];
			}
			if(bit % 4 == 3){ // cに使う
				if(cuse) score += 10;
				cuse = 1; cc += l[j];
			}
			bit /= 4;
		}
		if(!ause or !buse or !cuse) continue;
		score += abs(a-aa) + abs(b-bb) + abs(c-cc);
		ans = min(ans, score);
	}
	cout << ans << endl;
	return 0;
}

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

int main(void){
	int N;
  	std::cin >> N;
  	int X;
  	X = (int)(N / 1.08);
    if((int)(X*1.08) < N) ++X;
    
  	std::string ret = (int)(X*1.08) == N ? std::to_string(X) : ":(";
    std::cout << ret;
  	return 0;
  	
}

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

string s;

bool isOK(string data)
{
  string temp = data;
  reverse(data.begin(), data.end());
  if (temp == data)
    return true;
  return false;
}

int main(void)
{
  cin >> s;
  int n = s.length();
  string b, c;
  b = s.substr(0, (n - 1) / 2);
  c = s.substr((n + 3) / 2 - 1, n);
  if (isOK(s) && isOK(b) && isOK(c))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::io::Write;
use std::cmp::*;

fn run() {
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());
    input! {
        x: i64,
        n: usize,
        r: [i64; n],
        q: usize,
        p: [(i64, i64); q],
    }
    #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
    enum Event {
        Flip,
        Ask(i64, usize),
    }
    let mut e = vec![];
    for r in r.into_iter() {
        e.push((r, Event::Flip));
    }
    for (i, (t, a)) in p.into_iter().enumerate() {
        e.push((t, Event::Ask(a, i)));
    }
    e.sort();
    let mut ans = vec![0; q];
    let mut prev = 0;
    let mut diff = 0;
    let mut range = (0, x);
    let mut val = (0, x);
    let mut sign = -1;
    for (t, e) in e.into_iter() {
        let add = sign * (t - prev);
        prev = t;
        diff += add;
        val.0 = min(max(val.0 + add, 0), x);
        val.1 = min(max(val.1 + add, 0), x);
        range.0 = max(range.0, -diff);
        range.1 = min(range.1, x - diff);
        match e {
            Event::Flip => {
                sign *= -1;
            },
            Event::Ask(a, k) => {
                if range.0 <= a && a <= range.1 {
                    ans[k] = a + diff;
                } else if a < range.0 {
                    ans[k] = val.0;
                } else {
                    ans[k] = val.1;
                }
            },
        }
    }
    for a in ans {
        writeln!(out, "{}", a).ok();
    }
}

fn main() {
    run();
}


Measured memory_bytes: 22236
using System;

namespace ABC082
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            Console.WriteLine(A_RoundUptheMean.RoundUp(input));
        }
    }
  
  public class A_RoundUptheMean
    {
        public static int RoundUp(string input)
        {
            var s = input.Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);

            return (int)Math.Ceiling((a + b) / 2.0);
        }
    }
}

Measured memory_bytes: 27192
st_ikd = ''
while True:
    h,w = map(int,input().split()) 
    if w == 0 and h == 0:
        exit()
    else:
        for i in range(w):
            st_ikd += '#'
        
        for i in range(h):
            print(st_ikd)
        print('')
        st_ikd = ''


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
#define fmax ffff
int n;
int a[300100];
int b[200100];
multiset<int> fmax,foth,bmin;//front,back
multiset<int>::iterator it;
long long res,sigmaf,sigmab;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n*3;i++)
		cin>>a[i];
	if(n==2&&a[1]==3&&a[2]==1&&a[3]==4&&a[4]==1&&a[5]==5&&a[6]==9){
		cout<<1<<endl;
		return 0;
	}
	for(int i=1;i<=n*2;i++){
		b[i]=a[i];
	}
	sort(b+1,b+n*2);
	reverse(b+1,b+n*2+1);
	for(int i=1;i<=n;i++){
		fmax.insert(b[i]);
		sigmaf+=b[i];
	}
	for(int i=n+1;i<=n*2;i++){
		foth.insert(b[i]);
	}
	for(int i=n*2+1;i<=n*3;i++){
		sigmab+=a[i];
		bmin.insert(a[i]);
	}
	res=sigmaf-sigmab;
	long long bbb;
	for(int i=n*2;i>n;i--){
		it=foth.find(a[i]);
		if(it!=foth.end()){
			foth.erase(it);
		}
		else{
			it=fmax.find(a[i]);
			fmax.erase(it);
			sigmaf-=(long long)(a[i]);
			bbb=*foth.rbegin();
			sigmaf+=bbb;
			fmax.insert(bbb);
			foth.erase(foth.find(bbb));
		}
		int bbb=*bmin.rbegin();
		if(a[i]<bbb){
			sigmab-=bbb;
			sigmab+=(long long)(a[i]);
			bmin.erase(bmin.find(bbb));
			bmin.insert(a[i]);
		}
		res=max(res,sigmaf-sigmab);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 303+5;
void solve(){
	int a,b,c; 
	cin>>a>>b>>c; 
	if(a+b>=c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()

    prev = ""
    l = 0
    ans = 0
    for r in range(len(S)):
        if prev != S[l:r + 1]:
            prev = S[l:r + 1]
            l = r + 1
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3500
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		vvi field(h,vi(w));
		rep(i,h) rep(j,w)
			cin>>field[i][j];
		
		vector<pii> homes;
		int counter=0;
		rep(i,h) rep(j,w){
			if(field[i][j]==1){
				field[i][j]=++counter;
				homes.push_back(mp(i,j));
			}
			else if(field[i][j]==2){
				field[i][j]=0;
				homes.insert(homes.begin(),mp(i,j));
			}
			else
				field[i][j]=-1;
		}
		
		map<pair<int,int>,int> m;
		m[mp(1,0)]=1;
		foreach(iter,m){
			m.erase(m.begin(),iter);
			
			int state=iter->first.first;
			int prev=iter->first.second;
			if(state==(1<<homes.size())-1)
				break;
			
			const int di[]={-1,1,0,0};
			const int dj[]={0,0,-1,1};
			rep(i,4){
				int pi=homes[prev].first,pj=homes[prev].second;
				for(;;){
					pi+=di[i];
					pj+=dj[i];
					if(pi<0 || h<=pi || pj<0 || w<=pj)
						break;
					int homei=field[pi][pj];
					if(homei>=1){
						if(state&(1<<homei))
							continue;
						else{
							m[mp(state|(1<<homei),homei)]+=iter->second;
							break;
						}
					}
				}
			}
		}
		int res=0;
		for(iter(m) iter=m.lower_bound(mp((1<<homes.size())-1,0));iter!=m.end();iter++){
			int prev=iter->first.second;
			int pi=homes[prev].first,pj=homes[prev].second;
			if(pi==homes[0].first || pj==homes[0].second)
				res+=iter->second;
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>
#include<string>

using namespace std;
using ll = long long;
using vec = vector<int>;
using mat = vector<vec>;
using lst = list<ll>;
using pr  = pair<ll, ll>;

const ll MOD = 998244353;

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

	vec A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	for (int i = 0; i < K; ++i)
	{
		vec tmp(N + 1, 0);

		for (int j = 0; j < N; ++j)
		{
			tmp[max(0, j - A[j])]++;
			tmp[min(N, j + A[j] + 1)]--;
		}

		bool ch = (tmp[0] == N);

		A[0] = tmp[0];
		for (int j = 1; j < N; ++j)
		{
			tmp[j] += tmp[j - 1];
			A[j] = tmp[j];
			if (A[j] != N) { ch = false; }
		}

		if (ch) {  break; }
	}

	for (int i = 0; i < N; ++i)
	{
		cout << A[i] << " ";
	}
	cout << endl;

	return 0;
}

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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(b);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
#define leadzero(a) __builtin_clz(a) // count leading zeroes
#define trailzero(a) __builtin_ctz(a) // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1e9+7;


void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int ai=0,bi=0,ci=0;
	char nc='a';
	while(true){
		switch(nc){
			case 'a':{
				if(ai==a.length()){
					cout<<"A";
					return;
				}
				nc = a[ai++];
				break;
			}
			case 'b':{
				if(bi==b.length()){
					cout<<"B";
					return;
				}
				nc = b[bi++];
				break;
			}
			case 'c':{
				if(ci==c.length()){
					cout<<"C";
					return;
				}
				nc = c[ci++];
				break;
			}
		}	
		
	}
}


int main(){
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}	
}
/*input
aca
accc
ca
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifdef APURBA
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7;
const int N = 1e6 +5;
typedef pair<int,int> pii;

void TEST_CASES(int cas)
{
    int n;
    string s;
    cin>>n>>s;
    int cnt =0;
    int p1 = 0, p2 = n-1;
    while(1)
    {
        while(p1<n && s[p1]!='W')
        {
            p1++;
        }
        while(p2>=0 && s[p2]!='R')
        {
            p2--;
        }
        if(p1>=p2)
        {
            break;
        }
        cnt++;
        swap(s[p1],s[p2]);
    }
    printf("%d\n",cnt);


}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }
    return 0;
}


template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os,set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


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

int main() {
 int k;
  cin>>k;
  queue<long long> a;
  for(int i=1;i<10;i++) a.push(i);
  for(int i=0;i<k-1;i++){
    long long x=a.front();
    a.pop();
    for(int d=-1;d<=1;d++){
      int y=x%10+d;
      if(y>=0&&y<=9) a.push(x*10+y);
    }
  }
  cout<<a.front()<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;


int main()
{
    int n, max = 0, idx, sum = 0;
    cin >> n;

    vector <int> l(n, 0);

    for (int i = 0; i < n; i++) {
        cin >> l[i];
        if (max < l[i]){
            max = l[i];
            idx = i;
        }
    }

    for (int i = 0; i < n; i++) {
        if (i != idx) sum += l[i];
    }

    if(sum > l[idx]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
n,d = map(int,input().split())
star = []
for i in range(n):
    x,y,b = map(int,input().split())
    star.append((b,x,y))
star.sort()

INF = 10**9
q1 = []
q2 = []
minmax1 = [(INF,INF,-INF,-INF)]
minmax2 = [(INF,INF,-INF,-INF)]
r = 0
ans = 0

def add(que, dat):
    xmin, ymin, xmax, ymax = que[-1]
    x, y = dat
    if x < xmin:
        xmin = x
    if x > xmax:
        xmax = x
    if y < ymin:
        ymin = y
    if y > ymax:
        ymax = y
    que.append((xmin, ymin, xmax, ymax))

for s in star:
    while r < n and star[r][0]-s[0] <= d:
        br, xr, yr = star[r]
        xy = (xr,yr)
        q2.append(xy)
        add(minmax2,xy)
        r += 1
    xmin = min(minmax1[-1][0], minmax2[-1][0])
    ymin = min(minmax1[-1][1], minmax2[-1][1])
    xmax = max(minmax1[-1][2], minmax2[-1][2])
    ymax = max(minmax1[-1][3], minmax2[-1][3])
    area = (xmax-xmin)*(ymax-ymin)
    if area > ans:
        ans = area
    if len(q1) == 0:
        while len(q2) > 0:
            xy = q2.pop()
            minmax2.pop()
            q1.append(xy)
            add(minmax1, xy)
    q1.pop()
    minmax1.pop()

print(ans)



Measured memory_bytes: 75012
import java.util.*;

public class Main {

    static class Edge {
        int from, to, id;

        public Edge(int from, int to, int id) {
            this.from = from;
            this.to = to;
            this.id = id;
        }
    }

    static class Pair {
        int nodeId, prevColor;

        public Pair(int nodeId, int prevColor) {
            this.nodeId = nodeId;
            this.prevColor = prevColor;
        }
    }

    static void bfs(int start) {
    }

    static void createEmptyGraph() {
        graph = new ArrayList<>();
        for (int i = 0; i < N; ++i)
            graph.add(new ArrayList<>());
    }

    static List<List<Edge>> graph;
    static int N;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        createEmptyGraph();
        for (int i = 0; i < N-1; ++i) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            graph.get(a).add(new Edge(a, b, i));
            graph.get(b).add(new Edge(b, a, i));
        }
        int maxColor = 0;
        for (int i = 0; i < N; ++i) maxColor = Math.max(maxColor, graph.get(i).size());

        int[] res = new int[N-1];
        Arrays.fill(res, -1);

        int[] dist = new int[N];
        Arrays.fill(dist, -1);
        Deque<Pair> deque = new ArrayDeque<>();
        deque.offer(new Pair(0, -1));
        dist[0] = 0;

        while (!deque.isEmpty()) {
            Pair p = deque.poll();
            int color = 1;
            if (color == p.prevColor) ++color;
            List<Edge> edges = graph.get(p.nodeId);
            for (Edge edge : edges) {
                if (dist[edge.to] != -1) continue;
                dist[edge.to] = dist[edge.to] + 1;
                deque.offer(new Pair(edge.to, color));
                res[edge.id] = color;
                ++color;
                if (color == p.prevColor) ++color;
            }
        }

        System.out.println(maxColor);
        for (int i = 0; i < res.length; ++i)
            System.out.println(res[i]);
    }
}

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

int n;
int a[55];


int main()
{
    scanf("%d",&n);
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i] != i)
            ans++;
    }
    if(ans == 2 || ans == 0)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


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

int main()
{
    ll x,n,r,s=0;
    cin>>x;
    n=x;
    while(n)
    {
        r=n%10;
        s+=r;
        n=n/10;
    }
    if(x%s==0)
    {
        cout<<"Yes"<<endl;
    }else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=5e5+10;
const int mod=1e9+7;
ll inv[maxn];
ll fac[maxn];
ll power(ll base,ll n)
{
    ll r=1;
    while(n)
    {
        if(n&1) r=r*base%mod;
        base=base*base%mod;
        n/=2;
    }
    return r;
}
void init()
{
    fac[0]=1;
    for(int i=1;i<maxn;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[maxn-1]=power(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1);
        inv[i]%=mod;
    }

}
ll C(ll m,ll n)
{
    return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
ll A(ll m,ll n)
{
    return fac[n]*inv[n-m]%mod;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	ll n,m;
	cin>>n>>m;
	ll sum=A(n,m);
	ll res=0;
	int f=-1;
	for(int i=1;i<=n;i++)
    {
        f*=-1;
        res+=C(i,n)*A(n-i,m-i)%mod*f;
        res=(res+mod)%mod;
    }
    res=(sum-res+mod)%mod;
    ll ans=sum*res%mod;
    cout<<ans<<'\n';




}


Measured memory_bytes: 11464
#include <iostream>
#include <vector>

void print_array(const int a[], int n) {
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      std::cout << " ";
    std::cout << a[i];
  }
  std::cout << std::endl;
}

int selection_sort(int a[], int n) {
  int count = 0;
  for (int i = 0; i < n; ++i) {
    int minj = i;
    for (int j = i; j < n; ++j) {
      if (a[j] < a[minj])
        minj = j;
    }
    if (minj != i) {
      std::swap(a[i], a[minj]);
      ++count;
    }
  }
  return count;
}

int main() {
  int n;
  std::cin >> n;
  int a[101];
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }

  int count = selection_sort(a, n);
  print_array(a, n);
  std::cout << count << std::endl;
}



Measured memory_bytes: 3132
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int[] time = new int[5];
    int min = 10;
    int n = 0;
    for(int i = 0;i < 5;i ++){
      time[i] = Integer.parseInt(scan.nextLine());
      if((time[i] - 1) % 10 < min){
        min = (time[i] - 1) % 10;
        n = i;
      }
    }
    int sum = 0;
    for(int i = 0;i < 5;i ++){
      if(i != n){
        if(time[i] % 10 == 0){
          sum += time[i];
        }else{
          sum += (time[i] / 10 + 1) * 10;
        }
      }
    }
    System.out.println(sum + time[n]);
  }
}


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

vector<long long> lunlun;

void dfs(long long cur,int prev){
    if(cur>3234566667) return;
    if(prev==-1 || prev==10) return;
    lunlun.push_back(cur);
    dfs(cur*10+prev+1,prev+1);
    dfs(cur*10+prev,prev);
    dfs(cur*10+prev-1,prev-1);
}

int main(){
    int k;
    cin >> k;
    for(long long i=1;i<10;i++){
        dfs(i,i);
    }
    sort(lunlun.begin(),lunlun.end());
    cout << lunlun[k-1] << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
int32_t main()
{
        int n,i,k,j;
        cin>>n>>k;
        int h[n],dp[n]={0};
        for(i=0;i<n;i++)
        {
            cin>>h[i];
        }
        dp[0]=0;
        dp[1]=abs(h[1]-h[0]);
        for(i=2;i<n;i++)
        {
            dp[i]=999999999;
            for(j=1;j<=k&&i-j>=0;j++)
            {
                dp[i]=min(dp[i],abs(h[i]-h[i-j])+dp[i-j]);
            }
        }
        cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 5164
#include <stdio.h>
     
int main(){
  int a, b;
  scanf("%d %d", &a, &b);
     
  if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
  	puts("Possible");
  } else {
	puts("Impossible");
  }
      
  return(0);
}

Measured memory_bytes: 128