akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	while (n) {
		n--;
		string s;
		cin >> s;
		int cnt = 0;
		while (s.length() > 1) {
			cnt++;
			int ma = 0;
			REP(i, s.length() - 1) {
				int val1 = stoi(s.substr(0,i+1).c_str());
				int val2 = stoi(s.substr(i + 1,s.length()-(i+1) ).c_str());
				ma = max(ma, val1*val2);
			}
			s = to_string(ma);
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 3260
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
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;}
const long long INF=1LL<<60;

//入力
int N;
long long h[100010];

//dpテーブル
long long dp[100010];

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



Measured memory_bytes: 1792
using System;

    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split();

            int N = int.Parse(line[0]);
            int A = int.Parse(line[1]);
            int B = int.Parse(line[2]);

            Console.WriteLine((N * A >= B ? B : N * A));
        }
    }


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

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;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	int N;
	vector<PII> XY;
	cin >> N;
	REP(i,N){
	    int x,y;
	    cin >> x >> y;
	    XY.PB(MP(x,y));
	}

	int ans = 0;

	REP(i,N){
	    REP(j,N){
	    	int P = 0;
	    	if (i == j) continue;
	        int p = XY[i].fst - XY[j].fst;
			int q = XY[i].snd - XY[j].snd;

			REP(k,N){
			    REP(l,N){
			    	if (k == l) continue;
			        int a,b;
			        a = XY[k].fst;
			        b = XY[k].snd;
			        int a2,b2;
			        a2 = XY[l].fst;
			        b2 = XY[l].snd;

			        if ((a2 - p == a) and (b2 - q == b)){
			        	P++;
			        }

			    }
			}

			chmax(ans,P);

	    }
	}

	cout << N - ans << endl;




	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

long long gcd(long long a,long long b){
    while(b ^= a ^= b ^= a%=b);
    return a;
}

long long main(){
	long long n,x;
	long long i,j,g;

	scanf("%lld%lld",&n,&x);

	g = gcd(n,x);
	n /= g;
	x /= g;

	printf("%lld\n",(n-1)*3*g);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 1000119
int num[maxn],tree[maxn],booll[maxn],nnn[maxn],N,ww;;
//num数组保存原数列，tree树状数组，nnn保存结果
struct tt
{
    int l,r;//左右边界
    int pos;//原位置（因为我们要离线排序后处理）
};
tt ask[maxn];
bool cmp(tt x,tt y)
{ 
    return x.r<y.r;
    //快排大法好，没有什么是快排解决不来哦
    //实在不行就加上一个cmp
}
int lowbit(int n) 
{
    return n&(-n);
    //树状数组核心操作×1
}
void add(int n,int now)
{
    while(n<=N)
    {
        tree[n]+=now;
        n+=lowbit(n);
    }
    //树状数组核心操作×2-->更新操作
}
int sum(int n)
{
    int ans=0;
    while(n!=0)
    {
        ans+=tree[n];
        n-=lowbit(n);
    }
    return ans;
    //树状数组核心操作×3———>查询操作
}
int main()
{
        scanf("%d %d",&N,&ww);
        for(int i=1;i<=N;i++)
            scanf("%d",&num[i]);
        for(int i=1;i<=ww;i++)
        {
            scanf("%d%d",&ask[i].l,&ask[i].r);
            ask[i].pos=i; //存储初始位置
        }
        sort(ask+1,ask+1+ww,cmp);//按r排序
        int next=1;
        for(int i=1;i<=ww;i++)
        {
            for(int j=next;j<=ask[i].r;j++)
            {
                if(booll[num[j]]) 
                    add(booll[num[j]],-1);
                 //之前打过标记，在之前的位置加上-1，保证无重复
                add(j,1);
                booll[num[j]]=j;
            }
            next=ask[i].r+1;
            //更新下一次查询的位置
            nnn[ask[i].pos]=sum(ask[i].r)-sum(ask[i].l-1);
            //按询问编号存储每组询问的结果
        }
    for(int i=1;i<=ww;i++)
      cout<<nnn[i]<<endl;
    return  0;
}

Measured memory_bytes: 17388
{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import qualified Data.ByteString.Char8 as BS

main = do
    [a,b] <- map ((read :: String -> Int) . BS.unpack) . BS.words <$> BS.getLine
    case headSafe [ 10*b+l | l <- [0..9], floor ((fromIntegral (10*b + l))*0.08) == a] of
        Just x -> print x
        Nothing -> print (-1)

headSafe :: [a] -> Maybe a
headSafe (x:xs) = Just x
headSafe [] = Nothing

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

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var x = vars[0];

        var rank = 0;

        if(x <= 599)
        {
            rank = 8;
        }
        else if (x <= 799)
        {
            rank = 7;
        }
        else if (x <= 999)
        {
            rank = 6;
        }
        else if (x <= 1199)
        {
            rank = 5;
        }
        else if (x <= 1399)
        {
            rank = 4;
        }
        else if (x <= 1599)
        {
            rank = 3;
        }
        else if (x <= 1799)
        {
            rank =2 ;
        }
        else if (x <= 1999)
        {
            rank = 1;
        }
        Console.WriteLine(rank);
    }
}

