akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.BitSet;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		BitSet sb = new BitSet();
		while (!("0 0".equals(line))) {
			int k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			sb.clear();
			for (int i = 0; i < k; i++) {
				sb.set(Integer.parseInt(br.readLine()));
			}
			int sizeMax = 0;
			int start = sb.nextSetBit(1);
			while (start != -1) {
				final int end = sb.nextClearBit(start);
				sizeMax = Math.max(sizeMax, end - start);
				int nextstart = sb.nextSetBit(end);
				if (sb.get(0) && nextstart - end == 1) {
					sizeMax = Math.max(sizeMax, sb.nextClearBit(nextstart)
							- start);
				}
				start = nextstart;
			}
			System.out.println(sizeMax);
			line = br.readLine();
		}
	}

}

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

int main()
{
  int n, d, x, a;

  cin >> n >> d >> x;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    x += (d - 1) / a + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
	template <typename Arg1>
	void __f(const char* name, Arg1&& arg1){
		cerr << name << " : " << arg1 << std::endl;
	}
	template <typename Arg1, typename... Args>
	void __f(const char* names, Arg1&& arg1, Args&&... args){
		const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
	}
#else
#define debug(...)
#endif
#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 ln 		"\n"
#define mp make_pair
#define pb push_back
#define sz(a)	ll(a.size())
#define F first
#define S second
#define all(c)	c.begin(),c.end()
#define rall(c) c.rbegin(), c.rend()
#define trace(c,x) for(auto &x:c)
#define pii pair<ll,ll>
#define init(a, x) memset(a,x,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef	priority_queue<pii,std::vector<pii>,greater<pii> > revpr;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
// ordered_set X
//K-th smallest
//*X.find_by_order(k-1)
//NO OF ELEMENTS < A
//X.order_of_key(A)
const int L=1e6+7;
map<ll,ll> counter;
ll fastexpo(ll x,ll y,ll m)
{
	ll temp=1;
	while(y>0)
	{
		if(y&1)temp = ((temp%m)*(x%m))%m;
		x = ((x%m)*(x%m))%m;
		y>>=1;
	}return temp;
}
void fff()
{
	ll x;
	cin >> x ;
	if(x >= 30)cout <<"Yes\n";
	else cout <<"No\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//int t;cin >> t;while(t--)
	fff();
	return 0;
}

Measured memory_bytes: 3532
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	int h, w; cin >> h >> w;
	int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	vector<vector<int>> mp(h, vector<int>(w, iINF));
	vector<string> s(h);
	rep(i, h) cin >> s[i];

	deque<pair<P, int>> deq;
	deq.push_front(pair<P, int>(P(cw, ch), 0));
	while (!deq.empty()) {
		pair<P, int> p = deq.front(); deq.pop_front();
		if (mp[p.first.second][p.first.first] <= p.second) continue;
		mp[p.first.second][p.first.first] = p.second;
		for (int i = -2; i <= 2; ++i) {
			for (int j = -2; j <= 2; ++j) {
				if (i == 0 && j == 0) continue;
				if (p.first.first + j < 0 || w <= p.first.first + j) continue;
				if (p.first.second + i < 0 || h <= p.first.second + i) continue;
				if (s[p.first.second + i][p.first.first + j] == '#') continue;
				if (abs(i) + abs(j) <= 1) deq.push_front(pair<P, int>(P(p.first.first + j, p.first.second + i), p.second));
				else deq.push_back(pair<P, int>(P(p.first.first + j, p.first.second + i), p.second + 1));
			}
		}
	}

	if (mp[dh][dw] == iINF) cout << -1 << endl;
	else cout << mp[dh][dw] << endl;
	return 0;
}

Measured memory_bytes: 10540
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool ok, flag;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

struct Weighted_Graph {
  struct edge { ll node, cost; };
  vector<vector<edge>> e;

  void set(ll x) { e.resize(x + 1); }

  void add_edge(ll a, ll b, ll c) { e[a].pb(edge{ b,c }); }

  vll dijkstra(ll start) {
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll u;
	pll p;
	vll dist(e.size(), inf);
	dist[start] = 0;
	pq.push(pll(0, start));

	while (!pq.empty()) {
	  p = pq.top(); pq.pop();
	  u = p.second;
	  if (dist[u] < p.first) continue;
	  for (edge e1 : e[u]) {
		if (dist[e1.node] > dist[u] + e1.cost) {
		  dist[e1.node] = dist[u] + e1.cost;
		  pq.push(pll(dist[e1.node], e1.node));
		}
	  }
	}
	return dist;
  }

  void floyd(vvll &dist) {
	ll x = e.size();
	dist.resize(x);
	rep(i, x) dist[i].resize(x, inf);
	rep(i, x) dist[i][i] = 0;
	rep(i, x) rep(j, e[i].size()) dist[i][e[i][j].node] = e[i][j].cost;
	rep(k, x) {
	  rep(i, x) {
		if (dist[i][k] == inf) continue;
		rep(j, x) {
		  if (dist[k][j] == inf) continue;
		  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
		}
	  }
	}
  }

