akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
void SPFA(int st);
queue<int> q;
long long dis[1005] = {};
int n,m,timee[1005] = {};
bool flag, vis[1005];
vector< pair<int, long long> > a[100005];

int main()
{
    scanf("%d%d",&n,&m);
//    flag=1;
//        for(int i = 0; i <= n; ++i)
//        {
//            dis[i] = -INF;
//            for(int j = 0; j <= n; ++j)
//            {
//                a[i][j] = a[j][i] = -INF;
//            }
//        }
//        cout << dis[1] << endl;
    memset(dis, 0x3f, sizeof(dis));
    int a1,a2;
    long long a3;
    for(int j=0; j<m; ++j)
    {

        scanf("%d%d%lld",&a1,&a2,&a3);
        a[a1].push_back({a2, -a3});
    }

    SPFA(1);

    if(timee[n] > n)
        cout<<"inf"<<endl;
    else
    {
//            for(int i = 1; i <= n; ++i)
//                cout << dis[i] << ' ';
//            cout << endl;
        cout << (-dis[n]) << endl;
    }
    return 0;
}
void SPFA(int st)
{
//    for(int i = 0; i <= n; ++i)
//    {
//        dis[i] = INF;
//    }
    dis[st]=0;
    q.push(st);
    vis[st] = 1;
    timee[1] = 1;
    while(!q.empty())
    {
        int i=q.front();
        q.pop();
        vis[i] = 0;
        vector< pair<int, long long> >::iterator it;
        for(it = a[i].begin(); it != a[i].end(); ++it)
//        for (auto it : a[i])
        {
            if(dis[it->first] > dis[i] + it->second)
            {
                dis[it->first] = dis[i] + it->second;
                if(!vis[it->first])
                {
                    timee[it->first]++;
                    if(timee[it->first] > 2 * n)
                    {
                        flag=0;
                        return ;
                    }
                    q.push(it->first);
                    vis[it->first] = 1;
                }
//                printf("i1 = %d", i1);
            }
        }
    }
}


Measured memory_bytes: 2688
import math

def calc_d(a, b):
    return math.sqrt((a[0] - b[0])**2 + (a[1] - b[1])**2)

p = []
while True:
    try:
        p.append(list(map(float, input().split(","))))
    except:
        break

n = len(p)
s = 0
for i in range(1, n - 1):
    a = calc_d(p[0], p[i])
    b = calc_d(p[0], p[i+1])
    c = calc_d(p[i], p[i+1])
    z = (a + b + c)/2
    s += math.sqrt(z*(z - a)*(z - b)*(z - c))
print(s)



Measured memory_bytes: 5648
#include<bits/stdc++.h>
using namespace std;
bool check(long long a,long long b,long long c)
{
	if(a+b > c && a+c > b && b+c > a)
		return true;
	else
		return false;
}
int main()
{
     int n;
     cin>>n;
     int i;
     int a[n];
     for(i=0;i<n;i++)
     {
         cin>>a[i];
     }
     sort(a,a+n);
     reverse(a,a+n);
     int ans=0;
     for(i=0;i<n-2;i++)
     {
         for(int j=i+1;j<n-1;j++)
         {
            for(int k=j+1;k<n;k++)
            {
                if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] && check(a[i],a[j],a[k]))
                {
                    ans++;
                }
            }
         }
     }
     cout<<ans<<endl;
}


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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

template <class T>
inline istream& operator>>(istream &is, vector<T> &vec) {
    for (auto &e: vec) {
        is >> e;
    }
    return is;
}

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

template <class T>
inline bool chmax(T &a, const T &b) noexcept {
    return b > a && (a = b, true);
}

template <class T>
inline bool chmin(T &a, const T &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    var(string, s);

    size_t r = 0, b = 0;
    for (const auto e: s) {
        r += e == '0';
        b += e == '1';
    }

    dump(r, b);

    output(min(r, b) * 2);

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static Scanner sc = new Scanner(System.in);
    public void run() throws Exception {
    	int N = sc.nextInt();
    	

    	for(int i=1;i<=9;i++){
    		for(int j=1;j<=9;j++){
    			if(i*j == N){
    				System.out.println("Yes");
    				return;
    			}
    		}
    	}
    	
    	System.out.println("No");
    }
    public static void main(String[] args) throws Exception {
        new Main().run();
    }


}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	int cnt = 1;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		if (a[i] == cnt)
			cnt++;
	cnt--;
	if (cnt == 0) {
		cout << "-1";
		return 0;
	}
	cout << n - cnt;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])

Measured memory_bytes: 94524
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	int p;
	pair<pair<string, int>,int> v[110];
	for (int i = 0; i < n; i++) {
		cin >> s >> p;
		v[i] = make_pair(make_pair(s, -p), i);
	}
	sort(v, v + n);

	for (int i = 0; i < n; i++) {
		cout << v[i].second + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    if (a == 0) {
        cout << b / x + 1 << endl;
    } else {
        a--;
        cout << b / x - a / x << endl;
    }
}


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

using namespace std;
typedef         long long int   ll;


