akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Object o = run();
        if (o != null)
            System.out.println(o);
    }

    static Object run() {
        try (Scanner sc = new Scanner(System.in)) {
            int h1 = sc.nextInt();
            int m1 = sc.nextInt();
            int h2 = sc.nextInt();
            int m2 = sc.nextInt();
            int k = sc.nextInt();
            int t = (h2 * 60 + m2) - (h1 * 60 + m1);
            return t - k;
        }
    }
}

class ChenNumberUtil {
    static Collection<Integer> getDivisors(int n) {
        ArrayList<Integer> al = new ArrayList<>();
        for (int i = 1; i * i <= n; i++) {
            if (n % i == 0) {
                al.add(i);
                if (n / i != i)
                    al.add(n / i);
            }
        }
        Collections.sort(al);
        return al;
    }
}

class ChenBitUtil {
    static int popCount(int bit) {
        return Integer.bitCount(bit);
    }

    static boolean isFlag(int bit, int i) {
        return 0 != (bit & (1 << i));
    }

    static int setTrue(int bit, int i) {
        return bit |= (1 << i);
    }

    static int setFalse(int bit, int i) {
        return bit &= ~(1 << i);
    }

    static int setReverse(int bit, int i) {
        return isFlag(bit, i) ? setFalse(bit, i) : setTrue(bit, i);
    }

    static int reverseAll(int bit) {
        return ~bit;
    }
}


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

int main()
{
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> v(n + 1, 0);
  for (int i = 0; i < m; i++)
  {
    int a;
    cin >> a;
    v[a] = 1;
  }
  int a, b;
  a = b = 0;
  for (int i = x; i <= n; i++)
  {
    if (v[i] == 1)
    {
      a++;
    }
  }
  for (int i = x; i >= 0; i--)
  {
    if (v[i] == 1)
    {
      b++;
    }
  }
  int ans = min(a, b);
  cout << ans << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>s(n);
	int ans=0;
	for(auto&i:s)cin>>i,ans+=i;
	sort(s.begin(),s.end());
	if(ans%10==0){
		bool yes=false;
		for(int i=0;i<n;++i){
			if(s.at(i)%10!=0){
				ans-=s.at(i);
				yes=true;
				break;
			}
		}
		if(!yes)ans=0;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n)==1){
	int tot = 0;
	for(int i=0;i<10;++i){
		for(int j=0;j<10;j++){
			for(int k=0;k<10;++k){
				for(int w=0;w<10;++w){
					if(i+j+k+w==n){
						++tot;
					}
				}
			}
		}
	}
	cout<<tot<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
using System;

class Program
{
    static void Main(string[] args)
    {
        // 整数r, g, bの入力
        string[] input = Console.ReadLine().Split(' ');
        int number = (int.Parse(input[0]) * 100) + (int.Parse(input[1]) * 10) + (int.Parse(input[2]));

        if ( (number % 4) == 0 )
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 13140
import java.util.*;
import java.io.*;
 
class Main {
 
  static int INF = (int) 1e9 + 7;
  static List<List<Integer>> adj;
 
  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    
    int n = in.nextInt();
    adj = new ArrayList<>(n + 1);
    for (int i  = 0; i <= n; i++) {
      adj.add(new ArrayList<>());
    }
    for (int i = 1; i < n; i++) {
      int u = in.nextInt();
      int v = in.nextInt();
      adj.get(u).add(v);
      adj.get(v).add(u);
    }

    long[] res = dfs(1, -1);

   
    System.out.println(add(res[0], res[1]));
  }

  static long[] dfs(int cur, int parent) {

    // res[0]: counts when cur is painted black
    // res[1]: counts when cur is painted white
    long[] res = new long[2]; 
    Arrays.fill(res, 1);

    for (int next : adj.get(cur)) {
      if (next != parent) {
        long[] child = dfs(next, cur);
        res[0] = mul(res[0], child[1]);
        res[1] = mul(res[1], add(child[0], child[1]));
      }
    }

    return res;
    


    //System.out.println(cur);
  }

  static void add(int[] a, int i, int j) {
    a[i] += a[j];
    if (a[i] >= INF) {a[i] -= INF;}
  }

  static long add(long a, long b) {
    a = a + b;
    if (a >= INF) {a -= INF;}
    return a;
  }

  static long mul(long a, long b) {
    long res = a * b;
    
    return  (res % INF);
  }

  static int countSetBit(int a) {
    int count = 0; 
    while (a > 0) {
      count += (a & 1);
      a = a >> 1;
    }
    return count;
  }

 
}

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

#define MAX 100000007
int main(void){
  int h,w,k;
  cin >> h >> w >> k;

  int mat[h+1][w+1];
  for(int i=0;i<=h;i++){
    for(int j=0;j<=w;j++){
      mat[i][j] = 0;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      char work;
      cin >> work;
      if(work == '0') mat[i][j] = 0;
      else mat[i][j] = 1;
    }
  }

  /*for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cout << mat[i][j] << " ";
    }
    cout << endl;
    }*/

  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      mat[i][j] += mat[i-1][j]+mat[i][j-1]-mat[i-1][j-1];
    }
  }

  /*cout << "Cumulative sum" << endl;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cout << mat[i][j] << " ";
    }
    cout << endl;
    }*/

  int ans = MAX;
  for(int i=0;i<1<<(h-1);i++){
    int line[h+1],work=i,cur=1,ans_tmp = 0;
    line[0] = 0;
    for(int j=0;j<h-1;j++){
      if(work%2 == 1){
	line[cur] = j+1;
	cur++;
	ans_tmp++;
      }
      work /= 2;
    }
    line[cur] = h;
    cur++;
    
    /*cout << "line: ";
    for(int j=0;j<cur;j++)cout << line[j] << " ";
    cout << endl;*/
      
    int cur_w = 0;
    for(int j=1;j<=w;j++){
      bool flag = true;
      for(int l=1;l<cur;l++){
	int top = line[l-1],bottom = line[l],left = cur_w,right = j;
	//cout << "area: (" << top+1 << "," << bottom << "," << left+1 << "," << right << "):" << mat[bottom][right]+mat[top][left]-mat[bottom][left]-mat[top][right] << endl; 
	if(mat[bottom][right]+mat[top][left]-mat[bottom][left]-mat[top][right] > k){
	  flag = false;
	}
      }
      if(!flag){
	//cout << "out!" << endl;
	if(cur_w+1 == j){
	  ans_tmp = MAX;
	  break;
	}
	cur_w = j-1;
	j--;
	ans_tmp++;
      }
    }
    if(ans_tmp < ans)ans = ans_tmp;
  }

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


Measured memory_bytes: 256
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
        int n, x;
        scanf("%d %d", &n, &x);
        V a(n);
        scan(a);
        std::sort(be(a));
        int ans = 0;
        rep(i, 0, n-1){
                if(x>=a[i]){
                        ans++;
                        x -= a[i];
                }
        }
        if(x==a[n-1]) ans++;
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,a[100],A,B,ans1,ans2;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        A+=a[i];
    }
    A/=n;
    B=A+1;
    for(int i=0;i<n;i++){
        ans1+=(A-a[i])*(A-a[i]);
        ans2+=(B-a[i])*(B-a[i]);
    }
    cout<<min(ans1,ans2)<<endl;
}


