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

int main() {

        int n, k;

        std::cin >> n >> k;

        std::vector<long> h(n);

        for (auto& hi : h) {
                std::cin >> hi;
        }

        std::sort(std::begin(h), std::end(h));

        long result = std::numeric_limits<long>::max();

        k--;
        for (auto i = 0 ; i < h.size() - k; ++i) {
                long v = h[i + k]  - h[i];
                if (result > v) {
                        result = v;
                }
        }

        std::cout << result << std::endl;

        return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define MOD 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

llong dp[101][256][101] = {};
int main(){

  int n, k;
  scanf("%d %d", &n, &k);

  vector<int> v;
  SV(n,v);

  llong fact[101] = {};
  fact[0] = 1;
  FOR(i,1,n+1){
    fact[i] = fact[i - 1] * i % MOD;
  }

  dp[0][0][0] = 1;
  REP(i,n){
    REP(j,n){
      REP(k,256){
        dp[i + 1][k][j] += dp[i][k][j] % MOD;
        dp[i + 1][k ^ v[i]][j + 1] += dp[i][k][j] % MOD;
      
      }
    }
  }

  llong ans = 0;
  FOR(i,1,n+1){
    ans += dp[n][k][i] * fact[i] % MOD;
    ans %= MOD;
  }

  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 20480
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c,d=0;
    cin>>a>>b>>c;
    if(a>b&&a>c){
        if(a==b+c){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else if(b>a&&b>c){
        if(b==a+c){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else if(c>a&&c>b){
        if(c==a+b){
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    else {
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=2e5+5;
struct seg{int l,r,c;}st[N*2];
int n,a[N],w,l,r,m,i;
int main(){
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",a+i);
	for(l=1,r=n;l<r;){
		m=l+r>>1;st[w=1]=(seg){1,a[1],1};
		for(i=2;i<=n;++i)if(a[i]>a[i-1])st[++w]=(seg){a[i-1]+1,a[i],1};else{
			for(;w && st[w].l>a[i];--w);
			st[w].r=a[i];
			for(;w && st[w].c==m;--w);
			if(!w)break;
			if(st[w].l==st[w].r)++st[w].c;else st[w+1]=(seg){st[w].r,st[w].r,st[w].c+1},--st[w].r,++w;
			if(st[w].r<a[i])st[w+1]=(seg){st[w].r+1,a[i],1},++w;
		}
		if(i<=n)l=m+1;else r=m;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,sw,i,min;
  sw=0;
  cin >> n;
  string h;
  cin >> h;
  
  for(i=0;i<n;++i)
  {
  if(h.at(i)=='E') sw++;
  }
  
  min=sw;
  
  for(i=1;i<n+1;i++)
  {
  if(h.at(i-1)=='W') sw++;
  if(h.at(i-1)=='E') sw--;
  if(sw < min) min=sw;
  }
  
  printf("%d",min);
  
return 0;
}

Measured memory_bytes: 3884
#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using usize = std::size_t;

i64 dp[81];

auto main() -> i32 {
	i32 n;
	i64 a[80];
	scanf("%d", &n);
	for (i32 i = 0; i < n; ++i) {
		scanf("%ld", a + i);
	}
	dp[0] = 1000;
	for (i32 i = 0; i < n; ++i) {
		i64 m = dp[i] / a[i];
		i64 b = dp[i] - m * a[i];
		for (i32 j = i; j < n; ++j) {
			if (dp[j + 1] < b + m * a[j]) {
				dp[j + 1] = b + m * a[j];
			}
		}
	}
	printf("%ld\n", dp[n]);
	return 0;
}


Measured memory_bytes: 1728
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val h = sc.nextLong()
        val w = sc.nextLong()
        if (h % 3 == 0L || w % 3 == 0L) {
            println("0")
            return
        }

        fun calc(a: Long, b: Long, c: Long): Long {
            val min = min(a, min(b, c))
            val max = max(a, max(b, c))
            return max - min
        }

        var ans = min(h, w)
        for (w2 in 1 until w) {
            val a = h * w2
            val h2 = h / 2
            val b = h2 * (w - w2)
            val c = (h - h2) * (w - w2)
            ans = min(ans, calc(a, b, c))
        }

        for (h2 in 1 until h) {
            val a = h2 * w
            val w2 = w / 2
            val b = (h - h2) * w2
            val c = (h - h2) * (w - w2)
            ans = min(ans, calc(a, b, c))
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
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; }
const ll inf = 1ll << 60;

int main() {
    int n;
    scanf("%d", &n);
    vector<vector<int>> map(n, vector<int>(3));
    int x0, y0, h0;
    rp(i, 0, n) {
        int x, y, h;
        scanf("%d%d%d", &x, &y, &h);
        map.at(i) = {x, y, h};
        if(h != 0) {
            x0 = x;
            y0 = y;
            h0 = h;
        }
    }
    rp(i, 0, 101) {
        rp(j, 0, 101) {
            bool flag = true;
            int k = h0 + abs(i - x0) + abs(j - y0); //(i, j) が頂点の時の高さ
            rp(m, 0, n) {
                int x = map.at(m).at(0);
                int y = map.at(m).at(1);
                int h = map.at(m).at(2);
                if(h != max(k - abs(i - x) - abs(j - y), 0)) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                printf("%d %d %d", i, j, k);
                return 0;
            }
        }
    }
}

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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define REPR(i,n,m) for(int i=n;i>m;i--)
#define ALL(v) v.begin(),v.end()
#define elif else if
using ll=long long;

ll gcd(ll x,ll y){
    ll a;
    while(y!=0){
        a=x%y;
        x=y;
        y=a;
    }
    return x;
}

/*--- lcm a*b/gcd(a,b) ---*/

/*----------template----------*/

int main(){
    ll n, k, sum = 0;
    cin >> n >> k;

    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }

    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());

    for(int i = k; i < n; i++){
        sum += h.at(i);
    }

    cout << sum << endl;
}

Measured memory_bytes: 1024
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int X = sc.nextInt();


        // べき乗数のリストをつくる
		Set<Integer> set = new HashSet<>();

		set.add(1);

		for (int i = 2; i < 32; i++) {
			for (int j = 2; j < 10; j++) {
				set.add((int)Math.pow(i, j));
			}
		}

		for(int i = 0; i < X; i++) {
			if (set.contains(X-i)) {
				System.out.println(X-i);
				return;
			}
		}
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int a[N],n,len[N];

il int sta(int i,int j){
	return (j>a[i+1]?len[i]:len[i+1]^1)|((a[i]-j)&1);
}

int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	sort(a+1,a+n+1,greater<int>());
	int cur=0;
	per(i,n,1){
		if(a[i]==a[i+1]) cur^=1;else cur=0;
		len[i]=cur;
	}
	int i=n,j=1;
	while(i!=j){
		if(j!=a[i]) ++j;
		else --i; 
	}
	printf("%s\n",sta(i,j)?"First":"Second");
	return 0;
}


Measured memory_bytes: 1024
def main():
    n, k = map(int, input().split())
    s = input()

    かわいそうな人たち = s.count('LR') + s.count('RL')
    t = min(かわいそうな人たち, k)
    u = n - (かわいそうな人たち + 1) + 2 * t
    print(min(n - 1, u))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n=int(input())

march=[0]*5

march_dic={"M":0,"A":1,"R":2,"C":3,"H":4}

for i in range(n):
    name=input()
    if name[0] in "MARCH":
        march[march_dic[name[0]]]+=1

def count_type(march):
    ans=[]
    for i in march:
        if i!=0:
            ans.append(i)
    ans.sort()
    return len(ans),ans

type_num,each_num=count_type(march)
if type_num<3:
    print(0)
else:
    ans=0
    for i in range(type_num-2):
        for j in range(i+1,type_num-1):
            for k in range(j+1,type_num):
                ans+=each_num[i]*each_num[j]*each_num[k]

    print(ans)


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

bool has_t(const string& s, int n)
{
  if (n % 2 != 0) {
    return false;
  }
  for (int i = 0; i < n/2; i++) {
    if (s.at(i) != s.at(i+n/2)) {
      return false;
    }
  }
  return true;
}

int main()
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  if (has_t(s, n)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX = 100005;
const int INF = 1000000005;
int a[MAX];
int dp[MAX];


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

	for (int i = 0; i < MAX; ++i)
	{
		dp[i] = INF;
	}

	for (int i = 0; i < n; ++i)
	{
		*lower_bound(dp, dp+n, a[i]) = a[i];
	}

	cout << lower_bound(dp, dp+n, INF) - dp << endl;
	return 0;
}


Measured memory_bytes: 3884
program prob1
    implicit none
    integer::a,b,ans
    read(*,*) a,b
    ans = 0
    if(a == 1)then
        ans = 300000
        if(b == 1)then
            ans = 1000000
        else if(b == 2)then
            ans = ans + 200000
        else if(b == 3)then
            ans = ans + 100000
        end if
    else if(a == 2) then
        ans = 200000
        if(b == 1)then
            ans = ans + 300000
        else if(b == 2)then
            ans = ans + 200000
        else if(b == 3)then
            ans = ans + 100000
        end if
    else if(a == 3)then
        ans = 100000
        if(b == 1) then
            ans = ans + 300000
        else if(b == 2)then
            ans = ans + 200000
        else if(b == 3)then
            ans = ans + 100000
        end if
    else
        if(b == 1) then
            ans = ans + 300000
        else if(b == 2)then
            ans = ans + 200000
        else if(b == 3)then
            ans = ans + 100000
        end if
    end if

    write(*,*) ans
    stop
end program

Measured memory_bytes: 2832
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;

int N, D;

int main() {
    cin >> N >> D;
    if (N % (1 + 2 * D) == 0) {
        cout << N / (1 + 2 * D) << endl;
    } else {
        cout << N / (1 + 2 * D) + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

typedef pair<double,double> P;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

double r;
int s;
int w[101];

vector<P> dfs(vector<int> stones){
    if(stones.size()==1){
        vector<P> res;
        res.push_back(P(0,0));
        return res;
    }
    vector<int> v,v2;
    vector<P> ret;
    for(int s=0;s<(1<<stones.size());s++){
        v.clear();
        v2.clear();
        int sum1=0;
        int sum2=0;
        for(int i = 0; i < stones.size(); i++){
            if((s>>i)&1){
                sum1+=w[stones[i]];
                v.push_back(stones[i]);
            }
            else{
                sum2+=w[stones[i]];
                v2.push_back(stones[i]);
            }
        }
        if(v.size()==0||v2.size()==0)continue;
        double b=(double)sum1/(sum1+sum2);
        double a=(double)sum2/(sum1+sum2);
        vector<P> res1=dfs(v);
        vector<P> res2=dfs(v2);
        for(int i = 0; i < res1.size(); i++){
            for(int j = 0; j < res2.size(); j++){
                double left=res1[i].first-a;
                double right=res1[i].second-a;
                double left2=res2[j].first+b;
                double right2=res2[j].second+b;
                double minn=min(left,min(left2,min(right,right2)));
                double maxn=max(left,max(left2,max(right,right2)));
                ret.push_back(P(minn,maxn));
            }
        }
    }
    return ret;
}

const double INF=1000000000;
int main(){

    int t;
    cin>>t;
    while(t--){
        cin>>r>>s;
        vector<int> ss;
        for(int i = 0; i < s; i++){
            cin>>w[i];
            ss.push_back(i);
        }
        vector<P> res=dfs(ss);
        double maxl=-1;
        for(int i = 0; i < res.size(); i++){
            double len=abs(res[i].first-res[i].second);
            if(!EQ(len,r)&&len<r){
                maxl=max(maxl,len);
            }
        }
        if(!EQ(maxl,-1))
            printf("%.10f\n",maxl);
        else
            cout<<-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 1996
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<int> v(n);
  REP(i, n) cin >> v[i];
  REP(i, n){
    int c;
    cin >> c;
    v[i] -= c;
  }

  vector<int> dp(n+1, 0);
  REP(i, n){
    dp[i+1] = dp[i];
    chmax(dp[i+1], dp[i]+v[i]);
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
 
// 素集合データ構造というデータ構造ですj
struct UnionFind {
  std::vector<int> parent; // あるデータの親
  std::vector<int> sizes;  // あるデータが属する木のサイズ
 
  // コンストラクタ
  // データ一つ一つを木とし、親は自分自身に初期化する
  UnionFind(int n)
    : parent(n)
    , sizes(n, 1)
  {
    for (int i = 0; i < n; ++i) {
      parent[i] = i;
    }
  }
 
  // データxが属する木の根ノードを取得
  // findだがunion-find木の仕組み的に内部で破壊的更新を伴う
  int find(int x) {
    // 親と自分が同じであることが
    // 自分がルートノードであるということ
    if( x == parent[x] ) {
      return x;
    }
 
    // 経路を圧縮するため調べた辺を根に直接繋ぎ直す
    parent[x] = find(parent[x]);
    return parent[x];
  }
 
  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // それぞれのデータの根ノードを取得
    int root_x = find(x);
    int root_y = find(y);
 
    // x, yが同じ木に属するならマージしない
    if (root_x == root_y) return;
 
    // xの木がyの木より大きくなるようにする
    if (sizes[root_x] < sizes[root_y]) {
      std::swap(root_x, root_y);
    }
 
    // xがyの親になるようにマージする
    parent[root_y] = root_x;
    sizes[root_x] += sizes[root_y];
  }
 
  // 2つのデータx, yが同じ木に属するかどうか
  bool same(int x, int y) {
    return (find(x) == find(y));
  }
 
  // データxの属する木のサイズを返す
  int size(int x) {
    return sizes[find(x)];
  }
};
 
// 頂点a, bを繋ぐコストcostの無向辺
struct Edge {
  int a, b, cost;
 
  // コストで順序を決める(ソートのときに使われる)
  bool operator<(const Edge &o) const {
    return cost < o.cost;
  }
};
 
// 頂点数と辺集合の組として定義したグラフ
struct Graph {
  int n;           // 頂点数
  std::vector<Edge> edges; // 辺集合
 
  // クラスカル法で無向最小全域木を求め、コストの和を返す
  int kruskal() {
    // costの小さい辺から繫いでいくので、昇順にソートしておく
    sort(edges.begin(), edges.end());
 
    // UnionFindで同じ集合にいることを確認できます
    // これを使って「繋がってるノード」をすべて1つの集合にいることにします
    // 最初の状態では「どれも繋がっていません」が
    // エッジで繋いだ2つのノードは、同じ集合にいることにしてしまいます
    // 辺を追加するときに、すでにつながっているノード同士を繋ぐということが閉路ができる条件なので
    // 閉路を作らないようにつながっていないノードを繋ぐということを繰り返す
    UnionFind uf(n);
    int min_cost = 0;
    for (size_t i = 0; i < edges.size(); ++i) {
      Edge e = edges[i];
      if (!uf.same(e.a, e.b)) {
        min_cost += e.cost;
        uf.unite(e.a, e.b);
      }
    }
 
    return min_cost;
  }
};
 
int main() {
  int N;
  std::cin >> N;
  std::pair<int, int> x[N], y[N];
  for (size_t i = 0; i < N; ++i) {
    std::cin >> x[i].first >> y[i].first;
    x[i].second = y[i].second = i;
  }
 
  // 式 min( |a-c|, |b-d| ) を検討してみると
  // - "x軸側で一番近い"街
  // - "y軸側で一番近い"街
  // の2つだけがそれぞれの街に存在することがわかります。
  //
  // ということは言い換えると
  // - x軸側について街を並べた並び
  // - y軸側について街を並べた並び
  // の2つだけを検討したら十分なことがわかります
  sort(x, x + N);
  sort(y, y + N);
 
  // グラフ構造を引っ張る
  Graph g;
  g.n = N;  // Nノードあります
 
  // 辺を作っていく
  for (size_t i = 0; i < N - 1; ++i) {
    Edge e;
    e.a = x[i].second;
    e.b = x[i+1].second;
    e.cost = x[i+1].first - x[i].first;
    g.edges.push_back(e);
 
    e.a = y[i].second;
    e.b = y[i+1].second;
    e.cost = y[i+1].first - y[i].first;
    g.edges.push_back(e);
  }
 
  std::cout << g.kruskal() << std::endl;
  return 0;
}

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

int main() {
	int n, a[100];
	cin >> n;

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

	for (int i = n - 1; i >= 0; i--) {
		cout << a[i];
		if (i != 0)cout << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
int mod=1e9+7;


int32_t main() {
    int T;
    T=1;
    //cin>>T;
    while(T--){
        int n,W;
        cin>>n>>W;
        int w[n], v[n];
        for(int i=0;i<n;i++){
            cin>>w[i]>>v[i];
        }
        int dp[n][W+1], ans=0;
        memset(dp,0,sizeof(dp));
        for(int i=0;i<n;i++){
            for(int j=1;j<=W;j++){
                if(j-w[i]>=0){
                    dp[i][j]=v[i]+((i>0)?dp[i-1][j-w[i]]:0);
                }
                if(i>0)
                    dp[i][j]=max(dp[i][j], dp[i-1][j]);
                if(i==n-1){
                    ans=max(ans, dp[i][j]);
                }
            }
            
        }
        // for(int i=0;i<n;i++){
        //     for(int j=0;j<=W;j++){
        //         cout<<dp[i][j]<<" ";
        //     }cout<<endl;
        // }
        cout<<ans;
        cout<<'\n';
    }
	return 0;
}

Measured memory_bytes: 78336
from collections import Counter, defaultdict, deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b,c,d = inpl()
print(max(a*c, a*d, b*d, b*c))

Measured memory_bytes: 10520
#include <iostream>

using namespace std;

#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int result = C - (A - B);
  if (result < 0) {
    OUT(0);
  } else {
    OUT(result);
  }
}

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

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

    int N; cin >> N;
    long double ans = 0;
    for (int i = 0; i < N; i++) {
        long double x; cin >> x;
        string u; cin >> u;
        ans += u == "JPY" ? x : x * 380000.0;
    }
    cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define VMAX 20000

int main() {

	unsigned short *A, *B;

	int C[VMAX + 1], n, i;
	scanf("%d", &n);

	A = (unsigned short*)malloc(sizeof(short) * n + 1);
	B = (unsigned short*)malloc(sizeof(short) * n + 1);

	for (i = 0; i <= VMAX; i++) C[i] = 0;

	for (i = 0; i < n; i++) {
		scanf("%hu", &A[i+1]);
		C[A[i+1]]++;
	}

	for (i = 1; i <= VMAX; i++) C[i] += C[i-1];

	for (i = n; i >= 1; i--) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	printf("%d", B[1]);
	for (i = 2; i <= n; i++) {
		printf(" %d", B[i]);
	}
	printf("\n");

	free(A);
	free(B);
	return 0;
}



Measured memory_bytes: 10224
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    N = len(S)

    for i in range(N - 2):
        if S[i] == S[i + 1] or S[i] == S[i + 2]:
            print(i + 1, i + 3)
            return

    if S[N - 2] == S[N - 1]:
        print(N - 1, N)
        return

    print(-1, -1)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
        int N = input[0];
        int L = input[1];
        int left = L;
        int right = L + N - 1;
        int eat = 0;
        // i = 1かi = Nの美味しさ値で食べるりんごは特定できる
        if (left >= 0) eat = L;
        else if (right <= 0) eat = right;
        else eat = 0;

        int answer = (left + right) * N / 2 - eat;
        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 13268
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int A;
    
    string p,q;
    cin>>p>>q;
    int cnt=0;
    for(int i=0;i<p.length();i++)
    {
        if(p[i]!=q[i])
        cnt++;
    }
    cout<<cnt;

return 0;
}

Measured memory_bytes: 3808
# debug
debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if debugFlag

# util functions
def find_posmin(arr)
  m = arr.max
  arr.each do |e_i|
    m = e_i if e_i > 0 and m > e_i
  end
  return m
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if true
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

ls = inputs[0][0].split("/")
p ls if debugFlag

# body
if ls[0].to_i < 2019
  puts "Heisei"
elsif ls[1].to_i < 4 or ( ls[1].to_i == 4 and ls[2].to_i <= 30 )
  puts "Heisei"
else
  puts "TBD"
end

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

//For DP
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;
}

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N;  i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    int N,a,b;
    cin >> N >> a >> b;
    ll x[N+1];
    rep(i,N) cin >> x[i+1];
    ll res = 0;
    for(int i = 1; i < N;i++){
        res += MIN((x[i+1]-x[i])*a,b);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
dat = list(map(int, input().split()))
dat.sort()
#import collections
#c = list(collections.Counter(dat))
#c.sort()
#print(c)
#l = len(c)
res = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j + 1, n):
            a,b,c = dat[i], dat[j], dat[k]
            if a == b or a == c or b == c:
                continue
            if c < a+b:
                res += 1
print(res)

Measured memory_bytes: 67896
#include<bits/stdc++.h>
using namespace std;
main(){
    int a,b;
    cin>>a>>b;
    for(int i=(int)min(a/0.08,b/0.1);i<(int)min((a+1)/0.08,(b+1)/0.1);i++){
        if((int)(i*0.08)==a&&(int)(i*0.1)==b){
                cout<<i<<endl;
                return 0;
        }
    }
    cout<<-1<<endl;
}


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

int n;
int A[210];

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

int b = 0;
while(true){
bool exist_odd = false;
for(int i = 0;i < n;++i){
if(A[i] % 2 != 0) exist_odd =true;
}

if (exist_odd) break;

for(int i = 0;i<n;++i){
A[i] /= 2;
}
++b;
}
cout << b << endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int MAX=100000;
int main(){
  while(true){
    int n,m;
    cin>>n>>m;
    if(!n&&!m)
      break;
    int a,b,cost,timer;
    int costs[m][m];
    int timers[m][m];
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
        costs[i][j]=MAX;
        timers[i][j]=MAX;
      }
      costs[i][i]=0;
      timers[i][i]=0;
    }

    for(int i=0;i<n;i++){
      cin>>a>>b>>cost>>timer;
      costs[a-1][b-1]=cost;
      timers[a-1][b-1]=timer;
      costs[b-1][a-1]=cost;
      timers[b-1][a-1]=timer;
    }
    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
        for(int k=0;k<m;k++){
          if(costs[j][k]>(costs[j][i]+costs[i][k])){
            costs[j][k]=costs[j][i]+costs[i][k];
            costs[k][j]=costs[j][i]+costs[i][k];
          }
          if(timers[j][k]>(timers[j][i]+timers[i][k])){
            timers[j][k]=timers[j][i]+timers[i][k];
            timers[k][j]=timers[j][i]+timers[i][k];
          }
        }
      }
    }
    int k;
    int p;
    int q;
    bool r;
    cin>>k;
    for(int i=0;i<k;i++){
      cin>>p>>q>>r;
      if(r){
        cout<<timers[p-1][q-1]<<endl;
      }else if(!r){
        cout<<costs[p-1][q-1]<<endl;
      }
    }
  }
    return 0;
}



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

using namespace std;

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

  int max = 0, sum = 0;
  for (int i = 0; i < N; ++i)
  {
    int L;
    cin >> L;

    sum += L;
    if (max < L) max = L;
  }
  sum -= max;

  if (max < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
fn main(){
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let vec: Vec<&str> = s.trim().split(' ').collect();
	let x: i64 = vec[0].parse().unwrap();
	let t: i64 = vec[1].parse().unwrap();
	if x - t > 0 {
		println!("{}", x - t);
	} else {
		println!("0");
	}
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main()
{
   int i,a,b, temp;
   for(i=1;i<=3000; i++){
   cin >>a>>b;
   if (a>b){
   temp = a;
   a = b ;
   b = temp ;
   cout<<a<<" "<<b<<endl;
   }
   else{
       if(a==0,b==0)
       break;
   else
   cout<<a<<" "<<b<<endl;
   }
}
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 510000;
const int MOD =  998244353;
const int INV2 = (MOD+1)/2;

     signed main(){
    string s;
    cin>>s;
    int k=1;
    int dp[s.size()];
    dp[s.size()-1]=s[s.size()-1]-'0';k=(k*10)%2019;
    for(int i=s.size()-2;i>=0;i--){
      dp[i]=(dp[i+1]+k*(s[i]-'0'))%2019;
      k=(k*10)%2019;
    }
    int ans[2019]={};
    for(int i=0;i<s.size();i++)ans[dp[i]]++;
    int ans2=ans[0];
    for(int i=0;i<2019;i++)ans2+=ans[i]*(ans[i]-1)/2;
    cout<<ans2<<endl;
}


        


Measured memory_bytes: 5304
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

void chmax(ll& x, ll y) {
    if (x < y) x = y;
}

const ll MOD = 1000000007;
//const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    ll n; cin >> n;
    vector<int> v(n);
    REP(i, n) cin >> v[i];
    REP(i, n) v[i]++;

    vector<int> cnt(n + 1, 0);
    cnt[0] = 3;

    mint ans = 1;
    REP(i, n) {
        ans *= cnt[v[i] - 1];
        cnt[v[i] - 1]--;
        cnt[v[i]]++;
    }

    print(ans);
}

Measured memory_bytes: 3976
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
    int n,sum,s;
    int a[5][105]={0};
    while(cin>>n)
    {
        sum=0;
      for(int i=0;i<n;i++)
        cin>>a[0][i];
      for(int i=0;i<n;i++)
        cin>>a[1][i];
        int p=1,maxn=0;
          for(int i=0;i<n;i++)
            {
              sum=sum+a[0][i];
              s=sum;
            for(int j=i;j<n;j++)
            {sum=sum+a[1][j];
            //cout<<sum<<endl;
            }
          if(sum>maxn)
            {maxn=sum;}
            sum=s;
            }
          cout<<maxn<<endl;

      }

    }


Measured memory_bytes: 256
N = int(input().strip(" "))
a = list(map(int, input().strip().split(" ")))

a.sort()    #ソート

alice =[]
bob = []

i = 0

while(len(a) > 0):
    if (i % 2 == 0):        
        alice.append(a.pop(0))
        i += 1
    else:
        bob.append(a.pop(0))
        i += 1

print(abs(sum(alice) - sum(bob)))

Measured memory_bytes: 3064
def resolve():
  X, N = map(int, input().split(" "))
  if N == 0:
    print(X)
    return True

  p = [int(x) for x in input().split(" ")]
  set_p = set(p)

  for i in range(N+100):
    if (X-i) not in set_p:
      print(X-i)
      return True

    if (X+i) not in set_p:
      print(X+i)
      return True

if __name__ == "__main__":
  resolve()


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

int main()
{
	char str[1001];
	int sum=0;
	int i,len;
	while(1){
		scanf("%s",  str);
		if(strcmp(str, "0")==0){
			break;
		}
		else{
			len=strlen(str);
			for(i=0; i<len; i++){
				sum+=str[i]-'0';
			}
		}
		printf("%d\n", sum);
		sum=0;
	}
	return 0;
}

Measured memory_bytes: 536
# -*- coding: utf-8 -*-
from sys import stdin

s = stdin.readline().rstrip()
ans_list = []
ans = 0

for i in range(2**(len(s)-1)):
    s_plus = ""
    b = "{:0{}b}".format(i,len(s)-1)
    for j in range(len(s)-1):
        s_plus += s[j]
        if b[j] == "1":
            s_plus += ","
        else:
            s_plus += ""
    s_plus += s[-1]
    ans_list = s_plus.split(",")
    ans_list_int = [int(i) for i in ans_list]
    ans += sum(ans_list_int)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template <typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}
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 (a > b) { a = b; return 1;}
    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin >> a >> b >> c;
    if(a + b + c <= 21){
        cout << "win" << endl;
    }else{
        cout << "bust" << endl;
    }
    return 0;
}

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


using namespace std;

int main() {
    int N = 0, kind = 0;
    cin >> N;
    cin >> kind;
    vector<int> cakes;

    int arg = 0;
    for(int i = 0; i < kind; i++) {
        cin >> arg;
        cakes.push_back(arg);
    }

    int max = *max_element(cakes.begin(), cakes.end());
    max+=max;

    for(int i = 0; i < kind; i++) {
        max -= cakes[i];
        //cout << max << endl;
    }

    if (max > 0)
        cout << max-1 << endl;
    else
        cout << "0" << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
N, K = map(int, input().split())

if N%2 == 0 :
  if N//2 >= K :
    print ("YES")
  else :
    print ("NO")
else :
  if N//2 + 1 >= K :
    print ("YES")
  else :
    print ("NO")
  


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

int main(){
    int n;
    cin >> n;
    vector<double> gpa(n);
    for(int i=0; i<n; i++){
        cin >> gpa[i];
    }
    vector<double> s = gpa;
    sort(s.begin(), s.end());
    for(int i=0; i<n; i++){
        int point = 0;
        point += 3*(lower_bound(s.begin(), s.end(), gpa[i]) -s.begin());
        point += upper_bound(s.begin(), s.end(), gpa[i])
            -lower_bound(s.begin(), s.end(), gpa[i]) -1;
        cout << point << endl;
    }
    return 0;
}


Measured memory_bytes: 4348
let gcd m n =
  let rec doit x y =
    if y <= 0 then x
    else doit y (x mod y)
  in doit (max m n) (min m n)

let () =
  let (a, b) = Scanf.scanf "%d %d\n" (fun a b -> (a, b)) in
  Printf.printf "%d\n" (gcd a b)

Measured memory_bytes: 2428
$|=1;
$N = <STDIN>;chomp $N;
$line = <STDIN>;chomp $line;
@T = split " ", $line;
$line = <STDIN>;chomp $line;
@V = split " ", $line;

#stop
push @T,1;
push @V,0;
$N+=1;

$sumT=0;
for($i=0;$i<$N;$i++){
 $TT[$i]=$sumT;
 $sumT += $T[$i];
}


$v=0;$x=0;$t=0;$it=0;
while($t<$sumT-1) {
 $f=1;
 if ($TT[$it]<=$t) { $it+=1; }
 for($i=$it;$i<$N;$i++){
  if ( $v-($TT[$i]-$t)*1>=$V[$i] ) {
   $f=-1;
   goto NEXT1;
  }
 }
 if ($v>=$V[$it-1]) { $f=0; }
 
NEXT1:
 
 if($f==0)    { $x=$x+$v/2; }
 elsif($f==1) { $x=$x+$v/2+0.25; $v=$v+0.5; }
 else         { $x=$x+$v/2-0.25; $v=$v-0.5; }
 $t=$t+0.5;
}

print "$x\n";


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main(){

	long long int k, fi=101, two=200;
	char val='1';
	string s;

	cin>> s;
	cin>> k;

	for(int i=0;i<min(k, two);i++){
		if(s[i]!='1'){
			fi=i;
			val=s[i];
			break;
		}
	}

	if(k<fi) cout<< '1' << endl;
	else cout<< val << endl;

}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
*H, = map(int, input().split())
ans = None; v = 10**18
for i, h in enumerate(H):
    w = abs(A*1000 - T*1000 + 6*h)
    if w < v:
        v = w
        ans = i
print(ans+1)


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


#define max 2147483647
/*
中央値
中央値候補は二こしかない
それより大きいのか否かで場合分けでいけそう
要素NならN/2 orN/2+1番に限られる
123456
*/

void merge(int *a,int left,int mid,int right){
        int n1 = mid - left;
        int n2 = right - mid;
        int L[n1+1],R[n2+1];
        int i;
        for(i=0;i<n1;i++){
            L[i] = a[left + i];
        }
        for(i=0;i<n2;i++){
            R[i] = a[mid + i];
        }
        L[n1]=max;
        R[n2]=max;
        int j=0,k=0;
        for(i=left;i<right;i++){
            if(L[j]<R[k]){
                a[i] = L[j];
                j++;
            }
            else{
                a[i] = R[k];
                k++;
            }
        }

}


void merge_sort(int *a,int left,int right){
    int middle;
    if(left + 1 < right){
        middle = (left + right)/2;
        merge_sort(a,left,middle);
        merge_sort(a,middle,right);
        merge(a,left,middle,right);
    }
}

int main(void){
    int N;
    scanf("%d",&N);
    int i,X[N],s[N];
    for(i=0;i<N;i++){
        scanf("%d",&X[i]);
        s[i] = X[i];
    }
    merge_sort(s,0,N);
    int val1=s[N/2 - 1],val2 = s[N/2];
    for(i=0;i<N;i++){
        if(X[i]<val2){
            printf("%d\n",val2);
        }
        else{
            printf("%d\n",val1);
        }

    }

    return 0;
}

Measured memory_bytes: 4480
N, M, X, Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

max_x = max(x)
min_y = min(y)
z = [i for i in range(-100, 101) if X < i <= Y and max_x < i <= min_y]
if z:
    print("No War")
else:
    print("War")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int vs[100100][3];
int dp[100100][3];

void solve() {
    int N;
    cin >> N;
    for (int i = 1; i <= N; ++i) cin >> vs[i][0] >> vs[i][1] >> vs[i][2];
    dp[1][0] = vs[1][0], dp[1][1] = vs[1][1], dp[1][2] = vs[1][2];
    for (int i = 2; i <= N; ++i) {
        int *pre = dp[i - 1];
        int *v = vs[i];
        for (int j = 0; j < 3; ++j) {
            dp[i][j] = max(pre[(j+1)%3] + v[j], pre[(j+2) % 3] + v[j]);
        }
    }
    int *x = dp[N];
    int M = x[0];
    for (int i = 1; i < 3; ++i) {
        M = max(M, x[i]);
    }
    cout << M << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 2560
a[1<<18];
n=1<<18;
cnt;

main(i,j) {
	memset(a,-1,sizeof a);
	a[0]=a[1]=0;
	for(i=2;i<n;i++)
		if(a[i])
			for(j=2*i;j<n;j+=i)
				a[j] = 0;

	for(;scanf("%d",&n),n;){
		cnt=0;
		for(i=n+1;i<=2*n;i++)
			if(a[i])
				cnt++;
		printf("%d\n",cnt);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<(k) ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=(k) ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN =

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    char c;
    cin >> c;
    cout << char(c+1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <stdio.h>
#define ll long long
#define S second
#define F first
using namespace std;
const ll N = 1e5 + 100, P = 1e9 + 7;

string s;

int main(){
    ios_base::sync_with_stdio(false);
   // freopen("crypt.in", "r", stdin);
   // freopen("crypt.out", "w", stdout);
    cin >> s;
    for(int i = 0; i < 4; i++){
        cout << s[i];
    }
    cout << ' ';
    for(int i = 4; i < s.size(); i++){
        cout << s[i];
    }
    cout << endl;
}


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

using namespace std;

int main(int qtd, char* nome[])
{
    int a[5];
    for (int i = 0; i < 5; i++){
        cin >> a[i];
    }
    int t = 0;
    int ultima = a[0];
    for (int i = 1; i < 5; i++){
        if (a[i] % 10 != 0)
        if (10 - ultima % 10 < 10 - a[i] % 10){
            ultima = a[i];
        }
    }
    int ult = ultima;
    for (int i = 0; i < 5; i++){
        if (a[i] == ultima){
            ultima = -1;
            continue;
        }
        if (a[i] % 10 != 0)
            t += a[i] + 10 - (a[i] % 10);
        else
            t += a[i];
    }

    cout << t + ult << endl;

    return 0;
}

Measured memory_bytes: 256