#define         input           freopen("input.txt","r",stdin)
#define         output          freopen("output.txt","w",stdout)
#define         si(a)           scanf("%d",&a)
#define         sii(a,b)        scanf("%d%d",&a,&b)
#define         siii(a,b,c)     scanf("%d%d%d",&a,&b,&c)
#define         pi(a)           printf("%d",a)
#define         spc             printf(" ")
#define         bl              printf("\n")
#define         here(a)         printf("#### %d ####",a)
#define         pii             pair<int,int>
#define         fr(i,n)         for(int i=0;i<n;i++)
#define         case(num)       printf("Case %d:",num)
#define         inf             1000000050
#define         MAX             100010*3

int row[MAX+10],column[MAX+10];
vector<pii>v;
vector<int>pr,pc;
int main(){

    //input;
    //output;

    int h,w,m,x,y;
    cin>>h>>w>>m;
    int mr,mc;
    mr = -1; mc = -1;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        row[x]++;
        column[y]++;
        mr = max(mr,row[x]);
        mc = max(mc,column[y]);
        v.push_back(pii(x,y));
    }
    int l = max(h,w);

    for(int i=0;i<=l;i++){
        if(row[i]==mr) pr.push_back(i);
        if(column[i]==mc) pc.push_back(i);
    }

    int ans = mr+mc;
    int flag = 1;
    sort(v.begin(),v.end());

    for(int i=0;i<pr.size();i++){
        for(int j=0;j<pc.size();j++){
            /// search if the poing is exist
            int pos = lower_bound(v.begin(),v.end(),pii(pr[i],pc[j]))- v.begin();
            if(pos>=v.size()){
                flag = 0;
                break;
            }
            if(v[pos].first!=pr[i] || v[pos].second!=pc[j]){
                flag = 0;
                break;
            }
        }
    }

    //cout<<endl;
    //cout<<pr<<" "<<pc<<endl;
    cout<<ans-flag<<endl;

    return 0;
}
/**
*/


Measured memory_bytes: 12584
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
 
 
int main()
{
 
	int N,T;
 
	std::cin >> N >> T;
 
	int min_C = 3000;
 
	for (int i = 0; i < N; i++)
	{
		int c, t;
 
		std::cin >> c >> t;
 
		if (T >= t)
		{
			min_C = std::min(min_C, c);
		}
	}
	
	if (min_C == 3000)
		std::cout << "TLE" << std::endl;
	else
		std::cout << min_C << std::endl;
 
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,a=0,b=1,c,i;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    
    c=a+b;
    a=b;
    b=c;
  }

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

  return 0;

}

Measured memory_bytes: 596
from math import floor

t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

diff1 = (a1 - b1) * t1
diff2 = (a2 - b2) * t2
diff = diff1 + diff2

if diff1 * diff > 0:
    print("0")

elif diff == 0:
    print("infinity")

else:
    diff1 = abs(diff1)
    diff2 = abs(diff2)
    n = diff2 / (diff2 - diff1)

    if n == floor(n):
        n = floor(n)
        ans = 2 * n - 2
    else:
        n = floor(n)
        ans = 2 * n - 1

    print(ans)



Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 105;

int a, d;

int main() {
scanf("%d", &a);
d = 1;
while ((d * a) % 360) d++;
printf("%d\n", d);
return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)

int main(){
ll N;
cin>>N;
vector<ll> A(N);
for(ll i=0;i<N;i++){
  cin>>A[i];
}
ll tt=0;
sort(ALL(A));
ll pre = A[0];
for(ll i=1;i<N;i++){
if(A[i]==pre){
  tt++;
}
pre = A[i];
}

if(tt==0){
  cout<<"YES"<<endl;
}
else{
  cout<<"NO"<<endl;
}



}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
ll mulmod(ll a,ll b,ll c) 
{ 
    if (b==0) 
        return 0; 
    ll s = mulmod(a, b/2, c); 
    if (b%2==1) 
        return (a%c+2*(s%c)) % c; 
 
    else
        return (2*(s%c)) % c; 
} 

  
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{ll int t;
//t=1;
//cin>>t;
t=1;
while(t--)
{
    ll int n,d,a,i,temp,count=0,x,h,k;
    cin>>n>>d>>a;
    vector <pair<ll int,ll int>> vect;
    vector<ll int> mark,mar;
    
    for(i=0;i<n;i++)
    {
        cin>>x>>h;
        vect.push_back(make_pair(x,h));
    }
    sort(vect.begin(),vect.end());
    count=0;
    for(i=0;i<n;i++)
    {ll int zz = lower_bound(mark.begin(),mark.end(),vect[i].first)-mark.begin();
        if(zz>0)
        vect[i].second =  vect[i].second - (count-mar[zz-1])*a;
        else
        vect[i].second =  vect[i].second -(count)*a;
        if(vect[i].second>0)
       { k=(vect[i].first+a-1)/a;
        count+=(vect[i].second+a-1)/a;
        mark.push_back(vect[i].first+2*d);
        mar.push_back(count);}
        
    }
    cout<<count<<endl;

}
 
    return 0;
}