Measured memory_bytes: 256
N, M = map(int,input().split())
if N % 2 == 1:
    for i in range(1, M+1):
        print(*[i, N-i])
else:
    for i in range(1, M+1):
        if i <= N // 4:
            print(*[i, N-i+1])
        else:
            print(*[i, N-i])

Measured memory_bytes: 9288
#include<bits/stdc++.h>
using namespace std;
#define int long long

struct edge{ int to,cost; };
const int N = 2e5+10;
vector< edge > G[N];

struct TreeDP{
  vector<int> d; //始点(n/2とする)から最も遠い距離
  vector<int> dp; //各点から最も遠い距離
  void init(int n){
    d.resize(n+1); dp.resize(n+1);
  }

  void dfs1(int u,int par){
    for(auto e : G[u]){
      if(e.to == par) continue;
      dfs1(e.to,u);
      d[u] = max(d[u],d[e.to] + e.cost);
    }
  }

  int dfs2(int u,int d_par,int par){
    vector< pair<int,int> > d_child;
    d_child.push_back({0,-1}); //番兵
    for(auto e : G[u]){
      if(e.to == par) d_child.push_back({d_par + e.cost,e.to});
      else d_child.push_back({e.cost + d[e.to],e.to});
    }
    sort(d_child.rbegin(),d_child.rend());

    int res = d_child[0].first + d_child[1].first;
    dp[u] = d_child[0].first;
    for(auto e : G[u]){
      if(e.to == par) continue;
      int v = d_child[0].second == e.to;
      res = max(res,dfs2(e.to,d_child[v].first,u));
    }
    return res;
  }
}Tree;

