akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a,b,c;
  cin >> a>>b>>c;

  // N要素の配列
  vector<int> A={a,b,c};

  sort(A.begin(),A.end());
  
  
  
  
  cout << A.at(2)*10+A.at(0)+A.at(1) << endl;
  
}


Measured memory_bytes: 256
(let* ((a (read))
       (b (read)))
  (loop :for k :from 1 :upto 10000
        :do(if (and (= (floor (* k 0.08)) a) (= (floor (* k 0.1)) b))
               (progn (princ k) (return)))
        :finally (princ "-1")))

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

if(N%1==0 and N//1<=9) or (N%2==0 and N//2<=9) or (N%3==0 and N//3<=9) or (N%4==0 and N//4<=9) or (N%5==0 and N//5<=9) or (N%6==0 and N//6<=9) or (N%7==0 and N//7<=9) or (N%8==0 and N//8<=9) or (N%9==0 and N//9<=9):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
N = input()
for i in range(N):
	a, b, c = map(int, raw_input().split())
	t1 = a**2 + b ** 2 == c ** 2
	t2 = b**2 + c ** 2 == a ** 2
	t3 = c**2 + a ** 2 == b ** 2
	if t1 or t2 or t3:
		print("YES")
	else:
		print("NO")

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n--){
		int B=-1,C=-1;
		bool ok=true;
		for(int i=0;i<10;i++){
			int m;
			cin>>m;
			if(B<m){
				if(B<C && C<m)C=m;
				else B=m;
			}
			else if(C<m){
				C=m;
			}
			else ok=false;
		}
		cout<<(ok?"YES":"NO")<<endl;
	}
	return 0;
}

Measured memory_bytes: 1148
import java.io.IOException;
import java.util.Scanner;

public class Main {
    static char[] s, t;

    static int[][] memo;
    static boolean[][] vis;

    static int dp(int idxA, int idxB) {
        if(idxA == s.length || idxB == t.length) return 0;
        if(vis[idxA][idxB]) return memo[idxA][idxB];
        int ans = 0;
        if(s[idxA] == t[idxB]) {
            ans = 1 + dp(idxA + 1, idxB + 1);
        } else {
            ans = dp(idxA + 1, idxB);
            ans = Math.max(ans, dp(idxA, idxB + 1));
        }
        vis[idxA][idxB] = true;
        return memo[idxA][idxB] = ans;
    }

    static void trace(int idxA, int idxB) {
        if(idxA == s.length || idxB == t.length) {
            System.out.println();
            return;
        }
        if(s[idxA] == t[idxB]) {
            System.out.print(s[idxA]);
            trace(idxA + 1, idxB + 1);
        } else {
            int ans = dp(idxA, idxB);
            if(ans == dp(idxA + 1, idxB)) {
                trace(idxA + 1, idxB);
            } else {
                trace(idxA, idxB + 1);
            }
        }
    }

    static int solveBottomUp() {
        memo = new int[s.length + 1][t.length + 1];

        for(int i = 0; i <= s.length; i++)
            memo[i][t.length] = 0;
        for(int i = 0; i <= t.length; i++)
            memo[s.length][i] = 0;

        for(int idxA = s.length - 1 ; idxA >= 0; idxA--) {
            for(int idxB = t.length - 1 ; idxB >= 0 ; idxB--) {
                int ans = 0;
                if(s[idxA] == t[idxB]) {
                    ans = 1 + memo[idxA + 1][idxB + 1];
                } else {
                    ans = memo[idxA + 1][idxB];
                    ans = Math.max(ans, memo[idxA][idxB + 1]);
                }
                memo[idxA][idxB] = ans;
            }
        }
        return memo[0][0];
    }

    static int solveTopDown() {
        memo = new int[s.length][t.length];
        vis = new boolean[s.length][t.length];
        return dp(0, 0);
    }

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        s = sc.next().toCharArray();
        t = sc.next().toCharArray();
        solveTopDown();
        trace(0, 0);
    }
}


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

int main() {
  string A;
  cin >> A;
  int N = A.size();
 for(int i=0;i<N;i++){
   if(A[i] =='1'){
    A[i] ='9';
   }
   else if(A[i] =='9'){
    A[i] ='1';
   }
 }

 cout << A << endl;
}


Measured memory_bytes: 256
def resolve():
    H, W = list(map(int, input().split()))
    
    def _solve(H, W):
        mean_w = W // 2
        ans = float("inf")
        for h in range(1, H):
            s1 = h * W
            mean_h = (H-h) // 2
            for i in range(0, 2):
                if i == 0:
                    s2 = (H-h)*mean_w
                    s3 = (H-h)*(W-mean_w)
                if i == 1:
                    s2 = mean_h*W
                    s3 = (H-h-mean_h)*W
                ans = min(ans, max(s1, s2, s3)-min(s1, s2, s3))
        return ans

    print(min(_solve(H, W), _solve(W, H)))

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 3064
s = io.read()
a, b, c = s:match("(%w+) (%w+) (%w+)")
if a:sub(#a, #a) == b:sub(1, 1) and b:sub(#b, #b) == c:sub(1, 1) then
  print("YES")
else
  print("NO")
end


Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin >> a >> b;
  c=a*b;
  
  if (c%2 == 1){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
}
}

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