Measured memory_bytes: 28280
#include<iostream>
#include<vector>

using namespace std;

int main(void) {
    int N, M, sum = 0, cnt = 0;
    cin >> N >> M;
    double diff = 1 / (double)(4 * M);
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);

    for (int i = 0; i < N; i++) sum += A.at(i);

    vector<bool> ok(N, true);

    for (int i = 0; i < N; i++) {
        if ((double)A[i] < (double)sum * diff) ok[i] = false;
    }

    for (int i = 0; i < N; i++) {
        if (ok.at(i)) cnt++;
    }

    if (cnt >= M) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
package main

// Solution for https://atcoder.jp/contests/abc179/tasks/abc179_c

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	con.Scan(&n)
	s := make([]int, n+1)
	s[1] = 1
	for i := 2; i <= n; i++ {
		if s[i] == 0 {
			for j := i; j <= n; j += i {
				s[j] = i
			}
		}
	}
	var x int
	for c := 1; c < n; c++ {
		a := c
		m := map[int]int{}
		for a > 1 {
			m[s[a]]++
			a /= s[a]
		}
		y := 1
		for _, j := range m {
			//fmt.Printf("%d: %d ^ %d\n", c, i, j)
			y *= j + 1
		}
		x += y
	}
	con.Println(x)
	return nil
}


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

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> a(100);
  for(int i = 0;i < h;i++){
    cin>>a.at(i);
  }
  for(int i = 0;i < w + 2;i++){
    cout<<"#";
  }
  cout<<endl;
  for(int i = 0; i < h;i++){
    cout<<"#"<<a.at(i);
    cout<<"#"<<endl;
  }
  for (int i = 0; i < w + 2; i++)
  {
    cout << "#";
  }
  cout << endl;
}

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

int dp[3][100000]={};
int a[100000],b[100000],c[100000];

int help(int p,int i,int n)
{
    if(i>n) return 0;
    if(i==n){
        if(p==0) dp[p][i]= max(b[i],c[i]);
        else if(p==1) dp[p][i]= max(a[i],c[i]);
        else if(p==2) dp[p][i]= max(a[i],b[i]);
        return dp[p][i];
    }
    if(dp[p][i]!=0) return dp[p][i];

    if(p==0) dp[p][i]= max( b[i] + help(1,i+1,n), c[i] + help(2,i+1,n) );
    else if(p==1) dp[p][i]= max( a[i] + help(0,i+1,n), c[i] + help(2,i+1,n) );
    else if(p==2) dp[p][i]= max( a[i] + help(0,i+1,n), b[i] + help(1,i+1,n) );

    return dp[p][i];
}


int main()
{
    int n; cin>>n;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];

    dp[0][0]=a[0]+help(0,1,n-1);
    dp[1][0]=b[0]+help(1,1,n-1);
    dp[2][0]=c[0]+help(2,1,n-1);

    int mx= max(dp[0][0],dp[1][0]);
    mx= max(mx,dp[2][0]);
    cout<<mx;

//    for(int i=0;i<3;i++){
//        for(int j=0;j<n;j++) cout<<dp[j][i]<<" ";
//        cout<<endl;
//    }

    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

//ユークリッドの互除法　aとbの最大公約数
int euclid(int a, int b){
	int c = a % b;
	if(c == 0){
		return b;
	}else{
		return euclid(b, c);
	}
}


int main(void){
	int n,x,inp;
	cin>>n>>x;
	vector<int> sa;
	rep(i,n){
		cin>>inp;
		sa.push_back(abs(inp - x));
	}

	int ans = (sa[0] == 0 ? sa[1] : sa[0]);	

	rep(i,n){
		if(sa[i] == 0){
			continue;
		}
		ans = euclid(ans, sa[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(a[n-1])


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

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

    long long dp1[10][10];
    long long dp2[10][10];
    long long dp3[10][10];

    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            dp1[i][j]=0;
            dp2[i][j]=0;
            dp3[i][j]=0;
        }
    }

    for(int i=1; i<=N; i++ ){
        stringstream ss;
        ss << i;
        A = ss.str();
        //cout << "A " << A << endl;
        int ii,jj;
        ii = (int) A[0] - '0';
        jj = (int) A[A.size()-1] - '0';
        dp1[ii][jj]++;
    }

    long long ans=0;

    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            //cout << "i j dp1 dp2 " << i << " " << j << " " << dp1[i][j] << " " << dp2[j][i] << endl;
            long long tmp1,tmp2;

            ans += dp1[i][j]*dp1[j][i];
        }
    }    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

