akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        char[] S = sc.next().toCharArray();

        for (int i = 0; i < A; i++) {
            char ch = S[i];
            if (!(ch >= '0' && ch <= '9')) {
                System.out.println("No");
                return;
            }
        }

        if (S[A] != '-') {
            System.out.println("No");
            return;
        }

        for (int i = A + 1; i < A + B + 1; i++) {
            char ch = S[i];
            if (!(ch >= '0' && ch <= '9')) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
        return;
    }

}

Measured memory_bytes: 23764
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int n,a,b;
	cin>>n>>a>>b;
	cout<<min(n*a,b);
	return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <stdio.h>

#include <algorithm>
#include <map>
#include <random>
#include <queue>
#include <set>
#include <vector>

using namespace std;

struct Info {
  int l, r, d;
};

int main() {
  int N, M;
  scanf("%d%d", &N, &M);

  vector<Info> all_info;
  for (int i = 0; i < M; i++) {
    int l, r, d;
    scanf("%d%d%d", &l, &r, &d);
    Info info;
    info.l = l;
    info.r = r;
    info.d = d;
    all_info.push_back(info);
  }

  vector<vector<Info>> info_by_person(N+1);
  for (const Info& info : all_info) {
    info_by_person[info.l].push_back(info);
    info_by_person[info.r].push_back(info);
  }

  vector<int> pos(N+1);
  for (int i = 1; i <= N; i++) {
    pos[i] = INT_MIN;
  }

  set<int> left;
  for (int i = 1; i <= N; i++) {
    left.insert(i);
  }

  while (!left.empty()) {
    int id = *left.begin();
    pos[id] = 0;

    queue<int> q;
    q.push(id);

    while (!q.empty()) {
      int id = q.front();
      q.pop();
      left.erase(id);
      for (Info info : info_by_person[id]) {
        int opp = 0;
        int diff = 0;
        if (info.l == id) {
          opp = info.r;
          diff = info.d;
        } else {
          opp = info.l;
          diff = -info.d;
        }

        int expected_opp = pos[id] + diff;
        if (pos[opp] == INT_MIN) {
          assert(left.count(opp));
          q.push(opp);
          pos[opp] = expected_opp;
        } else {
          if (pos[opp] != expected_opp)
            goto fail;
        }

      }
    }
  }

  puts("Yes");
  return 0;

fail:
  puts("No");
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class a, int N, class T>
void fillArray(a(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }


int q;
void solve() {
    cin >> q;
    rep(i, q) {
        ll a, b;
        cin >> a >> b;
        if (a > b) swap(a, b);
        if (a >= b - 1) cout << 2 * a - 2 << endn;
        else {
            ll x = sqrt(a * b);
            if (x * x >= a * b) --x;
            cout << 2 * x - (x * (x + 1) < a * b ? 1 : 2) << endn;
        }
    }
}

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


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

int main(){
	int n,a,b,l,k=0;
  	cin >> n >>a >> b;
  	for (int i=1;i<=n;i++){
    	l= i%10+((i-(i%10))%100)/10+((i-(i%100))%1000)/100+((i-(i%1000))%10000)/1000+((i-(i%10000))%100000)/10000;
  	    if (l>=a && l<=b) k+=i;
      }
  cout << k << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
using namespace std;

int valuation(int n, int p)
{
  int ans = 0;
  while (true)
  {
    if (n % p == 0)
    {
      n /= p;
      ans++;
    }
    else
    {
      break;
    }
  }
  return ans;
}

int main()
{
  int n;
  cin >> n;
  int min = 50;
  int a[210];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    a[i] = valuation(a[i], 2);
    if (min > a[i])
    {
      min = a[i];
    }
  }
  cout << min << "\n";
}

Measured memory_bytes: 256
import sys

#+++++
		
def main():
	a,b = map(int, input().split())
	ans=max(0, a - b*2)
	print(ans)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define trav(x, v) for(auto &x : v)
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<ll> vl;


int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n;
	cin >> n;

	vl a(n), b(n);
	rep(i,0,n) cin >> a[i] >> b[i];

	ll budg = 0;
	rep(i,0,n) budg += max(0ll, b[i]-a[i]);

	vl c(n);
	rep(i,0,n) c[i] = max(a[i], b[i]);

	vi p(n);
	iota(all(p),0);
	sort(all(p), [&](int i, int j){
		return c[i] < c[j];
	});

	int k = 0;
	while(budg >= c[p[k]]){
		budg -= c[p[k]];
		k++;
	}
	pair<ll,ll> ans(0,1);
	rep(i,0,n){
		ll budg1 = budg + min(0ll, c[i] - c[p[k]]) + min(0ll, b[i]-a[i]);
		pair<ll,ll> cnd(budg1, b[i]);
		if(cnd.first*ans.second > cnd.second*ans.first) ans = cnd;
	}
	pair<ll, ll> res(ans.second * k + ans.first, ans.second);
	res.second *= n;
	ll d = __gcd(res.first, res.second);
	cout << res.first / d << ' ' << res.second / d << endl;
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <string.h>

char HA[1<<21], T[256];

int main() {
    unsigned int n, s, t;
    char c;
    T['A'] = 4;
    T['C'] = 3;
    T['G'] = 2;
    T['T'] = 1;
    scanf("%d", &n);
    getchar();
    while (n--) {
        s = 0;
        t = 1;
        int flag = ( c = getchar() ) == 'i';
        while ( ( c = getchar() ) != ' ' );
        while ( ( c = T[getchar()] ) != 0 ) {
            s += c * t;
            t *= 4;
        }
        if ( flag ) HA[s] = 1; else puts( HA[s] ? "yes" : "no" );
    }
    return 0;
}

Measured memory_bytes: 1748
#include<stdio.h>
typedef struct card{
  char suit;
  int value;
  int id;
}card;
int partition(card *,int,int);
void quicksort(card *,int,int);
int main(){
  int i,n,p=0,v,sta=1;
  char s;
  scanf("%d",&n);
  int r=n-1;
  card A[n];
  for(i=0;i<n;i++){
    scanf(" %c %d",&s,&v);
    A[i].suit = s;
    A[i].value = v;
  	A[i].id=i;
  }
  quicksort(A,p,r);
	for(i=0;i<n;i++){
		if(A[i].value==A[i+1].value && A[i].id>A[i+1].id){
			sta=0;
			break;
		}
	}
  if(sta==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].suit,A[i].value);
  }
  return 0;
}
void quicksort(card *A,int p,int r){
  if(p < r){
    int q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}
int partition(card *A,int p,int r){
  int j;
  card temp;
  int x = A[r].value;
  int i = p-1;
  for(j = p;j<r;j++){
    if(A[j].value <= x){
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  return (i+1);
}


Measured memory_bytes: 3036
import numpy as np
n,m,x = map(int, input().split())

#A = np.zeros((n, m))
CA = np.zeros((n,m+1))

for i in range(n):
    CA[i]=list(map(int, input().split()))
    # C[i],A[i]=T[0],T[1:]
#print(A,C)

min_cost = -1

for i in range(2**n):
    T = np.zeros((m+1))
    for j in range(n):
        if i&(2**j) > 0:
            T += CA[j]
    if all(T[1:] >= x):
        if min_cost == -1:
            min_cost = T[0]
        else: 
            min_cost = min(min_cost,T[0])        

print(int(min_cost))

Measured memory_bytes: 27188
from collections import defaultdict as d
s=input()+"T"
x,y=map(int,input().split())
p=[[],[]]
c,e=0,0
for i in s:
    if i=="T":
        if e!=0:
            p[c].append(e)
            e=0
        c=(c+1)%2
    else:
        e+=1
def f(a,c,q):
    g=d(int)
    r=0
    if q!=0:
        if len(a)>0 and s[0]=="F":
            g[a[0]]=1
            r=1
        else:
            g[0]=1
    else:
        g[0]=1
    for j in a[r:]:
        t=d(int)
        for i,h in g.items():
            t[i-j]=1
            t[i+j]=1
        else:
            g=t
    return g[c]!=0
print("Yes" if f(p[0],x,1)*f(p[1],y,0)==1 else"No")

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;

int main() {
  int n, y;
  cin >> n >> y;
  rep(i, n + 1) rep(j, n + 1 - i) {
    int k = (y - 10000 * i - 5000 * j) / 1000;
    if(i + j + k == n && k >= 0) {
      cout << i << ' ' << j << ' ' << k << endl;
      return 0;
    }
  }
  cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define WHITE 0
#define BLACK 1
static const int MAX = 500;
static const int INF = (1<<21);

int main(void){
  int n, i, j, u, v, c, k;
  int minv;
  int M[MAX][MAX];
  int check[MAX];
  int p[MAX];
  int key[MAX];
  
  scanf("%d", &n);


  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INF;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  /*
  for(i= 0;i < n;i++){
    for(j = 0;j < n;j++)
      printf("%d ", (M[i][j]==INF? 0:M[i][j]));
    printf("\n");
  }
  */

  for(i = 0;i < n;i++){
    key[i] = INF;
    p[i] = NIL;
    check[i] = WHITE;
  }


  key[0] = 0;

  while(1){
    u = NIL;  
    minv = INF;
    
    //printf("aa\n");
    //コストの少ないのーどみつける
    for(i = 0;i < n;i++){
      if(key[i] < minv && check[i] == WHITE){
	u = i;
	minv = key[i];
      }
    }
    
    if(u == NIL)
      break;  
    
    //使ったことにする    
    check[u] = BLACK;
    //sum += key[u];
    
    //隣接するそれぞれののーどに重みを入れる
    for(v = 0;v < n;v++){
      if(/*M[u][v] < key[v] &&*/ check[v] == WHITE && key[v] > key[u] + M[u][v]){
	key[v] = key[u] + M[u][v];
	p[v] = u;
      }
    }
  }  
  
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (key[i]==INF? 0:key[i]));
  }
  
  
  return 0;
}

Measured memory_bytes: 804
#include <iostream>
#include <map>
// C - Poll

using namespace std;

#define fi first
#define se second

map<string,int> m;

int main() {
    int N,i,mx;
    string S;

    cin >> N;
    mx = 0;
    for (i = 0;i < N;i++) {
        cin >> S;
        m[S]++;
        mx = max(mx,m[S]);
    }

    for (pair<string,int> p : m) {
        if (p.se == mx)
            cout << p.fi << "\n";
    }

    return 0;
}


Measured memory_bytes: 25216
H, W = list(map(int, input().split()))
c = [input() for _ in range(H)]

moves = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def bfs():
    visited = [[False for _ in range(W)] for _ in range(H)]
    dist = [[[] for _ in range(W)] for _ in range(H)]
    routes = [(0, 0)]
    visited[0][0] = True

    hop_count = 0
    while len(routes) > 0:
        x, y = routes.pop(0)
        for move in moves:
            cx, cy = x + move[0], y + move[1]
            if cx < 0 or cy < 0 or cx >= W or cy >= H or c[cy][cx] == '#' or visited[cy][cx]:
                continue
            if cx == W-1 and cy == H-1:
                return sum([line.count('.')for line in c]) - len(dist[y][x]) - 2
            visited[cy][cx] = True
            routes.append((cx, cy))
            dist[cy][cx] += dist[y][x] + [(x, y)]
    return -1

print(bfs())

Measured memory_bytes: 4596
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    string s;
    cin >> n >> s;
    if(s.length() % 2 == 1){
        cout << "No" << endl;
        return 0;
    }else{
        for(int i = 0; i < s.length()/2; i++){
            if(s[i] != s[s.length()/2 + i]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
($x,$y)=glob<>;
if($x==0){
	print abs($y)+($y<0),$/
}elsif($y==0){
	print abs($x)+($x>0),$/
}elsif($x*$y<0){
	print abs(abs($y)-abs($x))+1,$/
}elsif($x<$y){
	print$y-$x,$/
}else{
	print abs(abs($y)-abs($x))+2,$/
}


Measured memory_bytes: 768
x = int(input())

i = -1
b = 0
judge = 0
flag = True
while flag:
    i += 1
    judge = i ** 5 - x
    if judge < 0:
        b = -1
        judge = - judge
        temp = - b ** 5
        while temp <= judge:
            if temp == judge:
                flag = False
                break
            else:
                b -= 1
                temp = - b ** 5
    elif judge == 0:
        b = 0
        break
    else:
        b = 1
        temp = b ** 5
        while temp <= judge:
            if temp == judge:
                flag = False
                break
            else:
                b += 1
                temp = b ** 5
        
print(i, b)

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	map<string, int>m;
	int q = in();
	REP(i, q)
	{
		int n = in();
		string key;
		int x;
		switch (n)
		{
		case 0:
			key = in<string>();
			x = in();
			m[key] = x;
			break;
		case 1:
			key = in<string>();
			try
			{
				cout << m.at(key) << endl;
			}
			catch (out_of_range)
			{
				cout << 0 << endl;
			}
			break;
		case 2:
			key = in<string>();
			m.erase(key);
			break;
		case 3:
			string l = in<string>(), r = in<string>();
			for (auto itr1 = m.lower_bound(l), itr2 = m.upper_bound(r); itr1 != itr2; itr1++)cout << (*itr1).first << ' ' << (*itr1).second << endl;
			break;
		}
	}
}


Measured memory_bytes: 27784
;; E - Flatten

(defun main ()
  (let* ((n (read))
         (a (loop repeat n collect (read))))
    (princ (solve a))))

(defparameter *modulus* (+ (expt 10 9) 7))

(defun solve (a)
  (mod (* (apply #'lcm a) (loop for x in a sum (/ 1 x))) *modulus*))

(main)


Measured memory_bytes: 100832
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
    ll n,t,k,a,b,d,c;
cin>>n;
a=n-1;
for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
    k=i;
    if(a>abs(k-(n/k)))
    {
        a=abs(k-(n/k));
        b=k;
    }
    }
}
     if(a==n-1)
     cout<<a;
     else
    cout<<b-1+(n/b)-1;
    
    
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
const int ININF = 1000000;
using pint = pair<int, int>;
using Edge = pair<long long, pint>; //<cost,<u,v>>の形
vector<Edge> edges;

int N, M, P, s;
vector<long long> d;
vector<bool> neg;

//到達可能でNへの経路中に正の閉路がある場合にtrueを返す
bool large_path(int start) {
    rep(i, 0, N) { d[i] = -INF; }
    d[start] = 0LL;
    rep(i, 0, N) {
        rep(j, 0, M) {
            Edge e = edges[j];
            long long cost = e.first;
            int to = e.second.second;
            int fr = e.second.first;
            if(d[fr] != -INF && d[to] < d[fr] + cost) {
                d[to] = d[fr] + cost;
            }
        }
    }
    rep(i, 0, N) {
        rep(j, 0, M) {
            Edge e = edges[j];
            long long cost = e.first;
            int to = e.second.second;
            int fr = e.second.first;
            if(d[fr] != -INF && d[to] < d[fr] + cost) {
                d[to] = d[fr] + cost;
                neg[to] = true;
            }
            if(neg[fr]) {
                neg[to] = true;
            }
        }
    }
    return neg[N - 1];
}
int main() {
    cin >> N >> M >> P;
    s = 0;
    d.assign(N, 0);
    neg.assign(N, false);
    rep(i, 0, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges.push_back(make_pair(c - P, make_pair(a, b)));
    }
    if(large_path(s)) {
        cout << -1 << endl;
    } else {
        if(d[N - 1] < 0) {
            cout << 0 << endl;

        } else {
            cout << d[N - 1] << endl;
        }
    }
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#define MAX 1000
 
typedef struct dice{
 int num[7];
}dice;
 
 
 
 
int main(){
dice D;
int i,j;
int temp;
int q;
int mae,ue;
 
for(i=1;i<=6;i++)scanf("%d",&D.num[i]);
 
scanf("%d",&q);
 
for(i=0;i<q;i++){
 scanf("%d %d",&ue,&mae);
 
 if(D.num[1]==ue && D.num[2]!=mae){
 
  for(j=0;j<3;j++){
   temp=D.num[2];
   D.num[2]=D.num[4];
   D.num[4]=D.num[5];
   D.num[5]=D.num[3];
   D.num[3]=temp;
   if(D.num[2]==mae)break;
  }
 
 }
 
else if(D.num[1]!=ue && D.num[2]==mae){
 
 for(j=0;j<3;j++){
  temp=D.num[1];
  D.num[1]=D.num[4];
  D.num[4]=D.num[6];
  D.num[6]=D.num[3];
  D.num[3]=temp;
  if(D.num[1]==ue)break;
 }
 
}
 
else if(D.num[1]!=ue && D.num[2]!=mae){
 
 for(j=0;j<=3;j++){
  temp=D.num[1];
  D.num[1]=D.num[4];
  D.num[4]=D.num[6];
  D.num[6]=D.num[3];
  D.num[3]=temp;
  if(D.num[1]==ue)break;
 }
 
if(D.num[1]!=ue){
 
for(j=0;j<3;j++){
 temp=D.num[1];
 D.num[1]=D.num[2];
 D.num[2]=D.num[6];
 D.num[6]=D.num[5];
 D.num[5]=temp;
 if(D.num[1]==ue)break;
}
}
 
 
 
 
 
 for(j=0;j<3;j++){
   temp=D.num[2];
   D.num[2]=D.num[4];
   D.num[4]=D.num[5];
   D.num[5]=D.num[3];
   D.num[3]=temp;
   if(D.num[2]==mae)break;
  }
 
 
}
 
printf("%d\n",D.num[3]);
 
}
 
return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <string.h>

int main(){
    char *mark = "SHCD";
    int card[4][13] = { 0 };
    
    int i, j;
    int n, t;
    char c;
    
    scanf("%d", &n);
    
    for(i = 0; i < n; ++i){
        scanf(" %c %d", &c, &t);
        card[strchr(mark, c) - mark][t - 1] = 1;
    }
    
    for(i = 0; i < 4; ++i){
        for(j = 0; j < 13; ++j){
            if(!card[i][j]){
                printf("%c %d\n", mark[i], j + 1);
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 600
def solve(a, b):
    return a * b


def main():
    a, b = map(int, input().split())
    res = solve(a, b)
    print(res)


def test():
    assert solve(2, 5) == 10
    assert solve(100, 100) == 10000


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9176
#include<stdio.h>
 
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
void DFS(int);
void dfs();
 
int n,m[N][N];
int color[N],d[N],f[N],tt;
 
int main(){
 
  int u,v,k,i,j,l;
 
  scanf("%d",&n);
 
  for(i = 0;i < n; i++){
    for(j = 0; j < n; j++) {
      m[i][j] = 0;
    }
  }
  for(i = 0;i < n; i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j = 0; j < k; j++){
      scanf("%d",&v);
      v--;
      m[u][v] = 1;
    }
  }
  dfs();
 
  return 0;
}
 
void DFS(int u){
 
  int v;
 
  color[u] = GRAY;
  d[u] = ++tt;
  for(v = 0; v < n; v++){
    if(m[u][v] == 0)continue;
    if(color[v] == WHITE){
      DFS(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}
 
void dfs(){
 
  int u;
 
  for(u = 0; u < n; u++)color[u] = WHITE;
  tt = 0;
 
  for(u = 0; u < n; u++){
    if(color[u] == WHITE)DFS(u);
  }
 
  for(u = 0; u < n; u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}

Measured memory_bytes: 636
n, m = gets.split.map(&:to_i)
k = []
s = []
for i in 1..m do
  s[i] = gets.split.map(&:to_i)
  k[i] = s[i][0]
end
p = gets.split.map(&:to_i)
p.unshift(nil)

pow2 = [1]
(1..n).each { |p|
  pow2[p] = pow2[p-1] * 2
}
sw = []
res = 0
for x in 0...pow2[n] do
  for j in 1..n do
    sw[j] = (x >> (j-1)) & 1
  end
  flag = true
  for i in 1..m do
    sum = 0
    for kk in 1..k[i] do
      sum += sw[s[i][kk]]
    end
    if sum % 2 != p[i]
      flag = false
      break
    end
  end
  res += 1 if flag
end
puts res


Measured memory_bytes: 3836
n= int(input())
li = list(map(int,input().split()))
cnt1, cnt2 = 0,0
for i in li:
    if i % 2 == 0:
        cnt1 += 1
        if i % 3 == 0 or i % 5 == 0:
            cnt2 += 1
if cnt1==cnt2:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<class T>
T gcd(T a, T b){
	if(a<b) swap(a,b);
    if(b==0) return a;
    return gcd(b, a%b);
}

int main(){
    int n;
    cin >> n;
    ll a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    ll dl[n+1], dr[n+1];
    dl[0]=0, dr[n]=0;
    for(int i=1; i<=n; i++){
        dl[i]=gcd(dl[i-1], a[i-1]);
        dr[n-i]=gcd(dr[n-i+1], a[n-i]);
    }
    ll ans=0;
    for(int i=0; i<n; i++){
        ans=max(ans,gcd(dl[i], dr[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
fn main() {
    let cin = std::io::stdin();
    let mut sc = Scanner { stdin: cin.lock() };

    let x: u32 = sc.read();
    let a: u32 = sc.read();

    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let token = self
            .stdin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok().expect("token parse error")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] top = in.nextIntArraySorted(n);
            int[] middle = in.nextIntArraySorted(n);
            int[] bottom = in.nextIntArraySorted(n);

            long ans = 0;
            for (int i = 0; i < n; i++) {
                long t = ArrayUtils.upperBound(top, middle[i] - 1) + 1;
                long b = n - ArrayUtils.lowerBound(bottom, middle[i] + 1);
                ans += t * b;
            }

            out.println(ans);
        }

    }

    static class ArrayUtils {
        public static int lowerBound(int[] a, int x) {
            int high = a.length;
            int low = -1;
            while (high - low > 1) {
                int mid = (high + low) / 2;
                if (a[mid] < x) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            return high;
        }

        public static int upperBound(int[] a, int x) {
            int high = a.length;
            int low = -1;
            while (high - low > 1) {
                int mid = (high + low) / 2;
                if (a[mid] <= x) {
                    low = mid;
                } else {
                    high = mid;
                }
            }
            return low;
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArraySorted(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            Arrays.sort(res);
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 50776
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	while(1) {
		c-=b;
		if(c<=0) {
			cout<<"Yes"<<endl;
			break;
		}
		a-=d;
		if(a<=0) {
			cout<<"No"<<endl;
			break;
		}
	}
	return 0;
}

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


namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var str = Console.ReadLine()
                .Split(new[] { ' ' },StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x.ToString()))
                .ToList();
            var count = 0;
            while (true)
            {
                var isCan = true;
                foreach (var item in str)
                {
                    if (item % 2 == 1)
                    {
                        isCan = false;
                        break;
                    }
                }
                if (isCan)
                {
                    str = str.Select(x => x / 2).ToList();
                    count++;
                }
                else
                    break;

            }
            Console.WriteLine(count);
        }
    }

}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> seg_sum(n); // [0, i]の区間和;
    cin >> seg_sum[0];
    rep1(i, n-1) {
        ll a; cin >> a;
        seg_sum[i] = seg_sum[i-1] + a;
    }
    ll diff = INF;
    // [0, n-1)
    rep(i, n-1) chmin(diff, abs(seg_sum[i] - (seg_sum[n-1]-seg_sum[i])));
    cout << diff << endl;
    return 0;
}

Measured memory_bytes: 1792
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
C = [[0 for _ in range(W)] for _ in range(H)]
cur = [0,0,"R"]
for k in range(1,N+1):
#     ipdb.set_trace()
    a = A[k]
    cnt = 0
    y,x,d = cur
    for i in range(y,H):
        y = i
        if d=="R":
            for j in range(x,W):
                C[i][j]=str(k)
                cnt += 1
                if j+1<W:
                    x = j+1
                else:
                    x = j
                if cnt==a:break
            if cnt==a:break
            d="L"
        else:
            for j in range(x,-1,-1):
                C[i][j]=str(k)
                cnt += 1
                if j>=1:
                    x = j-1
                else:
                    x = 0
                if cnt==a:break
            if cnt==a:break
            d="R"
    if x==W-1:
        if C[y][x]!=0:
            y += 1
            d="L"
    elif x==0:
        if C[y][x]!=0:
            y += 1
            d="R"
    cur = [y,x,d]                
for i in range(H):
    print(*C[i])

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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


void MAIN() {
    LL A, B, C, K;
    scanf("%lld%lld%lld%lld", &A, &B, &C, &K);
    if (K & 1) {
	A = -A;
	B = -B;
	C = -C;
    }
    printf("%lld\n", A - B);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
//Coins
import java.io.*;
import java.util.*;
public class Main{
	static int n;
	static double[] prob=new double[3001];
	static double[][] dp=new double[3001][3001];
	public static double solve(int coins,int heads){
		if(heads==0)
			return 1;
		if(coins==0)
			return 0;
		//head comes
		if(dp[coins][heads]!=-1)
			return dp[coins][heads];
		double op1=prob[coins]*solve(coins-1,heads-1);
		//tail comes
		double op2=(1-prob[coins])*solve(coins-1,heads);
		return dp[coins][heads]=op1+op2;

	}
	public static void main(String[] args) throws IOException{
    	 BufferedReader br = new BufferedReader( 
                              new InputStreamReader(System.in)); 
       
		n=Integer.parseInt(br.readLine()); 
		// prob=new double[n+1];
		// dp=new double[]
		String[] str=br.readLine().split(" ");
		for(int i=1;i<=n;i++){			
		   prob[i]=Double.parseDouble(str[i-1]);		 
		}
		for(double[] x:dp){
			Arrays.fill(x,-1);
		}
		System.out.println(solve(n,(n+1)/2));
	
    }
}

Measured memory_bytes: 133068
import java.io.*;
import java.util.*;

class Main {

    // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long[] a = new long[(int)(N)];
        long[] b = new long[(int)(N)];
        long[] c = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                a[i] = sc.nextLong();
                b[i] = sc.nextLong();
                c[i] = sc.nextLong();
        }
        solve(N, a, b, c);
    }

    static void solve(long N, long[] a, long[] b, long[] c){
        long[][] dp = new long[(int)(N+1)][3];

        for (int i = 1; i <= N; i++){
            dp[i][0] = Math.max(dp[i-1][1] + a[i-1], dp[i-1][2] + a[i-1]);
            dp[i][1] = Math.max(dp[i-1][2] + b[i-1], dp[i-1][0] + b[i-1]);
            dp[i][2] = Math.max(dp[i-1][0] + c[i-1], dp[i-1][1] + c[i-1]);
        }

        long rst = 0;
        rst = Math.max(dp[(int)(N)][0], dp[(int)(N)][1]);
        rst = Math.max(rst, dp[(int)N][2]);
        System.out.print(rst);
        
    }
}


Measured memory_bytes: 98208
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
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 conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
ll modpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<ll> cnt(k + 1, 0);
    for(ll i = k; i >= 1; i--){
        ll tmp = modpow(k / i, n);
        for(ll j = 2 * i; j <= k; j += i){
            tmp -= cnt[j];
            tmp %= MOD;
        }
        cnt[i] = tmp; 
    }

    ll ans = 0;
    for(ll i = 1; i <= k; i++){
        ans += cnt[i] * i;
        ans %= MOD;
    }

    if(ans < 0) ans += MOD;
    cout << ans % MOD << endl;
}

Measured memory_bytes: 4052
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORL(i,a,b) for(LL i=(a);i<(b);++i)
#define REPL(i,n)  FORL(i,0,n)
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

template<typename T>
T gcd(T a, T b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b%a, a);
}

template<typename T>
map<T, T> prime_list(T n) {
    map<T, T> ret;
    for(T i = 2; i*i <= n; i++) {
        if(n % i == 0) {
            ret[i] = 0;
            while(n % i == 0) {
                n /= i;
                ret[i]++;
            }
        } 
    }
    if(n != 1) ret[n]++;
    return ret;
}

#define MOD 1000000007

LL mypow(LL a, LL n) {
    if(n == 1) return a % MOD;
    if(n % 2 == 1) return (a * mypow(a, n-1)) % MOD;
    LL t = mypow(a, n/2);
    return (t * t) % MOD; 
}

int main(void) {
    int n;
    cin >> n;
    int px = 0, py = 0, pt = 0;
    REP(hoge, n) {
        int x, y, t;
        cin >> t >> x >> y;
        if(abs(x - px) + abs(y - py) > t - pt || abs(x + y - px - py) % 2 != (t - pt) % 2) {
            cout << "No" << endl;
            return 0;
        }
        px = x;
        py = y;
        pt = t;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
typedef int key_t;

int main(){
	int r,c,n;
	scanf("%d%d%d",&r,&c,&n);
	map<key_t,vector<pair<key_t,long long>>>m;
	string s1,s2;
	for(;n;n--){
		int s1,s2,d;
		scanf("%d%d%d",&s1,&s2,&d);
		m[s1].emplace_back(s2+r,d);
		m[s2+r].emplace_back(s1,-d);
	}
	for(;!m.empty();){
		long long a=-1LL<<61,b=1LL<<61;
		auto s=m.begin()->first;
		vector<pair<key_t,long long> >st={{s,0}};
		map<key_t,long long>memo={{s,0}};
		for(;!st.empty();){
			auto p=*st.rbegin();st.pop_back();
			auto cur=p.first;long long d=p.second;
			memo[cur]=d;
			if(cur<=r)a=max(a,d);
			else b=min(b,d);
			for(auto &e:m[cur]){
				if(memo.find(e.first)==memo.end()){
					st.emplace_back(e.first,d+e.second);
				}else if(memo[e.first]!=d+e.second){
					puts("No");
					return 0;
				}
			}
		}
		if(a>b){
			puts("No");
			return 0;
		}
		for(auto &e:memo)m.erase(m.find(e.first));
	}
	puts("Yes");
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
int n, k;
int l[50];
int main(){
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> l[i];
	sort(l, l + n);
	reverse(l, l + n);
	int ans = 0;
	for(int i = 0; i < k; i++) ans += l[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
def end_of_loop():raise StopIteration
    
    
def main():
    N = I()
    result = 0
    mylist = sorted(LI())
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                if mylist[i] < mylist[j] and mylist[j] < mylist[k] and mylist[k] < mylist[i]+mylist[j]:                    
                    result+=1
    print(result)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 68516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
   string s;
   ll S,A;
   A=0;
   cin>>s;
   S=s.size();
   rep(i,S){
   if(i%2==1){if(s[i]=='R'){A=A+1;}
   else{A=A;}}
   else if(i%2==0){if(s[i]=='L'){A=A+1;}
   else{A=A;}
   }
   }
   if(A==0){cout<<"Yes"<<endl;}
   else if(A!=0){cout<<"No"<<endl;}
            
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let l : u32 = read();
    let r : u32 = read();
    let d : u32 = read();

    let mut count = 0;

    for i in l .. r + 1
    {
        eprintln!("({})", i);
        
        if i % d == 0
        {
            count += 1;
        }
    }

    println!("{}", count);
}


Measured memory_bytes: 2104
import sys
sys.setrecursionlimit(2**20)
n = int(input())
NIL = -1
class node:
    def __init__(self,parent,left,right,key):
        self.parent = parent
        self.left = left
        self.right = right
        self.key = key
T = [node(NIL,NIL,NIL,NIL) for _ in range(n)]
D = [0]*n
def setDepth(u,p):#uはノードの番号、pはノードpの深さ。
    if u == NIL:
        return
    D[u] = p      #uより下にあるノードの深さをDに保存し、かえす
    if T[u].left != NIL:
        setDepth(T[u].left,p+1)
    if T[u].right != NIL:
        setDepth(T[u].right,p+1)
    return D
H = [0]*n
def setHeight(u,H):
    hl = 0
    hr = 0
    if T[u].left != NIL:
        hl = 1 + setHeight(T[u].left,H)
    if T[u].right != NIL:
        hr = 1 + setHeight(T[u].right,H)
    ret = max(hl,hr)
    H[u] = ret
    return ret
def getDegree(u):
    cc = 0
    if T[i].left != NIL:
        cc += 1
    if T[i].right != NIL:
        cc += 1
    return cc
def getDepth(u):
    d = 0
    while T[u].parent != NIL:
        u = T[u].parent
        d += 1
    return d
def getBrother(u):
    if T[u].parent == NIL:
        return NIL
    elif T[T[u].parent].left == u:
        return T[T[u].parent].right
    elif T[T[u].parent].right == u:
        return T[T[u].parent].left
def printChildren(u):#番号uのノードの子供をlistでかえす
    child = []
    if T[u].left != NIL:
        child.append(T[u].left)
    if T[u].right != NIL:
        child.append(T[u].right)
    return child
def ppp():
	for i in range(n):
  		ccc = T[i]
  		print(i,ccc.parent,ccc.left,ccc.right)
def findroot(u): #根をみつける
    while T[u].parent != NIL:
        u = T[u].parent
    return u
#巡回
rl = []
def rootleft(u,rl): #どのパターンでもrootからスタート
    if u == NIL:
        return
    rl.append(u)
    rootleft(T[u].left,rl)
    rootleft(T[u].right,rl)
lro = []
def leftroot(u,lro):
    if u == NIL:
        return
    leftroot(T[u].left,lro)
    lro.append(u)
    leftroot(T[u].right,lro)
lri = []
def leftright(u,lri):
    if u == NIL:
        return
    leftright(T[u].left,lri)
    leftright(T[u].right,lri)
    lri.append(u)
# 入力
firstid = 0
for i in range(n):
    id,left,right = map(int,input().split())
    if n == 0:
        firstid = id
    if left != NIL:
        T[id].left = left
        T[left].parent = id
    if right != NIL:
        T[id].right = right
        T[right].parent = id
r = findroot(firstid)
D = setDepth(r,0)
setHeight(r,H)
leftright(r,lri)
leftroot(r,lro)
rootleft(r,rl)
#挿入
#ここから問題によって変わる
for i in range(n):
    node = i
    parent = T[i].parent
    sibling = getBrother(i)
    degree = getDegree(i)
    depth = D[i]
    height = H[i]
    s = "internal node"
    if i == r:
        s = "root"
    elif degree == 0:
        s = "leaf"
    print(f'node {i}: parent = {parent}, sibling = {sibling}, degree = {degree}, depth = {depth}, height = {height}, {s}')


Measured memory_bytes: 5764