signed main(){

  int n; cin >> n;
  for(int i = 0; i < n-1; i++){
    int s,t,w; cin >> s >> t >> w;
    G[s].push_back({t,w});
    G[t].push_back({s,w});
  }

  Tree.init(n);
  Tree.dfs1(n/2,-1);
  Tree.dfs2(n/2,0,-1);
  for(int i = 0; i < n; i++){
    cout << Tree.dp[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 8972
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

vector<ll> v;

void dfs(ll x,int s)
{
	v.pb(x);
	if(s>=10)
		return;
	ll y=x%10;
	dfs(x*10+y,s+1);
	if(y!=0)
		dfs(x*10+y-1,s+1);
	if(y!=9)
		dfs(x*10+y+1,s+1);
}
int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	for(ll i=1;i<10;i++)
	{
		dfs(i,1);
	}
	sort(ALL(v));
	int k;
	cin>>k;
	cout<<v[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int i = 1;

		while(true) {
			int x = sc.nextInt();
			if(x == 0)break;
			System.out.println("Case " + i++ + ": " + x);
		}

	}

}



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

int main()
{
	string s, t;
	cin >> s >> t;
	int check[s.length()+1][t.length()+1];
	memset(check, 0, sizeof(check));
	
	f(i, 0, s.length()+1)
	{
		f(j, 0, t.length()+1)
		{
			if(i == 0 || j == 0)
			check[i][j] = 0;
			else if(s[i-1] == t[j-1])
			check[i][j] = check[i-1][j-1]+1;
			else
			check[i][j] = max(check[i-1][j], check[i][j-1]);
		}
	}
	string X = "";
	int i = s.length(), j = t.length();
	while(i > 0 && j > 0)
	{
		if(s[i-1] == t[j-1])
		{
			X += s[i-1];
			i--;
			j--;
		}
		else if(check[i-1][j] > check[i][j-1])
		i--;
		else
		j--;
	}
	reverse(X.begin(), X.end());
	cout << X << endl;
}

Measured memory_bytes: 35456
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int c=0;c<n;c++) {
			int y = sc.nextInt(), m = sc.nextInt(), d = sc.nextInt(), cnt = 0;
			while( !( y == 1000 && m == 1 && d == 1 ) ) {
				cnt++; d++;
				if( d == (y%3==0? 21: ( m%2==0? 20: 21 ) ) ) {
					d = 1; m++;
					if(m == 11) {
						m = 1; y++;
					}
				}
			}
			System.out.println(cnt);
			
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

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

#define fi first
#define se second
#define pb push_back
#define sz(x) int((x).size())
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define testcase int _;cin>>_;while(_--)
#define all(x) ((x).begin(),(x).end())

void Solve(){
	int k;
	cin>>k;
	if(k%2==0 || k%5==0){
		cout<<"-1\n";
		return;
	}
	int n=0;
	for(int i=0;i<k;i++){
		n=(n*10+7)%k;
		if(n==0){
			cout<<i+1<<"\n";
			return;
		}
	}
	cout<<"-1\n";
}

int main(){
	fast
	//testcase
		Solve();
	return 0;
}

Measured memory_bytes: 3620
n,m = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort.reverse

sum = a.inject(:+)
isable = true
m.times do |i|
  if a[i] < sum / (4.0 * m)
    isable = false
  end
end
if isable
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14396
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$K = getq();
echo $K<1200?"ABC":"ARC";
?>

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
vector<int> Graph[210000];
vector<int> Depth[210000];
vector<int> Deep(210000);
vector<int> Parent(210000);
vector<int> child[210000];
int root;
void BFS() {
  for (int i = 0; i < (int)Deep.size(); i++) {
    Deep[i] = 999999;
  }
  priority_queue<P, vector<P>, greater<P>> Q;
  Q.push(make_pair(0,root));
  Depth[0].push_back(root);
  Deep[root] = 0;
  while (!Q.empty()) {
    P p = Q.top();
    Q.pop();
    for (int i = 0; i < (int)Graph[p.S].size(); i++) {
      if (Deep[Graph[p.S][i]] > p.F + 1) {
        Q.push(make_pair(p.F+1,Graph[p.S][i]));
        Deep[Graph[p.S][i]] = p.F + 1;
        Depth[p.F+1].push_back(Graph[p.S][i]);
        Parent[Graph[p.S][i]] = p.S;
        child[p.S].push_back(Graph[p.S][i]);
      }
    }
  }
}
int main() {
  int N,Q;
  cin >> N >> Q;
  
  int ans[N];
  for (int i = 0; i < N; i++) {
    ans[i] = 0;
  }
  for (int i = 0; i < N-1; i++) {
    int a,b;
    cin >> a >> b;
    a--; b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  root = 0;
  
  BFS();

  for (int i = 0; i < Q; i++) {
    int p,x;
    cin >> p >> x;
    p--;
    ans[p] += x;
  }
  for (int i = 0; i < N-1; i++) {
    for (int j = 0; j < (int)Depth[i].size(); j++) {
      for (int k = 0;  k < (int)child[Depth[i][j]].size(); k++) {
        ans[child[Depth[i][j]][k]] += ans[Depth[i][j]];
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 38960
N, T = gets.chomp.split().map(&:to_i)
data = []
N.times do
  a, b = gets.chomp.split().map(&:to_i)
  data << [a, b]
end
info =  data.select{ |ary| ary[1] <= T }.sort_by{ |ary| ary[0] }
if info.length == 0
  puts 'TLE'
else
  puts info[0][0]
end

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const llint INF = 999999999999999;




int main()
{
    string s, t;
    cin >> s >> t;
    int sz = s.size(); 

    map<char, int> smap, tmap;
    vector<int> snum, tnum;
    int sc = 1, tc = 1;

    rep(i, sz) {
        if (smap[s[i]] == 0) {
            smap[s[i]] = sc;
            sc++;
        }
        snum.push_back(smap[s[i]]);

        if (tmap[t[i]] == 0) {
            tmap[t[i]] = tc;
            tc++;
        }
         tnum.push_back(tmap[t[i]]);
    }

    
    bool jdg = true;
    rep(i, sz) if (snum[i] != tnum[i]) jdg = false;
   
    if (jdg) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 2428
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#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;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    rep(i, 0, H) { cin >> s[i]; }
    // {0, 1, ..., n-1} の部分集合の全探索
    long long res = INF;
    for(int bit = 0; bit < (1 << (H - 1)); ++bit) {
       // cout << "hei" << endl;
        vector<int> tmp;
        vector<int> sen(H - 1);
        tmp.push_back(0);
        for(int i = 0; i < H - 1; ++i) {
            if(bit & (1 << i)) { // 列挙に i が含まれるか
                tmp.push_back(0);
                sen[i] = 1;
            }
        }
        //cout << "size:" << tmp.size() << endl;
        long long kouho = tmp.size() - 1;
        rep(t, 0, W) {
            int ret = 0;
            int tmpnum = 0;
            bool koe = false;
            while(ret < H) {
                if(s[ret][t] == '1') {
                    tmp[tmpnum]++;
                 
                    if(tmp[tmpnum] > K) {
                        koe = true;
                    }
                }
                if(ret!=H-1&&sen[ret] == 1) {
                    tmpnum++;
                }
                ret++;
                
            }

            if(koe) {
                kouho++;
                rep(k, 0, tmp.size()) { tmp[k] = 0; }
                int ret2 = 0;
                int tmpnum2 = 0;
                bool koe2 = false;
                while(ret2 < H) {
                    if(s[ret2][t] == '1') {
                        tmp[tmpnum2]++;
                        if(tmp[tmpnum2] > K) {
                            koe2 = true;
                        }
                    }
                    if(ret2!=H-1&&sen[ret2] == 1) {
                        tmpnum2++;
                    }
                    ret2++;
                }
                if(koe2) {
                    kouho = INF;
                    break;
                }
            }
        }
        //cout << "kouho:" << kouho << endl;
        if(kouho < res) {
            res = kouho;
        }
    }
    cout << res << endl;
}


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

int main(){
  int n;
  while(cin >> n, n){
    vector<int> W(n);
    for(int i = 0; i < n; ++i) cin >> W[i];
    vector< vector<int> > DP(n, vector<int>(n,0));
    for(int k = 1; k < n; ++k){
      for(int i = 0; i < n-k; ++i){
        if(DP[i+1][i+k-1] == k-1 && abs(W[i]-W[i+k]) <= 1) DP[i][i+k] = k+1;
        for(int j = i; j < i+k; ++j){
          DP[i][i+k] = max(DP[i][i+k], DP[i][j]+DP[j+1][i+k]);
        }
      }
    }
    cout << DP[0][n-1] << endl;
  }
  return 0;
}



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


int main() {
  int A,B;
  cin >> A >> B;
  if(A-B>=2){
    cout << 2*A-1;
  }else if(B-A>=2){
    cout << 2*B-1;
  }else if(A-B<=1){
    cout << A+B;
  }else{
    cout << A+B;
  }
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

// グラフ用ヘッダ

typedef int Weight;
struct Edge {
    int src, dst;
    Weight weight;
    int limit;
    Edge(int src, int dst, Weight weight, int limit) :
        src(src), dst(dst), weight(weight), limit(limit) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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

#include <queue>

// d,spped,v,from
typedef tuple<double,int,int,int> State;

const double inf = 1e100;

// speed,v,from
double dp[32][32][32];
Graph g;
int src,dst;

string solve(){
    priority_queue<State> q;
    q.emplace(0.0,0,src,31);
    rep(i,32)rep(j,32)rep(k,32) dp[i][j][k] = inf;
    dp[0][src][31] = 0;
    while(q.size()){
        double d; int speed, v, from;
        tie(d,speed,v,from) = q.top(); q.pop();
        d = -d;
        if(v==dst && speed==1){
            char buf[100];
            sprintf(buf,"%.12lf",d);
            return buf;
        }
        if(d > dp[speed][v][from]) continue;
        for(Edge & e : g[v]){
            for(int diff : {-1,0,1}){
                int ns = speed + diff;
                double nd = d + (double)e.weight / ns;
                int nv = e.dst;
                if(ns < 1 || e.limit < ns) continue;
                if(nv == from) continue;
                if(dp[ns][nv][v] > nd){
                    dp[ns][nv][v] = nd;
                    q.emplace(-nd,ns,nv,v);
                }
            }
        }
    }
    return "unreachable";
}

int main(){
    int n,m;
    int cnt = 1;
    while(cin>>n>>m && n){
        dump(cnt,n,m);
        cnt++;
        cin>>src>>dst;
        g.assign(n+1,{});
        rep(i,m){
            int x,y,d,c; cin>>x>>y>>d>>c;
            g[x].eb(x,y,d,c);
            g[y].eb(y,x,d,c);
        }
        cout << solve() << endl;
    }
}

Measured memory_bytes: 2028
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <fstream>
#include <set>
#include <utility>
#include <algorithm>

#define rep(i,p,n) for(int i=p;i<n;i++)
#define lli long long int
#define vi vector<int> 

using namespace std;

void p(int x) {
	cout << x << endl;
}

void pp(string s) {
	cout << s << endl;
}


int main() {
	string s;
	cin >> s;
	rep(i, 0, s.length() - 8) {
		cout << s[i];
	}

	cout << endl;



	return 0;
}

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

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

int main()
{
  string s;
  rep(i, 4) cin >> s[i];
  int ans;
  vector<char> op(3);
  rep(bit, (1 << 3))
  {
    bitset<3> tmp(bit);
    ans = s[0] - '0';
    rep(i, 3)
    {
      if (tmp.test(i))
      {
        ans += s[i + 1] - '0';
        op[i] = '+';
      }
      else
      {
        ans -= s[i + 1] - '0';
        op[i] = '-';
      }
    }
    if(ans == 7){
      string shiki;
      rep(t,3){
        shiki = shiki + s[t] + op[t];
      }
      shiki = shiki + s[3] + "=7";
      cout << shiki;
      break;
    }
  }
}


Measured memory_bytes: 3584
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n, k;cin>>n>>k;
  int d[k+10];rep(i,0,k)cin>>d[i];
  vector<int>num;
  int c=0;
  rep(i,0,10){
    if(i==d[c]){c++;continue;}
    num.push_back(i);
  }
  string ans;int count=0;

  while(n){
    int r=n%10;
    n/=10;
    count++;
    bool e=true;
    rep(i,0,num.size()){
      if(r==num[i]){
        e=false;
        ans+=to_string(num[i]);
        break;
      }else if(r<num[i]){
        e=false;
        ans="";
        rep(i,0,count-1)ans+=to_string(num[0]);
        ans+=to_string(num[i]);
        break;
      }
    }
    if(e){
      ans="";
      rep(i,0,count)ans+=to_string(num[0]);
      n++;
    }
  }

  reverse(ans.begin(),ans.end());
  out(ans);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl
#define TGET(a, b) get<b>(a)

#define MAXN 200100

ll arr[MAXN] = {0};
ll odd_pos[MAXN] = {0};
ll even_pos[MAXN] = {0};

ll dp[MAXN] = {0};

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", arr + i);
    }

    for (int i = 1; i <= n; i += 2)
    {
        if (i == 1)
        {
            odd_pos[i] = arr[i];
            even_pos[i + 1] = arr[i + 1];
        }
        else
        {
            odd_pos[i] = arr[i] + odd_pos[i - 2];
            even_pos[i + 1] = arr[i + 1] + even_pos[i - 1];
        }
    }
    // ll ans = even_pos[n-1];
    // for (int i = 1; i <= n; i += 2)
    // {
    //     ans = max(ans, odd_pos[n] - arr[i]);
    //     ans = max(ans, (odd_pos[i] - arr[i]) + (even_pos[n - 1] - even_pos[i - 1]));
    //     ans = max(ans, (odd_pos[i] - arr[i]) + arr[i + 1] + (odd_pos[n] - odd_pos[i + 2]));
    // }
    // printf("%ld\n", ans);
    for (int i = 2; i <= n; i++)
    {
        if (i % 2)
        {
            dp[i] = max(dp[i - 2] + arr[i], dp[i - 1]);
        }
        else
        {
            dp[i] = max(odd_pos[i - 1], dp[i - 2] + arr[i]);
        }
    }
    printf("%lld\n", dp[n]);

    return 0;
}

Measured memory_bytes: 10056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
    cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " = " << arg1 << " | ";
    __f(comma + 1, args...);
}
ll max(ll a, ll b) { return (a > b ? a : b); }
ll min(ll a, ll b) { return (a < b ? a : b); }
#define all(x) (x).begin(), (x).end()

void solve()
{
    ll ans = 0;
    ll n;
    cin >> n;
    ll a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll mx = a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] < mx)
        {
            ans += (mx - a[i]);
            a[i] = mx;
        }
        mx = max(mx, a[i]);
    }
    cout << ans << "\n";
}
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    ll t;
    // cin >> t;
    solve();
    return 0;
}


Measured memory_bytes: 5140
function Main(input) {
    var num = parseInt(input.split("\n")[0]);
    var sideLength = input.split("\n")[1].split(" ");
    
    for(var a=0; a<num; a++){
        sideLength[a] = parseInt(sideLength[a]);
    }
   
   sideLength.sort(
       function(a,b){
           if(a>b){
               return 1;
           }else if(a<b){
               return -1;
           }else{
               return 0;
           }
       }
   )
   
   var count = 0;
   
   if(num<3){
       console.log(0);
   }else{
       for(var i=0; i<num; i++){
           for(var j=i+1; j<num; j++){
               for(var k=j+1; k<num; k++){
                   if(sideLength[i]!=sideLength[j] && sideLength[j]!=sideLength[k] && sideLength[i]!=sideLength[k]){
                       if(sideLength[i]+sideLength[j]>sideLength[k]){
                           count = count + 1;
                       }
                   }
               }
           }
       }
       console.log(count);
   }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32336
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>
#include<queue>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define dump(a) cout << a << endl; 

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}

/**
* @fn
* 自然数について、桁数を求める
*/
Int getDigit(Int num) {
	return (Int)(log10(num)) + 1;
}


int get2Digit(Int num) {
	int cnt = 0;
	while (num > 0) {
		if (num % 2 != 0) {
			return cnt;
		}
		cnt++;
		num /= 2;
	}
}

long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0; true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

void ansYes(bool a) {
	if (a == true) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void ansYES(bool a) {
	if (a == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Int euclidean_gcd(Int a, Int b) {
	while (true) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

typedef pair<int, int> pai;


//ここまでライブラリ
//ここから本文

int main() {
	int n;
	cin >> n;
	dump(24 + 24 - n);
}


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

struct dat {
  int d;
  vector<int> c;
  vector<vector<int>> s;
};

int calc(const dat &a, const vector<int> &last, int day, int t) {
  int v = 0;
  v += a.s.at(day - 1).at(t);
  for (int i = 0; i < 26; i++) {
    if (i == t) continue;
    v -= a.c.at(i) * (day - last.at(i));
  }
  return v;
}

int main() {
  int d;
  cin >> d;
  vector<int> c(26);
  vector<vector<int>> s(d, vector<int>(26));
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  dat a = {d, c, s};
  
  int w = 5;
  vector<vector<int>> last(w, vector<int>(26)), ans(w);
  vector<int> score(w);
  for (int i = 0; i < d; i++) {
    vector<tuple<int, int, int>> idx;
    for (int j = 0; j < w; j++) {
      vector<int> best(w, -1e9), best_t(w);
      for (int t = 0; t < 26; t++) {
        int v = calc(a, last.at(j), i + 1, t);
        if (v > best.at(w - 1)) {
          best.at(w - 1) = v;
          best_t.at(w - 1) = t;
        }
        for (int k = w - 1; k > 0; k--) {
          if (best.at(k - 1) < best.at(k)) {
            swap(best.at(k - 1), best.at(k));
            swap(best_t.at(k - 1), best_t.at(k));
          }
        }
      }
      for (int k = 0; k < w; k++) {
        idx.emplace_back(score.at(j) + best.at(k), j, best_t.at(k));
      }
    }
    sort(idx.rbegin(), idx.rend());
    vector<vector<int>> newans(w);
    for (int j = 0; j < w; j++) {
      int t = get<2>(idx.at(j));
      score.at(j) = get<0>(idx.at(j));
      newans.at(j) = ans.at(get<1>(idx.at(j)));
      newans.at(j).push_back(t);
      last.at(j).at(t) = i + 1;
    }
    ans = newans;
  }
  for (int i = 0; i < d; i++) {
    cout << ans.at(0).at(i) + 1 << endl;
  }
}


Measured memory_bytes: 3956
N,K = map(int, input().split())
l = list(map(int, input().split()))
num = [i for i in range(10) if i not in l]
 
#print(l)
while True:    
    N_str = str(N)
    frag = 0
    for i in range(len(N_str)):
        if int(N_str[i]) in l:
            #print("yes")
            frag = 1
            break
    if frag == 0:
        break
    else:
        N += 1
print(N)

Measured memory_bytes: 3060
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//vector<ll> cue: キューの宣言
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

ll a(ll n, ll x) {
	ll r = pow(10, x);
	n = (n % r);
	n /= pow(10, x - 1);
	return n;
}

int main() {
	ll N, K; cin >> N >> K;

	cout << N - (K-1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t x,int64_t y){
if(y==0)
  return x;
  else
    return gcd(y,x%y);
}
int main(){
int64_t A,B;
  cin>>A>>B;
  int64_t g=gcd(A,B);
  int64_t x=g;
  int64_t ans=1;
  for(int64_t i=2;i*i<=g;i++){
  if(x%i==0){
  while(x%i==0){
  x/=i;
  }
   ans++;
  }
  
  }if(x!=1)ans++;
  cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if (a != c)
		cout << 1;
	else
		cout << 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef long long ll;
const ll MAXN = 1e3 + 2;
const ll MAXK = 10 + 2;
const ll MOD = 1e9 + 9;
const ll MODH = 1e9 + 9;
const long double PI = acos(-1);
const ll p = 41;
const long double EPS = 1e-4;
#define x first
#define y second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
ll binpow(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
}return res;}





int main(){

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

int r,g,b,k;
cin >> r >> g >> b >> k;

int Ans = 1;
while(k--)
{

if(b <= g)
   {
       b*=2;
       continue;
   }
if(g <= r)
{
    g*=2;
    continue;
}

}

if(b > g and g > r) 
 cout << "Yes";
else
 cout << "No";
} 

Measured memory_bytes: 3636
N, M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |from,to|
  G[from] << to
end

STATUS = Array.new(N + 1, :unused)
def active?(v); STATUS[v] == :active; end
def activate!(v);  v.tap{ STATUS[v] = :active }; end
def inactivate!(v); v.tap{ STATUS[v] = :used }; end
def used?(v); STATUS[v] != :unused; end
def unused?(v); STATUS[v] == :unused; end
def use!(v); v.tap{ STATUS[v] = :used }; end
def subgraph_include?(v); STATUS[v] == :unused; end
def subgraph_init!(vset); STATUS.fill(:used); vset.each{|v| STATUS[v] = :unused}; end

def cycle_exists?
  (1 .. N).each do |s|
    next if used?(s)
    cycle = find_cycle([use!(s)])
    return cycle if cycle
  end
  false
end

def smaller_cycle?(cycle)
  subgraph_init!(cycle)
  cycle.each_with_index do |from, i|
    to = (i + 1 == cycle.size ? cycle[0] : cycle[i + 1])
    to_ = G[from].find{|t| subgraph_include?(t) && t != to }
    return find_cycle([activate!(from), use!(to_)]) if to_
  end
  false
end

def find_cycle(stack)
  until stack.empty?
    u = stack.pop
    
    if active?(u)
      inactivate!(u)
      next
    else
      stack << activate!(u)
    end
    
    G[u].each do |v|
      if active?(v)
        cycle = stack.select{|r| active?(r) }
                  .drop_while{|r| r != v } 
        return cycle
      end
      stack << use!(v) if unused?(v)
    end
  end
  false
end

cycle = cycle_exists?

if !cycle
  puts -1
else
  loop do
    smaller = smaller_cycle?(cycle)
    break if !smaller  
    cycle = smaller
  end
  puts cycle.size
  puts cycle
end


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

int main(){
  int x,y;
  cin >> x >> y;
  
  bool hantei = false;
  
  for(int i = 0;i < x + 1;i ++){
    if(i * 2 + (x - i) * 4 == y)hantei = true;
  }
  
  if(hantei == true)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const ll MOD = (ll) 998244353;
const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const double PI = acos(-1.0);

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

inline ll CEIL(ll a, ll b) {
    return (a + b - 1) / b;
}

void finish() {
    cout << -1 << endl;
    exit(0);
}

//------------------------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << setiosflags(ios::fixed);
    int n;
    cin >> n;
    int d[51];
    rep(i, n) cin >> d[i];
    int sum = 0;

    rep(i, n) {
        for (int j = i + 1; j < n; ++j) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int n,m,x,fr=0,ba=0;
    cin >> n >> m >> x;
    vector<int>y(m);
    for(int i=0;i<m;i++){
        cin >> y[i];
    }
    //mae
    for(int i=x;i<=n;i++){
        if(count(y.begin(),y.end(),i)==1){
            fr++;
        }
    }
    //usiro
    for(int i=x;i>=0;i--){
        if(count(y.begin(),y.end(),i)==1){
            ba++;
        }
    }
    cout << min(fr,ba);
}

Measured memory_bytes: 256
def main():
  mod=10**9+7
  s=int(input())
  if s<3:
    print(0)
    exit(0)
  dp=[1]*(s+1)
  for i in range(3,s):
    for j in range(3,s-i+1):
      dp[i+j]=(dp[i+j]+dp[i])%mod
  print(dp[s])
main()

Measured memory_bytes: 64704
let z=(-1);;let rec g()=Scanf.scanf"%d %d %d
"(fun m f r->if m<>z||f<>z||r<>z then g(print_endline(if m=z||f=z then"F"else let x=m+f in if x>=80then"A"else if x>=65then"B"else if x>=50||x>=30&&r>=50then"C"else if x>=30then"D"else"F")));;g()

Measured memory_bytes: 2332
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<double>p(N);
	rep(i, N)cin >> p[i];
	vector<vector<double>>dp(N, vector<double>(N + 1));
	//dp[i][j] : i枚のコインを投げた時、表がj枚となる確率
	dp[0][0] = 1 - p[0];
	dp[0][1] = p[0];
	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= N; j++) {
			if (j - 1 >= 0)dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
			else dp[i][j] = dp[i - 1][j] * (1 - p[i]);
		}
	}
	double ans = 0;
	for (int i = N / 2 + 1; i <= N ; i++)ans += dp[N - 1][i];
	printf("%.10f", ans);
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string N;
	int K;
	cin >> N;
	cin >> K;

	int len = N.size();

	vector<vector<vector<int>>> dp(len + 1, vector<vector<int>>(2, vector<int>(4, 0)));
	vector<int> digit(len);
	for (int i = 0; i < len; i++)
	{
		digit[i] = N[i] - '0';
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < len; i++)
	{
		dp[i + 1][0][0] = (digit[i] == 0 ? dp[i][0][0] : 0);
		dp[i + 1][0][1] = (digit[i] == 0 ? dp[i][0][1] : dp[i][0][0]);
		dp[i + 1][0][2] = (digit[i] == 0 ? dp[i][0][2] : dp[i][0][1]);
		dp[i + 1][0][3] = (digit[i] == 0 ? dp[i][0][3] : dp[i][0][2]);
		dp[i + 1][1][0] = dp[i][0][0] + dp[i][1][0];
		dp[i + 1][1][1] = dp[i][1][1] + (digit[i] != 0 ? dp[i][0][0] * (digit[i] - 1) + dp[i][0][1] : 0) + dp[i][1][0] * 9;
		dp[i + 1][1][2] = dp[i][1][2] + (digit[i] != 0 ? dp[i][0][1] * (digit[i] - 1) + dp[i][0][2] : 0) + dp[i][1][1] * 9;
		dp[i + 1][1][3] = dp[i][1][3] + (digit[i] != 0 ? dp[i][0][2] * (digit[i] - 1) + dp[i][0][3] : 0) + dp[i][1][2] * 9;
	}
	cout << dp[len][0][K] + dp[len][1][K] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

int main()
{
  int x, y;

  while (true)
  {
    cin >> x >> y;

    if (x == 0 && y == 0)
    {
      break;
    }

    if (x > y)
    {
      int tmp = x;
      x = y;
      y = tmp;
    }

    cout << x << " " << y << endl;
  }

  return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<cfloat>
#include<cassert>
#include<cmath>
#include<vector>
 
using namespace std;
 
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
#define dle(a, b) (equals(a, b) || a < b )
static const double PI = acos(-1);
 
class Point{
    public:
    double x, y;
     
    Point ( double x = 0, double y = 0): x(x), y(y){}
     
    Point operator + ( const Point &p ) const { return Point(x + p.x, y + p.y); }
    Point operator - ( const Point &p ) const { return Point(x - p.x, y - p.y); }
    Point operator * ( const double &a ){ return Point(x*a, y*a); }
 
    double abs() { return sqrt(norm());}
    double norm() { return x*x + y*y; }
 
    bool operator < ( const Point &p ) const {
    return x != p.x ? x < p.x : y < p.y;
    }
 
    bool operator == ( const Point &p ) const {
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
    }
};
 
typedef Point Vector;
 
class Segment{
    public:
    Point p1, p2;
    Segment(Point s = Point(), Point t = Point()): p1(s), p2(t){}
};
 
double norm( Vector a ){ return a.x*a.x + a.y*a.y; }
double abs( Vector a ){ return sqrt(norm(a)); }
double getDistance( Vector a, Vector b ){ return abs(a - b); }
double dot( Vector a, Vector b ){ return a.x*b.x + a.y*b.y; }
double cross( Vector a, Vector b ){ return a.x*b.y - a.y*b.x; }
 
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
 
int ccw( Point p0, Point p1, Point p2 ){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if ( cross(a, b) > EPS ) return COUNTER_CLOCKWISE;
    if ( cross(a, b) < -EPS ) return CLOCKWISE;
    if ( dot(a, b) < -EPS ) return ONLINE_BACK;
    if ( norm(a) < norm(b) ) return ONLINE_FRONT;
    return ON_SEGMENT;
}
 
int main(){
    double x1, y1, x2, y2, x3, y3, x, y;
    Segment S[3];
 
    while ( cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x >> y ){
    int ccw1 = ccw( Point(x1, y1), Point(x2, y2),  Point(x, y) );
    int ccw2 = ccw( Point(x2, y2), Point(x3, y3),  Point(x, y) );
    int ccw3 = ccw( Point(x3, y3), Point(x1, y1),  Point(x, y) );
    if ( ccw1 == ccw2 && ccw2 == ccw3 ) cout << "YES" << endl;
    else cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>

int main(void){
    int i,j,n;
    scanf("%d",&n);

    for(i=3;i<=n;i++){
        if(i % 3 == 0){
            printf(" %d",i);
        }
        else{
            j = i;
            while(j){
                if(j % 10 == 3){
                    printf(" %d",i);
                    break;
                }
                j /= 10;
            }
        }
    }
    printf("\n");
    return(0);
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

#define MOD (1000000007)
#define MAX (2010)

using namespace std;

typedef long long int Int;

Int N,M;
Int X;
struct Graph {
    Int u,v,w;
    bool operator < (const struct Graph &right) const {
        return w < right.w;
    }
}G[MAX];

int pa[MAX];
int find(int x) {
    return pa[x] == x ? x : pa[x] = find(pa[x]);
}

Int modPow(int x) {
    Int res = 1;
    for(int i = 0;i < x;i++) {
        res = res * 2 % MOD;
    }

    return res;
}

int main(void) {
    cin>>N>>M;
    cin>>X;
    
    for(int i = 0;i < M;i++) {
        Int u,v,w;
        cin>>u>>v>>w;
        G[i].u = --u;
        G[i].v = --v;
        G[i].w = w;
    }

    sort(G,G+M);

    Int cnt1 = 0,cnt2 = 0;
    for(int i = 0;i < M;i++) {
        for(int k = 0;k < N;k++)
            pa[k] = k;
        pa[find(G[i].u)] = find(G[i].v);
        Int cost = G[i].w;
        for(int j = 0;j < M;j++) {
            if(find(G[j].u) == find(G[j].v))
                continue;
            pa[find(G[j].u)] = find(G[j].v);
            cost += G[j].w;
        }
        if(cost < X)
            cnt1++;
        if(cost <= X)
            cnt2++;
    }

    cout<<(modPow(min(M,M-cnt1+1)) - modPow(min(M,M-cnt2+1)) + MOD ) % MOD<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
#ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   for(int i = 1 ; i <= 9 ; ++i){
      for(int j= 1 ; j <= 9 ; ++j){
         if(i * j == n){
            cout << "Yes\n";
            return 0;
         }
      }
   }
   cout << "No\n";
}

Measured memory_bytes: 256