int main(void) {
    int h, w, k;
    cin >> h >> w >> k;

    int c[h][w];
    rep(i,h) {
        string buf;
        cin >> buf;
        rep(j,w) {
            if (buf[j] == '.') c[i][j] = 0;
            else c[i][j] = 1;
        }
    }

    int imax = 1, jmax = 1;
    rep(i,h) imax *= 2;
    rep(i,w) jmax *= 2;
    int ans = 0;
    rep(i,imax) {
        rep(j,jmax) {
            int cnt = 0;
            rep(ih,h) {
                rep(iw,w) {
                    if (c[ih][iw] == 1 && ((i>>ih)&1) == 0 && ((j>>iw)&1) == 0) cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int m, D, ans = 0;
  cin >> m >> D;
  if(m >= 4) {
  for(int i = 4; i < m + 1; i++) {
    for(int j = 22; j < D + 1; j++) {
      int d1 = j % 10, d10 = j / 10;
      if(i == d1 * d10 && d1 >= 2 && d10 >= 2)
        ans++;
    }
  }
  }
  cout << ans << endl;
}

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

using namespace std;

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

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

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

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

//2 ≤ N ≤ 10^5 
//1 ≤ ai < bi ≤ N 
//入力はすべて整数 
//与えられるグラフは木である(閉路がない、どの頂点も辺を辿れば連結している)
const int N=100005;
int n;
vi tr[N];
map<string,int> color;
void dfs(int vert, int pvert, int pcolornum){
    //DEBUG2(vert,pvert);
    int colornum = 1;
    REP(i,tr[vert].size()){
        int nvert = tr[vert][i];
        
        if(nvert==pvert) {
            continue;
        }

        string sidx;
        if(nvert > vert)
            sidx = to_string(vert) + "-" + to_string(nvert);
        else
            sidx = to_string(nvert) + "-" + to_string(vert);

        if(colornum == pcolornum)  colornum++;
        color[sidx] = colornum;

        dfs(nvert, vert, colornum);
        colornum++;
    }

}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin>>n;
    vector<pii> ab;
    REP(i,n-1){
        int a,b;
        cin>>a>>b;
        tr[a].emplace_back(b);
        tr[b].emplace_back(a);
        ab.emplace_back(make_pair(a,b));
    }

    int degmax=0, degidx=-1;
    FOR(i,1,n+1){
        if(degmax < tr[i].size()){
            degmax = tr[i].size();
            degidx = i;
        }
    }

    dfs(degidx,-1,-1);

    cout<<degmax<<endl;
    REP(i,ab.size()){
        string sidx = to_string(ab[i].first) + "-" + to_string(ab[i].second);
        cout<<color[sidx]<<endl;
    }

    return 0;
}

Measured memory_bytes: 25980
#include<bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x, a;
  cin >> x >> a;
  if(x < a) {
      cout << 0 << '\n';
  } else {
      cout << 10 << '\n';
  }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int N,A[1000],i,j,v,k;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);

  for(i=1;i<N;i++)
    {
      v=A[i];
      j=i-1;
      while(j >=0 && A[j]>v)
	{
	  A[j+1]=A[j];
	  j=j-1;
	  A[j+1]=v;
	}
      for(k=0;k<N-1;k++){
	printf("%d ",A[k]);
      }
      printf("%d\n",A[k]); 
    }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

long long MOD = 1000000007;

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

    if (b == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }
    if (b <= a) {
        std::cout << 1 << std::endl;
        return 0;
    }

    b -= a;

    int remained = b % (a - 1);
    int count = b / (a - 1) + 1;
    if (remained == 0) {
        std::cout << count << std::endl;
    }
    else {
        std::cout << count + 1 << std::endl;
    }

    
    return 0;
}




Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

using namespace std;

const int oo = 0x3f3f3f3f;

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	int n, k, ans = 0;
	int h[(int)1e5 + 10];
	n = read(), k = read();
	for(rgi i = 1; i <= n; ++i) h[i] = read();
	for(rgi i = 1; i <= n; ++i) ans += (h[i] >= k);
	printf("%d", ans);
	return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    vector<vector<long long>> dp(N+1,vector<long long>(2,0));
    dp[0][0]=0;
    dp[0][1]=INT_MIN;
    for(int i=1;i<=N;i++){
        dp[i][0]=max(dp[i-1][0]+A[i-1],dp[i-1][1]-A[i-1]);
        dp[i][1]=max(dp[i-1][0]-A[i-1],dp[i-1][1]+A[i-1]);
    }
    
    cout<<dp[N][0]<<endl;
    
    return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>

int eval(int year, int month, int day);

int main(void){
    int n,y,m,d,i;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d",&y,&m,&d);
        printf("%d\n",eval(1000,1,1)-eval(y,m,d));
    }
    return 0;
}

int eval(int year, int month, int day){
    int days=day-1;
    while(month!=1){
        if((month-1)%2){
            days+=20;
        }else{
            if(year%3){
                days+=19;
            }else{
                days+=20;
            }
        }
        month--;
    }
    while(year!=1){
        if((year-1)%3){
            days+=195;
        }else{
            days+=200;
        }
        year--;
    }
    return days;
}

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

const int maxS = 3e3 + 7;
pair<int, pair< pair<int, int>, pair<int, int> > > dp[maxS][maxS];

int main() {
  string s, t;
  cin >> s >> t;
  
  int n = (int)s.length(), m = (int)t.length();
  // size of subsequece, index of last character used
 
  int maxLen = 0;
  for(int i = 0;i <= n;i ++) {
  	for(int j = 0;j <= m;j ++) {
    	if(i == 0 || j == 0) {
        	dp[i][j] = {0, {{0, 0}, {0, 0}}};
        } else {
            if(s[i-1] == t[j-1]) {
            	dp[i][j] = {dp[i-1][j-1].first + 1, {{i-1, j-1}, {i, j}}};
              	continue;
            }
        	maxLen = max(dp[i-1][j].first, max(dp[i][j-1].first, dp[i-1][j-1].first));
          	if(maxLen == dp[i-1][j].first) {
            	dp[i][j] = dp[i-1][j];
            } else if(maxLen == dp[i][j-1].first) {
            	dp[i][j] = dp[i][j-1];
            } else {
            	dp[i][j] = dp[i-1][j-1];
            }
        }
    }	
  }
  
  int i_itr = n, j_itr = m;
  
  string ans = "";
  pair<int, int> temp;
  while(i_itr > 0 && j_itr > 0) {
    if(dp[i_itr][j_itr].second.second.first == 0) {
    	break;
    }
  	ans += s[dp[i_itr][j_itr].second.second.first - 1];
    temp = dp[i_itr][j_itr].second.first;
    i_itr = temp.first;
    j_itr = temp.second;
  }
  
  reverse(ans.begin(), ans.end());
  cout << ans;  
}