  bool bellmanford(ll start, vll &dist) {
	ll x = e.size(), cou = 0;
	if (dist.size() == 0) {
	  dist.resize(x, inf);
	  dist[start] = 0;
	}
	while (1) {
	  bool cycle = false;
	  rep(i, n) {
		rep(j, e[i].size()) {
		  if (dist[i] != inf && dist[e[i][j].node] > dist[i] + e[i][j].cost) {
			dist[e[i][j].node] = dist[i] + e[i][j].cost;
			cycle = true;
			if (cou == x) return cycle;
		  }
		}
	  }
	  cou++;
	  if (!cycle) break;
	}
	return false;
  }

};

int main(void) {
  Weighted_Graph wg;
  vll d;
  ll a, b, c;
  cin >> n >> m;
  wg.set(n);
  FOR(i, 0, m) {
	cin >> a >> b >> c;
	a--; b--;
	wg.add_edge(a, b, -c);
  }

  wg.bellmanford(0, d);
  tmp = d[n - 1];
  wg.bellmanford(0, d);
  ans = d[n - 1];
  if (tmp != ans) {
	cout << "inf" << endl;
  }
  else {
	cout << -ans << endl;
  }

  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define LEN 1000005

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
    
}

P dequeue(P que, int q){
    
    if (que.t - q <= 0) {
        que.t = 0;
    }else{
        que.t = que.t - q;
    }

    return que;
}


int main(){
    int elaps = 0, c = 0;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    
    for ( i = 1; i <= n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    i = 1;
    while(1){
        
        u = dequeue(Q[i],q);
        if (u.t == 0) {
            c += Q[i].t;
            printf("%s ",Q[i].name);
            printf("%d\n",c);
            n--;
        }else{
            c += q;
            Q[i+n] = u;
        }
        
        if (n == 0)break;
        i++;
        
        
    }
    
    return 0;
}



Measured memory_bytes: 21000
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int x;
	cin >> x;
	if (x <= 3){
		cout << 1 << endl;
		return 0;
	}

	vector<int> vec;
	for (int i = 2; i < 40; i++){
		if (pow(i, 2) <= x){
			int tmp = 2;
			while (pow(i, tmp) <= x){
				tmp++;
			}
			vec.push_back(pow(i, tmp-1));
		}
	}
	sort(vec.begin(), vec.end(), greater<int>());
	cout << vec[0] << endl;
	return 0;
}


Measured memory_bytes: 4072
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long g[420][12];
int x[120000],y[120000],p[420];
int n,m,ans;
bool find(int o,int x){
	int k=x/50;x%=50;
	return (g[o][k]&(1LL<<x))>0;
}
int add(int o,int x){
	int k=x/50;x%=50;
	g[o][k]|=1LL<<x;
}
int solve(int o){
	add(o,o);
	for(int i=m;i>=1;i--){
		int fx=find(o,x[i]),fy=find(o,y[i]);
		if(fx+fy==0)continue;
		if(fx+fy==2){
			p[o]=1;
			return 0;
		}
		if(fx==0)add(o,x[i]);
		if(fy==0)add(o,y[i]);
	}
}
int cal(int x,int y){
	for(int i=0;i<=8;i++)if(g[x][i]&g[y][i])return 0;
	return 1;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&x[i],&y[i]);
	for(int i=1;i<=n;i++)solve(i);
