akhauriyash/Code-Regression huggingface dataset:
def main():
    X = int(input())
    if X >= 400 and X <= 599:
        print(8)
    elif X >= 600 and X <= 799:
        print(7)
    elif X >= 800 and X <= 999:
        print(6)
    elif X >= 1000 and X <= 1199:
        print(5)
    elif X >= 1200 and X <= 1399:
        print(4)
    elif X >= 1400 and X <= 1599:
        print(3)
    elif X >= 1600 and X <= 1799:
        print(2)
    elif X >= 1800 and X <= 1999:
        print(1)
main()  


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  string str;
  cin >> str;

  int r1 = 0;
  for (int i = 0; i < str.length(); i++) {
    char match = (i % 2 == 0) ? '0' : '1';
    if (str[i] != match) {
      r1++;
    }
  }

  int r2 = 0;
  for (int i = 0; i < str.length(); i++) {
    char match = (i % 2 == 1) ? '0' : '1';
    if (str[i] != match) {
      r2++;
    }
  }

  cout << min(r1, r2) << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  int N; 
  cin >> N;
  
  vector<ll> A(N);
  rep(i,N){
    int a; cin >> a;
    a--;
    A[i]=a;
  }
  
  int cnt=0;
  rep(i,N){
    if(A[A[i]] == i) cnt++;
  }
  cout<< cnt/2 << endl;
  
}
  



Measured memory_bytes: 1024
n=int(input())
import heapq
a=map(int, raw_input().split())
q=a[:n]
heapq.heapify(q)
x=[sum(q)]
for k in range(n,2*n):
    v=heapq.heappushpop(q,a[k])
    x.append(x[-1]+a[k]-v)
a=a[::-1]
q=[-v for v in a[:n]]
heapq.heapify(q)
y=[-sum(q)]
for k in range(n,2*n):
    v=-heapq.heappushpop(q,-a[k])
    y.append(y[-1]+a[k]-v)
print(max(v-w for v,w in zip(x,y[::-1])))

Measured memory_bytes: 34208
#include <iostream>

#define rep(i,n)     for(int i=0;i<n;++i)

using namespace std;

const int D[4] = { -1, 0, 1, 0 }; // High School DxD
int tiles[200][2];

int main()
{
	int N;
	while(cin>>N,N)
	{
		tiles[0][0] = tiles[0][1] = 0;
		rep(i,N-1)
		{
			int n,d;
			cin>>n>>d;
			tiles[i + 1][0] = tiles[n][0] + D[d];
			tiles[i + 1][1] = tiles[n][1] + D[(d + 1) % 4];
		}
		int min_x = 1<<20, min_y = 1<<20, max_x = 0, max_y = 0;
		rep(i,N)
		{
			min_x = min(min_x, tiles[i][0]);
			max_x = max(max_x, tiles[i][0]);
			min_y = min(min_y, tiles[i][1]);
			max_y = max(max_y, tiles[i][1]);
		}
		cout << (max_x - min_x + 1) << " " << (max_y - min_y + 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _02_ABC081A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int z = 0;
            bool check = false;
            string str;

            string s = Console.ReadLine();
            //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            //int b = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            //int c = int.Parse(str[1]);

            for (int i = 0; i < s.Length; i++)
            {
                if (!check)
                {
                    if (s[i] == 'A')
                    {
                        a = i;
                        check = true;
                    }
                }
            }
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'Z')
                {
                    z = i;
                }
            }

            str = s.Substring(a, z - a + 1);

            Console.WriteLine(str.Length);
            Console.Read();


        }
    }
}


Measured memory_bytes: 12000
/*      ex3_3
        Tarara  */
#include <stdio.h>

