akhauriyash/Code-Regression huggingface dataset:
import scala.collection.mutable

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val V, E = sc.nextInt()
    val G = Array.fill(V + 1)(List[Int]())
    (0 until E) foreach { _ =>
      val u, v = sc.nextInt()
      G(u) ::= v
    }

    def solve(V: Int, E: Int, G: Array[List[Int]]): Option[IndexedSeq[Int]] = {
      val visited = new Array[Boolean](V+1)
      val cycle = new Array[Boolean](V+1)

      def findCyclic(stack: List[Int]): Boolean =
        if (stack.nonEmpty) {
          val u = stack.head
          if (u > 0) {
            if (cycle(u)) {
              val copiedCycle = cycle.clone()
              if (check(takeEdges(u, u, stack.tail, mutable.Set.empty, copiedCycle), copiedCycle)) {
                takeEdges(u, u, stack.tail, mutable.Set.empty, cycle)
                true
              } else findCyclic(stack.tail)
            } else {
              cycle(u) = true
              visited(u) = true
              findCyclic(G(u).foldRight(-u :: stack.tail)((v, stack) => v :: stack))
            }
          } else {
            cycle(-u) = false
            findCyclic(stack.tail)
          }
        } else false

      def check(edges: Set[(Int, Int)], cycle: Array[Boolean]): Boolean =
        ((1 to V) filter cycle) flatMap (u => G(u).map((u, _))) forall { edge =>
          edges.contains(edge) || !cycle(edge._2)
        }

      def takeEdges(before: Int, start: Int, stack: List[Int], edges: mutable.Set[(Int, Int)], cycle: Array[Boolean]): Set[(Int, Int)] =
        if (stack.nonEmpty) {
          val u = stack.head
          if (-u == start) {
            removeOthers(stack.tail, cycle)
            edges.add((-u, before))
            edges.toSet
          } else {
            if (u < 0) {
              edges.add((-u, before))
              takeEdges(-u, start, stack.tail, edges, cycle)
            } else
              takeEdges(before, start, stack.tail, edges, cycle)
          }
        } else edges.toSet // unreachable.

      def removeOthers(stack: List[Int], cycle: Array[Boolean]): Unit =
        if (stack.nonEmpty) {
          val u = stack.head
          if (u < 0) cycle(-u) = false
          removeOthers(stack.tail, cycle)
        }

      def loop(s: Int): Option[IndexedSeq[Int]] =
        if (s <= V) {
          if (!visited(s) && findCyclic(s :: Nil)) Some((1 to V) filter cycle)
          else loop(s + 1)
        } else None

      loop(1)
    }

    solve(V, E, G) match {
      case Some(r) => println(r.size); println(r.mkString("\n"))
      case None => println(-1)
    }
  }

}


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

using namespace std;

int h, w, n;
int r, c;
string s, t;

int main() {
	cin >> h >> w >> n >> r >> c >> s >> t;
	r--; c--;
	int lb = 0, rb = w;
	for (int i = n-1; i >= 0; i--) {
		if (t[i] == 'L') rb = min(rb+1, w);
		if (t[i] == 'R') lb = max(0, lb-1);
		if (s[i] == 'L') lb++;
		if (s[i] == 'R') rb--;
		if (lb >= rb) {
			cout << "NO\n";
			return 0;
		}
	}
	if (c < lb || c >= rb) {
		cout << "NO\n";
		return 0;
	}
	int ub = 0, bb = h;
	for (int i = n-1; i >= 0; i--) {
		if (t[i] == 'U') bb = min(bb+1, h);
		if (t[i] == 'D') ub = max(0, ub-1);
		if (s[i] == 'U') ub++;
		if (s[i] == 'D') bb--;
		if (ub >= bb) {
			cout << "NO\n";
			return 0;
		}
	}
	if (r < ub || r >= bb) {
		cout << "NO\n";
		return 0;
	}
	cout << "YES\n";
	return 0;
}


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

ll n;
ll a[100010];