//	for(int i=1;i<=n;i++)printf("%d\n",g[i][0]);
	for(int i=1;i<=n;i++){
		if(p[i])continue;
		for(int j=i+1;j<=n;j++){
			if(p[j])continue;
			ans+=cal(i,j);
	//		if(cal(i,j)==1)
	//		printf("%d %d\n",i,j);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i += 2)
  {
    int count = 0;
    for (int j = 1; j <= i; j++)
    {
      if (i % j == 0)
        count++;
    }
    if (count == 8)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a_can, b_can = map(int, input().split())

if (a_can + b_can) % 3 == 0:
    print('Possible')
elif a_can % 3 == 0:
    print('Possible')
elif b_can % 3 == 0:
    print('Possible')
else:
    print('Impossible')

Measured memory_bytes: 9164
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,x;cin >> n >> x;
    vi a(n);
    rep(i, n) cin >> a[i];
    int count = 0;
    rep(i, n) {
        if(i==0) {
            if(a[i]>x) {
                count+=a[i]-x;
                a[i]=x;
            }
        }
        else {
            if(a[i-1]+a[i]>x) {
                count+=a[i]+a[i-1]-x;
                a[i]=x-a[i-1];
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 4024
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int A=stdIn.nextInt();int B=stdIn.nextInt();int C=stdIn.nextInt();
		if(A==B&&A!=C)
			System.out.println("Yes");
		else
			if(B==C&&B!=A)
				System.out.println("Yes");
			else
				if(A==C&&A!=B)
					System.out.println("Yes");
				else
					System.out.println("No");
	}
}


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

#define ll           long long
#define pii          pair<ll,ll>
#define bug(a)       cerr << #a << " : " << a << endl;
#define FastRead     ios_base::sync_with_stdio(false);cin.tie(NULL);

const int MAX = 5e5+10;

int main()
{
#ifdef Aaman007
    freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
#endif // Aaman007

    ll n,a,b,x,y;

    cin >> n >> a >> b;

    ll c1 = 1e18, c2 = 1e18, c3 = 1e8;;

    if((b-a)%2 == 0)
        c1 = b-a , c1 /= 2;

    x = a, y = b;
    c2 = a-1;
    a = 1;
    b -= c2;

    if((b-a)%2 == 1)
    {
        c2++;
        b--;
    }
    if(a != b)
        c2 += (b-a)/2;

    a = x, b = y;
    c3 = n-b;
    b = n;
    a += c3;

    if((b-a)%2 == 1)
    {
        c3++;
        a++;
    }
    if(a != b)
        c3 += (b-a)/2;

    cout << min({c1,c2,c3}) << endl;
}


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

#define int long long

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

    string str;
    cin>>str;

    int ctr=0;

    for(int i=0;i<n;i++)
    {
        if(str[i]=='R')
        {
            ctr++;
        }
    }

    int ans=0;

    for(int i=0;i<ctr;i++)
    {
        if(str[i]=='W')
            ans++;
    }

    cout<<ans;
}

Measured memory_bytes: 3748
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;
#define ll long long
int main(){
	int N;
	cin >> N;
	int i;
	ll tmp;
	ll ans=0;
	for(i=0;i<N;i++){
		cin >> tmp;
		ans+=tmp-1;
	}
	cout <<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

	for(int i=0;i<N;i++){
		int x,y,b,p;
		cin>>x>>y>>b>>p;

		int futsu=x*b+y*p;
		int oome=(x*5+y*2+x*max(b-5,0)+y*max(p-2,0))*8/10;

		if(b>=5&&p>=2){
			cout<<futsu*8/10<<endl;
		}else if(oome<futsu){
			cout<<oome<<endl;
		}else{
			cout<<futsu<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
// A - Takahashi Calendar
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
// #define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define vecmax(v) (*max_element(v.begin(),v.end()))
#define range(v,x) (iota((v).begin(),(v).end(),(x)))
void bye(auto x, int code=0){cout<<(x)<<endl;exit(code);}
// int in(){int x;cin>>x;return x;}
int in(){int x;scanf("%d",&x);return x;}
// template<class T> T in(){T x;cin>>x;return x;}

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
void vvprn(vector<vector<int>> &vv){ for(auto v:vv) vprn(v); }

// template<class T> void vprn(T &v, string s, string m, string e)
// {cout<<s;for(int i=0;i<v.size();i++)cout<<v[i]<<m;cout<<e;}
// template<class T> void vvprn(T &vv, string s, string m, string e)
// {for(auto v:vv) vprn(v,s,m,e);}

#define otreal(n,p) cout<<fixed<<setprecision(p)<<(n)

int main(){
	int M,D;
	cin>>M>>D;
	int ans = 0;
	up(m,1,M+1,1){
		up(d,2,D+1,1){
			int d10=d/10, d1=d%10;
			if(d10<2 || d1<2) continue;
			if(m==d10*d1){
				// cout<<m<<"/"<<d<<"\n";
				ans++;
			}
		}
	}

	ote(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

int main() {
  ll n, k;
  cin >> n >> k;
  cout << min(abs(n%k - k), n%k);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=105;
const long long INF=1000000000000LL;
int h[maxn],mem;
struct
{
    int v,next;
    long long cap;
}e[maxn*maxn];
void add(int u,int v,long long cap)
{
    e[mem].v=v;
    e[mem].cap=cap;
    e[mem].next=h[u];
    h[u]=mem++;

    e[mem].v=u;
    e[mem].cap=0;
    e[mem].next=h[v];
    h[v]=mem++;
}
int a[maxn];
void init()
{
    memset(h,-1,sizeof(h));mem=0;
}
int q[maxn],head,tail;
int dis[maxn];
bool BFS(int s,int t)
{
    memset(dis,127,sizeof(dis));
    dis[s]=0;
    head=tail=0;
    q[tail++]=s;
    while(head<tail)
    {
        int u=q[head++];
        for(int i=h[u];i+1;i=e[i].next)
        {
            int v=e[i].v;
        //printf("%d  %d\n",u,v);
            if(dis[v]>dis[u]+1&&e[i].cap){
                dis[v]=dis[u]+1;
                q[tail++]=v;
            }
        }
    }
    return dis[t]<100000;
}
long long DFS(int u,long long limit,int t)
{
    //printf("%d %I64d %d\n",u,limit,t);
    if(u==t) return limit;
    long long ans=0;
    for(int i=h[u];i+1;i=e[i].next)
    {
        int v=e[i].v;
        if(dis[v]==dis[u]+1&&e[i].cap)
        {
            long long tmp=DFS(v,min(e[i].cap,limit-ans),t);
            if(tmp){
                e[i].cap-=tmp;
                e[i^1].cap+=tmp;
                ans+=tmp;
            }
        }
    }
    if(ans==0) dis[u]=-2;
    return ans;
}
long long dinic(int s,int t)
{
    long long ans=0;
    while(BFS(s,t))
    {
        //printf("%d %d\n",s,t);
        long long tmp;
        while(tmp=DFS(s,INF,t))
            ans+=tmp;
        //printf("ans is %lld \n",ans);
        //break;
    }
    return ans;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int s=0,t=n+1;
    init();
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i)
        {
            add(i,j,INF);
        }
    }
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>0){
            ans+=a[i];
            add(i,t,a[i]);
        }
        else if(a[i]<0){
            add(s,i,-a[i]);
        }
    }
    long long fl=dinic(s,t);
    ans-=fl;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int[] num = new int[6];
		for(int i=0; i<num.length; i++){
			num[i] = sc.nextInt();
		}

		Dice dice = new Dice(num);

		char[] direction = sc.next().toCharArray();

		for(int i=0; i<direction.length; i++){
			dice.lotate(direction[i]);
		}

		System.out.println(dice.getUpside());

	}

	static class FastScanner
    {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	static class Dice {

		//0:?????¢???1:S??´??¢???2:E??´??¢???3:W??´??¢???4:N??´??¢???5:?????¢
		int[] num;

		Dice(int[] num){
			this.num = num;
		}

		int getUpside(){
			return num[0];
		}

		void lotate(char direction){
			int temp;
			switch(direction){
			case 'N':
				temp = num[0];
				num[0] = num[1];
				num[1] = num[5];
				num[5] = num[4];
				num[4] = temp;
				break;

			case 'S':
				temp = num[0];
				num[0] = num[4];
				num[4] = num[5];
				num[5] = num[1];
				num[1] = temp;
				break;

			case 'W':
				temp = num[0];
				num[0] = num[2];
				num[2] = num[5];
				num[5] = num[3];
				num[3] = temp;
				break;

			case 'E':
				temp = num[0];
				num[0] = num[3];
				num[3] = num[5];
				num[5] = num[2];
				num[2] = temp;
				break;
			}
		}

	}

}

Measured memory_bytes: 24364
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N;
	int i;
	cin>>N;
	LL ans=0;
	for (i=1;i<=N;i++){
		if (i%3==0 && i%5==0){
		}else if (i%3==0){
		}else if (i%5==0){
		}else{
			ans+=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.*;
import java.awt.*;
import java.awt.geom.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        char[] s=sc.next().toCharArray();
        char[] t=sc.next().toCharArray();
        TreeSet<String> ts=new TreeSet<>();
        int sizeS=s.length;
        int sizeT=t.length;
        for (int i = 0; i <= sizeS-sizeT; i++) {
            int count=0,temp=0;
            for (int j = i; j < sizeT+i; j++) {
                if(s[j]=='?'||s[j]==t[j-i]){
                    count++;
                    temp=i;
                }
            }
            if(count==sizeT){
                String ans="";
                //out.println("temp="+temp);
                for (int j = 0; j < sizeS; j++) {
                    //out.println("j="+j);
                    //out.println("ans="+ans);
                    if(j<temp){
                        if(s[j]=='?')ans+='a';
                        else ans+=s[j];
                    }else{
                        if(j-temp<sizeT)ans+=t[j-temp];
                        else if(s[j]=='?')ans+='a';
                        else ans+=s[j];
                    }
                }
                ts.add(ans);
            }
        }
        out.println(ts.size()==0?"UNRESTORABLE":ts.pollFirst());
    }
}


Measured memory_bytes: 23252
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int a,b,k;
	std::cin >> k >> a >> b; --a;
	std::cout << ((b/k-a/k)?"OK":"NG") << std::endl;
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
int main()
{
    long N;
    int n(1);
    long i, j;
    std::cin >> N;
    while (n <= std::sqrt(N))
    {
        if (N % n == 0)
        {
            i = n, j = N / n;
        }
        n++;
    }
    std::cout << i + j - 2 << std::endl;
}

Measured memory_bytes: 256
import heapq
n, m = [int(i) for i in input().split()]
a = [-int(i) for i in input().split()]
heapq.heapify(a)
for i in range(m):
    new_x = int(heapq.heappop(a) / 2)
    heapq.heappush(a, new_x)
print(-sum(a))

Measured memory_bytes: 14188
#include<bits/stdc++.h>
using namespace std;
 
template <int mod>
struct ModInt {
  int val;
  int trim(int x) const { return x >= mod ? x - mod : x < 0 ? x + mod : x; }
  ModInt(int v = 0) : val(trim(v % mod)) {}
  ModInt(const ModInt &v) : val(v.val) {}
  ModInt(long long v) : val(trim(v % mod)) {}
  ModInt &operator=(int v) { return val = trim(v % mod), *this; }
  ModInt &operator=(const ModInt &oth) { return val = oth.val, *this; }
  ModInt operator+(const ModInt &oth) const { return trim(val + oth.val); }
  ModInt operator-(const ModInt &oth) const { return trim(val - oth.val); }
  ModInt operator*(const ModInt &oth) const { return 1LL * val * oth.val % mod; }
  ModInt operator/(const ModInt &oth) const {
    function<int(int, int, int, int)> modinv = [&](int a, int b, int x, int y) {
      if (b == 0) return trim(x);
      return modinv(b, a - a / b * b, y, x - a / b * y);
    };
    return *this * modinv(oth.val, mod, 1, 0);
  }
  bool operator==(const ModInt &oth) const { return val == oth.val; }
  ModInt operator-() const { return trim(mod - val); }
  template<typename T> ModInt pow(T pw) {
    bool sgn = false;
    if (pw < 0) pw = -pw, sgn = true;
    ModInt ans = 1;
    for (ModInt cur = val; pw; pw >>= 1, cur = cur * cur) {
      if (pw&1) ans = ans * cur;
    }
    return sgn ? ModInt{1} / ans : ans;
  }
};
 
const int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
 
mint dp[1<<10][1<<10];
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int n, m; cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    string s; cin >> s;
    for (int j = 0; j < m; ++j) {
      if (s[j] == '.') {
        dp[i][j] = (i ? mint(dp[i - 1][j]) : 0) + (j ? mint(dp[i][j - 1]) : 0);
      }
      if (i == 0 and j == 0) dp[i][j] = 1;
    }
  }
  cout << dp[n - 1][m - 1].val << '\n';
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long target = sc.nextInt();
    int result = 0;
    long currentVal = 357;
    for (;;) {
       if (target >= currentVal) {
          result++;
       } else {
          break;
       }
       currentVal = nextVal(currentVal);
    }
    // 出力
    System.out.println(result);
  }
  private static long nextVal(long t) {
      String target = String.valueOf(t);
      for (;;) {
         target = roundUp(target, target.length() - 1);
         if (target.contains("3") && target.contains("5") && target.contains("7")) {
            break;
         }
      }
      return Long.valueOf(target);
  }
 
  private static String roundUp(String t, int n) {
      if (n < 0) {
         return "3" + t;
      }
      String a = t.substring(n,n+1);
      String replace = "";
      if (a.equals("3")) {
          replace = "5";
      } else if (a.equals("5")) {
          replace = "7";
      } else {
          if (n == t.length() - 1) {
             return roundUp(t.substring(0,n) + "3", n - 1);
          } else {
             return roundUp(t.substring(0,n) + "3" + t.substring(n+1, t.length()), n - 1);
          }
      }
      if (n == t.length() - 1) {
        return t.substring(0,n) + replace;
      } else {
        return t.substring(0,n) + replace + t.substring(n+1, t.length());
      }
  }
}

Measured memory_bytes: 36820
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int d[12] = {};

bool solve() {
  int n, m; cin >> n >> m;
  if (n == 0 and m == 0) return false;
    
  vector<pair<int,int>> info(n);
  for (int i = 0; i < n; i++) {
    int d, p; cin >> d >> p;
    info[i] = {p, d};
  }

  sort(RALL(info));
  for (int i = 0; i < n; i++) {
    swap(info[i].first, info[i].second);
  }

  for (int i = 0; i < n; i++) {
    if (info[i].first < m) {
      m -= info[i].first;
      info[i].first = 0;
    } else {
      info[i].first -= m;
      m = 0;
      break;
    }
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += info[i].first * info[i].second;
  }


  cout << ans << endl;
  return true;
}

int main() {
  
  while (solve()) {
  }
  return 0;
}



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

int main()
{
    string s,t;
    cin>>s>>t;
    int flag=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]==t[i])flag=1;
        else {flag=0;break;}
    }
    if(flag==0)cout<<"No";
    else cout<<"Yes";

    return 0;
}

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

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

  int a = 0;
  int b = 0;
  int ab = 0;

  // ABピザを2枚購入する方が、Aピザ・Bピザを1枚ずつ購入するより安い場合
  if ((C * 2) < (A + B)) {
    // 買える分だけABピザを買う
    int n = min(X, Y);
    ab = n * 2;

    int x_rest = X - n;
    int y_rest = Y - n;

    // Aピザ1枚 or ABピザ2枚の安い方で購入する
    if ((C * 2) < A) {
      ab += x_rest * 2;
    } else {
      a += x_rest;
    }

    // Bピザ1枚 or ABピザ2枚の安い方で購入する
    if ((C * 2) < B) {
      ab += y_rest * 2;
    } else {
      b += y_rest;
    }
  // ABピザを2枚購入した方が高い場合
  // Aピザ・Bピザを1枚ずつ購入する
  } else {
    // 買える分だけAピザ・Bピザを買う
    int n = min(X, Y);
    a += n;
    b += n;

    int x_rest = X - n;
    int y_rest = Y - n;

    // Aピザ1枚 or ABピザ2枚の安い方で購入する
    if ((C * 2) < A) {
      ab += x_rest * 2;
    } else {
      a += x_rest;
    }

    // Bピザ1枚 or ABピザ2枚の安い方で購入する
    if ((C * 2) < B) {
      ab += y_rest * 2;
    } else {
      b += y_rest;
    }
  }

  cout << (A * a + B * b + C * ab) << endl;
  return 0;
}

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