Measured memory_bytes: 176512
import kotlin.math.abs

fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(' ').map { it.toInt() }
    val A = readLine()!!.split(' ').map { it.toLong() }
    val positiveA = A.filter { it >= 0 }.sortedDescending()
    val negativeA = A.filter { it < 0 }.sorted()

    if (N == K) {
        println(A.reduce { acc, l -> mul(acc, l) })
        return
    }
    if (positiveA.isEmpty() && K % 2 == 1) {
        println(negativeA.takeLast(K).reduce { acc, l -> mul(acc, l) })
        return
    }

    var positiveIdx = 0
    var negativeIdx = 0
    var ans = 1L
    var remK = K

    while (remK > 0) {
        if (remK == 1) {
            ans = mul(ans, positiveA[positiveIdx])
            break
        }

        val positiveX = if (positiveA.size - positiveIdx >= 2) {
            positiveA[positiveIdx] * positiveA[positiveIdx + 1]
        } else {
            0L
        }
        val negativeX = if (negativeA.size - negativeIdx >= 2) {
            negativeA[negativeIdx] * negativeA[negativeIdx + 1]
        } else {
            0L
        }

        if (positiveX >= negativeX) {
            ans = mul(ans, positiveA[positiveIdx])
            positiveIdx++
            remK--
        } else {
            ans = mul(ans, negativeA[negativeIdx])
            ans = mul(ans, negativeA[negativeIdx + 1])
            negativeIdx += 2
            remK -= 2
        }
    }

    println(ans)
}

fun mul(x: Long, y: Long): Long {
    val mod = 1000000007L
    return ((x * y) + mod * mod) % mod
}

Measured memory_bytes: 77724
package main

import (
        "fmt"
)

type Monster struct {
        Hp  int
        Atk int
}

func battle(o, d *Monster) {
        d.Hp -= o.Atk
}

func main() {
        t := new(Monster)
        a := new(Monster)
        fmt.Scanf("%d %d %d %d", &t.Hp, &t.Atk, &a.Hp, &a.Atk)
        //fmt.Printf("t(%d:%d), a(%d:%d)", t.Hp, t.Atk, a.Hp, a.Atk)

        for {
                battle(t, a)
                if t.Hp < 1 {
                        fmt.Print("No\n")
                        return
                }

                battle(a, t)
                if a.Hp < 1 {
                        fmt.Print("Yes\n")
                        return
                }
        }
}


Measured memory_bytes: 1816
$n = gets.to_i

class Problem
  def initialize
    @array = []
  end
  
  def first(char1, char2)
    @array.clear()
    @array.push(char1)
    @array.push(char2)
  end
  
  def reverse(char)
    if char == "W"
      return "S"
    elsif char == "S"
      return "W"
    end
  end
  
  def maru(i)
    if @array[i] == "S"
      @array.push(@array[i-1])
    elsif @array[i] == "W"
      @array.push(reverse(@array[i-1]))
    end
  end
  
  def batsu(i)
    if @array[i] == "S"
      @array.push(reverse(@array[i-1]))
    elsif @array[i] == "W"
      @array.push(@array[i-1])
    end
  end
  
  def input(str)
    for i in 1..$n-1
      if str[i] == "o" 
        maru(i)
      elsif str[i] == "x"
        batsu(i)
      end
    end
  end
  
  def checkFirst()
      if @array.first == "S"
        if $str[0] == "o"
          if @array[1] == @array.last
            return true
          end
        else
          if @array[1] != @array.last
            return true
          end
        end
      else
        if $str[0] == "o"
          if @array[1] != @array.last
            return true
          end
        else
          if @array[1] == @array.last
            return true
          end
        end
      end        

      return false
  end
  
  def ans
    if @array.first == @array.last
      @array.pop()
      if checkFirst == true
        @array.length.times{|i|
          print @array[i]
        }
        return true
      end
    end
    
    return false
  end
end


problem = Problem.new()
$str = gets
4.times{|i|
    if i == 0
     problem.first("S", "S")
    elsif i == 1
     problem.first("S", "W")
    elsif i == 2
     problem.first("W", "S")
    elsif i == 3
     problem.first("W", "W") 
    end
    
    problem.input($str)
    if problem.ans() == true
      break
    end
    
    if i == 3
      print "-1"
    end
}