vector<int> a;
vector<int> b;
vector<int> c;
vector<int> d;
int m;
int n;
int q;
int ans = 0;
void rec(int num,string now){
	if(num == n){
		int now_sum = 0;
		for(int i = 0;i < q;i++){
			if((int)(now[b[i]] - now[a[i]]) == c[i])now_sum += d[i];
		}
		ans = max(ans,now_sum);
		return;
	}
	int nowc = now[num-1] - '0';
	for(int i = nowc;i < m;i++){
		rec(num+1,now+(char)('0'+i));
	}
}
int main(){
	cin >> n >> m >> q;
	a.resize(q);
	b.resize(q);
	c.resize(q);
	d.resize(q);
	for(int i = 0;i < q;i++){
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}
	
	for(int i = 0;i < m;i++){
		string emp = "";
		emp += (char)('0'+i);
		rec(1,emp);
	}

	cout << ans << endl;
}


Measured memory_bytes: 3608
import java.util.Scanner

import scala.collection.mutable.PriorityQueue


object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val k = sc.nextLong()

  val (_, ans) = Range(0, n).map(_ => (sc.nextInt(), sc.nextInt()))
    .sortWith {
      case (l, r) => l._1 < r._1
    }
    .foldLeft((0L, -1)) {
      case ((cnt, ans), (a, b)) =>
//        println(cnt, ans, a, b)
        if (ans > 0) (cnt, ans)
        else if (cnt + b >= k) (cnt + b, a)
        else (cnt + b, -1)
    }

  println(ans)
}