long long GCD(long long a, long long b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

long long LCM(long long a, long long b)
{
    return a * b / (GCD(a, b));
}

int main()
{
    cin >> n;
    cin >> a[0] >> a[1];
    ll ans = GCD(a[0], a[1]);
    for (int i = 2; i < n; i++)
    {
        cin >> a[i];
        ans = GCD(a[i], ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};

char s[N];
int f[N],c[N];
int ans[N];

int main(){
	int n = ci();
	scanf("%s",s+1);
	int cnt = 0;
	rep(i,1,n) cnt += s[i]=='1';
	if( cnt==0 ){
		rep(i,1,n) printf("1\n");
		return 0;
	}
	rep(i,1,cnt){
		c[i] = c[i&(i-1)]+1;
		f[i] = f[i%c[i]]+1;
	}
	if( cnt==1 ){
		rep(i,1,n){
			if( s[i]=='1' ) printf("0\n");
			if( s[i]=='0' ){
				if( i==n ){
					printf("2\n");
					continue;
				}
				if( s[n]=='1' ) printf("2\n");
				if( s[n]=='0' ) printf("1\n");
			}
		}
		return 0;
	}
	int pow2x = 1, pow2y = 1;
	int nx=0, ny=0;
	rev_rep(i,n,1){
		if( s[i]=='1' ){
			nx = (nx+pow2x)%(cnt-1);
			ny = (ny+pow2y)%(cnt+1);
		}
		pow2x = pow2x*2%(cnt-1);
		pow2y = pow2y*2%(cnt+1);
	}
	pow2x = 1, pow2y = 1;
	rev_rep(i,n,1){
		if( s[i]=='1' ){
			ans[i] = f[(nx-pow2x+cnt-1)%(cnt-1)]+1;
		}else{
			ans[i] = f[(ny+pow2y+cnt+1)%(cnt+1)]+1;
		}
		pow2x = pow2x*2%(cnt-1);
		pow2y = pow2y*2%(cnt+1);
	}
	rep(i,1,n) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 3492
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std; 
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
vector< vector <char> > board(8,vector<char>(8));
int check(int x,int y,char c)
{
  int res=0;
  if(board[y][x] !='.'){return 0;}
  for(int k=0;k<8;k++)
    {
      int nx=x;
      int ny=y;
      int count=0;
      while(true)
	{
	  nx +=dx[k];
	  ny +=dy[k];
	  if(nx < 0|| nx>=8 || ny<0 || ny>=8){ break;}
	  if(board[ny][nx]==c){res+=count;break;}
	  if(board[ny][nx]=='.'){break;}
	  count++;
	}
    }
  return res;
}
void put(int x,int y,char c)
{
  board[y][x]=c;
  for(int k=0;k<8;k++)
    {
      int nx=x;
      int ny=y;
      while(true)
	{
	  nx +=dx[k];
	  ny +=dy[k];
	  if(nx < 0|| nx>=8 || ny<0 || ny>=8){ break;}
	  if(board[ny][nx]==c){
	    while(1)
	      {
		nx -=dx[k];
		ny -=dy[k];
		if(nx == x && ny == y){break;}
		board[ny][nx]= c;
	      }
	    break;
	  }
	  if(board[ny][nx]=='.'){break;}
	}
    }
}

bool win()
{
  int o_count=0;
  int x_count=0;
  for(int x=0;x<8;x++)
    {
      for(int y=0;y<8;y++)
	{
	  if(board[x][y]=='o'){o_count++;}
	  if(board[x][y]=='x'){x_count++;}
	}
    }
  return o_count==0 || x_count==0 || o_count+x_count==64;
}
    
int main()
{
  for(int i=0;i<8;i++)
    {
      for(int j=0;j<8;j++)
	{
	  cin >> board[i][j];
	}
    }
  int turn=1;
  int max_x,max_y;
  int pass=0;
  while(1)
    {
      char player=(turn % 2) ? 'o' : 'x';
      int num=0;max_x=-1,max_y=-1;
      if(player == 'o')
	{
	  for(int y=0;y<8;y++)
	    {
	      for(int x=0;x<8;x++)
		{
		  int tmp=check(x,y,player);
		  if(num <tmp)
		    {
		      num=tmp;
		      max_x=x;
		      max_y=y;
		    }
		}
	    }
	}
      else
	{
	  for(int y=7;y>=0;y--)
	    {
	      for(int x=7;x>=0;x--)
		{
		  int tmp=check(x,y,player);
		  if(num <tmp)
		    {
		      num=tmp;
		      max_x=x;
		      max_y=y;
		    }
		}
	    }
	}
      if(max_x != -1)
	{
	  pass=0;
	  put(max_x,max_y,player);
	}
      else
	{
	  pass++;
	}
      turn++;
      if(pass>1){break;}
      if(win()){break;}
    }
    
  for(int y=0;y<8;y++)
    {
      for(int x=0;x<8;x++)
	{
	  cout << board[y][x];
	}
      cout << endl;
    }
  return 0;
}
  

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999



int main(){
    int n;
    while(cin>>n&&n){
        int d[20][20]={};
        rep(i,n){
            rep(j,n+1){
                cin>>d[i][j];
            }
        }
        int dp[(1<<16)]={};
        rep(i,1<<16)dp[i]=INF;
        dp[0]=0;
        rep(i,n){
            vector<int> vec;
            rep(j,i)vec.pb(1);
            rep(j,n-i)vec.pb(0);
            sort(all(vec));
//            cout<<"vec ";rep(k,vec.size())cout<<vec[k];cout<<endl;
            do{
                int j=0;
                rep(k,n){
                    j*=2;
                    j+=vec[k];
                }
//                cout<<j<<endl;
                rep(k,n){
                    if((j&(1<<k))!=0)continue;
                    rep(l,n+1){
                        if( l!=0 && (j&(1<<(l-1)))==0 )continue;
//                        cout<<"dp["<<(j^(1<<k))<<"]="<<dp[(j^(1<<k))]<<" "<<dp[j]+d[k][l]<<endl;
                        dp[(j^(1<<k))]=min(dp[(j^(1<<k))],dp[j]+d[k][l]);
                    }
                }
            }while(next_permutation(all(vec)));
        }
        cout<<dp[(1<<n)-1]<<endl;
    }
}

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

using namespace std;

int main()
{
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    for (auto& a_i : a) {
        cin >> a_i;
    }

    long long ans = 0;
    for (int i = 1; i < N; ++i) {
        if (a[i - 1] + a[i] > x) {
            int d = min(a[i], a[i - 1] + a[i] - x);
            ans += d;
            a[i] -= d;
        }
        if (a[i - 1] + a[i] > x) {
            int d = min(a[i - 1], a[i - 1] + a[i] - x);
            ans += d;
            a[i - 1] -= d;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ll long long
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define pii pair<ll, ll>
#define ls rt << 1
#define rs rt << 1 | 1
#define sz(x) (int)(x).size()
#define ALL(x) (x).insgin(), (x).end()
#define vi vector<int>
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 100010;
const int M = 200010;
const int mod = 1e9 + 7;
struct Edge
{
	int to,w,next;
}e[M * 2];
struct Que
{
	int id;
	ll Dis;
	Que(int id = 0, ll Dis = 0):id(id),Dis(Dis){}
};
struct cmp
{
	bool operator()(const Que &a,const Que &b){ return a.Dis > b.Dis; }
};
priority_queue< Que, vector<Que>, cmp> q;
int n, m, st, ed, cnt, head[N], v[N];
ll Dis1[N], Dis2[N], way1[N], way2[N];
struct Node
{
    int x, y, w;
}sv[2 * M];
void insert(int x,int y,int w)
{
    e[++ cnt].to = y;
    e[cnt].w = w;
    e[cnt].next = head[x];
    head[x] = cnt;
}
void dijkstra(int s,ll Dis[],ll way[])
{
	rep(i, 1, n) Dis[i] = 2147483647ll * 1000000ll, way[i] = 0;
    memset(v, 0, sizeof(v));
    Dis[s] = 0;
    way[s] = 1;
    q.push(Que(s, 0));
    while (!q.empty())
    {
        Que x = q.top();
        q.pop();
        if (v[x.id]) continue;
        v[x.id] = 1;
        for(int p = head[x.id]; p; p = e[p].next)
        {
            if (x.Dis + e[p].w < Dis[e[p].to])
            {
                Dis[e[p].to] = x.Dis + e[p].w;
                way[e[p].to] = way[x.id];
                q.push(Que(e[p].to, Dis[e[p].to]));
            }
            else
            	if (x.Dis + e[p].w == Dis[e[p].to])
                	way[e[p].to] = (way[e[p].to] + way[x.id]) % mod;
        }
    }
}
int main()
{
	n = read();
	m = read();
	st = read();
	ed = read();
    rep(i, 1, m)
    {
        int x,y,w;
        x = read();
        y = read();
        w = read();
        insert(x, y, w);
        insert(y, x, w);
        sv[i].x = x; sv[i].y = y; sv[i].w = w;
        sv[i + m].x = y; sv[i + m].y = x; sv[i + m].w = w;
    }
    dijkstra(st, Dis1, way1);
    dijkstra(ed, Dis2, way2);

    ll ans = way1[ed] * way2[st] % mod;
    rep(i, 1, n)
        if (Dis1[i] == Dis2[i] && 2 * Dis1[i] == Dis1[ed])
            {
                ll t = way1[i] * way2[i] % mod;
                t = t * t % mod;
                ans = ((ans - t) % mod + mod ) % mod;
            }
    rep(i, 1, 2 * m)
    {
        int x = sv[i].x;
        int y = sv[i].y;
        int w = sv[i].w;
        if (Dis1[x] * 2 < Dis1[ed] && Dis1[y] * 2 > Dis1[ed] && Dis1[x] + w + Dis2[y] == Dis1[ed])
        {
            ll t = way1[x] * way2[y] % mod;
            t = t * t % mod;
            ans = ((ans - t) % mod + mod) % mod;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 15732
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // sort(), reverse()

using namespace std;
static const double EPS = 1e-10;

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

class Point
{
public:
	int x, y;

	Point(int x = 0, int y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }

	bool operator < (const Point &p) const {
		return y != p.y ? y < p.y : x < p.x;
	}
};

typedef Point Vector;
typedef vector<Point> Polygon;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}

double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

int
ccw(Point p0, Point p1, Point p2)
{
	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if (cross(a, b) > EPS)
		return COUNTER_CLOCKWISE;

	if (cross(a, b) < -EPS)
		return CLOCKWISE;

	if (dot(a, b) < -EPS)
		return ONLINE_BACK;

	if (norm(a) < norm(b))
		return ONLINE_FRONT;

	return ON_SEGMENT;
}

Polygon
andrewScan(Polygon s)
{
	Polygon u, l;
	int res;

	if (s.size() < 3)
		return s;

	sort(s.begin(), s.end()); // x, y ??????????????????????????????
	// x ????°????????????????????????? u ?????????
	u.push_back(s[0]);
	u.push_back(s[1]);

	// x ?????§???????????????????????? l ?????????
	l.push_back(s[s.size() - 1]);
	l.push_back(s[s.size() - 2]);

	// ??????????????¨?????????
	for (unsigned int i = 2; i < s.size(); ++i)
	{
		for (int n = u.size(); n >= 2; --n)
		{
			res = ccw(u[n - 2], u[n - 1], s[i]);
			if (res == CLOCKWISE || res == ONLINE_FRONT)
				break;

			u.pop_back();
		}

		u.push_back(s[i]);
	}

	// ??????????????¨?????????
	for (int i = s.size() - 3; i >= 0; --i)
	{
		for (int n = l.size(); n >= 2; --n)
		{
			res = ccw(l[n - 2], l[n - 1], s[i]);
			if (res == CLOCKWISE || res == ONLINE_FRONT)
				break;

			l.pop_back();
		}

		l.push_back(s[i]);
	}

	// ????¨????????????????????????????????????????????????????
	reverse(l.begin(), l.end());
	for (int i = u.size() - 2; i >= 1; --i)
		l.push_back(u[i]);

	return l;
}

int
main(int argc, char** argv)
{
	int n;
	Polygon s, r;
	Point p;

	scanf("%d", &n);
	while (n--)
	{
		scanf("%d %d", &p.x, &p.y);
		s.push_back(p);
	}

	r = andrewScan(s);
	printf("%ld\n", r.size());
	for (unsigned int i = 0; i < r.size(); ++i)
		printf("%d %d\n", r[i].x, r[i].y);

	return 0;
}

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

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map
#define mtv(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out( 
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cout << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    stringstream ss; ss << H;
    cout << args[idx] << "- " << ss.str() << ", ";
    debug_out(args, idx + 1, LINE_NUM, T...);
}

void doit(){
	ll n,d,i,x,y;
	cin >> n >> d;
	vector<ll>v(n);
	d *= d;
	ll ans = 0;
	rep(i,0,n){
		cin >> x >> y;
		v[i] = x*x+y*y;
		if(v[i] <= d)ans ++;
	}
	cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


Measured memory_bytes: 4752
N, M = map(int, input().split())
S = input()
T = input()

from fractions import gcd
GCD = gcd(N, M)
LCD = N * M // GCD
A = N // GCD
B = M // GCD
for i in range(GCD):
    if S[A * i] != T[B * i]:
        print(-1)
        exit()
print(LCD)



Measured memory_bytes: 5304
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
using namespace std::chrono;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n;--i)
#define pb push_back
#define us unordered_set<lli>
#define um unordered_set<lli>
#define m_p make_pair
#define Fs first
#define Sc second
#define endl "\n"
#define MOD 1000000007
#define present(c,x)    ((c).find(x) != (c).end())
#define sz(p) p.size()
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define mem(p,v) memset(p,(lli)v,sizeof p);
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
void show(vector<lli> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(vector<int> v)
{
    fr(i,0,v.size())
    cout<<v[i]<<" ";
    cout<<endl;
}
void show(int a[], int arraysize)
{
    for (int i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(lli a[], lli arraysize)
{
    for (lli i = 0; i < arraysize; ++i)
        cout << a[i] << " ";
    cout<<endl;
}
void show(unordered_set<int> s)
{
    for (auto it = s.begin(); it != s.end(); it++)
    {
        cout << *it << " ";
    }
    cout<<endl;
}
void show(unordered_map<lli,lli> mp)
{
    for (auto it = mp.begin(); it != mp.end(); it++)
    {
        cout << it->first << " "<<it->second<<endl;
    }
    cout<<endl;
}

int main()
{
    run;
    lli n,m,ans,k,a,b;
    string s,p;
    cin>>s>>p;
    a=0;
    fr(i,0,s.length())
    {
        if(s[i]!=p[i])
            a++;
    }
    cout<<a<<endl;
    return 0;
}



Measured memory_bytes: 3780
#include <iostream>
#include <algorithm>

constexpr int MAX_N = 101, MAX_W = 10001, MAX_VW = 1001;

int n, max_w, w[MAX_N], v[MAX_N], dp[MAX_N][MAX_W];

void fill_dp(){
    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= max_w; ++j){
            if(j < w[i]) dp[i + 1][j] = dp[i][j];
            else dp[i + 1][j] = std::max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
        }
    }
    return;
}

void solve(){
    fill_dp();
    std::cout << dp[n][max_w] << std::endl;
    return;
}

int main(){
    std::cin >> n >> max_w;
    for(int i = 0; i < n; ++i)
        std::cin >> v[i] >> w[i];
    solve();
    
    return 0;
}

Measured memory_bytes: 7004
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<utility>

typedef long long ll;
#define INF 1000000000
#define MOD 1000000007

using namespace std;

ll dp[100001];

int main() {
	double t, x;
	cin >> t >> x;
	cout << t/x << endl;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>

using namespace std;

int main(void){

  int A,B,X;

  cin >> A;
  cin >> B;
  cin >> X;

  if(A+B-X >= 0 and X>=A ) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


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

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

ll x,k;
vll a;

bool possible(ll mid)
{
    if(mid<=0) return false;
    ll cnt = 0;
    for(ll i=0;i<x;i++)
    {
        if(a[i]<=mid) continue;
        //cnt += ceil(a[i]/(mid+0.0))-1;
        cnt += (a[i]-1)/mid;
    }
    return cnt<=k;
}

int main()
{
    //fastio
    sffl(x,k);
    a.resize(x+1);
    for(ll i=0;i<x;i++) sfl(a[i]);
    ll mini = 0,maxi = 1e9+100;
    
    while (mini<maxi)
    {
        ll mid = (mini+maxi)/2;
        //cout<<mid<<endl;
        if(possible(mid))
        {
            maxi = mid;
        }
        else
        {
            mini = mid+1;
        }
    }
    cout<<mini<<endl;
    

    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    ll X = A * 60 + B;
    ll Y = C * 60 + D;
    cout << Y - X - E << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    map<ll, ll> cnt;
    ll ans = 0;
    rep(i, N) {
        ll a = A[i];
        ans += cnt[i - a];
        cnt[a + i]++;
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 27396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

double func(int a,int b,int c,int d){
    double dx = a - c;
    double dy = b -d;
    return pow(dx*dx + dy*dy,0.5);
}

int main(){
    int n;cin >> n;
    vector<int> x(n),y(n);
    rep(i,n) cin >> x[i] >> y[i];
    double sum=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            sum += func(x[i],y[i],x[j],y[j]) * 2 / n;
        }
    }
    cout << fixed << setprecision(10) << sum << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC113
{
	class Program
	{
		static void Main(string[] args)
		{
			int a, b, s;
			var word = Console.ReadLine(). Split(' ');
			a = int.Parse(word[0]);
			b = int.Parse(word[1]);
			s = 0;
			s = a + (b / 2);
			Console.WriteLine(s);
			Console.ReadKey();
		}
	}
}


Measured memory_bytes: 11092
def main():
  n, m = map(int, input().split())
  if n == 1 and m == 1:
    print(1)
  elif n == 1 or m == 1:
    print(max(n-2, m-2))
  else:
    print(n*m-2*(n+m)+4)
if __name__ == "__main__":
  main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
#define amin(a, b) a = min((a), (b))
using namespace std;
using ll = long long;
const ll INF = 10000000000000;
int main()
{
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2), t(b + 2);
    s[0] = t[0] = -INF;
    s.back() = t.back() = INF;
    rep(i, 0, a) cin >> s[i + 1];
    rep(i, 0, b) cin >> t[i + 1];

    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    rep(qq, 0, q)
    {
        ll x;
        cin >> x;

        vector<ll>::iterator s_itr = upper_bound(s.begin(), s.end(), x);
        vector<ll>::iterator t_itr = upper_bound(t.begin(), t.end(), x);
        
        ll ans = INF;
        rep(i, 0, 2)
        rep(j, 0, 2)
        {
            amin(ans, abs(x - *(s_itr-i)) + abs(*(s_itr-i) - *(t_itr-j)));
            amin(ans, abs(x - *(t_itr-j)) + abs(*(t_itr-j) - *(s_itr-i)));
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2944
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	i := 0
	var ans int64
	for l, r := 0, 0; r < n; r++ {
		for (i & aa[r]) != 0 {
			i ^= aa[l]
			l++
		}
		i |= aa[r]
		ans += int64(r - l + 1)
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}


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

int bl0[16]={};
int nx0[16]={};
int bl[16]={};
int nx[16]={};
int largest0[3]={};
int largest[3]={};

int main() {
	int n,m,k,a,b,s,l1,l2;
	int ss[2]={};
	while(1){
		cin >> n >> m;
		if(n==0){ return 0;}
		for(int i=0;i<3;i++){
			cin >> k;
			b=0;
			for(int j=0;j<k;j++){
				cin >> a;
				bl0[a]=i;
				nx0[a]=b;
				b=a;
			}
			largest0[i]=b;
		}
		
		for(int i=0;i<2;i++){
			ss[i]=m+1;
			for(int j=0;j<=n;j++){
				bl[j]=bl0[j];
				nx[j]=nx0[j];
			}
			for(int j=0;j<3;j++){
				largest[j]=largest0[j];
			}
			for(int s=0;s<m;s++){
				l1=largest[(i+s)%2];
				l2=largest[(i+s)%2+1];
				if(l1==l2){
					ss[i]=s;
					s=m;
				}
				if(l1>l2){
					largest[(i+s)%2]=nx[l1];
					largest[(i+s)%2+1]=l1;
					bl[l1]=(i+s)%2+1;
					nx[l1]=l2;
				}else{
					largest[(i+s)%2]=l2;
					largest[(i+s)%2+1]=nx[l2];
					bl[l2]=(i+s)%2;
					nx[l2]=l1;
				}
			}
		}
		
		if(ss[0]<ss[1]){
			s=ss[0];
		}else{
			s=ss[1];
		}
		
		if( s<=m ){
			cout << s << endl;
		}else{
			cout << -1 << endl;
		}
	}
}

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

using namespace std;


void solve() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    vector<int> pre(n+1);
    vector<int> suf(n+1);
    pre[0] = -1;
    for (int i = 0; i < n; i++) {
        pre[i+1] = max(pre[i], a[i]);
    }
    suf[n] = -1;
    for (int i = n-1; i >= 0; i--) {
        suf[i] = max(suf[i+1], a[i]);
    }
    for (int i = 0; i < n; i++) {
        int res = max(pre[i], suf[i+1]);
        cout << res << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3968
#include<iostream>
#include<queue>
#include<vector>

using namespace std;

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

struct edge{
    int to, cost;
};

typedef pair<int, pair<int, int> > pii; // distance, edge, ticket

int INF = 10e8;
int c, n, m, s, d;

int dis[101][11];

int main(){
    while(1){
        cin >> c >> n >> m >> s >> d;

        if(n==0) break;

        vector<edge> g[101];
        REP(i, m){
            int a, b, f;
            cin >> a >> b >> f;
            edge ae;
            ae.to = b;
            ae.cost = f;
            g[a].push_back(ae);
            edge be;
            be.to = a;
            be.cost = f;
            g[b].push_back(be);
        }

        priority_queue<pii, vector<pii>, greater<pii> > que;
        REP(i, n+1){
            REP(j, c+1){
                dis[i][j] = INF;
            }
        }
        dis[s][c] = 0;
        pii init = make_pair(0, make_pair(s, c));
        que.push(init);

        while(!que.empty()){
            pii p = que.top();
            que.pop();

            int v = p.second.first;
            int t = p.second.second;
            if(dis[v][t]<p.first) continue;
            REP(i, g[v].size()){
                edge e = g[v][i];
                if(dis[e.to][t] > dis[v][t] + e.cost){
                    dis[e.to][t] = dis[v][t] + e.cost;
                    que.push(pii(make_pair(dis[e.to][t], make_pair(e.to, t))));
                }
                if(t>0 && dis[e.to][t-1] > dis[v][t] + e.cost / 2){
                    dis[e.to][t-1] = dis[v][t] + e.cost / 2;
                    que.push(pii(make_pair(dis[e.to][t-1], make_pair(e.to, t-1))));
                }
            }
        }
        /*
        REP(i, n+1){
            REP(j, c+1){
                cout << dis[i][j] << " ";
            }
            cout << endl;
        }
        */
        int output = INF;
        REP(i, c+1){
            output = min(output, dis[d][i]);
        }
        cout << output << endl;
    }
}

Measured memory_bytes: 3172
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

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

    int A, B, T;
    cin >> A >> B >> T;

    cout << B * (int)((T + 0.5) / A) << "\n";

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int main(void){
   int n;
   cin >> n;
   vector<int> a(n);
   vector<int> rev(n);
   for(int i = 0;i < n;i++){
       cin >> a[i];
   }
   
   for(int i = 0;i < n;i++){
       rev[a[i] - 1] = i + 1;
   }
   for(int i = 0;i < n;i++){
       cout << rev[i] << endl;
   }
   
}


Measured memory_bytes: 1664
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

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

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    int ans = 0;
    int p = c * d / gcd(c, d);
    ans = (b / c + b / d - (b / p));
    ans = (ans - (a / c + a / d - (a / p)));
    cout << (b - a) - ans;
    rr;
}


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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SZN = 2500 + 5;
coint SZM = 5000 + 5;

struct Edge { int v, w, head; };

int  ecnt, head[SZN];
Edge edge[SZM];

inline void addEdge(coint u, coint v, coint w) {
    edge[++ecnt] = (Edge){v, w, head[u]}, head[u] = ecnt;
    return;
}

int n, m, p;

ll rdcnt[SZN], mk[SZN], dis[SZN];
queue<int> que;

int spfa(void) {
    for (; !que.empty(); que.pop());
    for (reint i = 1; i <= n; ++i) rdcnt[i] = mk[i] = 0, dis[i] = (1ll << 55);
    dis[1] = 0, que.push(1);

    while (!que.empty()) {
        coint u = que.front();
        que.pop();
        mk[u] = 0;
        if ((++rdcnt[u]) > n) { dis[u] = -(1ll << 55); }
        //printf("u = %d, dis = %lld\n", u, dis[u]);
        for (reint i = head[u]; ~i; i = edge[i].head) {
            coint v = edge[i].v, w = edge[i].w;
            if (dis[v] <= dis[u] + w) continue;
            dis[v] = dis[u] + w;
            if (!mk[v] && rdcnt[v] <= n) mk[v] = 1, que.push(v);
        }
    }

    return 0;
}

int main(void) {
    ecnt = 0, memset(head, -1, sizeof head);
    scanf("%d%d%d", &n, &m, &p);
    for (reint i = 1; i <= m; ++i) {
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        addEdge(u, v, -w + p);
    }
    spfa();
    if (dis[n] < -(1ll << 40)) { puts("-1"); return 0; }
    printf("%lld\n", max(-dis[n], 0ll));
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <regex>
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pl4 = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpl4 = vector<pl4>;
using vvpl4 = vector<vpl4>;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rFOR(i,a,b) for(int i=(b);i>=(a);i--)
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) sort((a).rbegin(),(a).rend())
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define PREVP(a) prev_permutation((a).begin(),(a).end())
#define NEXTP(a) next_permutation((a).begin(),(a).end())
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Say(a) cout <<(a);
#define Sal(a) cout <<(a)<<endl;
#define dbg(a) cout <<(#a)<<": "<<(a)<<endl;
#define a2l(a) ((ll)(a-97))
#define A2l(a) ((ll)(a-65))
#define l2a(a) ((char)(a+97))
#define l2A(a) ((char)(a+65))
#define dNum2(a) ((llabs(a)==0)?(1):((ll)(log2(double(llabs(a))))+1))
#define dNum10(a) ((llabs(a)==0)?(1):((ll)(log10(double(llabs(a))))+1))

#define int ll

const ll MOD = 1e9+7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll min(ll a, ll b){if(a>=b) return b;if(a<b) return a;}
ll max(ll a, ll b){if(a>=b) return a;if(a<b) return b;}

ll dSum10(ll n){
    ll m=0;
    FOR(i,0,dNum10(n)-1){
        m+=(ll)((llabs(n)%(ll)(pow(10.0,(double)(i+1))))/(ll)(pow(10.0,(double)i)));
    }
    return m;
}

ll isP(ll n){
    if(n<=1) return 0;
    FOR(i,2,(ll)sqrt(n)){
        if(n%i==0) return 0;
    }
    return 1;
}

ll BinS(vll a,ll b){
    ll min=0,max=a.size()-1,mid=0;
    while(1){
        mid=(min+max)/2;
        if(a[min]==b) return min;
        if(a[mid]==b) return mid;
        if(a[max]==b) return max;
        if(max-min<=2) return -1;
        if(a[mid]<b) min=mid;
        if(a[mid]>b) max=mid;
    }
}

//seiki
//#include <regex>
/*bubun*/
//regex_search("u32", regex("[0-9]"));      // true
/*kanzen*/
//regex_match("u32", regex("(i|u)\\d+"));   // true

signed main() {

    ll N,chk=0;
    cin >>N;
    
    FOR(h,1,(3*N)/4){
        if(4*h==N) continue;
        FOR(n,1,((2*N*h)/(4*h-N))){
            if(4*h*n<=N*(h+n)) continue;
            if((N*h*n)%((4*h*n)-(N*(h+n)))==0){
                cout <<h<<" "<<n<<" "<<((N*h*n)/((4*h*n)-(N*(h+n))))<<endl;
                chk=1;
                break;
            }
        }
        if(chk==1) break;
    }

}






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

int main(){
	int a,b,c,d,e,k;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> k;
	
	int anko = max(e-a,e-b);
	int maojini = max(e-c,e-d);
	
	if(anko <= k && maojini <= k){
		cout << "Yay!" << endl;
	}else cout << ":(" << endl;
	
	return 0;
}
		

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <stack>
#include <iostream>
#include <string>
#include <tuple>
#include <random>
#include <map>
#include <queue>
#include <set>
#include <complex>
#include <algorithm>
#include <cassert>
#include <iterator>
#include <numeric>

using namespace std;

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

const ll INF = 1e15;
const double eps = 1e-6;
const ll MOD = 1000000007;


typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
	Edge(int src, int dst, Weight weight) :
		src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void shortestPath(const Graph &g, int s,
	vector<Weight> &dist, vector<int> &prev) {
	int n = g.size();
	dist.assign(n, INF); dist[s] = 0;
	prev.assign(n, -1);
	priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
	for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
		Edge e = Q.top(); Q.pop();
		if (prev[e.dst] != -1) continue;
		prev[e.dst] = e.src;
		for (auto f = g[e.dst].begin();f != g[e.dst].end();f++) {
			if (dist[f->dst] > e.weight + f->weight) {
				dist[f->dst] = e.weight + f->weight;
				Q.push(Edge(f->src, f->dst, e.weight + f->weight));
			}
		}
	}
}
vector<int> buildPath(const vector<int> &prev, int t) {
	vector<int> path;
	for (int u = t; u >= 0; u = prev[u])
		path.push_back(u);
	reverse(path.begin(), path.end());
	return path;
}

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

int main() {
	ll N, A;
	cin >> N >> A;
	if (N % 500 <= A)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

k=0

for i in range(n):

  if a[i]<b[i]:
    k+=a[i]
    b[i]=b[i]-a[i]
    a[i]=0

    if a[i+1]<b[i]:
      k+=a[i+1]
      b[i]=b[i]-a[i+1]
      a[i+1]=0
    else:
      k+=b[i]
      a[i+1]=a[i+1]-b[i]
      b[i]=0

  else:
    k+=b[i]
    a[i]=a[i]-b[i]
    b[i]=0

print(k)


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var ans = false;
            if (S.Substring(0, 7) == "keyence" || S.Substring(S.Length - 7, 7) == "keyence") ans = true;
            else if (S.Substring(0, 1) == "k" && S.Substring(S.Length - 6, 6) == "eyence") ans = true;
            else if (S.Substring(0, 2) == "ke" && S.Substring(S.Length - 5, 5) == "yence") ans = true;
            else if (S.Substring(0, 3) == "key" && S.Substring(S.Length - 4, 4) == "ence") ans = true;
            else if (S.Substring(0, 4) == "keye" && S.Substring(S.Length - 3, 3) == "nce") ans = true;
            else if (S.Substring(0, 5) == "keyen" && S.Substring(S.Length - 2, 2) == "ce") ans = true;
            else if (S.Substring(0, 6) == "keyenc" && S.Substring(S.Length - 1, 1) == "e") ans = true;

            Console.WriteLine(ans ? "YES" : "NO");
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int arr[100010],n;
int dp[100010];
int f(int pos){
	if(pos>=n-1)return 0;
	int &ret=dp[pos];
	if(ret^-1)return ret;
	if(pos+1==n-1)return ret=abs(arr[pos+1]-arr[pos]);
	return ret=min(f(pos+1)+abs(arr[pos]-arr[pos+1]),f(pos+2)+abs(arr[pos]-arr[pos+2]));
}

int main(int argc, char const *argv[])
{
	memset(dp,-1,sizeof dp);
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
		cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,k,a[N],b[N];
char s[N];
//char buf[1<<21],*p1=buf,*p2=buf;
//inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();m=read();k=read();
	int A=1e18,B=1e18;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		A=min(A,a[i]);
	}
	for(int i=1;i<=m;i++)
	{
		b[i]=read();
		B=min(B,b[i]);
	}
	ans=A+B;
	for(int i=1;i<=k;i++)
	{
		int x=read(),y=read(),z=read();
		ans=min(ans,a[x]+b[y]-z);
	}
	cout<<ans;
	return 0;
}

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

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

	
	if (N[0]=='S'){
		cout << "Cloudy" << endl;
	}else if (N[0]=='C'){
		cout << "Rainy" << endl;
	}else if(N[0]=='R'){
		cout << "Sunny" << endl;
	}
	return 0;
}



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

#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

using namespace std;

typedef pair<int, int> P;


int main(){
	ll n, k;
	cin >> n >> k;
	if (k%2==0) {
      	ll temp = n/(k/2)- n/k;
		cout <<temp*temp*temp + (n/k)*(n/k)*(n/k) << endl;
		
	} else {
		cout << (n/k)*(n/k)*(n/k) << endl;
	}
}


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

using namespace std;

int n, d, k;
bitset<105> check;

int main()
{

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n >> k;
    while(k--){
        cin >> d;
        while(d--){
            int x;
            cin >> x;

            if(!check[x]){
                check[x] = true;
                --n;
            }
        }
    }

    cout << n;

    return 0;
}


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

int main() {
    int N; cin >> N;
    pair<int, int> T[N];
    for (int i = 0; i < N; i++) cin >> T[i].second >> T[i].first;
    
    sort(T, T + N);
    long long now = 0, flag = 1;
    for (int i = 0; i < N; i++) {
        now += T[i].second;
        if (now > T[i].first) flag = 0;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	int n;
	cin >> n;
	while (n) {
		if (n % 10 == 7) {
			cout << "Yes" << endl;
			return 0;
		}
		n /= 10;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
int main()
{
	int a,b,i, flag ;
	char s[13];
	while(~scanf("%d %d %s", &a, &b, s))
	{
		flag = 0;
		if(s[a] != '-')
			flag = 1;
		if(!flag)
		{
			for(i=0; s[i] != 0; i++)
			{
				if(i==a) continue;

				else if(s[i]<'0' || s[i]>'9')
				{
					flag = 1;
					break;
				}
			}			
		}
		
		if(flag) printf("No\n");
		else printf("Yes\n");
	}
}

Measured memory_bytes: 504
import sys

def tri(x1,x2,y1,y2,z1,z2,p1,p2):
    a = (x1 - y1) * (y2 - p2) - (y1 - p1) * (x2 - y2)
    b = (y1 - z1) * (z2 - p2) - (z1 - p1) * (y2 - z2)
    c = (z1 - x1) * (x2 - p2) - (x1 - p1) * (z2 - x2)
    if(((a < 0) & (b < 0) & (c < 0)) | ((a > 0) & (b > 0) & (c > 0))):
        return 'YES'
    return 'NO'

ans = []
for i in sys.stdin:
    ans.append(tri(*map(float,i.split())))
print('\n'.join(map(str,ans)))

Measured memory_bytes: 7496
#define NDEBUG
NDEBUG


#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <memory>
#include <queue>
#include <random>


using namespace std;


#define FORA(i, a, n) for (int i = (a); i < (n); ++i)


#define all(c) c.begin(), c.end()


typedef int64_t i64;


// TC_REMOVE_BEGIN
/// caide keep
bool __hack = std::ios::sync_with_stdio(false);
/// caide keep
auto __hack1 = cin.tie(nullptr);
// TC_REMOVE_END


// Section with adoption of array and vector algorithms.


//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//
//template <class T> using StdTree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


namespace template_util {
    

    constexpr int bytecount(uint64_t x) {
        return x ? 1 + bytecount(x >> 8) : 0;
    }

    template<int N>
    struct bytetype {
        
    };

    
    /// caide keep
    template<uint64_t N>
    struct minimal_uint : bytetype<bytecount(N)> {
    };
}


template<class T>
T next(istream& in) {
    T ret;
    in >> ret;
    return ret;
}

template<class T>
vector<T> next_vec(istream& in, size_t n) {
  vector<T> ret(n);
  for (size_t i = 0; i < n; ++i) {
    ret[i] = next<T>(in);
  }
  return ret;
}


void solve(istream& in, ostream& out) {
  auto n = next<int>(in);
  auto a = next_vec<int>(in, n);
  sort(all(a));
  reverse(all(a));
  i64 res = a[0];
  int ptr = 1;
  int cnt = 0;
  FORA(i, 2, n) {
    res += a[ptr];
    ++cnt;
    if (cnt == 2) {
      cnt = 0;
      ++ptr;
    }
  }
  out << res << "\n";
}

//#include <fstream>


int main() {
//  ifstream fin("bridges.in");
//  ofstream fout("bridges.out");
    solve(cin, cout);
//  solve(fin, fout);
    return 0;
}



Measured memory_bytes: 3968