Measured memory_bytes: 6500
#include <iostream>
using namespace std;
//B - ATCoder
int main(void){
    string s;
    std::cin >> s;
    int maxlength=0,tmplength;
    for(int i=0;i<s.length();i++){
        tmplength=0;
        for(int j=i;j<s.length();j++){
            if(s[j]=='A' ||s[j]=='C' ||s[j]=='G' ||s[j]=='T'){
                tmplength++;
            }else{
                break;
            }
        }
        if(maxlength<tmplength)maxlength=tmplength;
    }
    cout << maxlength << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
 
int main(){
  int n;
  vector<vector<int>> a(3, vector<int>(3));
  rep(i,3) rep(j,3) cin >> a[i][j];
  cin >> n;
  set<int> mp;
  rep(i,n) {
    int b;
    cin >> b;
    mp.insert(b);
  }
  
  for (int i = 0; i < 3; i++) {
    bool ok = true;
    for (int j = 0; j < 3; j++) {
      if (!mp.count(a[i][j])) ok = false;
    }
    if (ok) {
      cout << "Yes" << endl;
      return 0;
    }
  }
 
  for (int j = 0; j < 3; j++) {
    bool ok = true;
    for (int i = 0; i < 3; i++) {
      if (!mp.count(a[i][j])) ok = false;
    }
    if (ok) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  bool ok = true;
  for (int i = 0; i < 3; i++) {
    if (!mp.count(a[i][2-i])) ok = false;
  }
  if (ok) {
      cout << "Yes" << endl;
      return 0;
   }
   ok = true;
  for (int i = 0; i < 3; i++) {
    if (!mp.count(a[i][i])) ok = false;
   
  }
  if (ok) {
      cout << "Yes" << endl;
      return 0;
    }
  cout << "No" << endl;
  return 0;
} 

Measured memory_bytes: 256
n, m = map(int,input().split())
a = list()
for i in range(n):
    a.append(list(map(int,input().split())))

b = list()
for k in range(m):
    b.append(int(input()))

for i in range(n):
    ans = 0
    for j in range(m):
        ans += a[i][j] * b[j]
    print(ans)


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

struct query{
    long long q,x,s,t;
};

ll N, Q, L, R;
vector<long long> A;
vector<query> queries;

long long solve();
long long calc(long long now);

int main(){
    cin >> N >> Q >> L >> R;
    A.resize(N);
    for(int i = 0;i < N;++i)cin >> A[i];
    queries.resize(Q);
    for(int i = 0;i < Q;++i)
        cin >> queries[i].q >> queries[i].x >> queries[i].s >> queries[i].t;
    cout << solve() << endl;
    return 0;
}

long long solve(){
    sort(A.begin(),A.end());
    long long l = 0,r = N - 1,ansl = 0,ansr = N-1;
    if(L <= calc(A[0]))r = 0;
    else if(calc(A[N-1]) < L)return 0;
    else
        while(r - l > 1){
            long long now = (l + r)/2,nowans = 0;
            nowans = calc(A[now]);
            if(L <= nowans)r = now;
            else l = now;
        }
    ansl = r;
    l = 0;
    r = N-1;
    if(R >= calc(A[N-1]))l = N-1;
    else if(calc(A[0]) > R)return 0;
    else
        while(r - l > 1){
            long long now = (l + r)/2,nowans = 0;
            nowans = calc(A[now]);
            if(R >= nowans)l = now;
            else r = now;
        }
        ansr = l;
    return ansr - ansl + 1;
}

long long calc(long long now){
    for(int i = 0;i < Q;++i){
        long long x = queries[i].x,s = queries[i].s,t = queries[i].t;
        if(queries[i].q == 1){
            if(x <= now)now = (now + s) * t;
        }
        else{
            if(x >= now)now = (now - s) / t;
        }
    }
    return now;
}


Measured memory_bytes: 10496
def main():
    k, n = [int(i) for i in input().split()]
    pos = [int(i) for i in input().split()]
    res = k - pos[-1] + pos[0]
    for i, j in zip(pos[:-1], pos[1:]):
        if res < j -i:
            res = j-i
    print(k - res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 26444
#pragma region template
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a) \
    REP(i, (a).size()) { cout << (a[i]) << (i == (a).size() - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

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

int main()
{

    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vi p(A), q(B), r(C);
    REP(i, A)
    {
        cin >> p[i];
    }
    REP(i, B)
    {
        cin >> q[i];
    }
    REP(i, C)
    {
        cin >> r[i];
    }

    RSORT(p);
    RSORT(q);
    RSORT(r);
    vi d;
    ll ans = 0;
    REP(i, X)
    {
        d.push_back(p[i]);
        ans += p[i];
    }
    REP(i, Y)
    {
        d.push_back(q[i]);
        ans += q[i];
    }
    SORT(d);
    REP(i, C)
    {
        if (i < d.size() and d[i] < r[i])
        {
            ans += r[i] - d[i];
        }
    }
    OUT(ans);
}
#pragma endregion template

Measured memory_bytes: 4724
#include <cstdio>

char ch;
int check[10000];

int main(){
    
    while((ch = getchar())!=EOF){
        ++check[ch];
    }
    
    for(int i=97; i<=122; ++i){
        printf("%c : %d\n", i, check[i]+check[i-32]);
    }
}


Measured memory_bytes: 2576
n = str(input())
a = "10" * int(len(n)/2) 
b = "01" * int(len(n)/2) 
if int(len(n)) % 2 !=0:
    a +="1"
    b +="0"
s = int(n) + int(a)
t = int(n) + int(b)
p = str(s)
q = str(t)
print(min(p.count("1"),q.count("1")))


Measured memory_bytes: 3700
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long 
#define INF 1e9
#define LINF 1e18
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FORr(i, j, 0)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;
 
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int A[100000];
P p[100000];
int ALL[100001];

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

    int N, M;
    cin >> N >> M;
    int res = 0;
    priority_queue<int, vector<int>, greater<int> > que;
    rep(i, N) {
        cin >> A[i];
        res += A[i];
        que.push(A[i]);
    }
    sort(A, A + N);
    rep(i, M) cin >> p[i].second >> p[i].first;
    sort(p, p + M);
    reverse(p, p + M);
    rep(i, M) {
        rep(j, p[i].second) {
            if(que.top() < p[i].first) {
                res -= que.top();
                res += p[i].first;
                que.pop();
                que.push(p[i].first);
            }
            else {
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3572
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <map>
#define int long long


using namespace std;

//素因数分解
map<int, int> fct(int N){
    map <int, int> m;
    int a = 2;
    
    while(N >= a * a){
        while(N % a == 0){
            ++m[a];
            N /= a;
        }
        ++a;
    }
    
    if(N != 1){
        m[N] += 1;
    }
    return m;
}



class Combination_mod{
public:
    Combination_mod(int mod);
    int power_mod(int a, int p);
    int div_mod(int A, int B);
    int combi_mod(int n, int k);
    
private:
    int mod;
    vector<int> power_2; //2の累乗のリスト
};

Combination_mod::Combination_mod(int MOD){
    mod = MOD; //mod の初期化
    power_2 = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824};
}

int Combination_mod::power_mod(int a, int p){
    a %= mod;
    
    vector<int> bin_a;
    int pp = p;
    
    for(int i = 30; i >= 0; --i){
        bin_a.push_back(pp / power_2[i]);
        pp = p % power_2[i];
    }
    reverse(bin_a.begin(), bin_a.end());
    
    
    
    //    aの2^n乗のリストを出力する。{a^(2^0=1), a^(2^1), ... , a^(2^30) }
    vector<int> list_a = {};
    for(int i = 0; i < 31; ++i){
        list_a.push_back(a);
        
        a = (a * a) % mod;
    }
    
    
    int ans = 1;
    for(int i = 0; i < 31; ++i){
        if(bin_a[i] == 1){
            ans = (ans * list_a[i]) % mod;
        }
    }
    return ans;
}

int Combination_mod::div_mod(int A, int B){
    A %= mod; B %= mod;
    int ans;
    int inv_B;
    inv_B = power_mod(B, mod - 2);
    ans = (A * inv_B) % mod;
    return ans;
}

int Combination_mod::combi_mod(int n, int k){
    int ans;
    int div = 1;
    int num = 1;
    
    for(int i = 1; i <= k; ++i){
        div = (div * i) % mod;
    }
    
    for(int i = n - k + 1; i <= n; ++i){
        num = (num * i) % mod;
    }
    
    ans = div_mod(num, div);
    return ans;
}


int mod = 1000000007;


signed main(){
    int N, M;
    cin >> N >> M;
    
    map<int, int> fact = fct(M);
    
  	vector<int> list = {};
    for(auto mp : fact){
        list.push_back(mp.second);
    }
  
    int ans = 1;
    
    
    Combination_mod CM(mod);
    
    for(int i = 0; i < list.size(); ++i){
        ans = (ans * CM.combi_mod(N + list[i] - 1, list[i])) % mod;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define  vi vector<long long int>
#define  set1 set<long long int>
#define  pb push_back
#define  map1 map<long long int,long long int>
#define  ll    long long int
#define  mp make_pair
#define  inf 1e17
#define  minf INT_MIN
#define  setbits(x) __builtin_popcountll(x)
#define  pres(x,y) fixed<<setprecision(y)<<x
#define  pair1 pair<long long int,long long int>
#define  mk(arr,n,type) type *arr=new type[n];
#define  mod 1000000007
#define  pi  3.1415926535897932384626433832
#define  ins insert
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//find_by_order() --> returns an iterator to the k-th largest element (counting from zero)
//order_of_key()  --> the number of items in a set that are strictly smaller than our item.
#define  w(t) long long int t;t=1;while(t--)


ll dp[3002][3002][2];

ll solve1(ll a[], ll s, ll e, ll t) {

	if (s > e) {
		return 0;
	}

	if (dp[s][e][t] != -1) {
		return dp[s][e][t];
	}


	if (t == 1) {
		return dp[s][e][t] = max(a[s] + solve1(a, s + 1, e, 0), a[e] + solve1(a, s, e - 1, 0));
	}

	return dp[s][e][t] = min(solve1(a, s + 1, e, 1), solve1(a, s, e - 1, 1));

}
void solve() {

	ll n;
	cin >> n;
	ll a[n], s = 0;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		s += a[i];
	}
	memset(dp, -1, sizeof(dp));
	ll x = solve1(a, 0, n - 1, 1);
	ll y = s - x;
	cout << x - y << "\n";

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inp.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	w(t) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 144680
import sys

w = sys.stdin.readline().rstrip().lower()
cnt = 0
while True:
    lines = sys.stdin.readline().rstrip()
    if not lines:
		break	
    words = lines.split( " " )
    for i in range( len( words ) ):
    	if w == words[i].lower():    		
			cnt += 1			
print( cnt )

Measured memory_bytes: 4200
#include <stdio.h>
#include <string.h>
#define cmin(x, y) ((y)<x?x=(y),1:0)
#define cmax(x, y) ((y)>x?x=(y),1:0)
#define dmin(x, y) ((x)<(y)?(x):(y))
#define dmax(x, y) ((x)>(y)?(x):(y))
const int N=2e5+5;
char s[N], cho[N], ans[N];
int f[N], from[N], last[26];
int main() {
	register int n, i, j, k;
	register char *p=ans;
	scanf("%s", s+1);
	n=strlen(s+1);
	for(i=0; i<26; ++i) last[i]=n+1;
	for(i=n; i>=0; --i) {
		register int &F=f[i];
		F=n+1;
		for(j=0; j<26; ++j) {
			k=f[last[j]]+1;
			if(cmin(F, k)) {
				cho[i]=j+'a';
				from[i]=last[j];
			}
		}
		if(i) last[s[i]-'a']=i;
	}
	for(i=0; i!=n+1; i=from[i]) *p++=cho[i];
	puts(ans);
	return 0;
}

Measured memory_bytes: 2176
public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        long n = scanner.nextLong(), m = scanner.nextLong();
        System.out.println((m * 2 > n ? (m - Math.min(n, m / 2) * 2) / 4 : 0) + Math.min(n, m / 2));
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    ll n; cin >> n;
    Vl t(n), x(n), y(n);
    rep(i, 0, n) cin >> t[i] >> x[i] >> y[i];

    bool f = true;
    ll T = 0, X = 0, Y = 0;
    rep(i, 0, n){
        if(t[i]%2 != (x[i]+y[i])%2) f = false;
        if(t[i] < x[i] + y[i]) f = false;
        if(!(abs((t[i]-T)%2) == abs(x[i]+y[i]-X-Y)%2)
        && (t[i]-T >= (x[i]+y[i]-X-Y))) f = false;
        T = t[i], X = x[i], Y = y[i];
    }

    if(f) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 2560
def XC2(X):
    if X <= 1:
        return 0
    else:
        return int(X*(X-1)/2)

if __name__ == '__main__':
    s = input().rstrip().split(' ')
    N = int(s[0])
    M = int(s[1])

    print(XC2(N)+XC2(M))


Measured memory_bytes: 2940
var
a:array[1..100] of longint;
i,j,t,n,k,m,s,sum:longint;
begin
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do 
for j:=i+1 to n do 
if a[i]>a[j] then 
 begin
  t:=a[i];
  a[i]:=a[j];
  a[j]:=t;
 end;
 while s<k do 
  begin
   sum:=sum+a[n];
   n:=n-1;
   inc(s);
  end;
  writeln(sum);
  end.
   
   

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
  
int main(){
    int x,y,g;
    cin >> x >>y >>g;
    if (x<y && y<g){
        cout<<"Yes"<<endl;
        return 0;
    }
    else {
        cout<<"No"<<endl;
        return 0;
    }
} 


Measured memory_bytes: 3088
//Abhigyan's Code:
             
    //YOU DON'T DARE TO COPY :) 

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
    #define checker cout<<"CHECKED" 
    #define modulo 1000000007
    bool vis[100005] ;

    vector<ll> adj[100005] ;

    void dfs(ll src , vector<ll> &dp)
    {
      vis[src] = true ; 
      for(auto z : adj[src])
      {
        if(!vis[z])
        {
          dfs(z , dp) ;
        }
        dp[src] = max(dp[src] , 1 + dp[z]) ;
      }
    }
  
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
     
      ll n , m ;
      cin >> n  >> m ;

      ll temp = m;

      while(temp--)
      {
        ll x , y ;
        cin >> x >> y;
        adj[x].push_back(y); 
      }
      vector<ll> dp(n+1) ;

      memset(vis , false , sizeof(vis)) ;

      for(ll i = 0 ; i<= n; i++)
        dp[i] = 0 ;
      
      for(ll i =1 ; i <= n ;i++)
      {
        if(!vis[i])
          dfs(i,dp);
      }

      cout << *(max_element(dp.begin() , dp.begin()+n + 1 ) ) <<endl ;

    return 0;

   }   

Measured memory_bytes: 12380
n=int(input())
L=list(map(int,input().split()))

cnt=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if L[i]!=L[j] and L[j]!=L[k] and L[k]!=L[i]:
                if L[i]+L[j]>L[k] and L[j]+L[k]>L[i] and L[k]+L[i]>L[j]:
                    cnt+=1
print(cnt)

Measured memory_bytes: 9240
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
template<class T>inline void chmin(T &a,T b){a=min(a,b);}
template<class T>inline void chmax(T &a,T b){a=max(a,b);}

int N;
vector<int>G[100005];
bool used[100005];
int dis[100005],par[100005];
bool match[100005];
int ans;
void dfs(int x){
	used[x]=true;
	for(int i:G[x]){
		if(!used[i]){
			dis[i]=dis[x]+1;
			par[i]=x;
			dfs(i);
		}
	}
}
signed main(){
	cin>>N;
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0);
	vector<P>v;
	rep(i,N)v.push_back({dis[i],i});
	sort(all(v),greater<>());
	rep(i,N-1){
		if(!match[v[i].second]&&!match[par[v[i].second]]){
			match[par[v[i].second]]=true;
			ans++;
		}
	}
	if(ans*2==N)cout<<"Second"<<endl;
	else cout<<"First"<<endl;
}


Measured memory_bytes: 10996
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int even = sc.nextInt();  //偶数の個数
		int odd = sc.nextInt();  //奇数の個数

		System.out.print(even*(even-1)/2+odd*(odd-1)/2);
	}
}


Measured memory_bytes: 22612
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <set>
#include <cstring> 

using namespace std;

#ifdef DEBUG_MODE
#define DBG(n) n;
#else
#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;

int mp[111111];
int a[111111];
int b[111111];

int main() {

	int n; cin >> n;
	vector<pair<ll,ll>> v;

	ll Asum = 0;
	ll Bsum = 0;
	ll tmpSum = 0;
	ll ans = LLINF;
	
	REP(i, n) {
		cin >> a[i] >> b[i];
		v.PB(MP(a[i], i));
		v.PB(MP(b[i], i));
		Asum += a[i];
		Bsum += b[i];
	}

	sort(ALL(v));
	REP(i, n) {
		tmpSum += v[i].first;
		mp[v[i].SE]++;
	}

	REP(i, n) {
		ll now = tmpSum;
		if (mp[i] == 0) {
			now -= v[n - 1].first;
			now -= v[n - 2].first;
			now += a[i];
			now += b[i];
		}
		else if (mp[i] == 1) {
			if (v[n - 1].second == i) {
				now -= v[n - 2].first;
				now += max(a[i], b[i]);
			}
			else {
				now -= v[n - 1].first;
				now += max(a[i], b[i]);
			}
		}
		else {
		}
		ans = min(ans, now);
	}

	cout << min(ans, min(Asum, Bsum)) << endl;

	return 0;
}


Measured memory_bytes: 6768
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c= 0;
		
		int i=1;		//最小公倍数を求める
		while(i<=b){
			if((long)a*i%b==0) {
				c=(long)a*i;
				break;
			}
			else{
				i++;
			}
		}
 		 System.out.println(c);
		 sc.close();
	}
}


Measured memory_bytes: 23508
#include<iostream>
#include<algorithm>
using namespace std;
bool ss(int a,int b){
	return a>b;
}

int main(){
	int a[105];
    int n,k;
    double s=0;
    cin>>n>>k;
    for(int i=0;i<n;i++) {
	cin>>a[i];
	s+=a[i];
     }
	sort(a,a+n,ss);
	int flag=1;
	for(int i=0;i<k;i++){
		if(a[i]<s/(4*k)) flag=0;
	} 
	
	if(flag==0) cout<<"No";
	else cout<<"Yes";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
int main(void){
  
 int r,d,saisho,number;
  
  cin>>r>>d>>saisho;
  
  number = saisho;
  
  
  for(int i = 0;i < 10;i++){
  
    number = r * number - d;
    
    cout<<number<<endl;
    
    
  }
  
  
  
  return 0;
  
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a,b,c,t;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a>b){
		t=b;
		b=a;
		a=t;
	}
	if(b>c){
		t=c;
		c=b;
		b=t;
	}
	if(a>b){
		t=b;
		b=a;
		a=t;
	}
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
using namespace std;
 
int main() {
  int K;
  string S;
  cin >> K >> S;
  
  for (int i = 0; i < K; i++) {
    cout << S[i];
    if (int(S.size() == i + 1)) {
      cout << endl;
      return 0;
    }
  }
  cout << "..." << endl;
  return 0;   
}


Measured memory_bytes: 3624
N = input()
if N.isdigit() and int(N) >= 1 and  int(N) <= 100:
  if int(N) % 2 == 0:
    ans = int(N) / 2
  else:
    ans = (int(N) - 1) / 2 + 1
  print(int(ans))
else:
  print('error')

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

int bs_upper_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x >= a[mid]) {
            l = mid + 1;
        } else {
            h = mid;
        }
    }
    return l;
}

