akhauriyash/Code-Regression huggingface dataset:
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    return (a*b)//gcd(a, b)


def f(abc):
    a, b, c = abc
    return b//c-a//c


a, b, c, d = map(int, input().split())
a -= 1
print(b-a+sum(map(f, [(b, a, c), (b, a, d), (a, b, lcm(c, d))])))

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int N, W;
int V[150][15000];
int v[150];
int w[150];

int main(){
  cin >> N >> W;
  for(int i = 1; i <= N; ++i){
    cin >> v[i] >> w[i];
  }
  
  for(int i = 1; i <= N; ++i){
    for(int c = 1; c <= W ; ++c){
      if(i <= 0 || c <= 0){
        V[i][c] = 0;
      }
      else if(c - w[i] < 0){
        V[i][c] = V[i - 1][c];
      }
      else{
        V[i][c] = max(v[i] + V[i - 1][c - w[i]], V[i - 1][c]) ;
      }
    }
  }
  cout << V[N][W]  << endl;
}


Measured memory_bytes: 7416
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"algorithm"
#include"queue"
using namespace std;
struct mmm
{
	int x,y;
}vv;
int dir[4][2] = {0,-1,-1,0,0,1,1,0};
char xx[105][105];
queue <mmm> qq;
int sum;
char pp;
void bfs()
{
	while(!qq.empty())
	{
		vv =qq.front();
		int x0 = vv.x;
		int y0 = vv.y;
		qq.pop();
		for(int i = 0;i < 4;i++)
		{
			int xt = x0 + dir[i][0];
			int yt = y0 + dir[i][1];
			if(xx[xt][yt] != '0' && xx[xt][yt] == pp)
			{
				xx[xt][yt] = '0';
				vv.x = xt;
				vv.y = yt;
				qq.push(vv);
			}
		}
	}
}
int main()
{
	int a,b,c,d;
	while(~scanf("%d %d",&a,&b))
	{
		if(a == 0 && b == 0)
		break;
		memset(xx,'0',sizeof(xx));
		sum = 0;
		getchar();
		for(int i = 1;i <= a;i++)
		{
			for(int j = 1;j <= b;j++)
			{
				xx[i][j] = getchar();
			}
			getchar();
		}
		for(int i = 1;i <= a;i++)
		{
			for(int j = 1;j <= b;j++)
			{
				if(xx[i][j] != '0')
				{
					pp = xx[i][j];
					vv.x = i;
					vv.y = j;
					qq.push(vv);
					xx[i][j] = '0';
					bfs();
					sum ++;
				}
			}
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn = 2000 + 100;
int N;
LL M;
LL A[Maxn], Min[Maxn][Maxn];
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d%lld", &N, &M);
	for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; ++i) Min[i][i] = A[i];
	for (int i = 1; i <= N; ++i)
		for (int j = i + 1; j <= N; ++j)
			Min[i][j] = min(Min[i][j - 1], A[j]);
	LL Ans = 0x3f3f3f3f3f3f3f3f;
	for (int i = 0; i < N; ++i)
	{
		LL Sum = i * M;
		for (int j = 1; j <= N; ++j)
			if (j > i) Sum += Min[j - i][j];
			else Sum += min(Min[1][j], Min[j - i + N][N]);
		Ans = min(Ans, Sum);
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 33024
#include <bits/stdc++.h>
using namespace std;
int main() {
     int N;
     cin >> N;
     vector<int> P(N);
     for(int i = 0; i < N; i++){
          cin >> P[i];
     }
     sort(P.begin(),P.end());
     int ans = 0;
     for(int i = 0; i < N-1; i++){
          ans += P[i];
     }
     ans += P[N-1]/2;
     cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  int ans = 0;
  rep(i, 2, n) {
    int x[3] = {p[i - 2], p[i - 1], p[i]};
    sort(x, x + 3);
    if (x[1] == p[i - 1]) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
// Answer by drken1215
// cf. http://drken1215.hatenablog.com/entry/2019/09/29/012000

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

vector< vector<int> > graph;
vector< vector<int> > revGraph;

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;
  graph.resize(N);
  revGraph.resize(N);
  rep(i, M) {
    int A, B;
    cin >> A >> B;
    --A; --B; // 0-indexed
    graph[A].push_back(B);
    revGraph[B].push_back(A);
  }

  int shortest = INF;
  vector<int> res;
  rep(s, N) {
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> q;
    q.push(s);
    dist[s] = 0;
    int t = -1;
    while (!q.empty()) {
      if (t >= 0) { break; }

      auto v = q.front(); q.pop();
      for (int nv : graph[v]) {
        if (nv == s) {
          t = v;
          break;
        }
        if (dist[nv] == -1) {
          dist[nv] = dist[v] + 1;
          prev[nv] = v;
          q.push(nv);
        }
      }
    }

    if (t >= 0) { // t is found.
      int d = dist[t] + 1; // cycle length
      if (d < shortest) {
        shortest = d;
        // Update res to the found shortest path.
        res.clear();
        int cur = t;
        while (cur != s) {
          res.push_back(cur);
          cur = prev[cur];
        }
        res.push_back(s);
      }
    }
  }

  if (shortest == INF) { // shortest is not updated. So, no cycle is found.
    cout << -1 << endl;
  } else {
    cout << res.size() << endl;
    for (auto v : res) {
      cout << v + 1 << endl; // shortest path
    }
  }
}


Measured memory_bytes: 384
import java.util.Scanner;

// https://atcoder.jp/contests/abc135/tasks/abc135_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int A = Math.min(a, b);
		int B = Math.max(a, b);

		if((A+B)%2==0) {
			int K = (A+B)/2;

			if((A-K)<=0 && (B-K)>=0) {
				System.out.println(K);
			} else {
				System.out.println("IMPOSSIBLE");
			}
		} else {
			System.out.println("IMPOSSIBLE");
		}





	}

}


Measured memory_bytes: 22996
import numpy as np

N, K = (int(i) for i in input().split())
x = np.sort(np.array([int(i) for i in input().split()]))

result = []
if(N==1):
    print(np.abs(x[0]))

else:
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]

        if (left * right < 0):
            if (np.abs(left) < np.abs(right)):
                diff = np.abs(left) * 2 + np.abs(right)
            else:
                diff = np.abs(left) + np.abs(right) * 2

        else:
            diff = np.max([np.abs(left), np.abs(right)])

        result.append(diff)

    print(np.min(result))


Measured memory_bytes: 23232
// https://atcoder.jp/contests/abc157/tasks/abc157_e
// 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
#define outl(x) cout<<x<<endl
#define outsp(x) cout<<x<<" "
typedef long long ll;
typedef pair<int,int> P;
#define MAX_N 500005

int N;
int tree[27][MAX_N+1];

int sum(int c,int i){
	int s=0;
	for(int j=i;j>0;j-=j&-j) s+=tree[c][j];
	return s;
}
void add(int c,int i,int v){
	i++;
	for(int j=i;j<=N;j+=j&-j) tree[c][j]+=v;
}

int main() {
	string s;
	int a[MAX_N];
	int q;
	cin >> N >> s;
	cin >> q;
	rep(i,N){
		a[i] = s[i]-'a';
		add(s[i]-'a',i,1);		
	}

	int idx,l,r;
	char c;

	rep(i,q){
		int type;
		cin >> type;
		if(type==1){
			cin >> idx >> c;
			idx--;
			int b = c-'a';
			add(a[idx],idx,-1);
			add(b,idx,1);
			a[idx] = b;
		}else{
			cin >> l >> r;
			l--;
			int cnt=0;
			rep(j,27){
				cnt += (sum(j,r)-sum(j,l)) > 0;
			}
			outl(cnt);
		}
	}


    return 0;
}



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

int main() {
  int A , B ; 
  cin >> A >> B ; 
  
  if(A >= 13 ){
   cout << B << endl ;  
  }
  else if (A >= 6 && 12 >= A ){
    cout << B/2 << endl ;
  }
  
  else {
    cout << 0 << endl ; 
  }
  
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#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 IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> dp;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

int main()
{
    IOS;
    string s;
    cin>>s;
    if(s[0]=='7' | s[1]=='7' | s[2]=='7') cout<<"Yes\n";
    else cout<<"No\n";
}     


Measured memory_bytes: 3652
from sys import exit, stdin
N = [int(_) for _ in stdin.readline().rstrip().split()]
A = []
no, ne = 0, 0
for i in stdin.readline().rstrip().split():
    if int(i) % 2 == 0:
        A.append('e')
        ne += 1
    else:
        A.append('o')
        no += 1
len_A = len(A)
if len_A % 2 == 0:
    if ne % 2 == 0:
        print('YES')
    else:
        print('NO')
else:
    if ne % 2 == 0:
        print('NO')
    else:
        print('YES')

Measured memory_bytes: 11104
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;


int main() {
    int n;
    double counter, s = -1;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for (int i = 0; i < n; i++){
        cin >> x[i];
    }
    for (int j = 0; j < n; j++){
        cin >> y[j];
    }
    for (int p = 1; p <= 3; p++){
        for (int l = 1; l <= n; l++){
            counter += pow((abs(x[l - 1] - y[l - 1])), p);
        }
        cout << pow(counter, (1.0 / p)) << endl;
        counter = 0;
    }
    for (int k = 1; k <= n; k++){
        if (s < (abs(x[k - 1] - y[k - 1]))){
            s = (abs(x[k - 1] - y[k - 1]));
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 3448
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
const int ms = 1e5 + 10;
int a[ms], l[ms][2], r[ms][2], b[ms];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    map<int, int> m;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        a[t] = i;
        b[i] = t;
    }
    set<int> s;
    s.insert(n);
    s.insert(-1);
    s.insert(-2);
    s.insert(n + 1);
    for (int i = n; i > 0; --i)
    {
        auto it = s.lower_bound(a[i]);
        r[a[i]][0] = *it;
        ++it;
        r[a[i]][1] = *it;
        --it;
        --it;
        l[a[i]][0] = *it;
        --it;
        l[a[i]][1] = *it;
        s.insert(a[i]);
    }
    ll res = 0;
    for (int i = 0; i < n; ++i)
    {
        if (r[i][0] == n && l[i][0] == -1) continue;
        if (r[i][0] == n)
        {
            res += 1ll * (r[i][0] - i)*(l[i][0] - l[i][1])*b[i];
        }
        else if (l[i][0] == -1)
        {
            res += 1ll * (r[i][1] - r[i][0])*(i - l[i][0])*b[i];
        }
        else
        {
            res += 1ll * (r[i][0] - i)*(l[i][0] - l[i][1])*b[i];
            res += 1ll * (r[i][1] - r[i][0])*(i - l[i][0])*b[i];
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 7296
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  string a,b,c;

  cin >> a >> b >> c;

  char X = b[0];

  cout << "A" << X << "C" ;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
using namespace std;
const int mod=998244353;
typedef long long ll;
int n;
int  a[7];
ll res=1;
ll ans=1;
char str[300010];
int  main(){
    cin>>n;
    scanf("%s",str+1);
    for(int i=1;i<=n;i++)res=1ll*res*i%mod;
    for(int i=1;i<=n*3;i++){
        if(str[i]=='R'){
            if(a[5]){
                ans=1ll*ans*a[5]%mod;
                a[5]--;
                continue;
            }
            if(a[2]){
                ans=1ll*ans*a[2]%mod;
                a[2]--;
                a[4]++;
                continue;
            }
            if(a[3]){
                ans=1ll*ans*a[3]%mod;
                a[3]--;
                a[6]++;
                continue;
            }
            a[1]++;
        }
        else if(str[i]=='G'){
            if(a[6]){
                ans=1ll*ans*a[6]%mod;
                a[6]--;
                continue;
            }
            if(a[1]){
                ans=1ll*ans*a[1]%mod;
                a[1]--;
                a[4]++;
                continue;
            }
            if(a[3]){
                ans=1ll*ans*a[3]%mod;
                a[3]--;
                a[5]++;
                continue;
            }
            a[2]++;
        }
        else{
            if(a[4]){
                ans=1ll*ans*a[4]%mod;
                a[4]--;
                continue;
            }
            if(a[1]){
                ans=1ll*ans*a[1]%mod;
                a[6]++;
                a[1]--;
                continue;
            }
            if(a[2]){
                ans=1ll*ans*a[2]%mod;
                a[2]--;
                a[5]++;
                continue;
            }
            a[3]++;
        }
    }
   
    cout<<(ans*res)%mod<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int sw=0;
    for (int i=0; i<n; i++){
        cin >> a[i];
    }
    for (int i=0; i<n; i++){
        int minj=i;
        for (int j=i; j<n; j++){
            
            if (a[j]<a[minj]){
                minj=j;
            }
        }
        if (i!=minj){
            sw++;
        }
        swap(a[i],a[minj]);
    }
    for (int i=0; i<n-1; i++){
        cout << a[i] << " " ;
    }
    cout <<a[n-1] <<endl;
    cout << sw <<endl;
}


Measured memory_bytes: 3072
unittest
{
	assert( [ "3", "0 1 3", "1 0 2", "3 2 0" ].parse.expand.solve == 3 );
	assert( [ "3", "0 1 3", "1 0 1", "3 1 0" ].parse.expand.solve == -1 );
	assert( [ "5", "0 21 18 11 28", "21 0 13 10 26", "18 13 0 23 13", "11 10 23 0 17", "28 26 13 17 0" ].parse.expand.solve == 82 );
	assert( [ "3", "0 1000000000 1000000000", "1000000000 0 1000000000", "1000000000 1000000000 0" ].parse.expand.solve == 3000000000 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto ass = new long[][]( n, n );
	foreach( ref as; ass )
	{
		input.popFront;
		as = input.front.split.to!( long[] );
	}
	return tuple( ass );
}

auto solve( long[][] ass )
{
	auto ans = 0L;
	auto dss = new long[][]( ass.length, ass[ 0 ].length );
	foreach( i, ref ds; dss )
	{
		ds[] = long.max;
		ds[ i ] = 0;
	}
	
	// 小さい順に辺を追加する
	auto queue = heapify!( ( a, b ) => b[ 0 ] < a[ 0 ] )( new Tuple!( long, long, long )[ ass.length * ( ass.length - 1 ) / 2 ], 0 );
	for( auto u = 0L; u < ass.length; u++ )
	{
		for( auto v = u + 1; v < ass[ u ].length; v++ )
		{
			queue.insert( tuple( ass[ u ][ v ], u, v ) );
		}
	}
	while( !queue.empty )
	{
		auto a = queue.front[ 0 ];
		auto u = queue.front[ 1 ];
		auto v = queue.front[ 2 ];
		queue.popFront;
		
		if( dss[ u ][ v ] <= a ) continue;		// 辺を追加しても最短経路が変わらない場合は追加しない
		ans += a;
		dss[ u ][ v ] = a;
		dss[ v ][ u ] = a;
		
		// ワーシャルフロイド法（中継点固定）で最短経路を計算
		warshallfloyd( dss, u );
		warshallfloyd( dss, v );
	}
	
	// 表Aと最短経路が一致するか判定
	foreach( as, ds; lockstep( ass, dss ) )
	{
		if( as != ds ) return -1;
	}
	return ans;
}

// 正負の重み付きグラフの全二点間最短経路探索（ワーシャルフロイド法）
auto warshallfloyd( ref long[][] dss, long p )
{
	foreach( f; 0L .. dss.length )
	{
		foreach( t; 0L .. dss.length )
		{
			if( dss[ f ][ p ] == long.max || dss[ p ][ t ] == long.max ) continue;
			dss[ f ][ t ] = min( dss[ f ][ t ], dss[ f ][ p ] + dss[ p ][ t ] );
		}
	}
	return dss;
}


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

int main(){
    int N;
    cin>>N;
    int H[N];
    for(int i=0;i<N;i++) cin>>H[i];

    int flag[N] = {};
    flag[0] = 1;
    int maxhigh = H[0];
    int ans=1;

    for(int i=0;i<N-1;i++){
        if(H[i]<=H[i+1]&&maxhigh<=H[i+1]){
        ans++;
        maxhigh=H[i+1];
        }
    }

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll gcd(ll a, ll b){
	if(b==0){
		return a;
	}
	return gcd(b, a%b);
}

// 約数を求める
vl divisor(ll n){
	vl res;
	for(ll i=1; i*i<=n; ++i){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i){
				res.push_back(n/i);
			}
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m;
	cin>>n>>m;
	if(n==1){
		cout<<m<<'\n';
		return 0;
	}
	ll ans=0;
	vl a=divisor(m);
	REP(i, a.size()){
		if(a[i]*n<=m){
			ans=max(ans, a[i]);
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


int main()
{
	ll n, T, t, s, i, ans = 0;

	cin >> n >> T >> t;
	s = t;
	for(i = 0; i < n - 1; i++){
		cin >> t;
		ans += min(t - s, T);
		s = t;
	}
	ans += T;

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define MOD 1'000'000'007LL
#define N 2123456
ll fct[N] = {1};
ll fctinv[N];
ll pw(ll a, ll b){
	ll c = 1;
	do{
		if(b&1) c = c * a % MOD;
		a = a * a % MOD;
	}while(b/=2);
	return c;
}
ll inv(ll a){
	return pw(a, MOD-2);
}
ll cmb(ll a, ll b){
	return fct[a] * fctinv[b] % MOD * fctinv[a-b] % MOD;
}
ll g(ll a, ll b){
	ll tmp = 0, sm = 0;
	REP(i, b){
		tmp = tmp*2 + cmb(a+i, i);
		tmp %= MOD;
		sm += tmp;
		sm %= MOD;
		DEBUG("  %d %lld %lld\n", i, tmp, sm);
	}
	DEBUG(" g(%lld, %lld) = %lld\n", a, b, sm);
	return sm;
}
ll f(ll a, ll b){
	ll ret = (pw(2, a+b+1) + MOD - 1) % MOD;
	DEBUG(" 2^() = %lld\n", ret);
	ret = (ret + MOD - g(a, b)) % MOD;
	ret = (ret + MOD - g(b, a)) % MOD;
	DEBUG("f(%lld, %lld) = %lld\n", a, b, ret);
	return ret;
}

int main(){
	FOR(i, 1, N) fct[i] = fct[i-1] * i % MOD;
	REP(i, N) fctinv[i] = inv(fct[i]);
	ll a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d); a--; b--;
	ll ans = f(c, d) - f(a, d) - f(c, b) + f(a, b);
	ans = (ans + MOD * 3) % MOD;
	printf("%lld\n", ans);
}



Measured memory_bytes: 33408
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1)
        cout << 1 << endl;
    else
        cout << (h*w+1)/2 << endl;
    return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<char, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

signed main(){
    string s; cin >> s;
    bool ok = true;
    REP( i, s.size() ){
        if( i % 2 == 0 ){
            if( s[i] == 'R' || s[i] == 'U' || s[i] == 'D' ){

            }else{
                ok = false;
            }
        }else{
            if( s[i] == 'L' || s[i] == 'U' || s[i] == 'D' ){

            }else{
                ok = false;
            }
        }
    }

    if( ok ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    int n,m;
    cin>>n>>m;
    map<int,int> hm;
    set<int> s;
    for(int i=0;i<m;i++)
    {   
        string s1;
        int x;
        cin>>x;
        cin>>s1;
        if(s1=="AC") {s.insert(x);}
        else 
        {
            if(s.find(x)==s.end()) hm[x]++;
        }
    }
    int ans=0;
    for(auto y:hm)
    {
        int x=y.first;
        if(s.find(x)!=s.end()) ans+=y.second;
    }
    cout<<s.size()<<" "<<ans;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;

ll N, M;
std::vector<int> G[100000];
int col[100000];

bool dfs( int v, int c )
{
  bool ret = true;

  col[v] = c;

  for( auto &u : G[v] )
  {
    if( col[u] == c )
      return false;
    if( !col[u] )
      ret &= dfs( u, -c );
  }

  return ret;
}

int main()
{
  scanf( "%lld%lld", &N, &M );
  rep( i, M )
  {
    int A, B;
    scanf( "%d%d", &A, &B );
    --A; --B;
    G[A].push_back( B );
    G[B].push_back( A );
  }

  bool bi = dfs( 0, 1 );

  if( bi )
  {
    ll B = 0, W = 0;

    rep( i, N )
    {
      if( col[i] == 1 )
        ++W;
      else
        ++B;
    }

    printf( "%lld\n", B*W-M );
  }
  else
    printf( "%lld\n", N*(N-1)/2-M );

  return 0;
}

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

int main() {
  int N, cnt=0;
  string S, T;
  cin >> N >> S >> T;
  rep(i, N){
    if(S.substr(S.size()-1-i, i+1)==T.substr(0,i+1)) cnt=i+1;
  }
  cout << max(N,(int)(S.size())*2-cnt) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
#include <iomanip>

int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);

double xp1, yp1, xp2, yp2; 
cin >> xp1 >> yp1 >> xp2 >> yp2;
int q; cin >> q;
rep(i, 0, q){
    double x, y;
    cin >> x >> y;

    double vx = xp2 - xp1, vy = yp2 - yp1;
    double ux = vx / hypot(vx, vy), uy = vy / hypot(vy, vx);
    double wx = x - xp1, wy = y - yp1;
    double ip = wx * ux + wy * uy;
    cout << xp1 + ip * ux << ' ' << yp1 + ip * uy << "\n";
}    



}

// 境界，出力文字列 チェック
// まずは全探索，次にDP
// 制限を見る
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり




Measured memory_bytes: 3360
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
  long int n;
  scanf("%ld", &n);
  
  long int* array = malloc(n * sizeof(long int));
  
  int i, j;
  for (i = 0; i < n; ++i)
  {
    scanf("%ld", &array[i]);
  }
  
  long int preAns = 0;
  for (i = 0; i < n; ++i)
  {
    preAns ^= array[i];
  }
  for (i = 0; i < n; ++i)
  {
    printf("%ld ", preAns ^ array[i]);
  }
  printf("\n");
  
  
  free(array);
  
  return 0;
}


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

int main() {
  int a;
  int b;
  double x;
  
  cin >> a;
  cin >> b;
  x = (a+b) / 2;
  
  if( (a+b) % 2 == 1){
    x = x+1;
  }
  
  cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
using namespace std;
typedef long long int llint;
int main() {
	int a, b;
	cin >> a >> b;
	if (a %b == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1 << endl;
	}
	return 0;
}

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

using namespace std;

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

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (ll i=(b)-1; i>=a;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector<vector<T> >& vec) {
    REP(i,vec.size()) {
        if(i) os << endl;
        os << vec[i];
    }
    return os;
}
struct Edge {
    int from, to, t, c;
};
bool operator<(const Edge& e1, const Edge& e2) {
    return e1.t < e2.t;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, s, g; cin >> n >> m >> s >> g; --s, --g;
    vector<Edge> edges;
    vector<vector<P>> Q(n);
    vector<int> idx(n, 0);
    REP(i, m) {
        int u, v, t, c; cin >> u >> v >> t >> c; --u, --v;
        edges.pb({u, v, t, c});
        Q[u].pb({t, linf});
    }
    REP(i, n) {
        sort(ALL(Q[i]));
    }
    if (Q[s].size() > 0) {
        Q[s][0].second = Q[s][0].first;
    }
    sort(ALL(edges));
    ll ans = linf;
    EACH(e, edges) {
        P& d00 = Q[e.from][idx[e.from]++];
        // wait
        assert(e.t == d00.first);
        if (idx[e.from] < Q[e.from].size()) {
            P& d01 = Q[e.from][idx[e.from]];
            d01.second = min(d01.second, d00.second+(d01.first - d00.first));
        }
        // ride
        if (e.to == g) {
            ans = min(ans, d00.second);
        }
        auto it = lower_bound(ALL(Q[e.to]), P(d00.first+e.c, -1));
        if (it != Q[e.to].end()) {
            it->second = min(it->second, d00.second + (it->first - (e.t+e.c)));
        }
    }
    cout << ans << endl;
}

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

int main(){
    int c1,c2,c3,Cards[10];
    
    while(cin >> c1 >> c2 >> c3){
        for(int i = 0 ; i < 10 ; i++){
            Cards[i] = i+1;
            if(c1 == Cards[i]) Cards[i] = 0;
            if(c2 == Cards[i]) Cards[i] = 0;
            if(c3 == Cards[i]) Cards[i] = 0;
        }
        
        int cnt = 0;
        int tc = c1 + c2;
        
        for(int i = 0 ; i < 10 ; i++){
            if(Cards[i]==0) continue;
            
            if(Cards[i]+tc <= 20) cnt++;
        }
        if(cnt >= 4) cout << "YES" << endl;
        else cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>

int main(){
	int a,b;
	while(std::cin >> a >> b){

		if(a == 0 && b == 0) return 0;
	
		int road[a][b];

		int n;
		std::cin >> n;
		int notRoad[n][2];

		int x,y;
		for(int i = 0; i < n; ++i){
			std::cin >> x >> y;
			notRoad[i][0] = x;
			notRoad[i][1] = y;
		}

		for(int i = 0; i < a; ++i){
			for(int j = 0; j < b; ++j){
				int construct = 0;
				for(int k = 0; k < n; ++k){
					if(i == (notRoad[k][0]) - 1 && j == (notRoad[k][1]) - 1){
						construct = 1;
					}
				}
				if(construct == 1){
					road[i][j] = 0;//工事中を除去
				} else if(i == 0 && j == 0){
					road[0][0] = 1;//スタート地点
				} else if((i - 1) < 0){
					road[i][j] = road[i][j-1];//最西
				} else if((j - 1) < 0){
					road[i][j] = road[i-1][j];//最南
				} else{
					road[i][j] = road[i-1][j] + road[i][j-1];
				}
			}
		}

		std::cout << road[a-1][b-1] << std::endl;
	}
}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(){
  string O[2];
  cin >> O[0] >> O[1];
  for(int i = 0; i < O[1].length(); ++i){
    for(int j = 0; j < 2; ++j) cout << O[j][i];
  }
  if(O[0].size() > O[1].size()) cout << O[0][O[0].size()-1];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

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




int main(void) {
	long long int n;
	string s;
	long long int count[26] = {};
	long long int total = 1;

	cin >> n >> s;
	FOR(i, 0, s.size() - 1) {
		count[s[i] - 'a']++;
	}
	FOR(i, 0, 25) {
		total *= (count[i] + 1);
		total %= MOD;
	}

	cout << (total - 1)%MOD << endl;

	

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  cout << (n+1)/2 << endl;
}


Measured memory_bytes: 764
/*
      author  : nishi5451
      created : 12.08.2020 22:17:17
*/

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


int main(){
    string s;
    cin >> s;
    int first,last;
    rep(i,int(s.size()))
        if(s[i]=='A'){
            first=i;
            break;
        }
    rep(i,int(s.size()))
        if(s[i]=='Z') last=i;
    
    cout << last-first+1 << endl;
    return 0;
}   

Measured memory_bytes: 3728
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;
ll getllSubstr(string s,ll start_index,ll length){
    return atoi(s.substr(start_index,length).c_str());
}
ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string S;
    cin >> S;

    ll ans = 0;
    rep(si,S.size()){
        ans += getllSubstr(S,si,1);
    }
    if(ans%9==0) cout << "Yes" << endl;
    else cout << "No" << endl;
    

}

Measured memory_bytes: 3840
x,n = list(map(int,input().split()))
p = set(map(int,input().split()))


ans = 0
check = 100000000000000000000000
for i in range(-100,201):
    if i in p:pass
    else:
        if check > abs(x-i):
            ans = i
            check = abs(x-i)

print(ans)


Measured memory_bytes: 9176
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public final class Main {

    private static final int[][] DIRS = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };

    private static final int[][] PAID = {
            { -2, -2 },
            { -2, -1 },
            { -2, 0 },
            { -2, 1 },
            { -2, 2 },
            { -1, -2 },
            { -1, -1 },
            { -1, 1 },
            { -1, 2 },
            { 0, -2 },
            { 0, 2 },
            { 1, -2 },
            { 1, -1 },
            { 1, 1 },
            { 1, 2 },
            { 2, -2 },
            { 2, -1 },
            { 2, 0 },
            { 2, 1 },
            { 2, 2 }
    };

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final String[] line1 = in.nextLine().split(" ");
        int n = Integer.parseInt(line1[0]);
        int m = Integer.parseInt(line1[1]);
        final String[] line2 = in.nextLine().split(" ");
        int sx = Integer.parseInt(line2[0]) - 1;
        int sy = Integer.parseInt(line2[1]) - 1;
        final String[] line3 = in.nextLine().split(" ");
        int dx = Integer.parseInt(line3[0]) - 1;
        int dy = Integer.parseInt(line3[1]) - 1;
        char[][] matrix = new char[n][m];
        for (int i = 0; i < n; i++) {
            matrix[i] = in.nextLine().toCharArray();
        }
        PriorityQueue<int[]> pq = new PriorityQueue<>(Comparator.comparingInt(a -> a[2]));
        boolean[][] visited = new boolean[n][m];
        pq.offer(new int[] { sx, sy, 0 });
        while (!pq.isEmpty()) {
            int[] curr = pq.remove();
            int x = curr[0];
            int y = curr[1];
            if (x == dx && y == dy) {
                System.out.println(curr[2]);
                return;
            }
            if (visited[x][y]) {
                continue;
            }
            visited[x][y] = true;
            for (int[] dir : DIRS) {
                int nx = x + dir[0];
                int ny = y + dir[1];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && matrix[nx][ny] != '#') {
                    pq.offer(new int[] { nx, ny, curr[2] });
                }
            }
            for (int[] dir : PAID) {
                int nx = x + dir[0];
                int ny = y + dir[1];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && matrix[nx][ny] != '#') {
                    pq.offer(new int[] { nx, ny, curr[2] + 1 });
                }
            }
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 79376
n,k =map(int,input().split())
p=list(map(int,input().split()))

tem=0
ans=0

for i in range(k):
    ans=ans+(p[i]/2)+1/2
    tem=tem+(p[i]/2)+1/2

for i in range(1,n-k+1):
    fi=p[i-1]/2 +1/2
    la=p[i+k-1]/2 +1/2
    tem=tem-fi+la
    ans=max(ans,tem)

print(ans)

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

int main() {
    int a, b;
    int ans=0;
    
    cin >> a >> b;
    
    if(a <= b){
        rep(i, b){
            ans = ans * 10 + a;
        }
    } else{
        rep(i, a){
            ans = ans * 10 + b;
        }
    }
    
    cout << ans << endl;
    
    return 0;
}




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

using namespace std;

long long int sum[4][101] = {0,};
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long int n,w,a,b;
	vector <long long int> item[4];
	long long int res = 0;
	long long int x = 0;
	cin >> n >> w;

	for(int i=0;i<n;i++)
	{
		cin >> a >> b;
		if(i==0)
		{
			x = a;
		}
		int idx = a - x;
		item[idx].push_back(b);
	}

	for(int i=0;i<4;i++)
	{
		sort(item[i].rbegin(),item[i].rend());
	}

	for(int i=0;i<4;i++)
	{
		for(int j=0;j<item[i].size();j++)
		{
			sum[i][j+1] = sum[i][j] + item[i][j];
		}
	}
	for(int i=0;i<=item[0].size();i++)
	{
		for(int j=0;j<=item[1].size();j++)
		{
			for(int k=0;k<=item[2].size();k++)
			{
				for(int l=0;l<=item[3].size();l++)
				{
					long long int W = x*i + (x+1)*j + (x+2)*k + (x+3)*l;
					//cout << i << ' ' << j << ' ' << k << ' ' << l << '\n';
					long long int V = sum[0][i] + sum[1][j] + sum[2][k] + sum[3][l];
					if(W<=w)
					{
						res = max(res,V);
					}
				}
			}
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int cnt5 = 0;
      	int cnt7 = 0;
      	int a = sc.nextInt();
      	cnt5 = (a == 5) ? cnt5 + 1:cnt5;
      	cnt7 = (a == 7) ? cnt7 + 1:cnt7;
      	int b = sc.nextInt();
      	cnt5 = (b == 5) ? cnt5 + 1:cnt5;
      	cnt7 = (b == 7) ? cnt7 + 1:cnt7;
      	int c = sc.nextInt();
      	cnt5 = (c == 5) ? cnt5 + 1:cnt5;
      	cnt7 = (c == 7) ? cnt7 + 1:cnt7;
      
      	if (cnt5 == 2 && cnt7 == 1) {
          System.out.println("YES");
        } else {
          System.out.println("NO");
        }
    }
}


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

const int mN = 200200;
int a[mN], nodes[mN];
int pos[mN];

int main()
{
    int n;
    long long k;
    cin >> n >> k;
    for (int i=1; i<=n; i++) cin >> a[i];
    int cnt = 0, start = 0, length = 1;
    memset(pos, -1, sizeof(pos));
    for (int u=1; ; u = a[u]) {
        if (pos[u] != -1) {
            start = pos[u];
            length = cnt - start;
            break;
        }
        nodes[cnt] = u;
        pos[u] = cnt++;
    }
//    cerr << k << "\n";
//    cerr << "cycle : "; for (int i=0; i<cnt; i++) cerr << nodes[i] << " ";
//    cerr << "start loop from : " << start << " length = " << length << "\n";
    if (k < start) cout << nodes[k];
    else {
        //cerr << k << "\n";
        int ord = (k-start) % length;
        cerr << ord << "\n";
        cout << nodes[start + (k-start)%length];
    }
}


Measured memory_bytes: 5936
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pci pair<char, int>
#define pic pair<int, char>
#define plvl pair<long long, vector<long long> >
#define pcvc pair<char, vector<char> >


using namespace std;

const int mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if(b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

template <typename T>
void show1(vector<T> dp) {
	for(auto d : dp) {
		cout << d << " ";
	}
	cout << endl;
}

template <typename T>
void show2(vector<vector<T> > dp) {
	for(auto d : dp) {
		for(auto dd : d) {
			cout << dd << " ";
		}
		cout << endl;
	}
}

void executeCode() {
	int n, m;
	cin >> n >> m;
	unordered_map<int, vector<int> > mp;
	vector<int> h(n);
	for(int i = 0 ; i < n ; i++) {
		cin >> h[i];
	}
	for(int i = 0 ; i < m ; i++) {
		int a, b;
		cin >> a >> b;
		mp[a].push_back(b);
		mp[b].push_back(a);
	}
	int cnt = 0;
	for(auto m : mp) {
		int mh = -1;
		// cout << m.first << " -- ";
		for(auto mm : m.second) {
			mh = max(mh, h[mm - 1]);
			// cout << mm << ", " << mh << "     ";
		}
		// cout << endl;
		if(mp[m.first].size() == 0 || h[m.first - 1] > mh) {
			cnt++;
		}
	}
	cout << cnt + n - mp.size() << endl;
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	while(tt--) {
		executeCode();	
	}
	return 0;
}

Measured memory_bytes: 11424
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
 *
 * @author Aeroui
 */
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);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
}



Measured memory_bytes: 50804
def main():
  result = 0
  k, s = map(int, input().split())
  for x in range(k + 1):
    for y in range(k + 1):
      z = s - x - y
      if 0 <= z <= k:
        result += 1
  print(result)
if __name__ == "__main__":
  main()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
const int N = 5e5 + 10;
//credit : ashish gupta
struct BIT{
	int N;
	vector<int> bit;
 
	void init(int n){
		N = n;
		bit.assign(n + 1, 0);
	}
 
	void update(int idx, int val){
		while(idx <= N){
			bit[idx] += val;
			idx += idx & -idx;
		}
	}
 
	void updateMax(int idx, int val){
		while(idx <= N){
			bit[idx] = max(bit[idx], val);
			idx += idx & -idx;
		}
	}
 
	int pref(int idx){
		int ans = 0;
		while(idx > 0){
			ans += bit[idx];
			idx -= idx & -idx;
		}
		return ans;
	}
 
	int rsum(int l, int r){
		return pref(r) - pref(l - 1);
	}
 
	int prefMax(int idx){
		int ans = -2e9;
		while(idx > 0){
			ans = max(ans, bit[idx]);
			idx -= idx & -idx;
		}
		return ans;
	}
};
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    BIT bt;
    bt.init(n+1);
    int v[N];
    for(int i = 1;i <= n;i++){
    	cin >> v[i];
    	bt.update(i,v[i]);
    }
    while(q--){
    	int ty;
    	cin >> ty;
    	if(ty == 0){
    		int id,val;
    		cin >> id >> val;
    		id++;
    		bt.update(id,val);
    	}
    	else{
    		int l,r;
    		cin >> l >> r;
    		l++;
    		cout << bt.rsum(l,r) << "\n";
    	}
    }
    return 0;
}
 

Measured memory_bytes: 12168
// inputに入力データ全体が入る
function Main(input) {
	console.log(input.replace(/.{4}/, s=>`${s} `).replace("\n", ""));
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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


int main(){
    
    int N = 0;
    int M = 0;
    int A = 0;
    int sumA = 0;
    
    cin >> N;
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> A;
        sumA = A + sumA;
    }
    
    if ((N - sumA) >= 0) {
        cout << N - sumA;
    }else{
        cout << -1;
    }
    
    return 0;
}


Measured memory_bytes: 3632