akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N, M, K;
    cin >> N >> M >> K;
    auto yes = []() {
        print("Yes");
        exit(0);
    };
    auto no = []() {
        print("No");
        exit(0);
    };
    REP(i, N + 1) {
        REP(j, M + 1) {
            ll sum = (ll)i * (M - j) + j * (N - i);
            if (sum == K)
                yes();
        }
    }
    no();

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ",0);
        String[] n = br.readLine().split(" ",0);
        int[] num = new int[2];
        num[0] = Integer.parseInt(n[0]);
        num[1] = Integer.parseInt(n[1]);
        String s = br.readLine();
        if(s.equals(str[0])){
            num[0]--;
        }else{
            num[1]--;
        }
        System.out.println(num[0] + " " + num[1]);
    }
}


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

int main() {
  int N; cin >> N;
  vector<tuple<string, int, int>> a;
  for (int i = 1; i <= N; ++i) {
    string S;
    int p;
    cin >> S >> p;
    p = -p;
    a.push_back(tie(S, p, i));
  }
  sort(a.begin(), a.end());
  
  for (int i = 0; i < N; ++i) {
    cout << get<2>(a[i]) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, D;
  cin >> N >> D;
  vector<vector<int>> v;
  rep(i,N){
    vector<int> x;
    rep(j,D){
      int a;
      cin >> a;
      x.push_back(a);
    }
    v.push_back(x);
  }

  int ret = 0;
  rep(i,v.size()){
    REP(j,i+1,v.size()){
      ll sum = 0;
      rep(k,D){
        sum += (v[i][k] - v[j][k])*(v[i][k] - v[j][k]);
      }
      ll sq = sqrt(sum);

      if(sq * sq == sum){
        ret++;
      }
    }
  }
  cout << ret << endl;
  
  return 0;
}

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

int main(){
    int ans=0,sum=0;

    int n,q;

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

    cin >> q;

    for (int i = 0; i < q; i++){
        int t;
        cin >>t;
        if(binary_search(s.begin(),s.end(),t))ans++;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 3140
x, n = [int(s) for s in input().split()]
p_set = set([int(s) for s in input().split()])
if x not in p_set:
    print(x)
    exit()
l = x - 1
while l in p_set:
    l -= 1
r = x + 1
while r in p_set:
    r += 1
print(l if abs(x - l) <= abs(x - r) else r)


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

#define ED return 0;
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) int(pow(x,y))
#define FI first
#define SE second
const long mod = 1000000007;

int main(){
    unsigned long long int N = 0;
    cin >> N;
    long long int count = 0;
    vector<pair <long long int,long long int>> vec (N);
    //vec.at(i) = pos,point
    for(unsigned long long int i = 0;i < N;i++){
        cin >> vec.at(i).first >> vec.at(i).second;
    }
    sort(vec.begin(),vec.end());
    unsigned long long int pos = vec.at(0).first;
    count += pos;
    unsigned long long int point = vec.at(0).second;
    for(unsigned long long int i = 1;i < N;i++){
        count += min(vec.at(i).first - pos, point - vec.at(i).second);
        pos = vec.at(i).first;
        point = vec.at(i).second;
    }
    count += point;
    cout << count << endl;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_4_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var S = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).Distinct().ToList();
            var q = int.Parse(Console.ReadLine());
            var T = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToList();
            int count = 0;
            foreach (var t in T)
            {
                if (BinarySearch(S, t))
                    count++;
            }
            Console.WriteLine(count);
        }
        static bool BinarySearch(List<int> S,int key)
        {
            int left = 0;
            int right = S.Count();
            while(left < right)
            {
                int mid = (left + right) / 2;
                if (S[mid] == key)
                    return true;
                if (key > S[mid])
                    left = mid+1;
                else if(key < S[mid])
                    right = mid;
            }
            return false;
        }
    }
}



Measured memory_bytes: 30344
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<LL, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