int N;
long long P[1001];

void factorize(int n){
	while(!(n % 2))
		P[2]++, n /= 2;
	for(int i = 3; i <= sqrt(n); i += 2)
		while(!(n % i))
			P[i]++, n /= i;
	if(n > 2) P[n]++;
}

int main(){
	scanf("%d", &N);
	for(int i = 2; i <= N; i++) factorize(i);
	long long res = 1;
	for(int i = 1; i < 1001; i++)
		if(P[i] > 0){
			res *= (P[i] + 1);
			res %= 1000000007;
		}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
#include <chrono>
#include <thread>

using namespace std;

//template<typename T>
//using Matrix2D = std::vector<vector<T>>;

const bool debug = false;

#ifndef M_PI
    const double M_PI = acos(-1.0);
#endif // M_PI

#define y1 roman_kaban
#define rank oryshych_konb
#define ull unsigned long long
//#define ll long long
//const int mod = int(1e9) + 7;
const int inf = 1e9;
//const long long infLL = 1e11;
//const int MX2 = 10100500; //  e7
//const long long INF = 1e18 + 0.5;
const int MX = 100500; //       e5
const int SZ = 1100;
//const int delta = 1 << 19;

int main()
{
    ios_base::sync_with_stdio(false);
    //if(debug)
  //  freopen("/Users/ozzy/Documents/in.txt","r", stdin);
    int n, t;
    cin >> n >> t;
    int ans = 0;
    int last = 0;
    for(int i =0 ; i < n; i++){
        int x;
        cin >> x;
        if(last < x) last = x;
        ans += x + t - last;
        last = x + t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


void solve() {
  // ある数が何回 2 番目になるか
  int n;
  cin >> n;
  vector<pii> a(n);
  rep(i, n) { cin >> a[i].F; a[i].S = i; }
  // すべての値が distinct
  sort(all(a), greater<pii>());

  // i より左に 1 つ i より大きいのある, 右に i より大きいのない
  // 逆も
  ll ans = 0;
  multiset<int> s;
  // 番兵
  s.insert(-1);
  s.insert(n);
  s.insert(-1);
  s.insert(n);

  rep(i, n) {
    int j = a[i].S;
    auto rl = s.upper_bound(j);
    // auto rr = --rl; error 
    auto rr = rl;
    rr++;

    auto lr = rl;
    lr--;
    auto ll = lr;
    ll--;

    // cout << *ll << " " << *lr << " " << *rl << " " << *rr << endl;

    bool b1 = (ll == s.begin()), b2 = (rr == --s.end());
    // cout << b1 << " " << b2 << endl;
    // 両側に i より大きいのない
    long long tmp = 0; // ll が衝突する
    if (b1 && b2) {

    } else if (b1) {
      // 右側に i より大きいのある
      // 左側は i を含めて端を選ぶ
      tmp = 1LL * (j + 1) * (*rr - *rl);
    } else if (b2) {
      tmp = 1LL * (n - j) * (*lr - *ll);
    } else {
      tmp = 1LL * (j - *lr) * (*rr - *rl);
      tmp += 1LL * (*lr - *ll) * (*rl - j);
    }
    tmp *= 1LL * a[i].F;
    ans += tmp;
    // cout << ans << endl;
    s.insert(a[i].S);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi 2*acos(0.0)
#define MOD 1000000007
#define N 100001
#define SZ 100000
int fx[5]= {0,0,0,-1,1};
int fy[5]= {0,-1,1,0,0};
int main()
{
    int a,b,i;
    cin>>a>>b;
    int ara[a];
    if(2*a<=b && 4*a>=b && b%2==0)
    {
        cout<<"Yes"<<endl;
    }
    else if(b%2!=0 || 2*a>b)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
N, M = map(int, input().split())

foods = list(range(1, M+1))

for i in range(N):
    fav_food = list(map(int, input().split()))
    fav_food = fav_food[1:]
    foods = [food for food in foods if fav_food.count(food) == 1]     
    

print(len(foods))


Measured memory_bytes: 2940
require 'set'

@n,@q = gets.split.map(&:to_i)
@s = gets.split("").map(&:to_sym)
@q = (1..@q).map{s,d=gets.split;[s.to_sym, d== 'L' ? -1:1]}
@memo = {}
def check(i)
    if @memo.key?(i) then
        return @memo[i]
    end
    cur = i
    @q.each{|s,d|
        if (s != @s[cur]) then
            next
        end
        cur+=d
        if cur == -1 || cur == @n then
            break
        end
    }
    @memo[i]=cur
    return cur
end
dropped = ((0...@n).bsearch{|i| check(i) >=0} || @n)
dropped+= (@n - ((0...@n).bsearch{|i| check(i) == @n} || @n))
puts (@n- dropped)

Measured memory_bytes: 28668
#include<bits/stdc++.h>
using namespace std;
char rem[100005];
const long long int MOD=1000000007;
long long int dp[100005][4];
int l;
long long int serc(int x, int e){
	if (x==l){
		if (e==3){
			return 1;
		}
		return 0;
	}
	if (dp[x][e]!=-1){
		return dp[x][e];
	}
	dp[x][e]=0;
	if (rem[x]=='?'){
		dp[x][e]+=(3*serc(x+1,e))%MOD;
		dp[x][e]%=MOD;
		if (e<3){
			dp[x][e]+=serc(x+1,e+1)%MOD;
			dp[x][e]%=MOD;
		}
	}
	else{
		if (rem[x]-'A'==e){
			dp[x][e]+=serc(x+1,e+1);
			dp[x][e]%=MOD;
		}
		dp[x][e]+=serc(x+1,e);
		dp[x][e]%=MOD;
	}
	return dp[x][e];
}
int main(){
	scanf("%s",rem);
	l=strlen(rem);
	for (int i=0;i<l;i++){
		dp[i][0]=dp[i][1]=dp[i][2]=dp[i][3]=-1;
	}
	printf ("%lld\n",serc(0,0));
}

Measured memory_bytes: 8192
n,a,b=map(int,input().split())
if (a+b)%2==1: 
    if (n-b)>(a-1):
        print(a+(b-a-1)//2)
    else:
        print(((n-b)+1)+(b-a-1)//2)
else:
    print((b-a)//2)

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

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

	int ans = 1;
	rep(i, 3) {
		ans *= n;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  vector<int> vec(5);
  for (int i=0; i<5; i++)
   cin>>vec.at(i);
  int a=0;
  for (int i=0; i<5; i++){
    if (vec.at(i)!=i+1)
      a=i+1;
  }
  cout<<a<<endl;
}
  

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

using namespace std;

int main(void){
  int n, m;
  cin >> n >> m;
  string in;
  cin >> in;
  if(in.size() == n + m + 1 && in[n] != '-'){
    puts("No");
    return 0;
  }
  for(int i = 0; i < in.size(); ++i){
    if(i == n)continue;
    if(!isdigit(in[i])){
      puts("No");
      return 0;
    }
  }
  if(in.size() != n + m + 1)
    puts("No");
  else puts("Yes");
}

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

int main()
{
  int N ;
  string color ;
  bool yellow = false ;
  
  cin >> N ;
  
  for(int i=0; i<N; i++)
  {
    cin >> color ;
    
    if(color=="Y")
    {
      yellow = true ;
      break ;
    }
  }
  
  if(yellow==true)
  {
    cout << "Four" << endl ;
  }else{
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import datetime

# 入力
#N = int(input())
#S = str(input())
#H, W = map(int, input().split())
P, Q, R = map(int, input().split())

list = []
list.append(P)
list.append(Q)
list.append(R)
list.sort()

print (list[0] + list[1])


Measured memory_bytes: 3312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,k;
    cin>>a>>b>>k;
    if(k==0)
    {
        cout<<a<<" "<<b<<endl;
        return 0;
    }
    if(a+b<=k)
    {
        cout<<0<<" "<<0<<endl;
        return 0;
    }
    if(a>=k)
    {
        cout<<(a-k)<<" "<<b<<endl;
        return 0;
    }
    if(a==0&&b>k)
    {
        cout<<0<<" "<<b-k<<endl;
        return 0;
    }
    if(a<=k&&b>=(k-a))
    {
        cout<<0<<" "<<b-(k-a)<<endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long dp[100010];
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int N, K, h[100000];
  cin >> N >> K;
  rep(i,N){
    cin >> h[i];
  }
  rep(i,100010){
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int i=0;i<N;i++){
    for(int j=1;j<=K;j++){
      chmin(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
    }
  }
  cout << dp[N-1] << endl;
}


Measured memory_bytes: 4780
from collections import deque
def main():
    H, W = map(int, input().split())
    sh,sw = map(int, input().split())
    gh,gw = map(int, input().split())
    gh,gw = gh-1,gw-1
    field = [list(input()) for _ in range(H)]
    q = deque()
    q.append((0, sh-1, sw-1))
    INF = 10 ** 30
    dist = [[INF] * W for _ in range(H)]
    dist[sh-1][sw-1] = 0
    while q:
        cnt, h, w = deque.popleft(q)
        if dist[h][w] < cnt: continue
        if h == gh and w == gw: return cnt
        for i in range(-2, 3):
            for j in range(-2, 3):
                nh = h+i
                nw = w+j
                if nh < 0 or nw < 0: continue
                if nh >= H or nw >= W: continue
                if field[nh][nw]  == "#": continue
                if (i, j) in ((1,0),(0,1),(-1,0),(0,-1)):
                    if dist[nh][nw] <= cnt: continue
                    dist[nh][nw] = cnt
                    deque.appendleft(q, (cnt, nh, nw))
                else:
                    if dist[nh][nw] <= cnt+1: continue
                    dist[nh][nw] = cnt+1
                    deque.append(q, (cnt+1, nh, nw))
    return -1

print(main())


Measured memory_bytes: 157100
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    rep(i, n){
        int A;
        cin >> A;
        a[i] = {A, i+1};
    }
    sort(a.begin(),a.end());
    rep(i, n) cout << a[i].second << ' ';
    cout << endl;
}

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

int main(){
 int N;
 cin >> N;
 vector<int> A(N);
 vector<int> B(N-1);
 for(int i = 0;i<N-1;i++){
   cin >> B[i];
 }
  A[0] = B[0];
  A[N-1] = B[N-2];
  
  for(int i = 1;i<=N-2;i++){
    A[i] = min(B[i-1],B[i]);
  }
  ll ans = 0;
   for(int i = 0;i<N;i++){
   ans += A[i];
 }
  cout << ans <<endl; 
}

Measured memory_bytes: 256
n=int(input())
t=[0]
x=[0]
y=[0]
for i in range(n):
   s=list(map(int,input().split()))
   t.append(s[0])
   x.append(s[1])
   y.append(s[2])

for i in range(n):
    dt=t[i+1]-t[i]
    dx=x[i+1]-x[i]
    dy=y[i+1]-y[i]
    dl=abs(dx)+abs(dy)
    if dl<=dt and dt%2==dl%2:
        continue
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 17452
def lcm(x, y):
    return x * y // gcd(x, y)

def gcd(x, y):
    if y== 0:
        return x
    else:
        return gcd(y, x % y)


def main():

    A, B = map(int, input().split())
    print(lcm(A, B))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif


string ans[1<<20];
char s[32];
char t[32];

int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif
    while(~scanf("%s",s) && s[0]!='#'){
        int sz = 0;
        int n = strlen(s);
        rep(i,n) t[i] = s[i];
        t[n] = 0;
        int change[32];
        rep(mask,1<<n){
            bool ok = true;
            rep(i,n){
                ok &= s[i]!='z' || ~mask>>i&1;
            }
            if(!ok) continue;
            rep(i,n){
                t[i] = s[i] + (mask>>i & 1);
            }
            rep(i,26){
                change[i] = 30;
            }
            rep(i,n){
                change[t[n-i-1]-'a'] = n-i-1;
            }
            change[0] = 30;
            rep(i,26){
                t[change[i]]--;
            }
            if(strcmp(t,s)==0){
                rep(i,n){
                    t[i] = s[i] + (mask>>i&1);
                }
                ans[sz++] = t;
            }
        }
        sort(ans, ans + sz);
        printf("%d\n",sz);
        if(sz > 10){
            rep(i,5) printf("%s\n", ans[i].c_str());
            rep(i,5) printf("%s\n", ans[sz-5+i].c_str());
        } else {
            rep(i,sz){
                printf("%s\n",ans[i].c_str());
            }
        }
    }
}

Measured memory_bytes: 10496
#include<iostream>
#include<cstdio>
#include<string>

using namespace std;

int n;
string s;
int a[27];
int minn[51];

int main()
{
   	cin>>n;
	for(int i=1;i<=26;i++)minn[i]=10086;
    for(int i=1;i<=n;i++)
    {
		for(int j=1;j<=26;j++)a[j]=0;
        cin>>s;
        for(auto j:s)a[j-'a'+1]++;
		for(int j=1;j<=26;j++)minn[j]=min(minn[j],a[j]);
    }
    for(int i=1;i<=26;i++)
		for(int j=1;j<=minn[i];j++)putchar('a'+i-1);
}

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

using namespace std;

int main() {
  int n, x, t;
  cin >> n >> x >> t;
  int a;
  if(n % x == 0) a = n / x;
  else a = (n / x) + 1;
  cout << t * a << '\n';
  
  return 0;
} 

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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;
typedef pair<int, int> ii;
typedef long long ll;
int deg[1000007];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;

    for(int i = 2; i <= n; ++i) {
        int a; cin >> a;
        deg[a]++;
    }

    for(int i = 1; i <= n; ++i) cout << deg[i] << '\n';
    cout << endl;
}

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

int main() {
  int N;
  int k, l, m, n;
    k = 0;
    l = 0;
    m = 0;
    n = 0;
  cin >> N;
  for ( int i = 0; i < N; i++){
    string co;
    cin >> co;
    if ( co == "G"){
      k = 1;
    }
    if ( co == "W"){
      l = 1;
    }
    if ( co == "P"){
      m = 1;
    }
    if ( co == "Y"){
      n = 1;
    }
  }
  int d;
  d = k + l + m + n;
  if (d == 1){
    cout << "One" << endl;
  }
   if (d == 2){
    cout << "Tue" << endl;
  }
   if (d == 3){
    cout << "Three" << endl;
  }
   if (d == 4){
    cout << "Four" << endl;
  }
      
      
}

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

    
int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i).first;
        a.at(i).second=i;
    }
    sort(a.rbegin(),a.rend());
    
    for(int i=0;i<n;i++){
        if(a.at(0).second != i){cout << a.at(0).first << endl;}
        else{
            cout << a.at(1).first << endl;  
        } 
    } 
}

Measured memory_bytes: 3200