int main(void)
{
    int number; //整数
    int base;   //進数

    scanf("%d %d", &number, &base);

    int digits = 1; //出力する桁数
    while (number >= base)
    {
        number /= base;
        digits++;
    }
    printf("%d\n", digits);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

satisf = b[a[0]-1]
for i in range(1,n):
	satisf += b[a[i]-1]
	if a[i] == a[i-1] + 1:
		satisf += c[a[i-1]-1]

print(satisf)


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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long N, a;
  cin >> N;

  bool isall = true;

  for(long long i = 0; i < N; i++){
    cin >> a;

    if(a % 2 == 0 && (a % 3 != 0 && a % 5 != 0)) isall = false;
  }

  cout << (isall ? "APPROVED" : "DENIED") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

#define INF 300001

using namespace std;

int main(){
    int N;
    string S;
    cin >> N >> S;
    int w = 0;
    int e = 0;
    for(int i=0; i<N; i++) if(S[i] == 'E') e++;
    int ans = INF;
    for(int i=0; i<N; i++){
        if (i != 0) if (S[i-1] == 'W') w++;
        if(S[i] == 'E') e--;
        ans = min(ans, e + w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

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

typedef long long ll;

int main()
{
	int n;
	cin >> n;
	int ans = (n % 2 == 0 ? n / 2 - 1 : n / 2);
	cout << ans;
	return 0;
}

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

int bs()
{
    int n;
    n = 10;
    int lo=0,hi=n;
    int key;
    key = 100;
    int arr[n] = {9,24,56,99,102,244,654,765,999,1002};
    while(lo < hi)
    {
        int md = (hi+lo)/2;//lo+(hi-lo)/2; lo+(hi-lo+1)/2;
        if(arr[md] > key)
        {
            hi = md-1;
        }
        else if(arr[md] < key)
        {
            lo = md+1;
        }
        else
        {
            return cout<<md<<endl,0;
            //hi = md;
            //lo = md;
        }
    }
}
int main()
{
    int n,k,q,a;
    cin>>n>>k>>q;

    map<int,int>mp;

    for(int i=0;i<q;i++)
    {
        cin>>a;
        mp[a]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(k - (q - mp[i]) > 0)puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 5376
a, b, c, k = map(int, input().split())

# ans = []

# ans += [1] * a
# ans += [0] * b
# ans += [-1] * c

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
elif k <= a + b + c:
    print(a - (k - a - b))

#print(sum(ans[:k]))

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

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[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 (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main() {
	int N, Q;
	cin >> N >> Q;
	UnionFind uf(N);
	for (int n = 0; n < Q; ++n) {
		int t, u, v;
		cin >> t >> u >> v;
		if (0 == t) {
			uf.merge(u, v);
		}
		else {
			if (uf.issame(u,v)) {
				cout << 1 << endl;
			}
			else {
				cout << 0 <<endl;
			}
		}
	}
	return 0;
}


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

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

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

    int q;
    cin >> q;

    int b, e, t;
    for(int i = 0; i < q; i++){
        cin >> b >> e >> t;
        swap_ranges(a+b, a+e, a+t);
    }

    for(int i = 0; i < n; i++)  cout << a[i] << " \n"[i == n-1];

    return 0;
}


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

int main(){
  stack<int> S;
  int a, b, x;
  string s;

  while (cin >> s){
    if (s[0] == '+'){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a + b);
    }else if(s[0] == '-'){
      b = S.top();
      S.pop();
      a = S.top();
      S.pop();
      S.push(a - b);
    }else if(s[0] == '*'){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(a * b);
    }else{
      S.push(atoi(s.c_str()));
    }
  }
  cout << S.top() << endl;
  return 0;
}



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

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

inline void Main() {
  // code
  int n,d,r=0;
  int x[10][10];
  cin>>n>>d;
  rep(i,n) rep(j, d) cin>>x[i][j];

  rep(i, n-1) {
    repi(j,i+1,n) {
      int dyz = 0;
      rep(k, d) {
        dyz += pow(x[i][k] - x[j][k], 2);
      }
      double yz = sqrt(dyz);
      if(ceil(yz) == floor(yz)) {
        r++;
      }
    }
  }

  cout<<r<<endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k,a,ans=0,cnt[30]={};
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>a;
			cnt[a-1]++;
		}
	}
	for(int i=0;i<m;i++)
		if(cnt[i]==n)
			ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

N = int(input())
data = input()
A = data.split(" ")
dict = {}
for i in A:
    if i in dict:
        dict[i] += 1
    else:
        dict[i] = 1

a = 0
b = 0
for i in sorted(dict.items(),key = lambda x:int(x[0])):
    if i[1] >= 4:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])
    if i[1] >= 2:
        if int(i[0]) >= min(a,b):
            if a >= b:
                b = int(i[0])

            else:
                a = int(i[0])

print(a*b)


Measured memory_bytes: 29520
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] a1=new int[n];
    int ans = 0;
    
    for(int i=0;i<n;i++){
      a1[i]=sc.nextInt();
    }

    int total = 0;
    for(int j=0;j<n;j++){
      total += a1[j]; 
    }
    
    Arrays.sort(a1);
    if(total % 10 != 0){
      ans = total;
    }else{
      for (int k = 0; k < n; k++) {
        if (a1[k] % 10 != 0) {
          ans = total - a1[k];
          break;
        }
      }
    }
    System.out.println(ans);
  }
}


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