int bs_lower_bound(int a[], int n, int x) {
    int l = 0;
    int h = n; // Not n - 1
    while (l < h) {
        int mid =  l + (h - l) / 2;
        if (x <= a[mid]) {
            h = mid;
        } else {
            l = mid + 1;
        }
    }
    return l;
}

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 

int main()
{
    IOS;
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll dp[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)
            dp[i][j]=LONG_MAX;
    }
    for(int i=0;i<n;i++)
        dp[i][i]=0;
    for(int k=2;k<=n;k++){
        for(int i=0;i<n-k+1;i++){
            ll s=a[i];
            for(int j=i+1;j<i+k;j++){
                s+=a[j];
                for(int l=i;l<j;l++)
                    dp[i][j]=min(dp[i][j],s+dp[i][l]+dp[l+1][j]);
            }
        }
    }
    cout<<dp[0][n-1];
}


Measured memory_bytes: 4804
#include <bits/stdc++.h>
#include<queue>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<double,double> Pdouble;

const int INF = 2000000000;

long long gcd(long long a, long long b){ //最大公約数
  if (a%b == 0){
    return(b);
  }
  else{
    return(gcd(b, a%b));
  }
}
int main(){

  ll a,b;
  cin >> a >> b;
  ll num;
  num = gcd(a,b);

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

  ll count = 1;
  vector<long long> Factors;
  for (long long i = 2; i*i <= num; i++){ // 他の素数（奇数）で割っていく
    if(num % i == 0){
      while (num % i == 0){
      Factors.push_back(i);
      num /= i;
      }
      count++;
    }
  }
  if(num != 1){
    count++;
  }
  cout << count << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sc second

const int N = (int) 1e6  +10;
int a[N], n;

bool check(int k) {
	vector< pair<int, int> > s;
	s.pb(mp(0, 0));
	for (int i = 1; i < n; ++i) {
		if (a[i] > a[i - 1]) {
			continue;
		}
		if (k == 1) {
			return false;
		}
		int j = a[i] - 1;
		while (!s.empty() && (s.back().fs > j)) {
			s.pop_back();
		}
		while (!s.empty() && (s.back() == mp(j, k - 1))) {
			s.pop_back();
			--j;
		}
		if (s.empty()) {
			return false;
		}
		if (s.back().fs != j) {
       		s.pb(mp(j, 1));
       		continue;
       	}
       	s.back().sc++;
	}
	return true;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
	}
	int l = 0, r = n;
	while (l + 1 < r) {
		int q = (l + r) / 2;
		(check(q) ? r : l) = q;
	}
	printf("%d\n", r);
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <map>
#include <queue>
#include <cstring>
using namespace std;

typedef int F;

const int MAXV = 410;
const int MAXE = 5005;
const F MAXF = 1<<29;
const int MAXH = 1<<29;

int last[MAXV], prev[MAXE], to[MAXE], h[MAXV], pv[MAXV], pe[MAXV];
F cap[MAXE], flow[MAXE], cost[MAXE], d[MAXV];

struct St { int v; int c; int f; int fe; };
bool operator<(const St &s, const St &t) {
    return (s.c != t.c)? s.c>t.c : s.v < t.v;
}

struct MinCostFlow {
    int V, E;
    MinCostFlow(int n) : V(n), E(0) { memset(last, -1, sizeof(last)); }
    inline F rcost(const int s, const int e) {
        return d[s] + cost[e] + h[s] - h[to[e]];
    }

    void add_edge(int f, int t, F ca, F co) { // from, to, cap, cost
        to[E] = t; prev[E] = last[f]; last[f] = E;
        cap[E] = ca; cost[E] = co; flow[E] = 0; E++;
        to[E] = f; prev[E] = last[t]; last[t] = E;
        cap[E] = flow[E] = 0; cost[E] = -co; E++;
    }
    void calc_potential(int s) {
        for (int i=0; i<V; ++i) h[i] = MAXH;
        h[s] = 0;
        for (int k=0; k<V; ++k)
            for (int i=0; i<V; ++i)
                for (int e = last[i]; e != -1; e = prev[e])
                    if (cap[e] > 0)
                        h[to[e]] = min(h[to[e]], h[i] + cost[e]);
    }
    void init_d() { for (int i=0; i<V; ++i) d[i] = MAXF; }

    pair<F, F> minimum_cost_flow(int s, int t, F max) {
        F total_flow = 0, total_cost = 0;
        calc_potential(s);
        for (F r = max; r > 0; ) {
            // do dijkstra
            init_d(); d[s] = 0;
            memset(pv, -1, sizeof(pv));
            priority_queue<St> q;
            for (q.push((St){s,0,s,-1}); !q.empty(); ) {
                St s = q.top(); q.pop();
                if (pv[s.v] != -1) continue;
                pv[s.v] = s.f; pe[s.v] = s.fe;
                for (int e = last[s.v]; e != -1; e = prev[e]) {
                    if (cap[e] - flow[e] > 0) {
                        if (d[to[e]] > rcost(s.v, e)) {
                            d[to[e]] = rcost(s.v, e);
                            q.push((St){to[e], d[to[e]], s.v, e});
                        }
                    }
                }
            }

            if (pv[t] == -1) break;
            F f = r;
            for (int u = t; u != s; u = pv[u])
                f = min(f, cap[pe[u]] - flow[pe[u]]);
            for (int u = t; u != s; u = pv[u]) {
                total_cost += f * cost[pe[u]];
                flow[pe[u]] += f; flow[pe[u]^1] -= f;
            }
            r -= f;
            total_flow += f;
            for (int u=0; u<V; ++u) if (h[u] != MAXH) h[u] += d[u];
        }
        return make_pair(total_cost, total_flow);
    }
};

int main() {
    int n, a, b, w;
    while(scanf("%d", &n), n) {
        MinCostFlow mcf(366);
        for (int i=0; i<n; ++i) {
            scanf("%d %d %d", &a, &b, &w); a--;
            mcf.add_edge(a, b, 1, -w);
        }
        for (int i=0; i<365; ++i)
            mcf.add_edge(i, i+1, 2, 0);
        printf("%d\n", -(mcf.minimum_cost_flow(0, 365, 2).first));
    }
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    bool D=true;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            if (i*j==N)
            {
                D = false;
            }
            
        }
        
    }
    if (D)
    {
        cout <<"No"<<endl;
    }
    else
    {
        cout <<"Yes"<<endl;
    }
    
    
}

