akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>

using ull = unsigned long long int;
using ll = long long int; 

int main(){
    int N;
    std::vector<int> a;

    std::cin >> N;

    for(int i=0;i<N;i++){
        int _a;
        std::cin >> _a;
        a.emplace_back(_a);
    }

    int _N = N;
    if(_N%2==1) _N++;

    for(int i=_N/2-1;i>=0;i--){
        int tmp=0;
        for(int j=i;j<_N;j=j+i+1){
            tmp+=a[j];
        }
        a[i]=tmp%2;
    }

    std::cout << std::accumulate(a.begin(), a.end(), 0) << std::endl;
    for(int i=0;i<N;i++){
        if(a[i]==1) std::cout << i+1 << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1908
#include <iostream>
#include <map>

using namespace std;
typedef long long ll;

pair<ll, ll> count12(const map<ll, ll>& m){
    ll v1 = -1;
    ll c1 = 0;
    ll v2 = -1;
    ll c2 = 0;
    for(auto p : m){
        if(p.second >= c1){
            v2 = v1;
            c2 = c1;
            v1 = p.first;
            c1 = p.second;
        }else if(p.second >= c2){
            v2 = p.first;
            c2 = p.second;
        }
    }
    return make_pair(v1, v2);
}

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

    map<ll, ll> odd;
    map<ll, ll> even;
    for(int i = 0; i < n; ++i){
        ll v;
        cin >> v;
        if(i % 2){
            odd[v] += 1;
        }else{
            even[v] += 1;
        }
    }

    auto podd = count12(odd);
    auto peven = count12(even);

    if(podd.first != peven.first){
        ll ans = 0;
        ans += n / 2 - odd.at(podd.first);
        ans += n / 2 - even.at(peven.first);
        cout << ans << endl;
    }else{
        ll ans1 = 0;
        ans1 += n / 2 - odd.at(podd.first);
        if(even.size() > 1){
            ans1 += n / 2 - even.at(peven.second);
        }else{
            ans1 += n / 2;
        }

        ll ans2 = 0;
        ans2 += n / 2 - even.at(peven.first);
        if(odd.size() > 1){
            ans2 += n / 2 - odd.at(podd.second);
        }else{
            ans2 += n / 2;
        }

        cout << min(ans1, ans2) << endl;
    }
    return 0;
}


Measured memory_bytes: 6528
int main()
{
    int a[100]= {1,3,5,7,8,10,12};
    int b[100]= {4,6,9,11};
    int x,y,k,i,h,l;
    scanf("%d %d",&x,&y);
    k=0;h=0;l=0;
    for(i=0; i<7; i++)
    {
        if(x==a[i])
            k++;
        if(y==a[i])
            k++;
    }
    for(i=0; i<4; i++)
    {
        if(x==b[i])
            h++;
        if(y==b[i])
            h++;
    }
    if(x==2&&y==2)
        l++;
    if(k>1||h>1||l>0)
        printf("Yes");
    else
        printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

double calc(double x1,double y1,double x2,double y2,double x3,double y3){
    double x4=x2-x1;
    double y4=y2-y1;
    double x5=x3-x1;
    double y5=y3-y1;

    double S=fabs(x4*y5-y4*x5);
    return S/2.0;
}
int main(){
    double x1,y1,x2,y2,x3,y3,pointX,pointY;
    while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
        &x1,&y1,&x2,&y2,&x3,&y3,&pointX,&pointY)!=EOF){
        double S=calc(x1,y1,x2,y2,x3,y3);
        double s1=calc(pointX,pointY,x1,y1,x2,y2),s2=calc(pointX,pointY,x2,y2,x3,y3),s3=calc(pointX,pointY,x3,y3,x1,y1);
        if(S>=s1+s2+s3)    printf("YES\n");
        else     printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 2000
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static int Main()
        {
            int[] w = new int[10];
            int[] k = new int[10];
            int[] wg = new int[3];
            int[] kg = new int[3];

            for (int i = 0; i < 10; i++)
            {
                w[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(w);
            for (int i = 0; i < 10; i++)
            {
                k[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(k);
            wg[0] = w[9];
            wg[1] = w[8];
            wg[2] = w[7];
            kg[0] = k[9];
            kg[1] = k[8];
            kg[2] = k[7];
            Console.Write((wg[0] + wg[1] + wg[2]) + " ");
            Console.WriteLine((kg[0] + kg[1] + kg[2]));

            return 0;
        }
    }
}

Measured memory_bytes: 5736
#include <iostream>
#include <algorithm>
using namespace std;
int a[200010],n,l[800010],r[800010],tree[800010];
void build(int v,int s,int f)
{
	l[v]=s;r[v]=f;
	if (s==f) 
	{
		tree[v]=s;
		return;
	}
	build(2*v,s,(s+f)/2);
	build(2*v+1,(s+f)/2+1,f);
	if (a[tree[2*v]]<a[tree[2*v+1]]) tree[v]=tree[2*v];
	else tree[v]=tree[2*v+1];
}
int find(int v,int s,int f)
{
	if (s<=l[v]&&f>=r[v])
	{
		return tree[v];
	}
	int t1=0,t2=0;
	if (s<l[2*v+1]) t1=find(2*v,s,f);
	if (f>r[2*v]) t2=find(2*v+1,s,f);
	if (t1!=0&&t2!=0)
	{
		if (a[t1]<a[t2]) return t1;
		else return t2;
	}
	else return t1+t2;
}
long long work(int l,int r)
{
	if (r<l) return 0;
	if (r==l) return a[l];
	int minn=find(1,l,r);
	long long ans=(long long)1*(minn-l+1)*(r-minn+1)*a[minn];
	return ans+work(l,minn-1)+work(minn+1,r);
}
main()
{
	cin>>n;
	for (int i=1;i<=n;i++) 
	{
		cin>>a[i];
	}
	build(1,1,n);
	cout<<work(1,n)<<endl;
}

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

#define MAX_DATA_NUM 2000000
int heap[MAX_DATA_NUM], size = 0;

int parent(int i)      { return (i-1) / 2;}
int left_child(int i)  { return 2*i + 1; }
int right_child(int i) { return 2*i + 2; }

void push(int x)
{
    int i = size++;

    while (i > 0) {
        int p = parent(i);
        if (heap[p] >= x) break;
        else {
            heap[i] = heap[p];
            i = p;
        }
    }

    heap[i] = x;
}

int pop()
{
    int ret = heap[0];
    int x = heap[--size];

    int i=0;
    while (left_child(i) < size) {
        int l = left_child(i), r = right_child(i);
        if (r < size && heap[r] > heap[l]) l = r;
        if (heap[l] <= x) break;
        heap[i] = heap[l];
        i = l;
    }
    heap[i] = x;

    return ret;
}
        
int main()
{
    string S;
    while (cin >> S, S != "end") {
        if (S == "insert") {
            int x;
            cin >> x;
            push(x);
        } else {
            cout << pop() << endl;
        }
    }
}

Measured memory_bytes: 7044
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string S;
  cin >> S;

  int l = S.size();

  int ans = 0;
  for(int i=1;i<l;i++){
    if(S[i]!=S[i-1]) ans++;
  }
	
  cout << ans <<endl;
 
    
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#ifdef BUG
    #include "debug.hpp"
#else
    #define DEBUG(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
typedef typename iterator_traits<FwdIter>::value_type value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */


int main(const int argc, char * argv [])
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    size_t n, x;
    cin >> n >> x;
    if(x == n)
    {
        cout << "Yes" << '\n';
        for(size_t i = 1; i < 2 * n; ++ i)
            cout << i << '\n';
    }
    else if (x == 1 || x == 2 * n - 1)
        cout << "No" << '\n';
    else
    {
        cout << "Yes" << '\n';

        if(x < n)
        {
            for(size_t i = x + 1; i < n + 1; ++ i)
                cout << i << '\n';

            for(size_t i = 1; i < x + 1; ++ i)
                cout << i << '\n';

            for(size_t i = n + 1; i < 2 * n; ++ i)
                cout << i << '\n';
        }
        else
        {
            for(size_t i = 1; i < n; ++ i)
                cout << i << '\n';

            for(size_t i = x; i < 2 * n; ++ i)
                cout << i << '\n';

            for(size_t i = n; i < x; ++ i)
                cout << i << '\n';
        }
    }

    return EXIT_SUCCESS;
}


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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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

    double a, b;
    cin >> a >> b;
    cout << ceil((a + b) / 2.0) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long A = int.Parse(str[1]);
        long B = int.Parse(str[2]);
        long[] X = new long[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            X[i] = int.Parse(str[i]);
        }
        long count = 0;
        for(int i=1;i<N;i++){
            long distance = X[i]-X[i-1];
            if(distance*A >= B){
                count += B;
            }
            else{
                count += distance*A;
            }
        }
        sb.Append(count+"\n");
    }
}

Measured memory_bytes: 20832
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll p = 0;
    while(b <= a){
        b *= 2;
        p++;
    }
    while(c <= b){
        c *= 2;
        p++;
    }
    if(p <= k){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000];
int main()
{
	int n,x;
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans=0;
	for(int i=1;i<n;i++)
	{
		if(x>=a[i])
		{
			x-=a[i];
			ans++;
		}
	}
	if(x==a[n])
	{
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, M);
  int apr = 1900 * M + 100 * (N - M);
  FOR(i, M) apr *= 2;
  print(apr);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(){
  int N,a[100000],i,b[100010]={};
  cin>>N;
  for(i=0;i<N;i++){
    cin>>a[i];
  }
  for(i=0;i<N;i++){
    b[a[i]+2]++;
    b[a[i]]++;
    b[a[i]+1]++;
  }
  sort(b,b+100000,greater<int>());
  cout<<b[0]<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;using int32=int_fast32_t;using uint32=uint_fast32_t;using int64=int_fast64_t;using uint64=uint_fast64_t;using pi=pair<int32,int32>;using pll=pair<int64,int64>;using vi=vector<int32>;using vvi=vector<vector<int32>>;using vll=vector<int64>;using ll=int64;using ull=uint64;constexpr int32 INF=1<<30;constexpr ll INFLL=1LL<<62;
#define all(x) x.begin(),x.end()
#define LB(V,x) lower_bound(all(V),x)-V.begin()
#define uint uint32
void Main(){
    int N, H;
    cin >> N >> H;
    int A = H;
    while(--N){
        int L = H;
        cin >> H;
        if(H>L) A+=H-L;
    }
    cout << A;
}
int main(){cin.tie(0);ios::sync_with_stdio(false);Main();return 0;}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  class Node {
    int x;
    int y;
    int d;
  }

  static int[][] ofs = {
      {1, 0},
      {0, 1},
      {-1, 0},
      {0, -1}
  };

  void run() {
    for (; ; ) {
      int w, h;
      w = ni();
      h = ni();
      if ((w | h) == 0) {
        break;
      }
      int[][] s = new int[h + 2][w + 2];
      for (int i = 0; i <= h + 1; ++i) Arrays.fill(s[i], -1);
      for (int i = 1; i <= h; ++i) {
        for (int j = 1; j <= w; ++j) {
          s[i][j] = ni();
        }
      }
      int[] c = new int[4];
      for (int i = 0; i < 4; ++i) {
        c[i] = ni();
      }

      int[][][] dp = new int[h + 2][w + 2][4];
      for (int i = 0; i < h + 2; ++i) {
        for (int j = 0; j < w + 2; ++j) {
          for (int k = 0; k < 4; ++k) {
            dp[i][j][k] = 1 << 28;
          }
        }
      }
      Node start = new Node();
      start.x = 1;
      start.y = 1;
      start.d = 0;
      dp[1][1][0] = 0;

      Queue<Node> meu = new PriorityQueue<>(new Comparator<Node>() {
        @Override
        public int compare(Node o1, Node o2) {
          if (dp[o2.y][o2.x][o2.d] == dp[o1.y][o1.x][o1.d]) {
            return h - o2.y + w - o2.x + o1.y - h + o1.x - w;
          } else {
            return dp[o1.y][o1.x][o1.d] - dp[o2.y][o2.x][o2.d];
          }
        }
      });
      meu.add(start);
      while (meu.size() > 0) {
        Node node = meu.poll();
//        debug(node.x, node.y, node.d, dp[node.y][node.x][node.d]);
        if (node.x == w && node.y == h) {
          break;
        }
        for (int i = 0; i < 4; ++i) {
          int addi = i == s[node.y][node.x] ? 0 : c[i];
          Node next = new Node();
          next.d = (node.d + i) % 4;
          next.x = node.x + ofs[next.d][0];
          next.y = node.y + ofs[next.d][1];
          if (s[next.y][next.x] == -1) {
            continue;
          }
          if (dp[next.y][next.x][next.d] > dp[node.y][node.x][node.d] + addi) {
            dp[next.y][next.x][next.d] = dp[node.y][node.x][node.d] + addi;
            meu.add(next);
          }
        }
      }

      int ans = 1 << 28;
      for (int i = 0; i < 4; ++i) {
        ans = Math.min(ans, dp[h][w][i]);
      }
      System.out.println(ans);
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 71608
#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 repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(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 bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

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

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(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) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 n, a, b;
  cin >> n >> a >> b;
  if (n == 1 && a != b) {
    cout << 0 << endl;
    return;
  }
  if (a > b) {
    cout << 0 << endl;
    return;
  }
  i64 mi = a * (n - 1) + b;
  i64 ma = b * (n - 1) + a;
  cout << (ma - mi + 1) << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for (int i = 0; i < N + 1; i++) cin >> A[i];
	vector<long long> MAX(N + 1);
	MAX[N] = A[N];
	for (int i = N - 1; i >= 0; i--) MAX[i] = MAX[i + 1] + A[i];
	if (N == 0) {
		cout << (A[0] == 1 ? 1 : -1) << endl;
		return 0;
	}
	else {
		if (A[0] != 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	long long ans = 1;
	long long node = 1;
	for (int i = 1; i < N + 1; i++) {
		ans += min(node * 2, MAX[i]);
		if (node * 2 <= MAX[i]) node = node * 2 - A[i];
		else node = MAX[i] - A[i];
		if (node < 0) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

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

int64_t solve();

int main()
{
	int64_t ans{solve()};
	if (ans < 0) puts("infinity");
	else printf("%lld\n", ans);

	return 0;
}

int64_t solve()
{
	int64_t T[2], A[2], B[2];
	for (auto& e: T) scanf("%lld", &e);
	for (auto& e: A) scanf("%lld", &e);
	for (auto& e: B) scanf("%lld", &e);
	int64_t diff[2]{T[0] * (A[0] - B[0]), T[1] * (A[1] - B[1])};
	if (diff[0] < 0)
	{
		diff[0] *= -1;
		diff[1] *= -1;
	}
	if (diff[0] + diff[1] > 0) return 0;
	if (diff[0] + diff[1] == 0) return -1;
	int64_t one_diff{-(diff[1] + diff[0])};
	int64_t turn{diff[0] / one_diff};
	int64_t ans{2 * turn};
	int64_t pos{diff[0] - turn * one_diff};
	if (pos == 0) return ans;
	else return ans + 1;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int W = sc.nextInt();
		int[] w = new int[N];
		long[] v = new long[N];
		for(int i = 0; i < N; i++) {
			w[i] = sc.nextInt();
			v[i] = sc.nextInt();
		}
		long[][] dp = new long[N+1][W+1];
		for(int i = 1; i <= N; i++) {
			for(int j = 0; j <= W; j++)
				dp[i][j] = dp[i-1][j];
			for(int j = 0; j <= W; j++) {
				if(j+w[i-1] <= W)
					dp[i][j+w[i-1]] = Math.max(dp[i][j+w[i-1]], dp[i-1][j]+v[i-1]);
				else
					break;
			}
		}
		System.out.println(dp[N][W]);

	}

}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll n;
ll v[100010];
ll even[100010];
ll odd[100010];

void input(){
    cin >> n;
    for(int i=0;i<n;i++) cin >> v[i];
    for(int i=0;i<n;i+=2) odd[v[i]]++;
    for(int i=1;i<n;i+=2) even[v[i]]++;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll emax = 0, omax = 0,es,os;
    for(int i=0;i<n;i+=2) omax = max(omax, odd[v[i]]);
    for(int i=1;i<n;i+=2) emax = max(emax, even[v[i]]);
    for(int i=0;i<n;i+=2) if(odd[v[i]] == omax) os = v[i];
    for(int i=1;i<n;i+=2) if(even[v[i]] == emax) es = v[i];
    sort(odd, odd + 100010, greater<>());
    sort(even, even + 100010, greater<>());
    if(es == os){
        cout << min((n/2 - odd[0]) + (n/2 - even[1]), (n/2 - odd[1]) + (n/2 -even[0])) << endl;
    }
    else cout << (n/2 - emax) + (n/2 - omax) << endl;
}

Measured memory_bytes: 2560
# UnionFind
class UnionFind():
    def __init__(self, n):
        self.nodes = [-1] * n  # nodes[x]: 負なら、絶対値が木の要素数

    def get_root(self, x):
        # nodes[x]が負ならxが根
        if self.nodes[x] < 0:
            return x
        # 根に直接つなぎ直しつつ、親を再帰的に探す
        else:
            self.nodes[x] = self.get_root(self.nodes[x])
            return self.nodes[x]

    def unite(self, x, y):
        root_x = self.get_root(x)
        root_y = self.get_root(y)
        # 根が同じなら変わらない
        # if root_x == root_y:
        # pass
        if root_x != root_y:
            # 大きい木の方につないだほうが計算量が減る
            if self.nodes[root_x] < self.nodes[root_y]:
                big_root = root_x
                small_root = root_y
            else:
                small_root = root_x
                big_root = root_y
            self.nodes[big_root] += self.nodes[small_root]
            self.nodes[small_root] = big_root


N, M = map(int, input().split())
uf = UnionFind(N)
get_root, unite, nodes = uf.get_root, uf.unite, uf.nodes

for _ in range(M):
    x, y, _ = map(int, input().split())
    x -= 1
    y -= 1
    unite(x, y)
ans = 0
for i in range(N):
    if nodes[i] < 0:
        ans += 1
print(ans)


Measured memory_bytes: 7012
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n,r;cin>>n>>r;
    if(n>=10)return cout<<r , 0;
    cout<< r + 100*(10-n);
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
constexpr ll mod = 1e9+7;
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){

    ll N;
    cin >> N;
    string s[2];
    cin >> s[0] >> s[1];

    ll ans = 1, srt;
    bool type = false;
    if(s[0][0] == s[1][0]){
        type = true;
        srt = 1;
        ans *= 3;
    }else{
        type = false;
        srt = 2;
        ans *= 6;
    }
    rep(i, srt, N){
        if(s[0][i] == s[1][i]){
            if(type){
                ans *= 2;
            }else{
                ans *= 1;
            }
            type = true;
        }else{
            if(type){
                ans *= 2;
            }else{
                ans *= 3;
            }
            type = false;
            i++;
        }
        ans %= mod;
    }
    cout  << ans << endl;
    return 0;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = i64(1e9) + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

bool solve(){
    int n, m;
    cin >> n >> m;
    if(!n)
        return false;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    vector<int> d(m);
    for(auto& x : d)
        cin >> x;

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

    vector<int> dp(1 << n, MOD);
    dp[0] = 0;

    for(int i = 0; i < (1 << n); ++i){
        int sum = 0;
        for(int j = 0; j < n; ++j)
            if(i & (1 << j))
                sum += a[j];
        int l_bound = distance(d.begin(), lower_bound(d.begin(), d.end(), sum));
        for(int j = 0; j < n; ++j){
            if(i & (1 << j))
                continue;
            int next_sum = sum + a[j];
            int r_bound = distance(d.begin(), lower_bound(d.begin(), d.end(), next_sum));
            int val = dp[i];
            for(int k = l_bound; k < r_bound; ++k){
                val += min(abs(d[k] - sum), abs(d[k] - next_sum));
            }
            chmin(dp[i | (1 << j)], val);
        }
    }

    int ans = dp.back();

    int sum = accumulate(a.begin(), a.end(), 0);
    int l_bound = distance(d.begin(), lower_bound(d.begin(), d.end(), sum));
    for(int k = l_bound; k < m; ++k)
        ans += abs(d[k] - sum);
    cout << ans << endl;

    return true;
}

signed main(){
    while(solve());
}



Measured memory_bytes: 3252
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		sc.close();

		int a = p + q;
		int b = q + r;
		int c = r + p;

		if (a > b) {
			if (b > c) {
				System.out.println(c);
			} else {
				System.out.println(b);
			}
		} else if (a > c) {
			System.out.println(c);
		} else {
			System.out.println(a);
		}
	}
}


Measured memory_bytes: 22100
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        Set<Integer> s=new HashSet<>();
        boolean flag=false;
        for(int i=0;i<n;i++){
            int x=in.nextInt();
            if(s.contains(x)){
                flag=true;
                break;
            }else
                s.add(x);

        }
        if(!flag)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 98936
//Power
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Professor{
	int first, last;//権力範囲
	bool operator<(const Professor& var) const{ return first < var.first; };
};

int main(){
	int N, M;//部屋,教授数
	vector<Professor> P;//守備可能範囲
	P.reserve(100);
	vector<Professor>::iterator cur;//prof現在値

	cin >> N >> M;//入力
	{
		Professor temp;
		for (int i = 0; i < M; ++i){
			cin >> temp.first >> temp.last;
			P.push_back(temp);
		}
	}
	sort(P.begin(), P.end());
	//範囲ダブり下位互換教授を削除
	{
		int f = 0, l = 0;
		for (vector<Professor>::iterator it = P.begin(); it != P.end(); ++it){
			if (f == it->first){//左の部屋一致
				if (it->last < l){//範囲小さいほうを削除
					it = P.erase(it);
				} else{
					it = P.erase(cur);
					f = it->first;
					l = it->last;
					cur = it;
				}
			} else{
				f = it->first;
				l = it->last;
				cur = it;
			}
		}
		//この時点でfirst値はそれぞれで一致しない.
	}


	//左から走査
	if (P.begin()->first == 1 && P.begin()->last == N){//一人でOK
		cout << 1 << endl;
		return 0;
	}
	if (P.begin()->first != 1){//初期値×
		cout << "Impossible" << endl;
		return 0;
	}

	cur = P.begin();
	vector<Professor>::iterator next = cur;
	int cnt = 1;
	while (1){
		for (vector<Professor>::iterator it=cur+1; it!=P.end(); ++it){
			if (it->first <= cur->last+1){
				if (it->last > next->last){
					next = it;
				}
			} else break;
		}
		if (cur == next){
			cout << "Impossible" << endl;
			break;
		}else{
			++cnt;
			cur = next;
			if (cur->last == N){
				cout << cnt << endl;
				break;
			}
		}
	}

	return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  int a[n];
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  int l = -1, r = n;
  vector<vector<bool>> v(n+1,vector<bool>(k,false));
  while(r - l > 1) {
    int m = (l + r) / 2;
    bool can = false;
    rep(i,n+1) rep(j,k) v[i][j] = false;
    v[0][0] = true;
    rep(i,n) {
      rep(j,k) {
        if(v[i][j]) {
          v[i+1][j] = true;
          if(i != m && j + a[i] < k) v[i+1][j+a[i]] = true;
        }
      }
    }
    for(int i = max(0,k-a[m]); i < k; i++) {
      if(v[n][i]) can = true;
    }
    if(can) r = m;
    else l = m;
  }
  cout << l + 1 << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <map>

const int MAX = 26;

using namespace std;

int main(void) {

	map<char, bool> m;
	string str;

	cin >> str;

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

		m[static_cast<char>('a' + i)] = false;

	}

	for (int i = 0; i < str.length(); ++i) {

		m[str[i]] = true;

	}

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

		if (!m[static_cast<char>('a' + i)]) {

			cout << static_cast<char>('a' + i) << endl;

			return 0;

		}

	}

	cout << "None" << endl;

	return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll mod = 1e9 + 7;

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

    ll n, k;
    cin >> n >> k;

    vvll vlist(n);
    vll d(n, 0);
    ll a, b;
    REP(i, n - 1){
        cin >> a >> b;
        a--, b--;
        d[a]++;
        d[b]++;
        vlist[a].push_back(b);
        vlist[b].push_back(a);
    }
    ll res = k;
    vll visited(n, 0);
    queue<ll> que;
    que.push(0);
    while(!que.empty()){
        ll cur = que.front();
        que.pop();
        visited[cur] = 1;
        ll tmp = d[cur];
        for(auto v : vlist[cur]){
            if(visited[v]) continue;
            res *= (k - tmp);
            res %= mod;
            tmp--;
            que.push(v);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()

int main() {
    int X;
    cin >> X;
    
    if (X >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#include<algorithm>
#include<stack>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

stack<long long> catstack;
int main(void)
{
	int L,i,c[1024];
	int catin[128]={0};
	cin>>L;
	for(i=0;i<L;i++)
	{
		cin>>c[i];
	}
	for(i=0;i<L;i++){
		if(c[i]>0){
			if(catin[c[i]]==1){
				cout<<i+1<<endl;
				return 0;
			}
			catin[c[i]]=1;
			catstack.push(c[i]);
		}else{
			if(catstack.empty()||catstack.top()!=-c[i]){
				cout<<i+1<<endl;
				return 0;
			}
			catstack.pop();
			catin[-c[i]]=0;
		}
	}
	cout<<"OK"<<endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const int INF = 1e8;

int main() {
  string s;
  cin >> s;
  map<ll,ll> mp;
  mp[0] =1;
  reverse(all(s));
  ll now = 0,ten=1;
  for(auto & e:s){
    now = (now + (e-'0') * ten) %2019;
    ten*=10;
    ten %=2019;//各桁でmod2019をとってるので，桁数の数もmodをとる
    mp[now]++;//s(j,0) - s(i,0) mod2019は s(j,0) = s(i,0) mod 2019にできる->同じ余りを集計
  }
  ll ans = 0;
  for(auto &e:mp){
    ans += e.second*(e.second-1) / 2;//nC2 = n*(n-1) / 2
  }
  cout << ans << "\n";

}


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

int main() {
	string s;
	cin >> s;

	int count = 0;
	int count2 = 0;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0 && s[i] == '0' || i % 2 != 0 && s[i] == '1') {
			count++;
		}
		if (i % 2 == 0 && s[i] == '1' || i % 2 != 0 && s[i] == '0') {
			count2++;
		}
	}
	cout << min(count, count2) << endl;

	return 0;
}

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

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

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

    if (a < 10 && b < 10)
        printf("%d\n", a * b);
    else
        printf("-1\n");

    return 0;
}


Measured memory_bytes: 256
b = [0,0,0]

n, b[0], b[1], b[2] = map(int, input().split())
L = [int(input()) for _ in range(n)]

s = [0 for _ in range(n)]

ans = 999999
for i in range(4 ** n):
    t = [0, 0, 0]
    u = [0, 0, 0]
    temp_ans = 0
    temp = i
    for j in range(n):
        s[j] = temp % 4
        if s[j] < 3:
            t[s[j]] += L[j]
            u[s[j]] += 1
        temp //= 4

    if 0 in u:
        continue

    for j in range(3):
        temp_ans += abs(b[j] - t[j]) + ((u[j] - 1) * 10)

    ans = min(ans, temp_ans)

print(ans)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  sort(all(a));
  ll ans = SUM(a);
  bool changed = true;
  if(ans % 10 == 0){
    changed = false;
    rep(i,n){
      if((ans - a[i]) % 10 != 0){
        ans -= a[i];
        changed = true;
        break;
      }
    }
  }
  print(ans * changed);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int n;
multiset<int> se;
int main()
{
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    reverse(a.begin(), a.end());
    rep(i, n)
    {
        if (se.empty())
        {
            se.insert(a[i]);
        }
        else
        {
            auto it = se.upper_bound(a[i]);
            if (it != se.end())
            {
                se.erase(it);
            }
            se.insert(a[i]);
        }
    }
    cout << se.size() << endl;
}

Measured memory_bytes: 5376
N = int(input())

if N == 1 or N == 2:
    print(N)
    exit()


candidate = [0] * 1001

candidate[2] = 1
candidate[3] = 1
for i in range(4,N + 1):
    tmp = i
    for j in range(2, int(i ** (1/2)) + 1):
        if tmp % j == 0:
            while tmp % j == 0:
                candidate[j] += 1
                tmp = tmp // j
    candidate[tmp] += 1

ans = 1
for i in range(2,len(candidate)):
    if candidate[i] != 0:
       ans = ans * (candidate[i] + 1) % 1000000007
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
int main(){
    char c;
    int i;
    vector<int> A(26,0);
    while(cin >> c){
        if(c>='a'&&c<='z'){
            A.at(c-'a')++;
        }
        if(c>='A'&&c<='Z'){
            A.at(c-'A')++;
        }
    }
    for(i=0;i<26;i++){
        cout << char('a'+i)<<" : "<<A.at(i)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3116
h,w=map(int,input().split())

a=[['.' for x in range(w+2)]]

for i in range(h):
    b=list(str(input()))
    b= ['.']+b+['.']
    a.append(b)

footer=['.' for x in range(w+2)]
a.append(footer)
    

for i in range(1,h+1):
    ans=''
    for j in range(1,w+1):
        count=0
        if a[i][j]=='#':
            ans += '#'
        else:
            if a[i-1][j-1]=='#':
                count += 1
            if a[i-1][j]=='#':
                count += 1
            if a[i-1][j+1]=='#':
                count += 1
            if a[i][j-1]=='#':
                count += 1
            if a[i][j+1]=='#':
                count += 1
            if a[i+1][j-1]=='#':
                count += 1
            if a[i+1][j]=='#':
                count += 1
            if a[i+1][j+1]=='#':
                count += 1

            ans += str(count)

    print(ans)
    



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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

int n, a[N];
int cnt;
LL res;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i ++ )
	{
		scanf("%d", a + i);
		res += abs(a[i]);
		if (a[i] < 0) cnt ++ ;
	}
	
	if (cnt & 1)
	{
		int mina = 0x3f3f3f3f;
		for (int i = 0; i < n; i ++ )
			mina = min(mina, abs(a[i]));
		res -= mina * 2;
	}
	
	printf("%lld\n", res);
    return 0;
}

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

typedef long long LL;

#define INF 4294967295
#define MOD 1000000000+7

vector<vector<LL>> graph;
LL cost[100000 + 10][3];

LL bfs(LL start, LL end)
{
	LL depth = 0;
	set<LL> node_list = {start};
	set<LL> next_node_list;
	while(0 < node_list.size()) {
		next_node_list.clear();
		//for (auto temp = node_list.begin(); temp != node_list.end(); temp++) {
		//	cout << *temp << "/";
		//}
		//cout << endl;
		if (0 == depth % 3) {
			if (node_list.end() != node_list.find(end)) {
				return (depth / 3);
			}
		}
		for(auto current = node_list.begin(); current != node_list.end(); current++) {
			if (cost[*current][depth % 3] <= depth) {
				continue;
			}
			cost[*current][depth % 3] = depth;
			for (LL node : graph[*current]) {
				next_node_list.insert(node);
			}
		}
		depth++;
		node_list = next_node_list;
	}
	return (-1);
}

int main(void)
{
	LL N, M;

	cin >> N >> M;
	graph.resize(N);
	for(LL i = 0; i < M; i++) {
		LL U, V;
		cin >> U >> V;
		graph[U - 1].push_back(V - 1);
	}
	LL S, T;
	cin >> S >> T;

	if (0 == M) {
		cout << -1 << endl;
		return 0;
	}

	for(LL i = 0; i < 100000 + 10; i++) {
		for(LL j = 0; j < 3; j++) {
			cost[i][j] = INF;
		}
	}
	
	cout << bfs(S - 1, T - 1) << endl;

	return 0;
}


Measured memory_bytes: 10360
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int m = stdin.nextInt();
		int k = stdin.nextInt();
		List<Integer> memo = new ArrayList<Integer>();
		for(int i=0;i<k;i++) {
			memo.add(stdin.nextInt());
		}
		for(int j=0;j<n-1;j++) {
			List<Integer> a = new ArrayList<Integer>();
			k = stdin.nextInt();
			for(int l=0;l<k;l++) {
				a.add(stdin.nextInt());
			}
			memo.retainAll(a);
		}
		System.out.println(memo.size());
	}

}


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

int main(){
  int a, b;
  int k;
  cin >> a >> b;
  k = a + b;
  if(k % 2 == 0){
    k = k / 2;
    cout << k << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    ll n,d;
    cin>>n>>d;
    cout<<ceil((ld)n/(2*d+1))<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  print(N * 800 - (N / 15) * 200);
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

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

	ll max_a = 0;
	ll aiueoon = 0;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;

		if (max_a < x) {
			max_a = x;
			aiueoon = y;
		}
	}
	cout << max_a + aiueoon << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000000;

int main(){
  string n;

  cin >> n;

  int streak = 0;


  if (((n[0] == n[1]) && (n[1] == n[2])) || ((n[1] == n[2]) && (n[2] == n[3]))) {
    cout << "Yes" << endl;
    return 0;
  }

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<stdlib.h>
#define M 102005
#define N 100
#define ll long long
#define oo 1000000000
#define mod 1000000007
using namespace std;
int m,n,A[M],cnt[M],bao[M],a,b,ans;
void pc(){
    int res=1;
    for(int i=1;i<=100002;i++){
        res=1LL*res*i%mod;
        bao[i]=res;
    }
}
int fast(int x,int n){
   	int res=1;
    int a=x;
    while(n){
        if(n&1)res=1LL*res*a%mod;
        a=1LL*a*a%mod;
        n>>=1;
    }
    res%=mod;
    return res;
}
int fff(int n,int k){
    if(n==k)return 1;
    if(k>n)return 0;
    int q=n-k;
    int res=1;
    int lll=1LL*bao[k]*bao[q]%mod;
    res=1LL*bao[n]*fast(lll,mod-2)%mod;
    res%=mod;
    return res;
}
int main(){
	int i,j,k;
	pc();
	cin>>n;
	for(i=1;i<=n+1;i++){
		scanf("%d",&A[i]);
		cnt[A[i]]++;
		if(cnt[A[i]]==2){
			m=A[i];
		}
	}
	for(i=1;i<=n+1;i++){
		if(A[i]==m){
			if(!a)a=i;
			else b=i;
		}
	}
	k=b-a;
	printf("%d\n",n);
	
	for(i=2;i<=n+1;i++){
		//printf("%d ",fff(n+1,i));
		ans=fff(n+1,i)-fff(n-b+a,i-1);
		if(ans<0)ans+=mod;
		//ans-=fff(a-1,i-1);
		printf("%d\n",ans);
	}
	return 0;
}
	

Measured memory_bytes: 2432
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <deque>
using namespace std;


int main() {
	long long n, a;
	cin >> n;
	bool k = true;
	for(int i = 0; i < n; ++i){
		cin >> a;
		if(a % 2 == 0 && a % 5 != 0 && a % 3 != 0) k = false;
	}
	if(k) cout << "APPROVED";
	else cout << "DENIED";
}



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

typedef long long ll;
int main(){

    string s; cin >> s;
    map<char,int> m;
    for(auto& c : s){
	if(m.find(c) != m.end() )
	    m[c] ++;
	else
	    m[c] = 1;
    }
    for( auto& it : m ){
	if( it.second %2 != 0 ){
	    cout << "No" << endl;
	    return 0;
	}
    }
    cout << "Yes" << endl;
    return 0;
    
 }


Measured memory_bytes: 256
N, M = list(map(int, input("").split(" ")))
permit = [list(map(int, input("").split(" "))) for i in range(M)]
l,r = 1, N
for i,j in permit:
  l = max(l, i)
  r = min(r, j)
print(max(r-l+1,0))

Measured memory_bytes: 27324
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String w = in.next();
            int cnt[] = new int[26];

            for (int i = 0; i < w.length(); i++) {
                cnt[w.charAt(i) - 'a']++;
            }
            // 出力
            boolean ok = true;
            for (int i = 0; i < 26; i++) {
                if (cnt[i] % 2 != 0) ok = false;
            }
            if (ok) {
                out.println("Yes");
            } else {
                out.println("No");
            }

        }

    }
}



Measured memory_bytes: 21716