int main() {
    int a, b, c, ans = 0;
    cin >> a >> b >> c;
    if (!((a & 1) == (b & 1) && (b & 1) == (c & 1))) {
        ans++;
        if ((a & 1) == (b & 1)) a++, b++;
        else if ((b & 1) == (c & 1)) b++, c++;
        else a++, c++;
    }
    if (a > b) swap(a, b);
    if (b > c) swap(b, c);
    if (a > b) swap(a, b);
    ans += c - b;
    a += c - b;
    ans += (c - a) >> 1;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
n,k=[int(j)for j in input().split()]
a=[int(j)for j in input().split()]
if n<=k:
    print(*[n]*n)
    exit()
import copy
for idx in range(k):
    table=[0]*n
    for i in range(n):
        table[max(i-a[i],0)]+=1
        if i+a[i]+1<n:
            table[i+a[i]+1]-=1
    for i in range(1,n):
        table[i]+=table[i-1]
    a=copy.deepcopy(table)
    if a==[n]*n:
        break
print(*a)

Measured memory_bytes: 178472
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vector<pii> AB(N);
    cin >> AB;
    sort(all(AB));
    int ans = 0;
    rep(i, 0, N) {
        int t = min(AB[i].second, M);
        ans += t * AB[i].first;
        M -= t;
        if (M == 0) break;
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 1792
//g++ test.cpp -o test.out
//入出力：http://kaitei.net/cpp/iostream/
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
using namespace std;

long N;
long sqrtN;
int ans = 0;

void solve(){
	sqrtN = (long)sqrt(N);
	for(long i=sqrtN;i>0;i--){
		if(N%i==0){
			ans = log10(N/i)+1;
			break;
		}
	}
}

int main(){
	cin >> N;

	solve();

	cout << ans;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long int n,i,j,k=0;
    cin>>n;
    vector <long int> a(10000001,2);
    for (i=2;i<=(10000001)/2;i++)
    {
        for (j=2;j<=10000001/i;j++)
        {
            if (i*j<10000001) a[i*j]++;
        }
    }
    for (i=1;i<=n;i++)
    {
        k+=i*a[i];
    }
    cout<<k-1<<endl;
    //cout<<a[16];
}


Measured memory_bytes: 81396
#!/usr/bin/env python3
import sys

def main():
    N, K = map(int,input().split())
    a = list(map(int,input().split()))

    answer = 0
    for i in range(N):
        if K + (i-1)*(K-1) >= N:
            answer = i
            break

    print(answer)
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
  int f[N2];
  int space;
  string path;

  bool operator < (const Puzzle &p) const{
    for (int i = 0; i < N2; i++) {
      if (f[i] == p.f[i] ) continue;
      return f[i] > p.f[i];
    }
    return false;
  }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u','l','d','r'};

bool isTarget(Puzzle p){
  for (int i = 0; i < N2; i++)
  if(p.f[i] != (i + 1)) return false;

  return true;
}

string bfs(Puzzle s){
  queue<Puzzle> Q;
  map<Puzzle, bool> V;
  Puzzle u, v;
  s.path = "";
  Q.push(s);
  V[s] = true;

  while (!Q.empty()){
    u = Q.front(); Q.pop();
    if (isTarget(u))return u.path;
    int sx = u.space / N;
    int sy = u.space % N;
    for (int r = 0; r < 4; r++) {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
      v = u;
      swap(v.f[u.space], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if ( !V[v] ){
        V[v] = true;
        v.path += dir[r];
        Q.push(v);
      }
    }
  }

  return "unsolvable";
}
int main() {
  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if (in.f[i] == 0){
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = bfs(in);
  cout << ans.size() << endl;

  return 0;
}



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

int main() {

    int size;
    std::cin >> size;
    std::vector<int> weight(size);
    for (auto& e : weight) std::cin >> e;

    std::vector<int> result(size - 1);
    for(auto i = 1 ;i < size; ++i){
        auto pre = 0;
        for (auto j=0; j < i; ++j){
            pre += weight[j];
        }
        auto post = 0;
        for (auto j=i; j < size; ++j) {
            post += weight[j];
        }
        result[i - 1] = std::abs(post - pre);
    }

    std::cout << (*std::min_element(result.begin(), result.end()));
    return 0;
}

Measured memory_bytes: 256
N, K = gets.split(" ").map(&:to_i)

ARR = []
while c = gets&.split(" ")&.map(&:to_i)
  ARR << c
end
ARR.sort!{|v1, v2| v1[0] <=> v2[0]}

k = 0;
ARR.each{|v|
  k += v[1]
  if K <= k
    puts v[0]
    break
  end
}


Measured memory_bytes: 10616
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

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

    if(a + b >= 10){
        std::cout<<"error"<<std::endl;
    }else{
        std::cout<<a + b<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n>> m;
  vp b(m);
  rep(i,m){
    cin >> b[i].se >> b[i].fi;
  }
  sort(rng(b));
  
  int et = 0;
  int cnt = 0;
  rep(i,m){
    if(et <= b[i].se){
      et = b[i].fi;
      cnt++;
    }
  }
  print(cnt);
  return 0;
}

Measured memory_bytes: 1024
/**
 🍪 the_hyp0cr1t3
 🍪 28.08.2020 22:49:51
**/
#ifdef W
#include "k_II.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define aylmao cin.tie(nullptr)->sync_with_stdio(false);
#endif
#define endl '\n'
#define pb emplace_back
// #define int long long
#define sz(x) (int)((x).size())
#define all(x) x.begin(), x.end()

using ll = long long;
using pii = pair<int, int>;
const ll DESPACITO = 2e18;
const int INF = 2e9, MOD = 1e9+7;

const int N = 2e4;
array<array<ll, N+5>, 2> dp;

struct box {
    int s, w, v;
    box(int s, int w, int v): s(s), w(w), v(v) {}
    bool operator<(const box& o) {
        return s+w < o.s+o.w;
    }
};

int32_t main() {
    aylmao
    int i, j, n; ll ans = 0;
    cin >> n;
    vector<box> a; a.reserve(n);
    for(i = 0; i < n; i++) {
        int x, y, z; cin >> x >> y >> z;
        a.pb(y, x, z);
    }
    sort(all(a));

    dp[0].fill(-1);
    dp[0][0] = 0;

    for(i = 0; i < n; i++) {
        for(j = a[i].s; ~j; j--)
            if(~dp[0][j])
                dp[1][j+a[i].w] = max(dp[1][j+a[i].w], dp[0][j] + a[i].v);
        dp[0] = dp[1];
    }

    for(i = 0; i <= N; i++) 
        ans = max(ans, dp[1][i]);

    cout << ans;
    return 0;
}

Measured memory_bytes: 3948
a,b,k=[int(i)for i in input().split()]
if 2*k<b-a+1:
    for i in range(k):
        print(a+i)
    for i in range(k):
        print(b-k+i+1)
else:
    for i in range(b-a+1):
        print(a+i)

Measured memory_bytes: 3060
//Intersection
//created by rokon 4.43 AM 9 / 3 / 2019

#include<bits/stdc++.h>
using namespace std;

int main()
{
    while(1)
    {
        int a,b;
        cin >> a >> b;
        if(a == 0 || b == 0)break;
        for(int i = 0 ; i < a ; i++){
            for(int j = 0 ; j < b ; j++){
                if((i + j) & 1)cout << ".";
                else cout << "#";
            }cout << endl;
        }cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int N;
    cin >> N;
    map<string, int> ss;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (ss.count(s) == 0) {
            ss[s] = 1;
        } else {
            ss[s] += 1;
        }
    }
    int M;
    cin >> M;
    for (int i = 0; i < M; i++) {
        string s;
        cin >> s;
        if (ss.count(s) > 0) {
            ss[s] -= 1;
        }
    }
    int ans = 0;
    for (auto& kv : ss) {
        ans = max(ans, kv.second);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
const int INF = 1010101010;
bool can[110][55][55];
int step[55];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    int a[3];
    cin >> n >> m;
    rep(i,3) cin >> a[i];
    vector<vector<int> > G(n);
    rep(i,m){
        int u,v;
        cin >> u >> v;
        u--; v--;
        G[u].pb(v);
    }
    rep(i,n) can[0][i][i] = 1;
    // 子からi歩 ==> 親からi+1歩
    rep(i,100)rep(u,n)for(auto &v:G[u])rep(j,n){
        if(can[i][v][j]) can[i+1][u][j] = 1;
    }
    rep(i,n) step[i] = INF;
    step[n-1] = 0;
    bool f = 1;
    while(f){
        f = 0;
        rep(u,n){
            int tmp = -1;
            rep(j,3){
                int mn = INF;
                rep(v,n) if(can[a[j]][u][v]) mn = min(mn, step[v]+1);
                tmp = max(tmp, mn);
            }
            if(tmp < step[u]){
                f = 1;
                step[u] = tmp;
            }
        }
    }

    if(step[0] == INF) cout << "IMPOSSIBLE" << endl;
    else cout << step[0] << endl;
    
}



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

bool solve(string s)
{
  bool ans = true;
  for (int i = 0; i < s.size(); i++)
  {
    if(s.at(i) != s.at(s.size() - 1 - i)) ans = false;
  }
  return ans;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  string S;
  cin >> S;
  
  bool ans1 = solve(S);
  if(!ans1)
  {
    cout << "No" << endl;
    return 0;
  }
  int size = S.size();
  string str1 = S.substr(0, (size-1)/2);
  string str2 = S.substr((size+3)/2 - 1);
  
  bool ans2 = solve(str1);
  bool ans3 = solve(str2);
  if(ans1 && ans2 && ans3) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 2100;

int n,m,q;
char str[maxn];
int a[maxn][maxn];
int s[maxn][maxn];
int re[maxn][maxn],ce[maxn][maxn];

int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;i++) 
	{
		scanf("%s",str+1);
		for(int j=1;j<=m;j++) 
			a[i][j]=str[j]-'0',
			s[i][j]=s[i][j-1]+a[i][j],
			re[i][j]=re[i][j-1]+(a[i][j]&a[i][j-1]);
		for(int j=1;j<=m;j++) s[i][j]+=s[i-1][j],re[i][j]+=re[i-1][j];
	}
	for(int j=1;j<=m;j++)
	{
		for(int i=1;i<=n;i++) ce[i][j]=ce[i-1][j]+(a[i][j]&a[i-1][j]);
		for(int i=1;i<=n;i++) ce[i][j]+=ce[i][j-1];
	}
	while(q--)
	{
		int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		int ans=s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
		int n1=0;
		if(y1<y2) n1=re[x2][y2]-re[x2][y1]-re[x1-1][y2]+re[x1-1][y1];
		int n2=0;
		if(x1<x2) n2=ce[x2][y2]-ce[x2][y1-1]-ce[x1][y2]+ce[x1][y1-1];
		printf("%d\n",ans-n1-n2);
	}	
	
	return 0;
}


Measured memory_bytes: 69888
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<usize>();
    let t=(0..n).map(|_|read::<usize>()).collect::<Vec<usize>>();
    let s=t.iter().sum::<usize>();
    let m=read::<usize>();
    for _ in 0..m{
        println!("{}",s-t[read::<usize>()-1]+read::<usize>())
    }
}


Measured memory_bytes: 4352
N,K=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N-1)]
graph=[[] for _ in [0]*N]
[graph[a-1].append(b-1) for a,b in ab]
[graph[b-1].append(a-1) for a,b in ab]
q=[[-1,0]]
cnt=0
ans=K
mod=10**9+7
while(q):
    q1=[]
    if cnt<2:
        cnt+=1
    for i,j in q:
        g=graph[j]
        if i!=-1:
            g.remove(i)
        for cnt2,k in enumerate(g):
            q1.append([j,k])
            ans=(ans*(K-cnt-cnt2))%mod
    q=q1
print(ans)


Measured memory_bytes: 90328
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define MAXV 100010

int V,E,r;
vector<vector<pll>> G(MAXV);
vector<int> l(MAXV,INF);

void dijsktra(){
    priority_queue<pll,vector<pll>,greater<pll>>pq;
    l[r]=0;pq.push(mp(0,r));
    while(!pq.empty()){
        int c=pq.top().fi,v=pq.top().se;
        pq.pop();
        if(l[v]<c)continue;
        REP(i,G[v].size()){
            int to=G[v][i].fi,cost=G[v][i].se;
            if(l[to]>l[v]+cost){
                l[to]=l[v]+cost;
                pq.push(mp(l[to],to));
            }
        }
    }
}

void solve()
{
    cin>>V>>E>>r;
    REP(i,E){
        int x,y,d;cin>>x>>y>>d;
        G[x].pb(mp(y,d));
    }
    dijsktra();
    REP(i,V){if(l[i]>=INF)cout<<"INF"<<endl;else cout<<l[i]<<endl;}
}

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



Measured memory_bytes: 19000
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    string s; cin >> s;

    int l = 0, r = n-1;
    int ans = 0;
    while (r > l) {
        while (s[l] == 'R') l++;
        while (s[r] == 'W') r--;

        if (s[l] == 'W' && s[r] == 'R' && l < r) ans++;
        l++; r--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3736
#include<stdio.h>

#define N 1000
#define INF 1000000

int n,d[N],pi[N],u,color[N],k,w[N][N];

void initializeSingleSource(){
  int v=0;
  for(v=0;v<n;v++){
    d[v]=INF;
    pi[v]=NULL;
    color[v]=1;
  }
  d[0]=0;
  
}

void dijkstra(){
  int mincost,i,v,sum=0,p;

  initializeSingleSource();

  for(p=0;p<n;p++){

    mincost=INF;

    for(i=0;i<n;i++){

      if(color[i]!=0 && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }

    for(v=0;v<n;v++){
      if( color[v]!=0 && d[u]+w[u][v]<d[v]){
	pi[v]=u;
	d[v]=w[u][v]+d[u];

      }
    }
    color[u]=0;

  }
}  

int main(){

  int i,j,a,s,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){

      w[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){

    scanf("%d%d",&u,&k);

    for(j=0;j<k;j++){

      scanf("%d%d",&s,&c);

      w[u][s]=c;

    }
  }
  
  dijkstra();

  for(i=0;i<n;i++){

    printf("%d %d\n",i,d[i]);
  }
  
  return 0;
}

Measured memory_bytes: 996
#include<stdio.h>
#include<string.h>
int main(void){
  int AA = 0;
  //char S[101];
  char S[101];
  scanf("%s",S,101);
  //int l = S[101].length;
  //int l = S.length;
  int l = strlen(S);
    for(int i = 0; i < l/2; i++){
  		if(S[0+i] != S[l-1-i]){
   	 	AA++;
  		}
   }
  printf("%d",AA);
  }

Measured memory_bytes: 128
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;  
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) {
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) {
	ll ans = 1;
	while (n) {
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() {
	string s,t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < t.size(); ++i) {
		if (s[i] != t[i]) {
			++ans;
		}
	}			
	cout << ans << endl;
}

int main() {
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;
int a[4][MAXN];
int b[MAXN];
int c[MAXN], d[MAXN];

void read(){
	scanf("%d", &n);
	for(int i = 1; i <= 3; i++){
		for(int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);
	}	
}

int solve(){
	for(int i = 1; i <= n; i++){
		int p = a[1][i], q = a[2][i], r = a[3][i];
		if (q % 3 != 2) return 0;
		if (p + r != q * 2) return 0;
		if (abs(p - q) != 1 || abs(r - q) != 1) return 0;
		if (p < r)
			b[i] = r / 3;
		else
			b[i] = -p / 3;
	}	
	for(int i = 1; i <= n; i++){
		if (abs(b[i]) % 2 != i % 2)
			return 0;
	}
	for(int i = 1; i <= n; i++){
		c[abs(b[i])] = i;
	}
	
	if (n == 3){
		if (b[1] == 1 && b[2] == 2 && b[3] == 3) return 1;
		if (b[1] == -3 && b[2] == -2 && b[3] == -1) return 1;
		
		return 0;
	}
	
	for(int i = 1; i <= n; i++){
		int x = c[i];
		if (x != i){
			d[i] = b[x] * ((x - i) % 4 == 0 ? 1 : -1);
			b[i+1] *= -1;
			b[x] = b[i] * ((x - i) % 4 == 0 ? 1 : -1);
			c[abs(b[x])] = x;
		}
		else
			d[i] = b[i];
	}
	for(int i = 1; i <= n - 2; i++){
		if (d[i] < 0){
			d[i + 2] *= -1;
		}
	}
	return d[n-1] > 0 && d[n] > 0;
	/*
	for(int i = 1; i <= n; i++)
		cout<<b[i]<<' '; cout<<endl;
	int p = 0, q = 0;
	for(int i = 1; i <= n; i++){
		if (i & 1){
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				p++;
		}
		else{
			if (abs(abs(b[i]) - i) / 2 % 2 != (b[i] < 0))
				q++;
		}
	}
	cout<<p<<' '<<q<<endl;
	return p % 2 == q % 2;*/
}

void printans(int flag){
	puts(flag ? "Yes" : "No");
}
	

int main(){
	int T = 1;
//	cin>>T;
	while(T--){
		read();
		;
		printans(solve());
	}
	return 0;
} 


Measured memory_bytes: 2560
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vector<pair<pi, int> > data;
    F0R(i, N) {
        int A; cin >> A;
        F0R(j, A) {
            int X, Y; cin >> X >> Y;
            data.pb({{i, X-1}, 1-Y});
        }
    }

    int ans = 0;
    F0R(mask, (1 << N)) {
        int cnt = 0;
        F0R(i, sz(data)) {
            cnt = 0;
            int X = data[i].f.f, Y = data[i].f.s, Z = data[i].s;
            if (mask & (1 << X)) {
                if (mask & (1 << Y)) cnt++;
                if (Z == cnt) goto bad;
            }
        }

        cnt = 0;
        F0R(i, N) if (mask & (1 << i)) cnt++;
        ans = max(ans, cnt);
        bad:;
    }

    cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
N,u,v=map(int,input().split())
E=[[] for i in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  E[a-1].append(b-1)
  E[b-1].append(a-1)
  
distU=[0]*N
distV=[0]*N

stack=[]
stack.append([u-1,0,-1])
while stack:
  node=stack.pop()
  e=node[0]
  dist=node[1]
  parent=node[2]
  distU[e]=dist
  children=E[e]
  for child in children:
    if child==parent:
      continue
    stack.append([child,dist+1,e])
    
stack=[]
stack.append([v-1,0,-1])
while stack:
  node=stack.pop()
  e=node[0]
  dist=node[1]
  parent=node[2]
  distV[e]=dist
  children=E[e]
  for child in children:
    if child==parent:
      continue
    stack.append([child,dist+1,e])

maxdist=0
Vpoint=0
maxi=-1
for i in range(N):
  if maxdist<distV[i] and distU[i]<distV[i]:
    maxdist=distV[i]

print(maxdist-1)

Measured memory_bytes: 29364
N,M=map(int,input().split())
ai=[0for i in range(M)]
bi=[0for i in range(M)]
for i in range(M):
    ai[i],bi[i]=map(int,input().split())

road=[0for i in range(N)]
for i in range(M):
    road[ai[i]-1]+=1
    road[bi[i]-1]+=1
for i in range(N):
    print(road[i])

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::usize;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n = read::<u64>();
    let chars = vec!['M', 'A', 'R', 'C', 'H'];
    let mut name_counts = HashMap::new();

    for c in &chars {
        name_counts.insert(*c, 0);
    }

    for _ in 0..n {
        let name = read::<String>();
        let c = name.chars().next().unwrap();

        if chars.iter().all(|&cc| cc != c) {
            continue;
        }

        let n = *name_counts.get(&c).unwrap();

        name_counts.insert(c, n + 1);
    }

    let mut ans: u64 = 0;
    for i in 0..chars.len() {
        let n_i = *name_counts.get(&chars[i]).unwrap();
        if n_i == 0 {
            continue;
        }

        for j in i+1..chars.len() {
            let n_j = *name_counts.get(&chars[j]).unwrap();
            if n_j == 0 {
                continue;
            }

            for k in j+1..chars.len() {
                let n_k = *name_counts.get(&chars[k]).unwrap();
                if n_k == 0 {
                    continue;
                }

                ans += n_i * n_j * n_k;
            }
        }
    }

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


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

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

    int k;
    long ans=0;
    cin >> k;
    for(int a=1 ; a<=k ; a++){
        for(int b=1 ; b<=k ; b++){
            for(int c=1 ; c<=k ; c++){
                long small=0, gcd=0;
                if(a>c && b>c) small=c;
                else if(a>b && c>b) small=b;
                else small=a;
                for(int i=1 ; i<=small ; ++i){
                    if((a%i == 0) && (b%i == 0) && (c%i == 0))
                        gcd=i;
                }
                ans += gcd;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define ll long long
#define vi vector<long long>
#define endl "\n"

int main(){
ll n,k;
cin>>n>>k;
vi dp(n,INT_MAX),a(n);
for(int i=0;i<n;i++)
	cin>>a[i];
dp[n-1]=0;
dp[n-2]=abs(a[n-1]-a[n-2]);

for(int i=n-3;i>=0;i--)
{
	for(int j=i+1;j<i+k+1 && j<n;j++)
		dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
}
cout<<dp[0]<<endl;
return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

int main() {
    double n,m,sum = 0,ans = 0;
    cin >> n >> m;
    vector<double> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; ++i) {
        double tmp;
        tmp = sum/4.0;
        tmp /= m;
        if(a[i] >= sum/4/m) ans++;
    }
    if(ans >= m){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	printf("%.15lf\n", 1.0*((N + 1) / 2) / N);
}

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

int N;
vector<ll> A;

int main() {
  cin >> N;
  A.resize(N);
  rep(i, N) cin >> A[i];

  const int D = 60;
  ll allXor = 0;
  rep(i, N) allXor ^= A[i];
  rep(i, N) A[i] &= ~allXor;

  int idx = 0;
  for (int d = D - 1; d >= 0; --d) {
    int j = idx;
    while (j < N && (((A[j] >> d) & 1) == 0)) ++j;
    if (j < N) {
      swap(A[idx], A[j]);
      rep(k, N) {
        if (k != idx && ((A[k] >> d) & 1)) {
          A[k] ^= A[idx];
        }
      }
      ++idx;
    }
  }

  ll ans = 0;
  rep(i, N) ans = max(ans, ans ^ A[i]);
  ans <<= 1;
  ans += allXor;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int dp[1010][1010];

int main(){
  string s, t;
  cin >> s >> t;

  int ss = s.size();
  int ts = t.size();
  // sからi文字分削除して0文字にするコスト
  for(int i = 0; i <= ss; ++i)dp[i][0] = i;
  // sが0文字の状態からj文字挿入してj文字にするコスト
  for(int j = 0; j <= ts; ++j)dp[0][j] = j;

  for(int i = 0; i < ss; ++i){
    for(int j = 0; j < ts; ++j){
      // 同じならコストその文字については0コストでok
      // そうでなければ1コスト払って置換or削除or挿入して片方に近づける
      // transform, erase, insert
      int cost = (s[i] == t[j]) ? 0 : 1;
      dp[i + 1][j + 1] = min({dp[i][j] + cost, dp[i + 1][j] + 1, dp[i][j + 1] + 1});
    }
  }

  cout << dp[ss][ts] << endl;

  return 0;
}



Measured memory_bytes: 7132
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;

signed main(){
    int a, b, c; cin >> a >> b >> c;
    cout << min(b / a, c) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N, Y;

    cin >> N >> Y;

    for(int count_m = 0; count_m <= N; count_m++) {
        for(int count_g = 0; count_g <= N-count_m; count_g++){
            int sum_m = count_m * 10000;
            int sum_g = count_g * 5000;
            int sum_s = (N - count_m - count_g) * 1000;

            if (sum_m + sum_g + sum_s == Y) {
                cout << count_m << " " <<  count_g << " " << (N-count_m-count_g) << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for p in range(a+1):
  for q in range(b+1):
    for r in range(c+1):
      if 500*p+100*q+50*r==x:
        ans+=1
        
print(ans)

Measured memory_bytes: 9072
a,b=gets.split
x=a.to_i
y=b.to_i
if x<y
  tmp=x
  x=y
  y=tmp
end
if x.between?(1,1000000000)==false then
   puts"Please input [1<= a,b <=1000000000]"
   exit
end

if y.between?(1,1000000000)==false then
   puts"Please input [1<= a,b <=1000000000]"
   exit
end

r=x%y

while r!=0 do
  x=y
  y=r
  r=x%y
end

puts y


Measured memory_bytes: 6876
n = gets.to_i
xs = gets.chop
xi = xs.to_i(2)
init_count = xs.count('1')
p_init_count = init_count + 1
m_init_count = init_count - 1
pxi = xi % p_init_count
mxi = xi % m_init_count if m_init_count > 0
(n-1).downto(0) do |i|
  if xi[i].zero?
    t = (pxi + 2.pow(i,p_init_count)) % p_init_count
  else
    if m_init_count.zero?
      puts 0
      next
    end
    t = (mxi - 2.pow(i,m_init_count)) % m_init_count
  end
  c = 1
  until t == 0
    t %= t.to_s(2).count('1')
    c += 1
  end
  puts c
end

Measured memory_bytes: 14864
import java.util.Scanner;

class Main
{
	private static int mesh[][];
	private static int dx[] = {0, 0, 1,1,1,-1,-1,-1};
	private static int dy[] = {1,-1,-1,0,1,-1, 0, 1};
	private static int w, h;
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		while (true)
		{
			w = sc.nextInt();
			h = sc.nextInt();
			if (w == 0 && h == 0) break;
			mesh = new int [h][w];
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					mesh[i][j] = sc.nextInt();
				}
			}
			System.out.println(countIlands(0));
		}
	}
	private static int countIlands(int n)
	{
		int x = -1;
		int y = -1;
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (mesh[i][j] == 1)
				{
						x = i;
						y = j;
				}
			}
		}
		if (x == -1) return n;
		check(x, y);
		return countIlands(++n);
	}
	private static void check(int x, int y)
	{
		try
		{
			if (mesh[x][y] == 1)
			{
				mesh[x][y] = 0;
				for(int i = 0;i < 8; i++){
					check(x+dx[i], y+dy[i]);
				}
			}
		}
		catch (ArrayIndexOutOfBoundsException e)
		{
			return;
		}
	}
}

Measured memory_bytes: 13000
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int s = b / a;
        if(s > c){
            System.out.println(c);
        }else{
            System.out.println(s);
        }
            
        
    }
}

Measured memory_bytes: 23764
N = int(input())
h = input().split()
h = [int(i) for i in h]

# dp[i] = 0,...,iの範囲での総和の最小値
# i>=2 -> dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))
# i == 1 -> dp[i] = abs(h[0]-h[1])
# i == 0 -> dp[i] = 0

dp = [0 for i in range(N)]
dp[1] = abs(h[0]-h[1])
if N == 2:
    print(dp[1])
else:
    for i in range(2,N):
        dp[i] = min( dp[i-1]+abs(h[i-1]-h[i]) , dp[i-2]+abs(h[i-2]-h[i]) )
    print(dp[N-1])
    
        

Measured memory_bytes: 13928
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>
#include <bitset>
#include <time.h>
#include <stdio.h>

using namespace std;
typedef long long ll;
typedef pair<int, ll> P;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) a.begin(), a.end()

template<typename T>
void vdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		if (i == size - 1) {
			cout << da[i] << endl;
		}
		else {
			cout << da[i] << ' ';
		}
	}
}
template<typename T>
void vvdeb(vector<T> &da) {
	int size = da.size();
	for (int i = 0;i < size;i++) {
		vdeb(da[i]);
	}
}

int main(){
	char s;
	cin >> s;
	s++;
	cout << s << endl;
}

Measured memory_bytes: 256