Measured memory_bytes: 256
const main = (input) => {
  var ip = input.trim().split("\n")[0].split(" ");
  var N = ip[0]-0;
  var K = ip[1]-0;
  if(N<=K/2){
    console.log(N);
    return;
  }
  var inputs = input.trim().split("\n")[1].split("");
  var maps = [];
  var tobj = {t:-1,s:-1,e:-1};
  for(var i=0;i<inputs.length;i++){
    if(tobj.t != inputs[i]-0){
      if(tobj.t != -1){
        tobj.e = i-1;
        maps.push(tobj);
        tobj = {t:-1,s:-1,e:-1};
      }
      tobj.t = inputs[i]-0;
      tobj.s = i;
    }
  }
  tobj.e = N-1;
  maps.push(tobj);
  var ans = 0;
  var omap = {}, zmap = {};
  var maxd = K*2;
  for(var s=0;s<maps.length;s++){
    var cnt = 0, zflg=false,zcnt=0;
    var mapst = maps[s];
    var mapen = maps[Math.min(s+maxd-1+mapst.t, maps.length-1)];
    ans = Math.max(ans, mapen.e-mapst.s+1);
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 26828
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
#define fs(i, x, y) for(int i = x;i >= y;i--)
#define maxn 200005
using namespace std;
typedef long long ll;
typedef struct node {
    int id, val;
    node(int a1, int a2) {
        id = a1;
        val = a2;
    }
};
bool operator <(const node &a1, const node &a2) {
    if(a1.val <= a2.val) return true;
    return false;
}
int a[maxn], b[maxn], n;
priority_queue<node>p;
int main() {
    scanf("%d", &n);
    ff(i, 1, n)
    scanf("%d", &a[i - 1]);
    ff(i, 1, n)
    scanf("%d", &b[i - 1]);
    ff(i, 1, n) {
        if(a[i - 1] < b[i - 1])
            p.push(node(i - 1, b[i - 1]));
      	else if(a[i - 1] > b[i - 1]) {
          printf("-1");
       	  return 0;
        }
    }
    int flag = 1;
    ll ans = 0;
    while(!p.empty()){
        node temp = p.top();
        p.pop();
        int pos = temp.id, v = temp.val;
        //printf("%d\n", v);
        int mod;
        if(pos == 0)
            mod = b[n - 1] + b[1];
        else if(pos == n - 1)
            mod = b[0] + b[n - 2];
        else
            mod = b[pos - 1] + b[pos + 1];
        if(v <= mod) {
            flag = 0;
            break;
        }
        v = (b[pos] - a[pos]) % mod;
        ans += (b[pos] - a[pos]) / mod;
        b[pos] = a[pos] + v;
        if(v == 0);
        else
            p.push(node(pos, b[pos]));
    }
    while(!p.empty()) {
        p.pop();
    }
    if(flag)
        printf("%lld", ans);
    else
        printf("-1");
    return 0;
}


Measured memory_bytes: 3956
x=input().split()
h=int(x[0])
n=int(x[1])
import numpy as np
a=np.full(n,0,int)
b=np.full(n,0,int)
for k in range(n):
  x=input().split()
  a[k]=int(x[0])
  b[k]=int(x[1])
m=max(a)  
inf=10**8
dp=np.full(h+m,inf,int)
dp[0]=0
for k in range(1,h+m):
  dp[k]=(dp[k-a]+b).min()
print(dp[h:h+m].min())

  

Measured memory_bytes: 12520
#include <bits/stdc++.h>
namespace xxx{
using namespace std;
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define CaseT int T;cin >> T;for(int cas=1;cas<=T;cas++)
#define TCase int T;scanf("%d",&T);for(int cas=1;cas<=T;cas++)
#define clr(a,b) memset(a,b,sizeof(a))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define _1s __builtin_popcountll
#define sqr(x) ((x)*(x))
#define upd(a,b) (a%b?a/b+1:a/b)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define fst first
#define sec second
#define MAIN int main
#define GG exit(0)
#define bug cout << "!!!" << endl;
#define bugc(x) cout << "! " << (x) << endl;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;

inline ll rd(){
    ll 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;
}
 
}using namespace xxx;
const int N = 100+20;

struct node{
	ll x, y, h;
};

ll n;
node a[N];

void ok(ll x,ll y){
	set<ll>st;
	for(ll i=1;i<=n;i++) if(a[i].h) st.insert(a[i].h+abs(x-a[i].x)+abs(y-a[i].y));
	if(st.size()>1) return;
	for(ll i=1;i<=n;i++){
		if(!a[i].h){
			if(abs(x-a[i].x)+abs(y-a[i].y)<*st.begin()) return;
		}
	}
	if(st.size()==1){
		cout << x << ' ' << y << ' ' << *st.begin() << endl;
		GG;
	}
}

MAIN(){
	cin >> n;
	for(ll i=1;i<=n;i++) cin >> a[i].x >> a[i].y >> a[i].h;
	for(ll i=0;i<=100;i++) for(ll j=0;j<=100;j++) ok(i,j);
	GG;
}

Measured memory_bytes: 256