struct edge{
  //int from; //始点
  int to; //終点
  LL weight;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
//graph[始点][エッジのインデックス]

vector<LL> dist; //ノードまでの最小コスト
vector<int> prever; //最小木の親ノード

void dijkstra(int n, int s){
    dist = vector<LL>(n,LINF);
    prever = vector<int>(n,-1);
    dist[s] = 0;

    //P(終点までの最小コスト, 終点)
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();
        //dist[p.second]はこの時点で確定
        que.pop();
        int v = p.second;
        if(dist[v] < p.first){
            continue;
        }
        for(int i=0; i<graph[v].size(); i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.weight){
                dist[e.to] = dist[v] + e.weight;
                prever[e.to] = v;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

vector<int> get_path(int t){ //頂点tへの最短路
    vector<int> path;
    --t;
    for(; t != -1;t=prever[t]){
        path.push_back(t);
    }

    reverse(path.begin(), path.end());
    return path;
}



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

  graph = AdjList(n);
  for(int i=0;i<n-1;i++){
      int from, to;
      LL weight;
      cin >> from >> to >> weight;
      graph[from-1].push_back((edge){to-1,weight});
      graph[to-1].push_back((edge){from-1,weight});
  }
  int q, k;
  cin>>q>>k;
  dijkstra(n,k-1);

  int x, y;
  LL ans;
  REP(i, q){
    cin>>x>>y;
    ans=dist[x-1] + dist[y-1];
    cout<<ans<<endl;
  }

  return 0;
}


Measured memory_bytes: 11504
import sys
from itertools import combinations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    H, W, K = map(int, readline().split())
    G = [readline() for _ in range(H)]

    # black = 0
    # for row in G:
    #     black += row.count('#')

    # target = black - K

    ans = 0
    for rh in range(1, H + 1):
        for combh in combinations(range(H), rh):
            for rw in range(1, W + 1):
                for combw in combinations(range(W), rw):
                    tmp = 0
                    for i in combh:
                        for j in combw:
                            if G[i][j] == '#':
                                tmp += 1
                    if tmp == K:
                        ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68340
n = int(input())

ans = 0

for i in range(105, n + 1, 2):
    divisor = []
    for j in range(1, int(i ** 0.5) + 1):
        if i % j == 0:
            divisor.append(j)
            divisor.append(i // j)

    if len(divisor) == 8:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

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


int main() {
	int n,k;
	string s;
	cin >> n >> k;
	cin >> s;

	vector<int> c;

	int cur_count = 0;

	if (s[0] == '0') {
		c.push_back(0);
	}


	char cur = s[0];
 
	rep(i, n) {

		if (cur != s[i]) {
			c.push_back(cur_count);
			cur_count = 0;
			cur = s[i];
		}
		cur_count ++;

	}
	if (cur_count > 0) {
		c.push_back(cur_count);
	}


/*	
	rep(i, c.size()) {
		cout << "i:" << i << " c:" << c[i] << endl; 
	}
*/	

	vector<int> imos(c.size() + 1);
	imos[0] = 0;
	for(int i = 0; i < c.size();i++) {
		imos[i + 1] = imos[i] + c[i];
		//cout << "i:" << i + 1 << " imos:" << imos[i + 1] << endl; 
	}
	
	int block = k * 2 + 1;
	if ((int) c.size() - block <= 0) {
		cout << imos[imos.size() - 1] << endl;
		return 0;
	}

	int max_v = 0;

	imos.push_back(imos[imos.size() - 1]);
	imos.push_back(imos[imos.size() - 1]);
	imos.push_back(imos[imos.size() - 1]);
	imos.push_back(imos[imos.size() - 1]);


	for(int i = 0; i < imos.size() - 1 - block; i += 2) {
		//cout << "i:" << i << " imos[i + block]:" << imos[i + block] << " imos[i]" << endl;
		max_v = max(max_v, imos[i + block] - imos[i]);		
	}
	cout << max_v << endl;

	return 0;
}

Measured memory_bytes: 1656
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int gcd(int a, int b) {//最大公約数
	if (b == 0)return a;
	return gcd(b, a%b);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;
	VI X(N), Y(N);
	REP(i, N)cin >> X[i] >> Y[i];

	REP(i, N) {
		map<pii, int>cnt;
		REP(j, N) {
			if (i == j)continue;
			int a = Y[j] - Y[i];
			int b = X[j] - X[i];
			int div = gcd(abs(a), abs(b));

			if (++cnt[pii(a / div, b / div)]>=K-1) {
				cout << 1 << endl;
				return 0;
			}
		}
	}

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




Measured memory_bytes: 3364
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    int val = 7;
    for(int i=1;i<=1e8;i++) {
        if(val%n==0) {
            cout<<i;
            return;
        }
        val = (val*10+7)%n;
    }
    cout<<-1;

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

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

void bubbleSort( int* a, int v )
{
    for( int i = 1; i <= v; i++ )
        for( int j = v; j >= i + 1; j-- )
            if( a[j] < a[j-1] )
            {
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}
int main()
{
    int v, d;
    const int N = 1001;

    while( cin >> v >> d )
    {
        int a[v+1];
        a[0] = 1;
        a[1] = 2;
        for( int i = 2; i <= v; i++ )
            a[i] = ( ( a[i-1] % N ) + ( a[i-2] % N ) ) % N;
        
        bubbleSort( a, v );

        int cnt = 1;
        for( int i = 2; i <= v; i++ )
            if( a[i] - a[i-1] >= d )
                cnt++;

        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int ma = max({a,b,c});
  if(ma == a+b+c-ma){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int ans;

	if (K <= A) {
		ans = K;
	} else if (K <= A + B) {
		ans = A;
	} else {
		ans = A - (K - (A + B));
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long  a,b,n,i,r=0,d;
  double c,w,u;
  cin>>n>>d;
  u=double(d);
  while(n--)
  {
    cin>>a>>b;
    c=(a*a)+(b*b);
    w=sqrt(c);
    //cout<<w<<endl;
    if(w<=u) r++;
  }
cout<<r<<endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0; i<n; ++i) {
    cin >> v[i];
  }
  sort(all(v));
  int h = v[n/2-1];
  int hn = v[n/2];
  int cnt =0;
  if(h < hn){
    cnt += hn - h;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
h = list(map(int,input().split()))
ab = [list(map(int,input().split())) for i in range(m)]
hill = [i for i in range(1,n+1)]
for i in range(len(ab)):
    a,b = ab[i][0],ab[i][1]
    if h[a-1] > h[b-1]:
        hill[b-1] = 0
    elif h[a-1] < h[b-1]:
        hill[a-1] = 0
    elif h[a-1] == h[b-1]:
        hill[a-1] = 0
        hill[b-1] = 0

print(n-hill.count(0))


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

int main()
{
	string S, rs;
	int cnt = 0;
	cin >> S;
	rs = S;
	reverse(rs.begin(), rs.end());

	for (int i = 0; i < S.size(); i++)
	{
		if ((S[i] != rs[i]))
		{
			cnt++;
		}
	}
	if (cnt == 0)
	{
		cout << cnt << endl;
	}
	else
	{
		cout << cnt / 2 << endl;
	}
	return 0;
}

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

int main() {
    int a, b; cin >> a >> b;
    string S; cin >> S;
    bool can_match = true;
    for (int i = 0; i < a + b + 1; i++) {
        if (i < a) {
            if (S[i] >= 48 && S[i] <= 57) {
                continue;
            } else {
                can_match = false;
            }
        } else if (i == a) {
            if (S[i] == '-') {
                continue;
            } else {
                can_match = false;
            }
        } else {
            if (S[i] >= 48 && S[i] <= 57) {
                continue;
            } else {
                can_match = false;
            }
        }
    }
    if (can_match) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;

int main() {
ll n;
 cin>>n;
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  
  ll dis=b-a;
  for(int p=0;p<=n-1;p++){
    ll q=n-1-p;
    ll dismax=d*p-c*q;
    ll dismin=c*p-d*q;
    if(dismin<=dis&&dis<=dismax){
      cout<<"YES"<<endl;
      return 0;}
  }
  
  cout<<"NO"<<endl;
  return 0;
    
  
  
}


Measured memory_bytes: 256
s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0 for _ in range(len(t)+1)] for _ in range(len(s)+1)]

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = ''
i = n
j = m
while i >= 0 and j >= 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1

print(ans[::-1])


Measured memory_bytes: 119900
import sys
import math
import time
import numpy
sys.setrecursionlimit(int(1e6))
#dprint = print
def dprint(*args):
    pass

k = list(map(int, input().split()))[0]

s = set()
i = 1
x = 7 % k

while(not (x in s)):
    if (x == 0):
        print(i)
        exit()
    s.add(x)
    x = (x*10+7)%k
    i = i + 1

print(-1)


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

using i64 = long long int;

pair<i64, i64> f[1<<18+1];

int main(){
    int n;
    cin >> n;
    vector<i64> v;
    for(int i=0;i<(1<<n);++i){
        i64 a;
        cin >> a;
        v.push_back(a);
        f[i] = make_pair(a, 0);
    }

    for(int i=0;i<n;++i){
        for(int j=0;j<(1<<n);++j){
            if(j&(1<<i)){
                vector<i64> tmp;
                tmp.push_back(f[j].first);
                tmp.push_back(f[j].second);
                tmp.push_back(f[j^(1<<i)].first);
                tmp.push_back(f[j^(1<<i)].second);
                sort(tmp.rbegin(), tmp.rend());
                f[j].first = tmp[0];
                f[j].second = tmp[1];
            }
        }
    }

    i64 maxi = 0;
    for(int i=1;i<(1<<n);++i){
        maxi = max(maxi, f[i].first + f[i].second);
        cout << maxi << endl;
    }

    return 0;
}


Measured memory_bytes: 11376
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool e[1000001],dp[1001110];
main(){
  e[0]=e[1]=1;
  for(int i=2;i<1000001;i++)
    for(int j=i*2;j<1000001;j+=i)
      e[j]=1;
  int n,m;
  while(cin>>n>>m,n){
    for(int i=0;i<m+110;i++)dp[i]=0;
    int a[n],c=1,p;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)
      for(int j=1;j<=m;j++){
        if(dp[j]&&a[i]+j<=m)dp[a[i]+j]=1;
        if(a[i]*j<=m)dp[a[i]*j]=1;}
    for(p=m;p>=0;p--)if(dp[p]&&!e[p]){c=0;break;}
    if(c)cout<<"NA"<<endl;
  else cout<<p<<endl;
  }
}

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

struct Node{
    Node *left;
    Node *right;
    Node() { left = NULL, right = NULL; }
};

int findcc(string s) {
    int dd = 0;
    for(int i=0; i<s.length(); ++i) {
        if(s[i] == '(') dd++;
        else if(s[i] == ')') dd--;
        else if(s[i] == ',' && dd == 1) return i;
    }
    return -1;
}

Node* parse(string s) {
    Node *r = new Node();
    int ff = findcc(s);
    if(ff != 1) r->left = parse(s.substr(1,ff-1));
    if(ff != s.length()-2) {
        string tmp = s.substr(ff+1);
        r->right = parse(tmp.substr(0,tmp.length()-1));
    }
    return r;
}

Node *intersect(Node *r1,Node *r2) {
    Node *ret = new Node();
    if(r1->left != NULL && r2->left != NULL)
        ret->left = intersect(r1->left,r2->left);

    if(r1->right != NULL && r2->right != NULL)
        ret->right = intersect(r1->right,r2->right);

    return ret;
}

Node* uni(Node *r1,Node *r2) {
    if(r1 == NULL && r2 == NULL) return NULL;

    Node *ret = new Node();
    ret->left = uni(((r1 == NULL)?NULL:r1->left),(r2 == NULL)?NULL:r2->left);
    ret->right = uni(((r1 == NULL)?NULL:r1->right),(r2 == NULL)?NULL:r2->right);
    return ret;
}

string toStr(Node *tree) {
    string res = "(";
    if(tree->left != NULL) res += toStr(tree->left);
    res += ",";
    if(tree->right != NULL) res += toStr(tree->right);
    res += ")";
    return res;
}

void treedel(Node *node) {
    if(node->left != NULL) treedel(node->left);
    if(node->right != NULL) treedel(node->right);
    delete node;
    return;
}

int main() {
    string op,t1,t2;
    while(cin>>op>>t1>>t2) {
        Node *r1 = parse(t1);
        Node *r2 = parse(t2);
        Node *ans;
        if(op == "i") ans = intersect(r1,r2);
        else if(op == "u") ans = uni(r1,r2);

        cout<<toStr(ans)<<endl;
        treedel(r1); treedel(r2); treedel(ans);
    }
}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = (int)1e5 + 10;
ll sum[Maxn];

vector<bool> prime_table(int n) {
    vector<bool> prime(n + 1, true);
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= n; ++i) {
        if (prime[i]) {
            for (int j = 2 * i; j <= n; j += i) prime[j] = false;
        }
    }
    return prime;
}

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    auto table = prime_table(Maxn);
    for (int i = 3; i < Maxn; ++i) {
        if (i % 2 != 0 && table[i] && table[(i + 1) / 2]){
            sum[i] = sum[i - 1] + 1;
        }else{
            sum[i] = sum[i - 1];
        }
    }

    int m;
    cin >> m;
    while(m--){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l - 1] << endl;
    }
}


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


int main() {
    int n,k;
    cin >> n >> k;
    int total = 0;
    for(int i=0;i<n;i++) {
        int s;
        cin >> s;
        total += min(2 * s, 2 * (k - s));
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  double sum = 0;
  double odd_cnt = 0;
  for(int i=1;i<=n;i++){
    if(i%2!=0) odd_cnt++;
    sum++;
  }
  cout<< double(odd_cnt/sum) <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#include <math.h>
#include <iomanip>
#include <fstream>
#include <random>
using namespace std;

inline void InitRand()
{
    srand((unsigned int)time(NULL));
}
int main() {
     InitRand();
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    int c[3][3];
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            cin>>c[i][j];
        }
    }
    for(int i=0;i<3;++i){
        if(c[0][0]-c[1][0]!=c[0][i]-c[1][i]){cout<<"No"<<endl;return 0;}
    }
    for(int i=0;i<3;++i){
        if(c[1][0]-c[2][0]!=c[1][i]-c[2][i]){cout<<"No"<<endl;return 0;}
    }
    for(int i=0;i<3;++i){
        if(c[0][0]-c[2][0]!=c[0][i]-c[2][i]){cout<<"No"<<endl;return 0;}
    }
    for(int i=0;i<3;++i){
        if(c[0][0]-c[0][1]!=c[i][0]-c[i][1]){cout<<"No"<<endl;return 0;}
    }
    for(int i=0;i<3;++i){
        if(c[0][1]-c[0][2]!=c[i][1]-c[i][2]){cout<<"No"<<endl;return 0;}
    }
    for(int i=0;i<3;++i){
        if(c[0][2]-c[0][0]!=c[i][2]-c[i][0]){cout<<"No"<<endl;return 0;}
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b

main = do
 inputs <- readLnInt
 putStr $ (solve inputs)?("Yes","No")

solve [a,b,c,d]
 | c < 1 = True
 | a < 1 = False
 | otherwise = solve [(a-d),b,(c-b),d]


Measured memory_bytes: 3784
#include <iostream>
#include <algorithm>
#include <string>

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

using namespace std;

int main() {
	for(string s; cin >> s && s != "0";) {
		int ans = 0;
		int e[11] = {}, o = 0;
		REP(i,s.size()) {
			int d = s[i] - '0';
			if (d != 0) e[o]++;
			o = (o + (i & 1 ? 11 - d : d)) % 11;
			ans += e[o];
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int n,a,b;
    scanf("%d",&n);
    for(a=1;a<=n;a++)
    {
        b=a;
        if(b%3==0)
            printf(" %d",a);
        else if(b%10==3)
            printf(" %d",a);
        else
        {
            while(b!=0)
            {
                b/=10;
                if(b%10==3)
                {
                    printf(" %d",a);
                    break;
                }
            }
        }
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

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

typedef long long ll;

int N;
int n[202],d[202];
int dx[] = {-1,0,1,0};
int dy[] = {0,-1,0,1};

void solve(){
  int maxx=0,maxy=0,minx=0,miny=0;
  int x[202],y[202];
  x[0] = y[0] = 0;

  rep(i,N-1){
    x[i+1] = x[n[i]] + dx[d[i]];
    y[i+1] = y[n[i]] + dy[d[i]];

    if(x[i+1] > maxx) maxx = x[i+1];
    if(x[i+1] < minx) minx = x[i+1];
    if(y[i+1] > maxy) maxy = y[i+1];
    if(y[i+1] < miny) miny = y[i+1];
  }

  cout<<maxx-minx+1<<" "<<maxy-miny+1<<endl;
}

int main(){
  while(cin>>N,N){
    rep(i,N-1){
      cin>>n[i]>>d[i];
    }
    solve();
  }
}

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

int N,M;
vector<bool> used(100005);
vector<int> vec;
vector<vector<int>> G(100005);

void dfs(int s){
  	if(used[s])return;
    used[s]=true;
    for(auto v:G[s]){
        if(!used[v])dfs(v);
    }
    vec.push_back(s);
}

int main(){
    cin>>N>>M;
  	rep(i,N)used[i]=false;
    int x,y;
    rep(i,M){
        cin>>x>>y;x--;y--;
        G[x].push_back(y);
    }
    rep(i,N)dfs(i);
    reverse(vec.begin(),vec.end());

    vector<int> d(N,0);
    rep(i,N){
        int u=vec[i];
        for(auto v:G[u]){
            d[v]=max(d[v],d[u]+1);
        }
    }
    int res=0;
    rep(i,N){
        res=max(res,d[i]);
    }

    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 8696
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long int
#define dbl double
#define pi acos(-1)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pb push_back
#define mxx 100000
map<string,ll>mp,mp2;
map<ll,ll>vis1;
map<ll,ll>vis;
map<ll,ll>vis_s;
map<pair<ll,ll>,ll>vis2;
priority_queue<ll>pq;
priority_queue<ll>pq2;
vector<ll>vec;
vector<ll>vec_s;
vector<ll>vec1;
map<vector<ll>,ll>mp3;
ll ara[1000006],ara1[1000006];


ll dx[]= {-1,0,+1,-1,+1,-1,0,+1};
ll dy[]= {-1,-1,-1,0,0,+1,+1,+1};
string v="aeiou";
ll n,m,t,cnt=0,a,b,c=0,no,d,sum=0,ans=0,item,mx=0,mn=10000000;

int main()
{
    sc2(n,m);
    swap(n,m);
    for(ll i=1; i<=n; i++)
    {
        sc1(item);
        vis[item]++;
    }
    ll m1=m;
    if(vis[m]==0){
        cout<<m<<endl;
        return 0;
    }
    if(n!=0)
    {
        for(ll i=1;; i++)
        {
            m1-=1;
            if(m1<0 || vis[m1]==0)
            {
                cout<<m1<<endl;
                return 0;
            }
            if(vis[m+i]==0)
            {
                cout<<m+i<<endl;
                return 0;
            }
        }
    }
    else
        cout<<m<<endl;

    return 0;
}


Measured memory_bytes: 3680
s=gets.chomp
c=0
l=0
r=s.size-1
while l<r
  if s[l]!=s[r]
    if s[l]=="x"
      c+=1
      l+=1
    elsif s[r]=="x"
      c+=1
      r-=1
    else
      puts "-1"
      exit
    end
  else
    l+=1
    r-=1
  end
end
puts c


Measured memory_bytes: 1916
while True:
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        for y in range(H):
            if y == 0 or y == H-1:
                print('#'*W)
            else:
                print('#'+'.'*(W-2)+'#')
        print('')


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

int main() {
    int A,B,C;
    string r = "NO";
    cin >> A >> B >> C;

    if(A==5 && B==5 && C==7)
        r = "YES";
    else if(A==5 && B==7 && C==5)
        r = "YES";
    else if(A==7 && B==5 && C==5)
        r = "YES";
    
    cout << r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
using namespace std;

int b[105];
int c[105];

void print(int a[],int n)
{

        for(int i=1;i<=n;i++)
        {
            for(int p=0;p<n;p++)
                {

                    if(p!=n-1)
                        printf("%d ",a[p]);
                    else
                        printf("%d\n",a[p]);
                    }
            for(int g=0;g<i;g++)
            {

                if(a[g]>=a[i])
                {
                    int t=a[i];
                    for(int k=i;k>=g;k--)
                        a[k]=a[k-1];
                    a[g]=t;


                    break;
                }

            }
        }

    return ;
}

int main()
{
    int n;

    scanf("%d",&n);
    for(int i=0;i<n;i++)
        scanf("%d",&b[i]);
    print(b,n);
    return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  Graph(int n):E(n){E.resize(n);V=n;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  int n;cin>>n;
  ll ans=0;
  ll now=0;
  vector<ll>hoge;
  for(int i=0;i<n;i++){
    ll num;cin>>num;
    if(now+1==num){now++;hoge.pb(ans);continue;}
    if(num%(now+1)==0){
      ans+=num/(now+1)-1;
      now=max(now,1LL);
    }else{
      ans+=num/(now+1);
      now=max(now,1LL);
    }
    hoge.pb(ans);
  }
  /*for(int i=0;i<hoge.size();i++)
    cout<<hoge[i]<<" ";
    cout<<endl;*/
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    int ans = INF;
    for(int i = 0; i < s.size()-2; i++){
        string now = s.substr(i, 3);
        int nowint = stoi(now);
        int a = abs(753-nowint);
        if(a < ans){
            ans = a;
        }
    }

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


Measured memory_bytes: 256
n,m=map(int,input().split())
g=[[] for _ in range(n)]
for _ in range(m):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    g[u].append(v)

import sys
sys.setrecursionlimit(10**7)

def func(loop):
    sl=set(loop)
    k=len(loop)
    for i in range(k):
        v=loop[i]
        for nv in g[v]:
            if nv not in sl:continue
            if nv==loop[(i+1)%k]:continue
            j=[j for j in range(k) if loop[j]==nv][0]
            if i<j:
                ary=loop[:i+1]+loop[j:]
            else:
                ary=loop[j:i+1]
            func(ary)
    print(len(loop))
    for x in loop:
        print(x+1)
    exit()

mi=set(range(n))
def dfs(v,par):
    mi.discard(v)
    for nv in g[v]:
        if par[nv]==-1:
            par[nv]=v
            dfs(nv,par)
            par[nv]=-1
        else:
            loop=[v]
            while v!=nv:
                loop.append(par[v])
                v=par[v]
            loop.reverse()
            func(loop)
while mi:
    v=mi.pop()
    dfs(v,[-1]*n)
print(-1)


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

int main()
{
  i64 x1, y1, w1, h1, x2, y2, w2, h2;
  cin >> x1 >> y1 >> w1 >> h1 >> x2 >> y2 >> w2 >> h2;
  if (x1 + w1 <= x2 || x2 + w2 <= x1 || y1 + h1 <= y2 || y2 + h2 <= y1)
    cout << h1 * w1 + h2 * w2 << endl;
  else
  {
    i64 hh, ww;
    if (x1 < x2 && x2 + w2 < x1 + w1)
      ww = w2;
    else if (x2 < x1 && x1 + w1 < x2 + w2)
      ww = w1;
    else if (x1 < x2)
      ww = x1 + w1 - x2;
    else
      ww = x2 + w2 - x1;
    if (y1 < y2 && y2 + h2 < y1 + h1)
      hh = h2;
    else if (y2 < y1 && y1 + h1 < y2 + h2)
      hh = h1;
    else if (y1 < y2)
      hh = y1 + h1 - y2;
    else
      hh = y2 + h2 - y1;
    cout << h1 * w1 + h2 * w2 - hh * ww * 2 << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
from queue import Queue as Q
k = int(input())
q = Q()
[q.put(i) for i in range(1, 10)]

for i in range(k):
    x = q.get()
    if x % 10 != 0:
        q.put(10*x+(x % 10)-1)
    q.put(10*x+(x % 10))
    if x % 10 != 9:
        q.put(10 * x+(x % 10)+1)

print(x)


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

int main(){
    ll N, M;
    cin >> N >> M;

    vvi adj(N);

    for (int i=0;i<M;i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    vi comps(N, -1);
    vb color(N, true);
    ll num_iso = 0;
    ll num_bip = 0;

    ll ncomps = 0;
    for (int i=0;i<N;i++) {
        if (comps[i] == -1) {
            queue<int> bfs;
            bfs.push(i);
            comps[i] = ncomps;

            int cursize = 0;
            bool bi = true;

            while (!bfs.empty()) {
                int cur = bfs.front();
                bfs.pop();

                cursize++;

                for (int nbr : adj[cur]) {
                    if (comps[nbr] == -1) {
                        comps[nbr] = ncomps;
                        color[nbr] = !color[cur];
                        bfs.push(nbr);
                    } else {
                        if (color[nbr] == color[cur]) bi = false;
                    }
                }
            }

            if (cursize == 1) num_iso++;
            else if (bi) num_bip++;
            ncomps++;
        }
    }

    ncomps -= num_iso;

    ll ans = N*N - (N - num_iso)*(N - num_iso) + ncomps*ncomps + num_bip*num_bip;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7296
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())

Adist1=T1*A1
Adist2=T2*A2
Bdist1=T1*B1
Bdist2=T2*B2

# 最初から同じ速度の場合
if Adist1==Bdist1:
  print("infinity")
# Aが先に行ってしまってBが絶対おいつけない場合
elif Adist1>Bdist1 and Adist1+Adist2>Bdist1+Bdist2:
  print(0)
# Bが先に行ってしまってAが絶対おいつけない場合
elif Adist1<Bdist1 and Adist1+Adist2<Bdist1+Bdist2:
  print(0)
# 無限に出会う場合
elif Adist1+Adist2==Bdist1+Bdist2:
  print("infinity")
# 追いついたり追いつかなかったりパターン(Aが先に行く)
elif Adist1>Bdist1 and Adist1+Adist2<Bdist1+Bdist2:
  diff=(Bdist1+Bdist2)-(Adist1+Adist2)
  print(2*((Adist1-Bdist1)//diff)+((Adist1-Bdist1)%diff!=0))
# 追いついたり追いつかなかったりパターン(Bが先に行く)
elif Adist1<Bdist1 and Adist1+Adist2>Bdist1+Bdist2:
  diff=(Adist1+Adist2)-(Bdist1+Bdist2)
  print(2*((Bdist1-Adist1)//diff)+((Bdist1-Adist1)%diff!=0))


Measured memory_bytes: 3192
sx,sy,tx,ty = map(int,input().split())
X = tx-sx
Y = ty-sy
print('R'*X + 'U'*Y + 'L'*X + 'D'*Y,end='')
print('D'+'R'*(1+X) + 'U'*(1+Y) + 'LU'+ 'L'*(1+X) + 'D'*(1+Y)+'R')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int maxn = 300300;
int s[maxn], t[maxn], cc[maxn];
int tree[maxn<<2], lazy[maxn<<2];
void push(int id, int l, int r){
    if(lazy[id]){
        tree[id] |= lazy[id];
        if(l != r){
            lazy[id<<1] |= lazy[id];
            lazy[id<<1|1] |= lazy[id];
        }
        lazy[id] = 0;
    }
}
void upd(int id, int l, int r, int x, int y, int v){
    push(id, l, r);
    if(l > y || r < x) return;
    if(x <= l && r <= y){
        lazy[id] = v;
        push(id, l, r);
        return;
    }
    int mid = (l + r)>>1;
    upd(id<<1, l, mid, x, y, v);
    upd(id<<1|1, mid + 1, r, x, y, v);
    tree[id] = tree[id<<1] | tree[id<<1|1];
}
int get(int id, int l, int r, int x){
    push(id, l, r);
    if(l == r) return tree[id];
    int mid = (l + r)>>1;
    if(x <= mid) return get(id<<1, l, mid, x);
    else return get(id<<1|1, mid + 1, r, x);
}
int main(){
    int n, c;
    scanf("%d %d", &n, &c);
    for(int e = 0; e < n; e++){
        scanf("%d %d %d", s + e, t + e, cc + e);
        s[e] *= 2; s[e] += 1;
        t[e] *= 2; t[e] += 1;
        upd(1, 0, maxn, s[e], t[e], 1<<cc[e]);
    }
    int nd = 0;
    for(int e = 0; e < maxn; e++){
        nd = max(nd, __builtin_popcount(get(1, 0, maxn, e)));
    }
    cout << nd << endl;
    return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>
int some_sum(int n){
    int n1,n2,n3,n4,n5,temp;
    n1=n%10;
    n=n/10;
    n2=n%10;
    n=n/10;
    n3=n%10;
    n=n/10;
    n4=n%10;
    n=n/10;
    n5=n%10;
    temp=n1+n2+n3+n4+n5;
    return temp;
}
int main(void){
    int N,A,B;
    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);
    int i,sum;
    sum=0;
    for (i=1;i<=N;i++){
        int mp;
        mp=some_sum(i);
        if((A<=mp)&&(mp<=B))
            sum+=i;
    }
    printf("%d",sum);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<int,P> PP;

vector<PP> v;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
int n,q,node[200005] = {0};
vector<int> V[200005];
bool flag[200005];
void func(int p, int cost){
	
	rep(i,V[p].size()){
		if(flag[V[p][i]] == false){
			flag[V[p][i]] = true;
			node[V[p][i]] += cost;
			func(V[p][i], node[V[p][i]]);
		}
	}
}

int main()
{
	
	cin >> n >> q;
	rep(i,n-1){
		int a,b;
		cin >> a >> b;
		V[a].push_back(b);
		V[b].push_back(a);
		flag[i] = false;
	}
	flag[n] = false;
	rep(i,q){
		int p,x;
		cin >> p >> x;
		node[p] += x;
	}
	flag[1] = true;
	func(1,node[1]);
	srep(i,1,n){
		cout << node[i] << " ";
	}
	cout << node[n] << endl;
	return 0;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k,x,ans=0;

cin >> n >>k;
vector <int> price;

for(int i=0;i<n;i++)
{
cin >> x;
price.push_back(x);

}

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

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

ans+= price[i];
}

cout << ans;


return 0;
}


Measured memory_bytes: 3608
n = int(input())
a_input = list(map(int,input().split()))

#a_i*a_(i+1)が4の積になるにはeven*even or ood*4の倍数であることが必要
#奇数を数えて、odd,4,...4,odd,4...4,oddにできるか判定
#odd,4,odd,4,odd,4...が最小
#odd,4,odd,4,odd
#if len(odd)+len(4)-1==n: yes
#else:len(odd)<=len(4):yes

odd=0
multiple4=0

for i in range(n):
    a = a_input[i]
    if a%2!=0:
        odd+=1
    if a%4==0:
        multiple4+=1

if odd+multiple4==n and odd-multiple4==1:print('Yes');exit()
if odd<=multiple4:print('Yes');exit()
print('No')


Measured memory_bytes: 14252
#include <cstdio>
int getdaycount(int y,int m,int d){
	int res=0,u;
	u=(y%4==0)&&((y%100!=0)||(y%400==0));
	for(int i=1;i<y;i++){
		res+=365;if((i%4==0)&&((i%100!=0)||(i%400==0))) res+=1;
	}
	for(int i=1;i<m;i++){
		res+=31;
		if(i==4||i==6||i==9||i==11) res--;
		if(i==2){res-=3;if(u)res++;}
	}
	for(int i=1;i<d;i++){
		res+=1;
	}
	return res;
}

int main(){
	int y1,m1,d1,y2,m2,d2;
	while(1){
		scanf("%d%d%d%d%d%d",&y1,&m1,&d1,&y2,&m2,&d2);
		if(y1<0) return 0;
		printf("%d\n",getdaycount(y2,m2,d2)-getdaycount(y1,m1,d1));
	}
	return 0;
}

Measured memory_bytes: 0
// Problem : C - Poll
// Contest : AtCoder - AtCoder Beginner Contest 155
// URL : https://atcoder.jp/contests/abc155/tasks/abc155_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n;
    map<string,int> m;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        m[s]++;
    }
    vector<string> ans;
    int mx = 0;
    for(auto [k,v] : m){
        if(v > mx){
            ans.clear();
            ans.pb(k);
            mx = v;
        } else if(v == mx) ans.pb(k);
    }
    for(string s : ans) cout<<s<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 27224
n, m = map(int, input().split())
lst = []
for _ in range(n):
    lst.append([0, 0])

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if s == 'AC':
        lst[p-1][0] = 1
    elif lst[p-1][0] == 0:
        lst[p-1][1] += 1

correct = 0
wrong = 0
for i in range(n):
    correct += lst[i][0]
    if lst[i][0] == 1:
        wrong += lst[i][1]
print(correct, wrong)

Measured memory_bytes: 53792
#include <iostream>
#include <cstdlib>

bool isgood(const int A, const int B, const int X){
  if(A > X) return false;
  else if(X - A > B) return false;
  else return true;
}

int main() {
  int A, B, X;
  std::cin >> A;
  std::cin >> B;
  std::cin >> X;

  if(isgood(A, B, X))
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
}

Measured memory_bytes: 256
import math
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

S = list(_S())
T = list(_S())
ans = 0

for i in range(len(S)):
    if not S[i]==T[i]:
        ans += 1


print(ans)

Measured memory_bytes: 12372
#include <iostream>
#include <algorithm>
#include <string>

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

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int sum = n!=1;
		for(int i = 2; i*i <= n; i++){
			if(n%i==0){
				sum += i;
				if(i*i != n) sum += n/i;
			}
		}
		string s;
		if(sum == n){
			s = "perfect number";
		}else if(sum < n){
			s = "deficient number";
		}else{
			s = "abundant number";
		}
		cout << s << endl;
	}


	return 0;
}

Measured memory_bytes: 1188