Measured memory_bytes: 77464
#include <stdio.h>
#include <string.h>
int main(void){ 
    char b;
    scanf("%c",&b);
    if(b=='A'){
        printf("T\n");
    }
    else if(b=='T'){
        printf("A\n");
    }
    else if(b=='G'){
        printf("C\n");
    }
    else{
        printf("G\n");
    }
    return 0;
}

	

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
char a[10000005];
int b[10000005],l;
int main()
{
	scanf("%s",a);
	int x=strlen(a);
	for(int i=0;i<x;i++)
	{
		if(a[i]=='0')b[++l]=0;
		else if(a[i]=='1')b[++l]=1;
		else if((a[i]=='B')&&(l))l--;
	}
	for(int i=1;i<=l;i++)printf("%d",b[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int f[200005];
int d[200005];
const int inf=0x3f3f3f3f;
int main(){
//	int a,b;
//	scanf("%d%d",&a,&b);
//	map<int,int>m;
//	m[a]=1;
//	m[b]=1;
//	for(int i=1;i<=3;i++)
//		if(m[i]==0){
//			printf("%d\n",i);
//			break;
//		}
//	int n;
//	cin>>n;
//	string s,t;
//	cin>>s>>t;
//	int f=0;
//	for(int i=0;i<n;){
//		if(f==0)
//			cout<<s[i],f=!f;
//		else{
//			f=!f;
//			cout<<t[i];
//			i++;
//		}
//	}
	
//	long long a,b;
//	cin>>a>>b;
//	cout<<a*b/__gcd(a,b)<<"\n";
	int n;
	scanf("%d",&n);
	//fill(f, f+n, inf); 
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	int cnt=0,t=1;
//	int mx=-1;
//	for(int i=0;i<n;i++){
//		int j=lower_bound(f,f+n,a[i])-f;
//		d[i]=j+1;
//		if(mx<d[i])
//			mx=d[i];
//		f[j]=a[i];
//	}
	for(int i=0;i<n;i++){
		if(a[i]==t){
			t++;
			cnt++;
		}
	}
	if(cnt==0)
		puts("-1");
	else
	cout<<n-cnt<<"\n";
	return 0;
} 

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

int main() {


    int x;
    scanf("%d", &x);

    int mysum = 0;

    int num1 = x / 500;
    x -= num1 * 500;
    mysum += num1 * 1000;
    int num2 = x / 5;
    mysum += num2 * 5;

    printf("%d", mysum);


    return 0;

}


Measured memory_bytes: 128
sx,sy,tx,ty=map(int,input().split())

ans='U'*(ty-sy)+'R'*(tx-sx)+'D'*(ty-sy)+'L'*(tx-sx)
ans+='L'+'U'*(ty-sy+1)+'R'*(tx-sx+1)+'D'
ans+='R'+'D'*(ty-sy+1)+'L'*(tx-sx+1)+'U'

print(ans)

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

int main() {
  int N, S = 0;
  cin >> N;
  
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    int c = 1;
    for (int j = i+1; j < N; j++) {
       if (d.at(i) == d.at(j)) {
         c = 0;
         break;
       }
    }
    S += c;
  }
  
  cout << S << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int N, K; 
int A[5010] = {}; 
bool dp[5010][5010] = {}; // dp[i番目まで][和がちょうどj] = 可能？
bool necessary(int m){ // m番目を除いて[K-A[m], K)の値を作れるか？
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= K; j++){
			dp[i][j] = false; 
		}
	}
	dp[0][0] = true; 
	for(int i = 1; i <= N; i++){
		if(i == m){
			for(int j = 0; j < K; j++){
				dp[i][j] = dp[i-1][j]; 
			}
		}
		else{
			for(int j = 0; j < K; j++){
				if(dp[i-1][j]) {
					dp[i][j] = true; 
					dp[i][min(j+A[i], K)] = true; 
                }
			}
		}
	}
	bool ans = false; 
	for(int a = max(K - A[m], 0); a < K; a++){
		if(dp[N][a]){ans = true;}
	}
	return ans; 
}
int main() {
	cin >> N >> K; 
	for(int i = 1; i <= N; i++){
		cin >> A[i]; 
	}
	sort(A, A+N+1); 
	// a<bでaが必要かつbが不必要とすると矛盾．
	// aが属し，K<=(Sの元の和)<K+aなるSを1つとる．bがSの元のときはSそのものが，
	// bがSの元でないときはSからaを除きbを加えたものが反例．
	if(necessary(1)){cout << 0 << endl;}
	else if(!necessary(N)){cout << N << endl;}
	else{
		int L = 1, R = N; 
		while(R - L > 1){
			int M = (L + R) / 2; 
			if(necessary(M)){R = M;}
			else{L = M;}
		}
		cout << L << endl;
	}
}

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

int main(){
    int d[9], a[9];
    for(int i = 0; i < 9; i++)  cin >> a[i];
    for(int i = 0; i < 9; i++)  d[i] = i+1;

    int ans = 0;
    do{
        bool judge = true;
        for(int i = 0; i < 9; i++)  if(a[i] != -1 && a[i] != d[i])  judge = false;
        if(!judge)  continue;

        int plus = d[0] + 10*d[1] + d[2] + 100*d[3] + 10*d[4] + d[5];
        int res = 100*d[6] + 10*d[7] + d[8];
        if(plus == res) ans++;
    }while(next_permutation(d, d + 9));

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


Measured memory_bytes: 3116
#!/usr/bin/env python3
import collections as cl
import sys


class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """

    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * \
                modinv[self.mod % i] % self.mod
        return modinv


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    X, Y = MI()

    if (X+Y) % 3 != 0:
        print(0)
        return

    ttl = int((X+Y)/3)
    a = X - ttl

    if (ttl < a or a < 0):
        print(0)
        return

    comb = Combination(ttl)

    tmp = comb(ttl, a)
    print(tmp)


main()


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

int main() {
    int n, r, minr, maxr;
    cin >> n;
    minr = INT_MAX;
    maxr = INT_MIN;
    for (int i = 0;i < n;++i) {
        cin >> r;
        maxr = max(maxr, r-minr);
        minr = min(minr, r);
    }
    cout << maxr << endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;

int main(int argc, char* argv[]) {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  /* */
  string s;
  cin >> s;

  int count = - 1;
  int prev = '\0';
  for (char c : s) {
    if (c != prev) {
      ++count;
      prev = c;
    }
  }
  cout << count << endl;
  /* */

  return EXIT_SUCCESS;
}


Measured memory_bytes: 512
a, b = map(int, input().split())

def f(a):
    if a <= 200:
        rv = 0
        for i in range(a + 1):
            rv ^= i
        return rv
    d = 1
    while d <= a:
        d <<= 1
    d >>= 1
    return (0 if a & 1 else d) | f(a - d)

print(f(b) ^ f(a-1))


Measured memory_bytes: 38448
#include <stdio.h>
#include <stdlib.h>


int main(){
	int H,W;

	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0){
			break;
		}else{
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					printf("#");
				}
				printf("\n");
			}
			printf("\n");
		}
	}

	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <stdio.h>
#define maxN 100016

using namespace std;

int par[maxN], rank[maxN];

int find(int x)
{
	if (par[x] == x)
		return x;
	return find(par[x]);
}

int main()
{
	int n, t, i, j, x;
	long long sum;
	char c;
	while (scanf("%d%d", &n, &t) && (n || t))
	{
		par[1] = 1;
		for (i = 2; i <= n; i++)
			scanf("%d", &par[i]);
		getchar();
		for (i = sum = 0; i < t; i++)
		{
			scanf("%c%d%*c", &c, &x);
			if (c == 'Q')
				sum += find(x);
			else
				par[x] = x;
		}
		printf("%lld\n", sum);
	}
	return 0;
}

Measured memory_bytes: 1588
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }

    int64_t result = 0;
    rep(i, n)
    {
        if ((~k & a[i]) == 0) {
            result += b[i];
        }
    }
    rep(i, 30)
    {
        if (((k >> i) & 1) == 1) {
            int mask = ((~(k >> (i + 1)) << 1) + 1) << i;

            int64_t score = 0;
            rep(i, n)
            {
                if ((a[i] & mask) == 0) {
                    score += b[i];
                }
            }
            result = max(result, score);
            //cout << i << " " << bitset<30>(mask) << endl;
        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1024
import sys


def input():
    return sys.stdin.readline()[:-1]


def main():
    count = 0
    n = int(input())
    p = [int(i) for i in input().split()]

    for i in range(1, n+1):
        if p[i-1] != i:
            count += 1

    print("YES" if count < 3 else "NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
#include <stdio.h>

int N(int A, int B, int K){
  int n, c;
  c = 0;
  for(n = 100;n > 0;n--){
    if(A % n + B % n == 0) c++;
    if(c == K) break;
  }
  return n;
}

int main(void){
  int A, B, K;
  scanf("%d %d %d", &A, &B, &K);
  printf("%d\n", N(A, B, K));
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> v(n);
  for(int i = 0; i < n; i++){
    cin >> v.at(i);
  }
  
  sort(v.begin(), v.end(), greater<int>());
  
  for(int i = n - 1; i > 0; i--){
    v.at(i - 1) = (v.at(i - 1) + v.at(i))/2;
  }
  
  cout << v.at(0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<memory.h>
#include<math.h>

int sprInput(char *retstr, char *str, int strnum)
{
	char buf[256]={};
	int h, i, j;

	i = 0;
	for(h=0;h<strnum;h++){
		memset(buf, '\0', sizeof(buf));
		j = 0;
		if (str[i] == '\0') break;
		while(str[i] != ' ' && str[i] != '\n' && str[i] != '\0')
		{
			buf[j] = str[i];
			i++;
			j++;
		}
		i++;
	}
	memcpy(retstr, buf, sizeof(buf));

	return (retstr[0] == '\0' ? 0 : 1);
}

int main(int argc, char *argv[])
{
	char str[256]={};
	char buf[256]={};
	int x, i=0;

	while( fgets(str, 256, stdin) != '\0'){
		i++;
		sprInput( buf, str, 1 );
		x = atoi( buf );
		if( x == 0){
			break;
		}
		printf("Case %d: %d\n", i, x);
	}
	return 0;
}

Measured memory_bytes: 528
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int maxc = max(a, b);
    vector<int> di;
    for (int i = maxc; i > 0; i--) {
        if (a % i == 0 && b % i == 0) di.push_back(i);
    }
    cout << di[k - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
lli MOD = 1e9 + 7;
int main()
{
    // x,y is sorted
    //sum i<j,k<l (xj_xi)*(y_k-y_l)
    //(x_j) * (y_l - y_k) - (x_i) * (y_l - y_k)
    //iを固定したときjとなりうるのは(n-i-1)個
    //sum_(i+1..n-1)x_j*(y_l-y_k)-x_i(y_l-y-k)
    //(sum_(i+1..n-1)x_j-(n-i-1)*x_i)(O(1)で全部求まる) * (y_l-y_k)
    //(sum(n)-sum(i+1)-x_i(n-i-1)) * (y_l-y_k)
    lli n, m;
    cin >> n >> m;
    lli x[100005] = {};
    lli y[100005] = {};

    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    lli sumx[100005] = {};
    lli sumy[100005] = {};


    lli sum = 0;
    rep(i, n)
    {
        sumx[i + 1] = sumx[i] + x[i];
        sumx[i + 1] %= MOD;
    }
    rep(i, m)
    {
        sumy[i + 1] = sumy[i] + y[i];
        sumy[i + 1] %= MOD;
    }

    rep(i, n)
    {
        sum += sumx[n] - sumx[i + 1] - x[i] * (n - i - 1);
        sum = (sum + MOD) % MOD;
    }
    lli hoge = 0;
    rep(i, m)
    {
        hoge += sumy[m] - sumy[i + 1] - y[i] * (m - i - 1);
        hoge = (hoge + MOD) % MOD;
    }
    cout << (hoge * sum + MOD) % MOD << endl;
}


Measured memory_bytes: 3328
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;

# define INF ((int)(1<<30))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12

template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };


int main()
{
	int n;
	while (cin >> n&&n)
	{
		set<int> a;
		for (int i = 1; i<n; i++)
		{
			long long x = (long long)i*i;
			x %= n;
			a.insert(x);
		}
		int ans[11000] = {};
		for (auto it : a)
		{
			for (auto i : a)
			{
				if (i == it)continue;
				int d = i - it;
				while (d<0)d += n;
				while (d>(n - 1) / 2)d = n - d;
				while (d<0)d += n;
				while (d>(n - 1) / 2)d = n - d;
				ans[d]++;
			}
		}
		for (int i = 1; i <= (n - 1) / 2; i++)
		{
			cout << ans[i] << endl;
		}
	}
}

Measured memory_bytes: 3360
#include <iostream>
 
using namespace std;
 
int main()
{
   int x, h, m, s;
   cin >> x;
   h = x / 3600 ;
   m = ((x-(h*3600))/60) ;
   s = x % 60 ;
   cout << h << ":" << m << ":" << s << endl;
 
   return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
string S;
 
void solve() {
    //cout.precision(10);
    cin >> N >> S;
    S.push_back('#');
    int ans = 0;
    for(int i = 0; i + 1 < S.size(); i++) {
        if(S[i] != S[i+1]) ans++;
    }
    cout << ans << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 512
#include "iostream"
#include "algorithm"

using namespace std;

int a[3];
int main(){
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] - a[1] + (a[1] - a[0]) / 2 + ((a[1] - a[0]) % 2 != 0 ? 2 : 0) << endl;
	return 0;
}

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

struct UnionFind
{
    vector<int> par;  // 親ノード
    vector<int> rank; // ランク
    vector<int> size; // ランク

    UnionFind(int n = 1)
    {
        init(n);
    }

    void init(int n = 1)
    {
        par.resize(n);
        rank.resize(n);
        size.resize(n);
        for (int i = 0; i < n; ++i)
            par[i] = i, rank[i] = 0, size[i] = 1;
    }

    int root(int x)
    {
        if (par[x] == x)
        {
            return x;
        }
        else
        {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    int cnt(int x)
    {
        return size[root(x)];
    }

    bool issame(int x, int y)
    {
        return root(x) == root(y);
    }

    bool merge(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (rank[x] < rank[y])
            swap(x, y);
        if (rank[x] == rank[y])
            ++rank[x];
        par[y] = x;
        size[x] += size[y];
        return true;
    }
};

int main()
{
    ll N, M;
    cin >> N >> M;
    vector<pair<int, int>> vec(M);
    for (ll i = 0; i < M; i++)
    {
        cin >> vec[i].first >> vec[i].second;
        vec[i].first--;
        vec[i].second--;
    }

    UnionFind uf(N);
    vector<ll> his(M);
    ll cnt = N * (N - 1) / 2;
    for (ll i = M - 1; i >= 0; i--)
    {
        his[i] = cnt;
        if (uf.issame(vec[i].first, vec[i].second))
        {
            continue;
        }
        cnt -= uf.cnt(vec[i].first) * uf.cnt(vec[i].second);
        uf.merge(vec[i].first, vec[i].second);
    }

    for (ll i = 0; i < M; i++)
    {
        cout << his[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5872
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define vll vector<ll>
typedef long long int ll;
using namespace std;

vector<ll> candi;
int MAX_NUM;
void f(ll now, ll cnt){
  if(cnt==MAX_NUM+1){
    candi.push_back(now);
    return;
  }
  vector<int> yaku;
  for(int i=2;i*i<=cnt;i++){
    if(cnt%i==0){
      yaku.push_back(i);
      if(i*i!=cnt) yaku.push_back(cnt/i);
    }
  }
  if(cnt!=1) yaku.push_back(1);

  bool flag = true;
  for(int i=0;i<yaku.size();i++){
    if((now>>(yaku[i]-1))&1){
      flag = false;
      break;
    }
  }
  f(now, cnt+1); //使わない
  if(flag) f(now|(1LL<<(cnt-1)), cnt+1);
}
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n+1);
  ll s = 0;
  for(int i=1;i<=n;i++){
    scanf("%lld", &a[i]);
    s += a[i];
  }
  ll ans = -1000000000000000000;
  if(n<=32) MAX_NUM = n;
  else MAX_NUM = 32;
  f(0, 1);

  for(auto use:candi){
    ll tmp = 0;
    vector<bool> d(n+1, false);

    for(int i=1;i<=MAX_NUM;i++){
      if(!((use>>(i-1))&1)) continue;
      for(int j=i;j<=n;j+=i) {
        if(d[j]) continue;
        d[j] = true;
        tmp += a[j];
      }
    }//useの倍数

    // n>32の場合
    for(int i=MAX_NUM+1;i<=n;i++){
      if(d[i]) continue;
      ll ret = 0;
      for(int j=i;j<=n;j+=i){ //始点
        ll t = 0;
        for(int k=j;k<=n;k+=j) {
          if(!d[k]) t += a[k];
        }
        ret = min(ret, t);
        d[j] = true;
      }
      tmp += ret;
    }
    //bitset<10> b(use);
    //std::cout << b << " " << s << " " << tmp << '\n';
    ans = max(ans, s - tmp);
  }
  std::cout << ans << '\n';
  return 0;
}



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


class Dice{
    public : int diceNum[6];

    public : void set(int Num,int label){
        diceNum[label] = Num;
    };

    public : void roll(char label){
        switch (label)
        {
        case 'E':
            setAll(diceNum[3],diceNum[1],diceNum[0],diceNum[5],diceNum[4],diceNum[2]);
            break;
        case 'N':
            setAll(diceNum[1],diceNum[5],diceNum[2],diceNum[3],diceNum[0],diceNum[4]);
            break;
        case 'S':
            setAll(diceNum[4],diceNum[0],diceNum[2],diceNum[3],diceNum[5],diceNum[1]);
            break;
        case 'W':
            setAll(diceNum[2],diceNum[1],diceNum[5],diceNum[0],diceNum[4],diceNum[3]);
            break;
        }
    };
    public : int upNum(){
        return diceNum[0];
    }


    private : void setAll(int a1,int a2,int a3,int a4,int a5,int a6){
        set(a1,0);
        set(a2,1);
        set(a3,2);
        set(a4,3);
        set(a5,4);
        set(a6,5);
    };
};


int main(){
    

    Dice dice;

    for(int i = 0;i<6;i++){
        int diceNum;
        scanf("%d",&diceNum);
        dice.set(diceNum,i);
    }
    //printf("%d %d %d %d %d %d\n",dice.diceNum[0],dice.diceNum[1],dice.diceNum[2],dice.diceNum[3],dice.diceNum[4],dice.diceNum[5]);

    char order[101];

    scanf("%s",order);
    for(int i = 0;i<strlen(order);i++){
        if(order[i] == '\n'){
            break;
        }
        dice.roll(order[i]);
        //printf("%d %d %d %d %d %d\n",dice.diceNum[0],dice.diceNum[1],dice.diceNum[2],dice.diceNum[3],dice.diceNum[4],dice.diceNum[5]);
    }

    printf("%d\n",dice.upNum());


    return 0;
}



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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  ll h, w;
  cin >> h >> w;

  vector<string> mp(h);
  rep(i, h) cin >> mp[i];

  rep(i, 2 * h) { cout << mp[i / 2] << endl; }

  return 0;
}


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

#define ll long long

struct mv
{
	int p,q;
};

bool bb(mv a,mv b)
{
	return a.q<b.q;
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int h,n;
    cin>>h>>n;
    struct mv a[n];
    for(int i=0;i<n;i++)
    	cin>>a[i].p>>a[i].q;
    sort(a,a+n,bb);

    // for(int i=0;i<n;i++)
    // 	cout<<a[i].p<<a[i].q<<'\n';

    int dp[h+1];
    for(int i=0;i<h+1;i++)
    	dp[i] = 1000000000;
    dp[0]=0;

    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<=h;j++)
    	{
    		if(j+a[i].p<h)
    		dp[j+a[i].p] = min(dp[j+a[i].p],dp[j]+a[i].q); 	
    	else
    		dp[h] = min(dp[h],dp[j]+a[i].q);

    	}
    	//cout<<j<<" "<<dp[j]<<'\n';
    }
    cout<<dp[h];
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


f64 A, B;


bool C(f64 x) {
    return floor(x * 0.08) == A && floor(x * 0.1) == B;
}


int main() {
    cin >> A >> B;

    for (f64 x = 1; x <= 1100; x++) {
        if (C(x)) {
            cout << (i64)x << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    std::string s;
    cin >> s;
    /*
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    */
    int cnt = 0;
    for(int i=0; i<n; i++){
        if(s[i] != s[i+1]){
            cnt++;
        }
    }
    cout << cnt << endl; 
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
  int W, H, x, y, r;
  
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}

Measured memory_bytes: 584
/**
 * File              : B - Frog 2 .cpp
 * Author            : horcrux2301 <khajuriaharsh729@gmail.com>
 * Date              : 06.01.2019
 * Last Modified Date: 06.01.2019
 */
#include <bits/stdc++.h>
#define ll long long
#define mp(a,b)     make_pair(a,b)
#define newline     cout << endl;
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.ff<<", "<<p.ss<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int main(){
    //clock_t tStart = clock();
    int test;
    test=1;
    //cin >> test;
    while(test--){
        ll n,k;
        cin >> n >> k;
        ll arr[n];
        for(ll i=0;i<n;i++){
            cin >> arr[i];
        } 
        ll dp[n];
        for(ll i=0;i<n;i++){
            dp[i]=1e10;
        }
        dp[0]=0;
        for(ll i=1;i<n;i++){
            for(ll j=i-1;j>=i-k && j>=0;j--){
                dp[i] = min(dp[i], dp[j]+abs(arr[j]-arr[i])); 
            }
        }
        cout << dp[n-1] << endl;
    }
    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[200005],ma;
int main()
{
    int k,n;  cin>>k>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        ma=max(a[i]-a[i-1],ma);
    }
    ma=max(ma,k+a[1]-a[n]);
    cout<<k-ma;
}



Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
int main(){
	double x0,y0,x1,y1,x,y,s=0;
	char c;
	std::cin>>x0>>c>>y0;
	x1=x0;y1=y0;
	while(std::cin>>x>>c>>y){
		s+=x1*y-y1*x;
		x1=x;y1=y;
	}
	s+=x1*y0-y1*x0;
	std::cout<<fabs(s/2)<<"\n";
}

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

#define int long long
const int mod = 1e9+7;

class FermatCombination{
private:
	vector<int> fac, inv;
	
	int Pow(int x, int n){
		int ans = 1;
		while(n > 0){
			if(n & 1)ans = (ans*x)%mod;
			x = (x*x)%mod;
			n >>= 1;
		}
		return ans;
	}
	void Factrial(int n){
		fac[0] = inv[0] = 1;
		for(int i = 1;i <= n;i++){
			fac[i] = (fac[i-1]*i)%mod;
			inv[i] = Pow(fac[i], mod-2);
		}
	}
	
public:
	void init(int n){	//nCk
		fac.resize(n+1);
		inv.resize(n+1);
		Factrial(n);
	}
	int combine(int n, int k){
		int tmp = (fac[n]*inv[k])%mod;
		return (tmp*inv[n-k])%mod;
	}
};

FermatCombination C;
int comb(int h, int w){
	return C.combine((h+w), w);
}

signed main(){
	int h, w, a, b;
	C.init(200000);
	scanf("%lld%lld%lld%lld", &h, &w, &a, &b);
	h--;w--;a--;b--;
	int ans = 0;
	for(int i = b+1;i <= w;i++){
		int y = h-a-1, x = i;
		ans += comb(y, x)*comb(h-y-1, w-x);
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	double a, b;
	cin >> a >> b;
	if (a == b) {
		cout << "EQUAL" << endl;
	}
	else {
		if (a > b) {
			cout << "GREATER" << endl;
		}
		else {
			cout << "LESS" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#include <list>
#include <unordered_map>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define SQ 317
#define MAG 33554431
#define RED 0
#define BLUE 1
#define ALP 26
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,k,l,m,r,x,y,K,tot,sz,cur,sum,n,c, maxlvl,q,z,N,ans;
ll a[400500], b[100500], used[100500][15];
vector<ll> g[100500];
pair<ll, pii> queries[100500];
vector<pii> bfs;
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("input.txt","w",stdout);
    cin >> n >> m;
    for (i = 0; i < m; i++)
    {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cin >> q;
    for (i = 0; i < q; i++)
        cin >> queries[i].X >> queries[i].Y.X >> queries[i].Y.Y;
    reverse(queries, queries+q);
    for (i = 0; i < q; i++)
    {
        ll v = queries[i].X, d = queries[i].Y.X, c = queries[i].Y.Y;
        if (used[v][d])
            continue;
        bfs.clear();
        bfs.push_back(mp(v,d));
        for (k = 0; k <= d; k++)
            used[v][k] = 1;
        if (a[v] == 0)
            a[v] = c;
        j = 0;
        while (j < bfs.size())
        {
            ll v = bfs[j].X;
            ll d = bfs[j].Y;
            j++;
            if (d == 0)
                continue;
            for (k = 0; k < g[v].size(); k++)
            {
                ll to = g[v][k];
                if (!used[to][d-1])
                {
                    for (l = 0; l <= d-1; l++)
                        used[to][l] = 1;
                    if (a[to] == 0)
                        a[to] = c;
                    bfs.push_back(mp(to, d-1));
                }
            }
        }
    }
    for (i = 1; i <= n; i++)
        cout << a[i] << endl;
    return 0;
}


Measured memory_bytes: 24820
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;

int main() {

	ll A, B;
	ll C, D;
	cin >> A >> B >> C >> D;

	ll x, y, r;

	x = C;
	y = D;
	ll z = x * y;
	if (x < y) {
		ll tmp = x;
		x = y;
		y = tmp;
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	ll R = z / y;
	
	ll cnt = 0;

	if (A % C != 0) {
		cnt += (B / C) - (A / C);
	}
	else {
		cnt += (B / C) - (A / C) + 1;
	}
	if (A % D != 0) {
		cnt += (B / D) - (A / D);
	}
	else {
		cnt += (B / D) - (A / D) + 1;
	}
	if (A % R != 0) {
		cnt -= (B / R) - (A / R);
	}
	else {
		cnt -= (B / R) - (A / R) + 1;
	}
	cnt = B - (A - 1) - cnt;

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256