Measured memory_bytes: 8940
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin>>N;
  char c = 'a';
  int i,j;

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

  for (i=0;i<N.size();i++){
    if(N[i]==c){
      c += 1; 
    }
  }

  if(c>'z'){
    cout << "None" << endl;
  }else{
    cout << c << endl;
  }
  //reverse(a,a+N);
  
  //cout << ans << endl;
}

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

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

int N, M;
int a[21][21];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	while(cin>>N,N) {
		rep(i, 21) {rep(j, 21)a[i][j]=false;}
		
		int x, y;
		rep(i, N) {
			cin>>x>>y;
			a[x][y] = true;
		}
		
		cin>>M;
		x=10;
		y=10;
		rep(i, M) {
			char d;
			int l;
			cin>>d>>l;
			rep(j, l) {
				switch(d) {
					case 'N':y++;break;
					case 'E':x++;break;
					case 'S':y--;break;
					case 'W':x--;break;
				}
				a[x][y]=false;
			}
		}
		
		bool f = true;
		rep(i, 21) {
			rep(j, 21) {
				if(a[i][j]) {
					f=false;
					break;
				}
			}
			if(!f)break;
		}
		cout<<(f?"Yes":"No")<<endl;
	}
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N; cin >> N;
  vi32 s(N); cin >> s;
  i64 ans = 0;
  for (int c = 1; c <= N - 1; c++) {
    i64 score = 0;
    unordered_set<int> se;
    for (int x = 0; x * c < N - 1; x++) {
      int a = N - 1 - x * c;
      int b = a - c;
      if (a <= 0 || b <= 0 || a <= b) continue;
      int i = x * c;
      int j = N - 1 - i;
      if (i == j || se.count(i) > 0 || se.count(j) > 0) break;
      se.insert(i), se.insert(j);
      score += s[i] + s[j];
      amax(ans, score);
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 4784
#include <iostream>
using namespace std;
 
int main() 
{
  int n,m;
  cin >> n >> m;
  int i;
  int x[n+1],y[m+1];
  cin >> x[n] >> y[m];
  for(i = 0;i < n;i++){
    cin >> x[i];
  }
  for(i = 0;i < m;i++){
    cin >> y[i];
  }
  int supx,infy;
  supx = x[0];
  for(i = 1;i <= n;i++){
    if(supx < x[i]){
      supx = x[i];
    }
  }
  supx++;
  infy = y[0];
  for(i = 1;i <= m;i++){
    if(infy > y[i]){
      infy = y[i];
    }
  }
  if(supx <= infy){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using static System.Console;
class K
{
	const int MOD = 1000000007;
	static void Main()
	{
		const int M = 10;
		var N = int.Parse(ReadLine());
		var g = new int[M, 4] {
			{ 3, 4, 1, 1 }, { 2, 2, 2, 2 },
			{ 3, 5, 6, 7 }, { 8, 4, 1, 1 },
			{ 8, 9, 2, 10 }, { 3, 2, 1, 1 },
			{ 3, 9, 1, 1 }, { 3, 5, 2, 7 },
			{ 8, 4, 2, 1 }, { 3, 4, 2, 1 } };
		for (var i = 0; i < M; i++) for (var j = 0; j < 4; j++) g[i, j]--;
		// start = 0, accepted = {1}
		var dp = new long[N + 1, M];
		dp[0, 0] = 1;
		for (var i = 0; i < N; i++) for (var s = 0; s < M; s++) for (var c = 0; c < 4; c++) Add(ref dp[i + 1, g[s, c]], dp[i, s]);
		WriteLine((Pow(4, N) - dp[N, 1] + MOD) % MOD);
	}
	static void Add(ref long a, long b) => a = (a + b) % MOD;
	static long Pow(long a, long b)
	{
		long p = 1, x = a;
		while (b > 0)
		{
			if ((b & 1) == 1) p = p * x % MOD;
			b >>= 1;
			x = x * x % MOD;
		}
		return p;
	}
}


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

using namespace std;

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

    int n;
    while(cin>>n,n){
        int res=0,l=0,r=0,last=0;//floor->0 step->1
        for(int i=0;i<n;i++){
            string s;cin>>s;
            if(s=="lu") l=1;
            else if(s=="ru") r=1;
            else if(s=="ld") l=0;
            else r=0;
            if(l!=r) continue;
            if(last!=l){
                res++;
                last=l;
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[MAX];

void dijkstra() {
  priority_queue<pair<int, int>> PQ;
  int color[MAX];
  int d[MAX];
  for (int i = 0; i < n; i ++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (!PQ.empty()) {
    pair<int, int> f = PQ.top();
    PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if (d[u] < f.first * -1) continue;

    for (int j = 0; j < adj[u].size(); j ++) {
      int v = adj[u][j].first;
      if (color[v] == BLACK) continue;
      if (d[v] > d[u] + adj[u][j].second) {
        d[v] = d[u] + adj[u][j].second;
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }

  for (int i = 0; i < n; i ++) {
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main() {
  int k, u, v, c;

  cin >> n;
  for (int i = 0; i < n; i ++) {
    cin >> u >> k;
    for (int j = 0; j < k; j ++) {
      cin >> v >> c;
      adj[u].push_back(make_pair(v, c));
    }
  }

  dijkstra();

  return 0;
}


Measured memory_bytes: 8096
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;

ll mod=998244353;

int main(){
    ll n;
    cin>>n;
    
    map<ll,ll> m;
    for(ll i=1;i<=n;++i){
        ll t;
        cin>>t;
        m[t]++;
    }
    ll cnt=0;
    for(auto v:m){
        cnt+=v.second%2;
    }
    cout<<cnt;
}

Measured memory_bytes: 9784
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long t;
	cin>>t;
	long long a[t]={0},b[t]={0};
	for(long long i=0;i<t;i++){
		cin>>a[i];
		if(i==0){
			b[i]=0;
		}
		else if(i==1){
			b[i]=(abs(a[1]-a[0]));
		}
		else if(i==2)
		{
			long long y=(abs(a[2]-a[1]))+(abs(a[1]-a[0]));
			long long z=(abs(a[2]-a[0]));
			if(y<z){
				b[i] = y;
			}else{
				b[i] = z;
			}
		}
		else{
			long long p=(abs(a[i]-a[i-2]))+b[i-2];
			long long q=(abs(a[i]-a[i-1]))+b[i-1];
			if(p<q){
				b[i] = p;
			}else{
				b[i] = q;
			}
		}
	}
	cout<<b[t-1]<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  // data loading
  int x;
  char line[128];

  fgets(line,sizeof(line),stdin);
  sscanf(line,"%d",&x);

  // calculation
  int n_500,n_5;
  int grad;

  n_500 = x/500;
  n_5 = (x%500)/5;

  grad = n_500*1000 + n_5*5;

  printf("%d",grad);

  return 0;
}


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

typedef pair <int, int> ii;
typedef pair <int, ii> iii;
typedef long long ll;

const int Maxn = 305;
const ll Inf = 1000000000000000000ll;

int n;
int B[Maxn][Maxn];
vector <iii> E;
ll res;
ll dist[Maxn][Maxn];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++) 
		for (int j = 0; j < n; j++) {
			dist[i][j] = i == j? 0: Inf;
			scanf("%d", &B[i][j]);
			if (i < j) E.push_back(iii(B[i][j], ii(i, j)));
		}
	sort(E.begin(), E.end());
	for (int e = 0; e < E.size(); e++) {
		int a = E[e].second.first, b = E[e].second.second;
		if (dist[a][b] < E[e].first) { printf("-1\n"); return 0; }
		if (dist[a][b] > E[e].first) {
			res += E[e].first;
			for (int i = 0; i < n; i++)
				for (int j = i + 1; j < n; j++)
					dist[i][j] = dist[j][i] = min(dist[i][j], min(dist[i][a] + E[e].first + dist[b][j], dist[i][b] + E[e].first + dist[a][j]));
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2040
import java.util.Scanner;
import java.util.Arrays;

class Main {
	public static void main(String[] args) {
		int[] mountains = new int[10];
		Scanner scanner = new Scanner(System.in);
		for (int i = 0; i < mountains.length; i++) {
			int value = scanner.nextInt();
			mountains[i] = value;
		}
		//int[] top3 = top3(mountains);
		Arrays.sort(mountains);
		int[] top3 = new int[3];
		int j = 0;
		for (int i = mountains.length - 1; j < 3; i--) {
			top3[j] = mountains[i];
			j++;
		}
		for (int i = 0; i < 3; i++) {
			System.out.println(top3[i]);
		}
	}
}

Measured memory_bytes: 17180
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define out() fflush(stdout)
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define pii pair < int, int >
typedef vector<int> vi;
typedef   long long ll;
const int mod =1e9+7;

void solve(){
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=105;i++){
		for(int j=0;j<=105;j++){
			if((i*2+j*4)==y && (i+j)==x){
				//cout<<i<<' '<<j<<' ';
				cout<<"Yes";
				return;
			}
		}
	}
	cout<<"No";
}


int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

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

using namespace std;

int main(void) {
    int N,K,cnt=0,back_pos=0,for_pos=0;

    cin>>N>>K;
    int a[N];
    for(int i=0;i<N;i++) cin >> a[i];


    for (int i=0;i<9;i++){
      if(a[i]==1){
        back_pos = i;for_pos=i;
      }
    }

    if(back_pos!=N-1){
      while((N-back_pos-1)>=(K-1)){
        back_pos+=K-1; cnt++;
        //cout<<back_pos<<endl;
      }
      if(back_pos!=N-1) cnt++;
    }
    if(for_pos!=0) {
      while((for_pos-1)>=(K-1)){
        for_pos-=K-1; cnt++;
      //  cout<<for_pos<<endl;
      }
      if(for_pos!=0) cnt++;
    }

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


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0)
    {
        cout << "Even";
    }
    else
    {
        cout << "Odd";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [None] + [int(i) for i in input().split()]  # 1-based index
ans = []
choose = [0] * (n + 1)


for i in range(n, 0, -1): # 大きい数から評価する
    x = sum(choose[2 * i::i]) # その箱の倍数に入っている玉の和を求める
    if x % 2 == A[i]: # 偶奇の一致を確認
        continue
    choose[i] += 1
    ans.append(str(i))

print(len(ans))
print(" ".join(ans))


Measured memory_bytes: 102404
#include <bits/stdc++.h>
using namespace std;
int n,m,k;
const int N = 100005;
vector<int> bad[N];
vector<int> graph[N];
int sz[N];
int parent[N];
int sets;
void setup(int n) {
    sets = n;
    for(int i = 0; i < n; i++) {
        sz[i] = 1;
        parent[i] = i;
    }
}
int find(int a) {
    int p= a;
    while(parent[a]!=a) a = parent[a];
    while(parent[p]!=a) {
        int t = parent[p];
        parent[p] = a;
        p = t;
    }
    return a;
}
bool unite(int a, int b) {
    int pa = find(a);
    int pb = find(b);
    if (pa == pb) return false;
    if (sz[pa] <= sz[pb]) {
        parent[pa] = pb;
        sz[pb] += sz[pa];
    }
    else {
        parent[pb] = pa;
        sz[pa] += sz[pb];
    }
    return true;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> k;
    setup(n);
    for(int i= 0; i < m; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
        unite(a,b);
    }
    for(int i = 0; i < k; i++) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        bad[a].push_back(b);
        bad[b].push_back(a);
    }
    for(int i= 0; i< n; i++) {
        int val = find(i);
        int ans = sz[val]-1;
        set<int> badd;
        for(int j = 0; j < (int)bad[i].size(); j++) {
            if (val == find(bad[i][j])) {
                ans--;
                badd.insert(bad[i][j]);
            }
        }
        for(int j = 0; j < (int)graph[i].size(); j++) {
            if (!badd.count(graph[i][j])) {
                ans--;
            }
        }
        cout << ans << " ";
    }
    cout << endl;
}


Measured memory_bytes: 12664
# -*- coding: utf-8 -*-

while(True):
    try:
        n = int(raw_input())
        sum = 0
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if (a + b + c + d == n):
                            sum += 1
        print sum
    except EOFError:
        break

Measured memory_bytes: 4204
#include<stdio.h>
#define N 10000
#define M 500
int main(){
  int i,j,k,n,q,a[N],b[M],count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
    scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&b[j]);
  }
  for(j=0;j<q;j++){
    for(i=0;i<n;i++){
      if(b[j]==a[i]){
	count++;
	break;
      }
    }
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2048
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;


vector<ll> calc(ll x){
  vector<ll> v;
  for (int l=0;l<100;l++){
    ll c=x%2;
    v.push_back(c);
    x/=2;
  }
  return v;
}


vector<ll> counter(vector<ll> x){
  ll N=x.size();
  ll cnt[100];
  for (int l=0;l<100;l++){
    cnt[l]=0;
  }

  for(ll i=0;i<N;i++){
    vector<ll> v=calc(x[i]);
    for(ll l=0;l<100;l++){
      cnt[l]+=v[l];
    }
  }

  vector<ll> ans;
  for(int l=0;l<100;l++){
    ans.push_back(cnt[l]);
  }
  return ans;
}


int main(){
  ll N,K;cin>>N>>K;
  vector<ll> x;
  for(ll i=0;i<N;i++){
    ll a;cin>>a;
    x.push_back(a);
  }

  vector<ll> count=counter(x);
  vector<ll> bin_K=calc(K);

  ll X=0;
  int flag=0;

  for(int l=99;l>=0;l--){
    int X_l=0;
    if((flag==0)&&(bin_K[l]==0)){
      X+=0;
    }
    else{
      if((N%2==0) and(count[l]==N/2)){
        X+=0;
      }
      else if(count[l]<=N/2){
        X+=pow(2,l);
        X_l=1;
      }
      else{
        X+=0;
      }
    }

    if (X_l!=bin_K[l]){
      flag=1;
    }
  }
  ll ans=0;
  for (ll i=0;i<N;i++){
    ans+=X^x[i];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXN = 2e5 + 100;
VI e[MAXN];
int d1[MAXN], d2[MAXN];

void DFS(int x, int par, int dep, int *dis) {
  dis[x] = dep;
  for (int u : e[x]) {
    if (u == par)
      continue;
    DFS(u, x, dep + 1, dis);
  }
}

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 1; i < N; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[a].PB(b);
    e[b].PB(a);
  }

  DFS(1, 0, 0, d1);
  int p = 1;
  for (int i = 2; i <= N; i++)
    if (d1[i] > d1[p])
      p = i;

  DFS(p, 0, 0, d2);

  int len = 0;
  for (int i = 1; i <= N; i++)
    len = max(len, d2[i]);

  debug("%d\n", len);

  if (len % 3 == 1)
    puts("Second");
  else
    puts("First");
  return 0;
}


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

int main() {
    int N, K; cin >> N >> K;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        ans += min(abs(K - x), abs(x));
    }
    cout << ans * 2 << endl;
}


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
const double EPS = 1e-8;
typedef pair<double, double> pt;
#define x first
#define y second

pt operator-(pt a, pt b) {
  return pt(a.x - b.x, a.y - b.y);
}

bool zero(double x) {
  return fabs(x) <= EPS;
}

double sq(double a) { return a * a; }

double dist(pt p, pt q) {
  return sqrt(sq(p.x - q.x) + sq(p.y - q.y));
}

pt midpoint(pt p1, pt p2){
    double midx = (p1.x+p2.x)/2;
    double midy = (p1.y+p2.y)/2;
    return make_pair(midx, midy);
}

int get_max_points(pt centre, vector<pt> points){

    int count = 0;
    for (int i = 0; i < points.size(); i++){
        pt current = points[i];
        double num = sq(current.x - centre.x) + sq(current.y - centre.y);
        // cout << num << endl;
        // cout << fabs(num - 1) << endl;
        if (sqrt(num) < 1+EPS) {
            count++;
        }
    }
    return count;
}

int find_max_points(vector<pt> points){
    // for every pair of two points, create a cricle and check num points in circle

    int max_points = 1;
    for (int i = 0; i < points.size(); ++i){
        pt p1 = points[i];
        for (int j = i+1; j < points.size(); ++j){
            pt p2 = points[j];

            pt mid = midpoint(p1, p2);
            double q = dist(p1, p2);

            double x1 = mid.x + sqrt(1-sq(q/2))*(p1.y-p2.y)/q;
            double y1 = mid.y + sqrt(1-sq(q/2))*(p2.x-p1.x)/q;
            pt c1(x1, y1);
            int m = get_max_points(c1, points);
            max_points = max(m, max_points);
            // cout << mid.x << " " << mid.y << endl;
            // int m = get_max_points(mid, points);
            double x2 = mid.x - sqrt(1-sq(q/2))*(p1.y-p2.y)/q;
            double y2 = mid.y - sqrt(1-sq(q/2))*(p2.x-p1.x)/q;
            pt c2(x1, x2);
            m = get_max_points(c2, points);

            max_points = max(max_points, m);
        }
    }
    // cout << max_points 
    return max_points;
}

int main(){

    int n;

    while (1){
        cin >> n;
        if (n == 0) break;
        vector<pt> points;
        for (int i = 0; i < n; ++i){
            double x, y;
            cin >> x >> y;
            points.push_back(make_pair(x, y));
        }
        cout << find_max_points(points) << endl;
    }


    return 0;
}


Measured memory_bytes: 3304
package main

/*
H W
h w
*/
import (
	"bufio"
	"fmt"
	// "log"
	"os"
	"strconv"
	"strings"
)

type Cdiv struct {
	s   int
	num int
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	line := strings.Split(stdin.Text(), " ")
	H, _ := strconv.Atoi(line[0])
	W, _ := strconv.Atoi(line[1])
	stdin.Scan()
	line2 := strings.Split(stdin.Text(), " ")
	h, _ := strconv.Atoi(line2[0])
	w, _ := strconv.Atoi(line2[1])
	allcells := H * W
	blackcells := h*W + w*H - h*w
	/*
		****xxx  x: h*w
		****xxx
		oooo***
		oooo***
		oooo***
	*/
	fmt.Println(allcells - blackcells)

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[100003],b[100003],n,k,res=0;
int main(){
    cin>>n>>k;
    for(int i=0;i<n;i++){
    	cin>>a[i]>>b[i];
        if((a[i]&k)==a[i]){
        	res+=b[i];
		}
    }
    for(long long i=30;i>=0;i--){
        long long tmp=1<<i;
        if(k&tmp){
            long long f=(k^tmp)|(tmp-1);
            long long ans=0;
            for(int j=0;j<n;j++){
                if((a[j]&f)==a[j]){
                	ans+=b[j];
				}
            }
            res=max(res,ans);
        }
    }
    cout<<res<<endl;
    return 0;
}
/*

in:
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9

out:
32

*/ 
/*
给定n个数，每个数有一个a值一个b值，一个k。
从所有的a中取数，这些数的按位或不能大于k，并且使得他们的b的和最大。
*/

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a)%MOD)+((b)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using VLL = std::vector<llint>;
using MCI = std::map<char, int>;
using namespace std;


string S;
int accA[100010];
int accC[100010];
int accQ[100010];
int pow3[100010];


void makeAcc(){
	repe(i, 1, SIZE(S)) accA[i] = accA[i-1]+(S[i-1] == 'A' ? 1 : 0), accC[i] = accC[i-1]+(S[i-1] == 'C' ? 1 : 0), accQ[i] = accQ[i-1]+(S[i-1] == '?' ? 1 : 0);
}


void makePow3(){
	pow3[0] = 1;
	rep(i, 1, SIZE(S)) pow3[i] = MUL(pow3[i-1], 3);
}


int solve(){
	int ans = 0;
	int N = SIZE(S);
	rep(i, 0, N){
		if(S[i] == 'A' || S[i] == 'C') continue;
		int a = accA[i]-accA[0];
		int c = accC[N]-accC[i+1];
		int l = accQ[i]-accQ[0];
		int r = accQ[N]-accQ[i+1];
		ans = ADD(ans, MUL(a, MUL(c, pow3[l+r])));
		ans = ADD(ans, MUL(a, MUL(r, pow3[l+r-1])));
		ans = ADD(ans, MUL(l, MUL(c, pow3[l+r-1])));
		ans = ADD(ans, MUL(l, MUL(r, pow3[l+r-2])));
	}
	return ans;
}


signed main(){
	cin >> S;

	makeAcc();
	makePow3();

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 3584
n = int(input())
xx = 0
yy = 0
tt = 0
for i in range(n):
    t, x, y = map(int, input().split())
    d = abs(xx - x) + abs(yy - y)
    if t - tt < d or (t - tt - d) % 2 == 1:
        print('No')
        exit()
    xx = x
    yy = y
    tt = t
print('Yes')

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

#include <tuple>
#include <queue>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main()
{
    int N, K;

    cin >> N >> K;

    int sum = 0;

    REP(i, N)
    {
        int x;
        cin >> x;

        int distA = x * 2;
        int distB = abs(K - x) * 2;

        sum += distA < distB ? distA : distB;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c=1;
  char s[20];
  scanf("%d%d%s",&a,&b,s);
  for(int i=0;i<a;i++)if(!('0'<=s[i]&&s[i]<='9'))c=0;
  if(!(s[a]=='-'))c=0;
  for(int i=a+1;i<a+b+1;i++)if(!('0'<=s[i]&&s[i]<='9'))c=0;
  puts(c?"Yes":"No");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

const long long MOD=998244353;
const long long MAXA=1123456;
long long C[MAXA];
long long inv[MAXA];

void tr(long long a) {
  std::cout<<a<<std::endl;
}

int main() {
  inv[0]=inv[1]=1;
  for (int i=2;i<MAXA;++i) {
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
  }

  for (int i=1;i<MAXA;++i) {
    C[i]=(C[i]+inv[i])%MOD;
    for (int j=2*i;j<MAXA;j+=i) {
      C[j]=(C[j]-C[i]+MOD)%MOD;
    }
  }
  
  int N;
  std::cin>>N;
  std::vector<long long > A(N);
  for (int i=0;i<N;++i) {
    std::cin>>A[i];
  }
  std::sort(A.begin(), A.end());

  long long ans=0;
  std::vector<long long> cnt(MAXA, 0);
  for (int i=0;i<N;++i) cnt[A[i]]++;
  for (int i=1;i<MAXA;++i) {
    long long s2=0;
    for (int j=i;j<MAXA;j+=i) {
      s2=(s2+cnt[j]*j)%MOD;
    }
    ans=(ans+s2*s2%MOD*C[i]%MOD)%MOD;
  }
  for (int i=0;i<N;++i) ans=(ans-A[i]+MOD)%MOD;
  std::cout<<ans*inv[2]%MOD<<std::endl;

  
  return 0;
}


Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//初めにXをあり得る全通り試し、配列aの各々の要素についてXに出来るならXにし、Xに出来る要素の個数をカウント
//Xに出来る要素はXから+-1の範囲にある数
//i番目の要素が、配列aの要素がiであるものの個数であるような配列bを作ると、b[i=X-1]~b[i=X+1]の要素の和がX化できる要素の個数となる
//その個数のmaxを求める。
int main() {
 int N;
 cin >> N;
 vector<int> a(N);
 for(int i = 0;i<N;i++){
	 cin >> a[i];
 }
 
 sort(a.begin(),a.end());
 int aMax = a[N-1];
 int aMin = a[0];
 vector<int> b(aMax+1);

 a.push_back(-1);
 int c = 1;//aの各要素の個数
 for(int i = 0;i<N;i++){
	 if(a[i] == a[i+1]){
		 c++;
	 }
	 if(a[i] != a[i+1]){
		 b[a[i]] = c;
		 c = 1;
	 }
 }

  b.push_back(0);
  int ans = 0;
 for(int X = aMin;X <= aMax;X++){
   ans = max(ans,b[X-1] + b[X] + b[X+1]);
 } 
 cout << ans << endl;
  
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if (S.at(5) == '1'){
    cout << "TBD";
  } else if (S.at(6) < '5'){
    cout << "Heisei";
  } else {
    cout << "TBD";
  }
}
    

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);
int check(void);
int a[31],mn;
int main(void)
{
    int n,i,j,nn,flg;
    scanf("%d",&n);
    for(i=0;i<n;i++) {
        for(j=1;j<=30;j++)   {
            scanf("%d",&a[j]);
        }
        mn=8;
        func(0);
        printf("%d\n",mn);
    }
    return 0;
}
void func(int nn)
{
    int i,j,flg;
    int pat[4][10]={{1,24,4,27,7,30,10,21,16,18},{1,28,2,29,3,30,15,16,19,21},
		{3,22,6,25,9,28,12,19,13,15},{7,22,8,23,9,24,13,18,10,12}};
    int b[31];              
    if(nn<mn)    {
        flg=check();
        if(flg==1)  {
            mn=nn;
        }
        else {
			for(i=0;i<4;i++)	{
				for(j=0;j<10;j+=2)	{
					swap(a[pat[i][j]],a[pat[i][j+1]]);
                } 
				func(nn+1);
				for(j=0;j<10;j+=2)	{
					swap(a[pat[i][j]],a[pat[i][j+1]]);
                } 				
            }
        }
    }
}
int check(void)
{
    int i,j,flg;
    int f;
    flg=1;
    for(i=2;i<=9;i++)    {
        if(a[1]!=a[i])  {
            flg=0;
            break;
        }
    }
    for(i=11;i<=12;i++)  {
        if(a[10]!=a[i]) {
            flg=0;
            break;
        }
    }
    for(i=14;i<=15;i++)  {
        if(a[13]!=a[i]) {
            flg=0;
            break;
        }
    }
    for(i=17;i<=18;i++)  {
        if(a[16]!=a[i]) {
            flg=0;
            break;
        }
    }
    for(i=20;i<=21;i++)  {
        if(a[19]!=a[i]) {
            flg=0;
            break;
        }
    }
    for(i=23;i<=30;i++)  {
        if(a[22]!=a[i]) {
            flg=0;
            break;
        }
    }
    return flg;
}


Measured memory_bytes: 2760
#include <iostream>
#include <cmath>

using namespace std;

bool is_prime(int x)
{
    if (x == 2)
    {
        return true;
    }
    if (x < 2 || x % 2 == 0)
    {
        return false;
    }

    int i = 3;
    while (i <= sqrt(x))
    {
        if (x % i == 0)
        {
            return false;
        }
        i += 2;
    }
    return true;
}

int main()
{
    int n, p, count = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p;
        if (is_prime(p))
        {
            count++;
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;

void solve() {
	ll n;
	cin >> n;
	map<string, int> cnt;
	rep(i, 0, n) {
		string s;
		cin >> s;
		cnt[s]++;
	}
	cout << "AC x " << cnt["AC"] << endl;
	cout << "WA x " << cnt["WA"] << endl;
	cout << "TLE x " << cnt["TLE"] << endl;
	cout << "RE x " << cnt["RE"] << endl;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}







Measured memory_bytes: 3664
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7); const int B(1), W(0);
int n, m;
vector<vector<int>>v;
int dfs(vector<int>d, int s = 0) {
	d[s] = B;
	int ans(0); bool f = true;
	rep(i, 0, n) {
		if (d[i] == W&&v[s][i] == 1) {
			ans += dfs(d, i);
			f = false;
		}
	}

	if (f) {
		if(accumulate(d.begin(),d.end(),0)==n)return 1;
		else return 0;
	}


	return ans;
}
signed main() {
	cin >> n >> m; v = vector<vector<int>>(n, vector<int>(n, 0));
	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		v[--a][--b] = 1;
		v[b][a] = 1;
	}
	vector<int>d(n, W);
	cout << dfs(d, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

mod = 1000000007
inf = 1 << 60

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

h = ni()

ans = 0
a = h // 2
c = 0
while h != 0:
    ans += 2 ** c
    h //= 2
    if c == 0:
        c += 1
    else:
        c += 1

print(ans)

Measured memory_bytes: 38484
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF (LLONG_MAX - 1e5)
#define fcout cout << fixed << setprecision(10)

using namespace std;

int calc(int i, int o, int j, int l){
    int ans = 0;
    ans += 4 * (i/2);
    ans += 2 * o;
    ans += 4 * (j/2);
    ans += 4 * (l/2);
    return ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;

    int a1 = calc(I, O, J, L);
    if (I > 0 && J > 0 && L > 0) a1 = max(a1,calc(I-1, O, J-1, L-1) + 6);
    cout << a1 / 2 << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;
const int B_MAX = 42;

ll n, k;
vector<ll> as;
vector<ll> cnt1;
ll dp[2][B_MAX];

ll go(bool limited, int d) {
    if (d == -1) {
        return 0;
    }
    if (dp[limited][d] >= 0) {
        return dp[limited][d];
    }

    ll kd = ((k >> d) & 1);
    ll ma = 0;
    if (kd) {
        // 1
        ma = max(ma, (n - cnt1[d]) * (1LL << d) + go(limited, d - 1));
        // 0
        ma = max(ma, cnt1[d] * (1LL << d) + go(false, d - 1));
    } else {
        ma = max(ma, cnt1[d] * (1LL << d) + go(limited, d - 1));
        if (!limited) {
            ma = max(ma, (n - cnt1[d]) * (1LL << d) + go(limited, d - 1));
        }
    }
    dp[limited][d] = ma;
    return ma;
}

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

    for (int i = 0; i < n; i++) {
        ll a; cin >> a;
        as.push_back(a);
    }

    cnt1.assign(B_MAX, 0);
    for (int b = 0; b < B_MAX; b++) {
        for (int i = 0; i < n; i++) {
            ll a = as[i];
             cnt1[b] += ((a >> b) & 1);
        }
    }
    for (int i = 0; i < B_MAX; i++) {
        dp[0][i] = dp[1][i] = -1;
    }
    cout << go(true, B_MAX - 1) << endl;
    return 0;
}

Measured memory_bytes: 1400