akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

char s[18][18];
string buf;
int main(){
	do{
		memset(s,0,sizeof(s));
		for(int i=1;i<=8;i++)scanf("%s",s[i]+1);
		for(int i=1;i<=8;i++){
			for(int j=1;j<=8;j++){
				if(s[i][j]!='1')continue;
				if(s[i][j+1]=='1'&&s[i+1][j+1]=='1'&&s[i+1][j]=='1'){puts("A");goto p;}
				if(s[i+1][j]=='1'&&s[i+2][j]=='1'&&s[i+3][j]=='1'){puts("B");goto p;}
				if(s[i][j+1]=='1'&&s[i][j+2]=='1'&&s[i][j+3]=='1'){puts("C");goto p;}
				if(s[i+1][j-1]=='1'&&s[i+1][j]=='1'&&s[i+2][j-1]=='1'){puts("D");goto p;}
				if(s[i][j+1]=='1'&&s[i+1][j+1]=='1'&&s[i+1][j+2]=='1'){puts("E");goto p;}
				if(s[i+1][j]=='1'&&s[i+1][j+1]=='1'&&s[i+2][j+1]=='1'){puts("F");goto p;}
				if(s[i][j+1]=='1'&&s[i+1][j-1]=='1'&&s[i+1][j]=='1'){puts("G");goto p;}
			}
		}
		p:;
	}while(getline(cin,buf));
	return 0;
}

Measured memory_bytes: 3212
#include<stdio.h>

#define N 100005

int n,parent[N],left[N],right[N],D[N];

int GetDepth(int);
void SetDepth(int,int);
void PrintChildren(int);

int main(){
  int i,j,d,v,c,l,r;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    parent[i]=-1;
    left[i]=-1;
    right[i]=-1;
  }

  for(i=0;i<n;i++){
    scanf("%d",&v);
    scanf("%d",&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0){
	left[v]=c;
      }
      else {
	right[l]=c;
      }
      l=c;
      parent[c]=v;
    }
  }

  for(i=0;i<n;i++){
    if(parent[i]==-1){
      r=i;
    }
  }

  SetDepth(r,0);

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

  return 0;
}

int GetDepth(int u){
  int d=0;

  while(parent[u]!=-1){
    u=parent[u];
    d++;
  }

  return d;
}

void SetDepth(int u,int p){
  D[u]=p;
  if(right[u]!=-1){
    SetDepth(left[u],p+1);
  }
}

void PrintChildren(int u){
  int i,c;

  printf("node %d: parent = %d, depth = %d, ",u,parent[u],GetDepth(u));
  
  if(parent[u]==-1){
    printf("root, ");
  }
  else if(left[u]==-1){
    printf("leaf, ");
  }
  else {
    printf("internal node, ");
  }
  printf("[");

  for(i=0,c=left[u];c!=-1;i++,c=right[c]){
    if(i)  printf(", ");
      printf("%d",c);
  }
  printf("]\n");
}

  
     
    
    



Measured memory_bytes: 2916
N,K = map(int, input().split())
D = list(map(int, input().split()))
dt = [True] * 10
for d in D:
    dt[d] = False

def check(x):
    while x:
        if not dt[x%10]:
            return False
        x //= 10
    return True

for i in range(N, 10*N):
    if check(i):
        print(i)
        break


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


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n, x, t;
  cin >> n >> x >> t;
  int ans = (n / x) * t;
  if (n % x != 0) ans += t;
  cout << ans;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    int n, k, c;
    cin >> n >> k >> c;
    string s;
    cin >> s;

    vector<pair<int, int>> can(k, make_pair(-1, -2));
    int idx = 0;
    for (int i = 0; i < n;)
    {
        if (s[i] == 'x') { ++i; continue; }

        can[idx++].first = i;
        if (idx >= k) break;
        i += c + 1;
    }
    idx = k - 1;
    for (int i = n - 1; i >= 0;)
    {
        if (s[i] == 'x') {--i; continue; }

        can[idx--].second = i;
        if (idx < 0) break;
        i -= (c + 1);
    }

    rep(i, 0, k)
    {
        if (can[i].first == can[i].second)
        {
            cout << can[i].first + 1 << endl;
        }
    }
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N=200005;

 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
    */
    string q;
    cin>>q;
    int len=q.length();
    bool ok=1;
    for(int i=0;i<len;i++) {
        if(i%2==0) {
            if(q[i]=='R' || q[i]=='U' || q[i]=='D') {
                continue;
            }
            else {
                ok=0;
                break;
            }
        }
        else {
            if(q[i]=='L' || q[i]=='U' || q[i]=='D') {
                continue;
            }
            else {
                ok=0;
                break;
            }
        }
    }
    if(ok) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 26004
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 1e-9;

long long int N, M, K, H, W, L, R;

struct node {
	int y, x, dir;
	bool operator < (const node& n)const {
		return y < n.y;
	}
};

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

	cin >> W >> H;
	int dir[] = { 0,1,0,-1,0 };
	vector<int>ans;
	while (H) {
		vector<vector<int>>v(H, vector<int>(W));
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> v[i][j];
			}
		}
		vector<int>cost(4);
		for (int i = 0; i < 4; i++)cin >> cost[i];
		vector<vector<vector<int>>>dp(H, vector<vector<int>>(W, vector<int>(4, MOD)));
		dp[0][0][0] = 0;
		priority_queue<pair<int, node>, vector<pair<int, node>>, greater<pair<int, node>>>PQ;
		PQ.push({ 0,{0,0,0} });
		while (!PQ.empty()) {
			int c = PQ.top().first;
			node n = PQ.top().second;
			PQ.pop();
			if (dp[n.y][n.x][n.dir] < c)continue;
			for (int i = 0; i < 4; i++) {
				int ndir = (n.dir + i) % 4;
				int ny = dir[ndir] + n.y;
				int nx = dir[ndir + 1] + n.x;
				if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
				if (dp[ny][nx][ndir] > c + cost[i]) {
					dp[ny][nx][ndir] = c + cost[i];
					PQ.push({ c + cost[i],{ny,nx,ndir} });
				}
			}
			if (v[n.y][n.x] == 4)continue;
			int ndir = (n.dir + v[n.y][n.x]) % 4;
			int ny = dir[ndir] + n.y;
			int nx = dir[ndir + 1] + n.x;
			if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			if (dp[ny][nx][ndir] > c) {
				dp[ny][nx][ndir] = c;
				PQ.push({ c ,{ ny,nx,ndir } });
			}
		}
		ans.push_back(min(dp[H - 1][W - 1][0], dp[H - 1][W - 1][1]));
		cin >> W >> H;
	}
	for (auto i : ans)cout << i << endl;
	return 0;
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    string s;
    cin>>s;
    int ans=1e9;
    for(char c='a';c!='{';c++){
        int cnt=0;
        for(int i=0;i<s.length();i++) if(s[i]==c) cnt++;
        if(cnt==s.length()){
            ans=0;
            break;
        }
        string tmp=s;
        cnt=0;
        while(tmp.length()>1){
            string tmp2;
            int num=0;
            for(int i=0;i<tmp.length()-1;i++){
                if(tmp[i]==c || tmp[i+1]==c) {
                    tmp2+=c;
                    num++;
                }else tmp2+=s[i];
            }
            tmp=tmp2;
            cnt++;
            if(num==tmp.length()) break;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		long x = scan.nextLong();

		List<Long> srimeList = new ArrayList<>(N);
		for (long i = 0; i < N; i++) {
			srimeList.add(scan.nextLong());
		}

		List<Long[]> costList = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			costList.add(new Long[N]);
		}
		for (int i = 0; i < N; i++) {
			costList.get(i)[0] = srimeList.get(i);
			for (int castNum = 1; castNum < N; castNum++) {
				costList.get(i)[castNum] = Math.min(costList.get(i)[castNum - 1],
						srimeList.get((i - castNum + N) % N));
			}
		}
		List<Long> result = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			final int j = i;
			result.add(i * x + costList.stream().mapToLong(costArray -> costArray[j]).sum());
		}
		System.out.println(result.stream().mapToLong(i -> i).min().getAsLong());
	}

}


Measured memory_bytes: 156436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, m;
  cin >> n >> m;
  ll k = 1LL << m;
  ll t = 100 * (n - m) + 1900 * m;
  cout << t * k << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    string s;
    cin >> s;
    if(s=="hi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi"||s=="hihi")cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

string tb[12];
int cnt = 0;

void dfs(int y, int x) {
	tb[y][x] = 0;

	if (y + 1 < 12 && tb[y + 1][x] == '1')dfs(y + 1, x);
	if (y-1 >=0 && tb[y-1][x] == '1')dfs(y-1, x);
	if (x + 1 < 12 && tb[y][x+1] == '1')dfs(y, x+1);
	if (x-1>=0 && tb[y][x-1] == '1')dfs(y, x-1);
}

int main() {
	while (cin>>tb[0]) {

		for (int i = 1; i < 12; i++) {
			cin >> tb[i];
		}

		cnt = 0;

		for (int i = 0; i < 12; i++) {
			for (int j = 0; j < 12; j++) {
				if (tb[i][j] == '1') {
					cnt++;
					dfs(i, j);
				}
			}
		}

		cout << cnt << endl;


	}
}


Measured memory_bytes: 3212
s=input()
k=int(input())
list=[]
if len(s)>=5:
    for i in range(1,6):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
else:
    for i in range(1,len(s)+1):
        for j in range(len(s)-i+1):
            list.append(s[j:j+i])
list_set_sorted=sorted(set(list))
print(list_set_sorted[k-1])


Measured memory_bytes: 5068
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

using namespace std;

int main(){
    int X, N;
    cin >> X >> N;
    int p[N];
    int difference;
    bool exicetanceCheck;


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

    if(N == 0){
        cout << X << endl;
    }
    else{
        difference = 0;
        while(true){
            exicetanceCheck = true;
            for(int i=0;i<N;i++){
                if(p[i] == X - difference){
                    exicetanceCheck = false;
                }
            }
            if(exicetanceCheck == true){
                cout << X - difference << endl;
                return 0;
            }
            exicetanceCheck = true;
            for(int i=0;i<N;i++){
                if(p[i] == X + difference){
                    exicetanceCheck = false;
                }
            }
            if(exicetanceCheck == true){
                cout << X + difference << endl;
                return 0;
            }
            difference++;
        }
    }

    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string str;
        string[] strer = new string[2];
        var strlist = new List<string>();
        var data = new List<int>();
        int cou = 0;
       
        do
        {
            str = Console.ReadLine();
            if (str == "0 0")
            {
                break;
            }

            strer = str.Split(' ');

            foreach (string s in strer)
            {
                data.Add(int.Parse(s));
            }            
          
        } while (true);

        
        for (int i = 0; i < (data.Count/2); i++)
        {

            for (int j =0; j < data[cou]; j++)
            {
                for (int k = 0; k < data[cou+1]; k++)
                {
                    Console.Write("#");
                }
                Console.Write("\n");
            }
            Console.Write("\n");
            cou += 2;

        }
               
    }
}


Measured memory_bytes: 15936
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    int a,b,c,d;cin>>a>>b>>c>>d;
    if((a+d-1)/d < (b+c-1)/b) cout <<"No" <<endl;
    else cout<<"Yes"<<endl;

    return 0;
}

Measured memory_bytes: 3632
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	uni = make([]int, n)
	for i := range uni {
		uni[i] = -1
	}
	for i := 0; i < m; i++ {
		var x, y, z int
		fmt.Scan(&x, &y, &z)
		connect(x-1, y-1)
	}
	sum := 0
	for _, v := range uni {
		if v < 0 {
			sum++
		}
	}
	fmt.Println(sum)
}

var uni []int

func root(a int) int {
	if uni[a] < 0 {
		return a
	}
	uni[a] = root(uni[a])
	return uni[a]
}

func connect(a, b int) bool {
	a = root(a)
	b = root(b)
	if a == b {
		return false
	}
	if uni[a] > uni[b] {
		a, b = b, a
	}
	uni[a] = uni[a] + uni[b]
	uni[b] = a
	return true
}

func isConnect(a, b int) bool {
	return root(a) == root(b)
}

func size(a int) int {
	return -uni[root(a)]
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

class UnionFind {
    public:
        vector<ll> rank, p, size;

        UnionFind() {}
        UnionFind(int s) {
            rank.resize(s, 0);
            p.resize(s, 0);
            size.resize(s, 0);
            rep (i, s) init(i);
        }

        void init(ll x) {
            p[x] = x;
            rank[x] = 0;
            size[x] = 1;
        }

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

        void unite(int x, int y) {
            link(root(x), root(y));
        }

        void link(int x, int y) {
            if (rank[x] > rank[y]) {
                p[y] = x;
                size[x] += size[y];
            } else {
                p[x] = y;
                size[y] += size[x];
                if (rank[x] == rank[y]) {
                    rank[y]++;
                }
            }
        }

        int root(int x) {
            if (x != p[x]) {
                p[x] = root(p[x]);
            }
            return p[x];
        }

        ll getSize(int x) {
            return size[root(x)];
        }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    UnionFind uf = UnionFind(n);
    vector<pair<int, int> > bridge;
    rep (i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        bridge.emplace_back(a, b);
    }
    ll r = (ll)n * (n - 1) / 2;
    vector<ll> res;
    rrep (i, m) {
        res.push_back(r);
        if (!uf.isSame(bridge[i].first, bridge[i].second)) {
            r -= uf.getSize(bridge[i].first) * uf.getSize(bridge[i].second);
            uf.unite(bridge[i].first, bridge[i].second);    
        }
    }
    rrep (i, m) cout << res[i] << endl;
    
    return 0;
}



Measured memory_bytes: 5492
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

/*int par[100000];

void init(int n){
    for(int i=0; i<n; i++) par[i] = i;
}

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

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    par[x] = y;
}*/

int main(){
int W;
cin>>W;
cout<<W*32<<endl;

    return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>
long long int dp[1001][1001]; //動的計画法の表
int main(void){
    int i,j,n,m,d[1001],c[1001]; //n=都市の数,m=日数,d=都市間の距離,c=天候
    long long int min,M; //min=最小値
    M=922337203685477580; //最大値代入
    scanf("%d %d",&n,&m); //都市の数と日数の入力
	//↓表のすべての場所にM代入
    for(i=0;i<=m;i++){
        for(j=0;j<=n;j++) dp[i][j]=M;
    }
    for(i=0;i<n;i++) scanf("%d",&d[i]); //都市間の距離の入力
    for(i=0;i<m;i++) scanf("%d",&c[i]); //天候の入力
    dp[0][0]=0; //スタート位置に0代入
    for(i=0;i<m;i++){
        for(j=0;j<=n;j++){
            if(dp[i][j]!=M){
                if(dp[i+1][j]>dp[i][j]) dp[i+1][j]=dp[i][j]; //縦方向に疲労度比べて代入
                if(dp[i+1][j+1]>dp[i][j]+d[j]*c[i]) dp[i+1][j+1]=dp[i][j]+d[j]*c[i]; //斜め方向に
            }
        }
    }
    min=M; //minにM代入
    for(i=0;i<=m;i++){
        if(min>dp[i][n]) min=dp[i][n]; //minと比べて更新
    }
    printf("%lld\n",min); //最小の疲労度出力
    return 0;
}

Measured memory_bytes: 8428
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
using namespace std;
int main(){
  string s;
  cin>>s;
  stack<string> a;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      a.push("0");
    }else if(s[i]=='1'){
      a.push("1");
    }else{
      if(a.size()==0){
	continue;
      }else{
	a.pop();
      }
    }
  }
  string t="";
  while(a.size()>0){
    t=a.top()+t;
    a.pop();
  }
  cout<<t<<endl;
  return 0;
}
  

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M; cin >> N >> M;
  vector<ll> H(N); REP(i, N) cin >> H[i];
  vector<vector<ll>> graph(N + 1);
  REP(i, M) {
    ll a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  vector<ll> ans(N + 1); REP(i, N + 1) ans[i] = 0;
  for(int i = 1; i <= N; ++i) {
    ll tmp = 0;
    for(int k = 0; k < graph[i].size(); ++k) {
      if(tmp < H[graph[i][k] - 1]) {
        tmp = H[graph[i][k] - 1];
      }
    }
    ans[i] = tmp;
  }
  ll res = 0;
  for(int i = 1; i <= N; ++i) {
    if(ans[i] < H[i - 1]) res++;
  }
  cout << res << endl;
}

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

#define ull unsigned long long
#define ll long long
#define null NULL
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main (){
	int n , k ;
	cin >> n >> k ;
	vector <int> v(n) ;
	for(auto &it : v) cin >> it ;
	int dp[n] ;
	dp[0] = 0 ;
	dp[1] = abs(v[1] - v[0]) ;
	for(int i = 2 ;i<n;i++){
		int ans = 0 ;
		dp[i] = dp[i-1] + abs(v[i] - v[i-1]) ;
		for(int j = 2 ;j<=k;j++){
			if(i - j >= 0){
				dp[i] = min(abs(v[i] - v[i - j]) + dp[i-j] ,  dp[i]) ;
			}else break ;
		}
	}
	cout << dp[n-1] ;
	return 0 ;
}
		

Measured memory_bytes: 1024
s = input()
n,a,b = len(s),0,0
for i in range(n):
    if i%2 and s[i]=="0": a+=1
    elif not i%2 and s[i]=="1": b+=1
c,d = (n+1)//2-a,n//2-b
print(min(a+b,c+d))

Measured memory_bytes: 3188
package main

import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func solve(io *Io) {
	n := io.NextInt()
	s := []byte(io.Next())

	type K struct{}

	ans := 0
	for i := 0; i < n; i++ {
		mp1 := map[byte]K{}
		for _, a := range s[:i] {
			mp1[a] = K{}
		}
		mp2 := map[byte]K{}
		for _, a := range s[i:] {
			mp2[a] = K{}
		}
		cur := 0
		for k, _ := range mp1 {
			_, ok := mp2[k]
			if ok {
				cur++
			}
		}

		ans = intMax(ans, cur)
	}

	io.PrintLn(ans)
}

func main() {
	io := NewIo()
	defer io.Flush()

	solve(io)
}

Measured memory_bytes: 640
n, k =  map(int, input().split())
X = list(map(int, input().split()))
c = float("inf")
for i in range(n-k+1):
  if X[i] < 0 and X[i+k-1] >= 0:
    temp = min(2*(-X[i])+X[i+k-1], 2*X[i+k-1]+(-X[i]))
  else:
    temp = max(abs(X[i]), abs(X[i+k-1]))
  c = min(c, temp)
print(c)

Measured memory_bytes: 14568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  if (s.size() % 2 == 1) {
    No();
    return 0;
  }
  for (ll i = 0; i < s.size(); i++) {
    if (i % 2 == 0 && s[i] == 'h') continue;
    if (i % 2 == 1 && s[i] == 'i') continue;
    No();
    return 0;
  }
  Yes();
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
int INF=1e9;
const long long mod=1e9+7;

int main(){
  string w;
  cin>>w;
  bool beautiful[25];
  for(int i=0;i<26;i++){
    beautiful[i]=true;
  }
  for(char j='a';j<='z';j++){
    for(int i=0;i<w.size();i++){
      if(j==w[i]){
        if(beautiful['z'-j]){beautiful['z'-j]=false;}
        else{beautiful['z'-j]=true;}
      }
    }
  }
  for(char i='a';i<='z';i++){
    if(!beautiful['z'-i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

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

using namespace std;

typedef long long ll;
#define WEST 0
#define NORTH 1

int main(){
  string s;
  while( cin >> s, s != "#" ){
    vector<bool> vec;
    for(int i=0;i<s.size();){
      if( s.substr(i,4) == "west" ) {
        i += 4;
        vec.push_back(WEST);
      } else {
        i += 5;
        vec.push_back(NORTH);
      }
    }
    
    reverse(vec.begin(),vec.end());
    ll numerator = vec[0] ? 0LL : 90LL;
    REP(i,1,vec.size()){
      numerator <<= 1;
      if( vec[i] ) numerator -= 90;
      else         numerator += 90;
    }
    ll denominator = 1<<((int)vec.size()-1);
    if( numerator % denominator ) {
      ll temp = __gcd(numerator,denominator);
      numerator /= temp, denominator /= temp;
      cout << numerator << "/" << denominator << endl;
    } else cout << (ll)(numerator/denominator) << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,m,ans = 1e9 + 7;
    cin >> n >> m;
    vector<int> a(m),b(m);
    vector<vector<int>> c(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        for(int j=0;j<b[i];j++){
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    vector<int> dp(1<<n,1e9+7); // dp[i] := i個の箱を開けるのにかかる最小の費用
    dp[0] = 0;
    for(int i=0;i<m;i++){
        int cost = a[i];
        int mask = 0; // i番目の鍵でどの箱を開けることが出来るか
        for(int j=0;j<b[i];j++){
            mask |= 1<<c[i][j];
        }
        for(int j=0;j<(1<<n);j++){
            // 状態jについて考えると
            int next = j | mask;
            dp[next] = min(dp[next],dp[j] + cost);
        }
    }
    cout << (dp[(1<<n)-1]==1e9+7?-1:dp[(1<<n)-1]) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    vector <int> d(n);
    rep(i,0,n) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    if (d.size() %2 ==1) {
        cout << 0 << endl;
    } else {
        cout << d[d.size()/2] - d[d.size()/2-1] << endl;
    }
}

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

int A[300005];

void solve(int L, int lim, int a, int b)
{
    if(lim == 0)
        return;

    a = min(a, lim - b + 1);

    for(int i=lim-a+1; i<=lim; i++)
        A[i] = L++;
    
    solve(L, lim-a, a, b-1);
}

int main() {

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

    int n, a, b;
    cin >> n >> a >> b;

    if(1LL * a * b < n || a + b > n + 1)
    {
        cout << -1 << "\n";
        return 0;
    }

    solve(1, n, a, b);

    for(int i=1; i<=n; i++)
        cout << A[i] << " ";

    return 0;
}


Measured memory_bytes: 3456
program payment
  implicit none
  character(1000001) :: s
  integer :: a(0:1000001) = 0, n, i, j, x = 0
  read(*,*) s
  n = len_trim(s)
  do i = 1, n
    a(n-i) = ichar(s(i:i))-48
  end do
  do i = 0, n
    if (a(i) > 5 .or. (a(i) == 5 .and. a(i+1) >= 5)) then
      x = x+10-a(i)
      j = i+1
      do while (a(j) == 9)
        a(j) = 0
        j = j+1
      end do
      a(j) = a(j)+1
    else
      x = x+a(i)
    end if
  end do
  write(*,'(i0)') x
end program payment

Measured memory_bytes: 6152
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 1e5 + 10;
int qs[maxn];

int n, m, q;

int read() {
  if (scanf("%d%d%d", &n, &m, &q) < 3) {
    return 0;
  }
  for (int i = 0; i < q; ++i) {
    scanf("%d", qs + i);
    --qs[i];
  }
  return 1;
}

int lev[maxn];

int used[maxn];
int a[maxn];
int back[maxn];

void solve() {
  for (int i = 0; i < m; ++i) {
    used[i] = 0;
  }
  int k = 0;
  for (int iter = q - 1; iter >= 0; --iter) {
    int x = qs[iter];
    if (!used[x]) {
      used[x] = 1;
      a[k++] = x;
    }
  }
  for (int i = 0; i < m; ++i) {
    if (!used[i]) {
      a[k++] = i;
    }
  }
  assert(k == m);

  int stop = m;
  for (int last = inf; stop && a[stop - 1] < last; --stop) {
    last = a[stop - 1];
  }

  for (int i = 0; i <= stop; ++i) {
    lev[i] = 0;
  }
  lev[0] = n;

  for (int i = 0; i < m; ++i) {
    //eprintf("%d%c", a[i], " \n"[i == m - 1]);
    back[a[i]] = i;
  }

  for (int iter = q - 1; iter >= 0; --iter) {
    int x = qs[iter];
    int pos = back[x];
    if (pos < stop && lev[pos]) {
      --lev[pos];
      ++lev[pos + 1];
    }
  }
  if (lev[stop] == n) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 2176
### constant

HANDS = [
  "Rock", "Fire", "Scissors", "Snake", "Human",
  "Tree", "Wolf", "Sponge", "Paper", "Air",
  "Water", "Dragon", "Devil", "Lightning", "Gun"
]

NH = HANDS.length
NW = (NH - 1) / 2
  
### main

hhash = {}
for i in (0...NH)
  hhash[HANDS[i]] = i
end

wlmtx = Array.new(NH){Array.new(NH){0}}
for i in (0...NH)
  for j in (1..NW)
    k = (i + j) % NH
    wlmtx[i][k] = 1
    wlmtx[k][i] = -1
  end
end
#p wlmtx

loop do
  n = gets.to_i
  break if n == 0

  hs = Array.new(n){hhash[gets.strip]}
  ws = Array.new(n){0}
  ls = Array.new(n){0}

  for i in (0...n)
    for j in ((i + 1)...n)
      wl = wlmtx[hs[i]][hs[j]]
      if wl > 0
        ws[i] += 1
        ls[j] += 1
      elsif wl < 0
        ls[i] += 1
        ws[j] += 1
      end
    end
  end
  #p [ws, ls]

  win = 'Draw'
  for i in (0...n)
    if ws[i] > 0 && ls[i] == 0
      win = HANDS[hs[i]]
      break
    end
  end

  puts win
end

Measured memory_bytes: 6140
n,m,q=map(int,input().split())
s,v,el,eu=([[0]*(m+2) for _ in range(n+2)] for _ in range(4))
for i in range(1,n+1):
    s[i][1:m+1]=map(int,input())
    for j in range(1,m+1):
        v[i][j]=v[i][j-1]+s[i][j]
        el[i][j]=el[i][j-1]+s[i][j]*s[i][j-1]
        eu[i][j]=eu[i][j-1]+s[i][j]*s[i-1][j]
for i in range(2,n+1):
    for j in range(1,m+1):
        v[i][j]+=v[i-1][j]
        el[i][j]+=el[i-1][j]
        eu[i][j]+=eu[i-1][j]
for _ in range(q):
    x1,y1,x2,y2=map(int,input().split())
    print(v[x2][y2]-v[x1-1][y2]-v[x2][y1-1]+v[x1-1][y1-1]
            -(el[x2][y2]-el[x1-1][y2]-el[x2][y1]+el[x1-1][y1])
            -(eu[x2][y2]-eu[x1][y2]-eu[x2][y1-1]+eu[x1][y1-1]))

Measured memory_bytes: 171784
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;
int dp[N][N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	int o = 0;
	for (int i = 1; i <= n; i++)
	{
		int w, v;
		cin >> w >> v;
		if (o == 0) o = w;
		w -= o;
		for (int j = i; j >= 1; j--)
		{
			for (int k = w; k <= 300; k++)
			{
				dp[j][k] = max(dp[j][k], dp[j - 1][k - w] + v);
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= 300 && 1LL * o * i + j <= m; j++)
			ans = max(ans, dp[i][j]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(void) {
	int i, n;
	long *heap = NULL;
	
	scanf("%d", &n);
	
	heap = (long*)malloc(sizeof(long) * (n + 1));
	
	for (i = 1; i <= n; i++) {
		scanf("%ld", &heap[i]);
	}
	
	for (i = 1; i <= n; i++) {
		printf("node %d: key = %ld, ", i, heap[i]);
		if (i != 1) {
			printf("parent key = %ld, ", heap[i / 2]);
		}
		if (i * 2 <= n) {
			printf("left key = %ld, ", heap[i * 2]);
		}
		if (i * 2 + 1 <= n) {
			printf("right key = %ld, ", heap[i * 2 + 1]);
		}
		printf("\n");
	}
	
	return 0;
}



/*
1
23
4567
89101112
*/

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,a,b) for (int i = (b-1); i >= (a); i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  string S; cin >> S;
  int N = S.size();

  //map<string,bool> exist;
  string before = "";
  int pos = 0;
  int ans = 0;
  while(true) {
    if (pos == N) break;
    string tmp = "";
    while(true) {
      tmp += S[pos];
      if (pos==N-1&&tmp==before) {
        pos++;
        break;
      }
      if (pos==N-1&&tmp!=before) {
        pos++;
        ans++;
        break;
      }
      
      if (tmp == before) {
        pos++;
        continue;
      }
      else {
        before = tmp;
        ans++;
        pos++;
        break;
      }
    }
  }

  cout << ans << endl;
}

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

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

using namespace std;

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size(){ return n; }
	int size(int u){ return -p[find(u)]; }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> p(n);
	rep(i,n) scanf("%d",&p[i]), p[i]--;

	union_find U(n);
	rep(i,m){
		int a,b; scanf("%d%d",&a,&b); a--; b--;
		U.unite(a,b);
	}

	int ans=0;
	rep(i,n) if(U.is_same(i,p[i])) ans++;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
string a;

int main(){
  cin >> a;
  REP(i,3){
    if(a[i] == '1') a[i]='9';
    else if (a[i] == '9') a[i]='1';
  }
  cout << a << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>

#include <sstream>

using namespace std;

namespace stoi{
  int stoi(std::string str){
    int num;
    std::stringstream ss;
    ss << str;
    ss >> num;
    return num;
  }
}

int main(){
  stack<int> por;
  string tmp;
  while(cin >> tmp){
    if(tmp == "+" || tmp=="-" || tmp=="*"){
      long long int o2 = por.top();
      por.pop();
      long long int o1 = por.top();
      por.pop();
      long long int o3;

      if(tmp=="+"){
	o3 = o1 + o2;
	por.push(o3);
      }
      if(tmp=="-"){
	o3 = o1 - o2;
	por.push(o3);
      }
      if(tmp=="*"){
	o3 = o1 * o2;
	por.push(o3);
      }
    }else{
      long long int num = stoi::stoi(tmp);
      por.push(num);
    }
  }
  long long int res = por.top();
  cout << res << endl;
  
      
  

}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,k,c; cin >> n >> k >> c;
    bool work[n+1];
    rep(i,1,n+1){ 
        char a;
        cin >> a;
        if(a=='x') work[i] = false;
        else work[i] = true;
    }
    int l[k+1]; // x回目の出社は最低何日目か
    int r[k+1]; // 後ろからみたx回目の出社は最低何日目か
    l[0] = 0; r[k]= 0;
    int locateL=1,locateR=k;
    rep(i,1,n+1){
        if(!work[i]) continue;
        l[locateL] = i;
        i+=c;
        locateL++;
        if(locateL==k+1) break;
    }
    rel(i,n+1,1){
        if(!work[i]) continue;
        r[locateR] = i;
        i-=c;
        locateR--;
        if(locateR==-1) break;
    }
    rep(i,1,k+1){
        //cout << l[i] << " " << r[i] << endl;
        if(l[i]==r[i]) cout << l[i] << endl;
    }

}

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

int main(){
	int N;
	cin >> N;
	int tmp;
	int four=0,two=0;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		if ((tmp & 3) == 0)
			++four;
		else if ((tmp & 1) == 0)
			++two;
	}
	if (two == 0) two++;
	cout << (four >= N - four - two ? "Yes" : "No" ) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 3100;
int N, T, S;
int joy[MAX], ti[MAX];

int dp[MAX][MAX];

int main() {
    while (cin >> N >> T >> S) {
        for (int i = 0; i < N; ++i) cin >> joy[i] >> ti[i];
        
        memset(dp, -1, sizeof(dp));
        int res = -1;
        dp[0][0] = 0;
        for (int i = 0; i <= N; ++i) {
            for (int t = 0; t <= T; ++t) {
                //if (dp[i][t] >= 0) cout << i << ", " << t << " : " << dp[i][t] << endl;
                if (i == N) chmax(res, dp[i][t]);
                
                chmax(dp[i+1][t], dp[i][t]);
                if (t < S) {
                    chmax(dp[i+1][S], dp[i][t]);
                    if (t + ti[i] <= S && dp[i][t] >= 0) chmax(dp[i+1][t+ti[i]], dp[i][t] + joy[i]);
                }
                else {
                    if (t + ti[i] <= T && dp[i][t] >= 0) chmax(dp[i+1][t+ti[i]], dp[i][t] + joy[i]);
                }
            }
        }
        
        cout << res << endl;
    }
    return 0;
}


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

#define For(i, l, r) for (register int i = (l), i##end = int(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = int(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

typedef long long ll;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

ll k, a, b, c;

int main () {

	File();

	cin >> k;

	a = k / 50 + 50; b = k % 50; c = a - b - 1;
	puts("50");
	For (i, 1, 50)
		printf ("%lld%c", i <= b ? a : c, i == iend ? '\n' : ' ');

	return 0;

}

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

int main()
{
    int N;
    long long T;
    cin>>N>>T;
    vector<long long> a(N), b(N);
    for (int i=0; i<N; i++)
        cin>>a[i]>>b[i];

    vector<long long> a0, b0, a1, b1;
    for (int i=0; i<N; i++)
        if (a[i]==0)
            a0.push_back(a[i]),
            b0.push_back(b[i]);
        else
            a1.push_back(a[i]),
            b1.push_back(b[i]);
    int n0 = (int)a0.size();
    int n1 = (int)a1.size();

    sort(b0.begin(), b0.end());

    vector<pair<long long, long long>> ab(n1);
    for (int i=0; i<n1; i++)
        ab[i] = make_pair(a1[i], b1[i]);
    sort(ab.begin(), ab.end(), [&](pair<long long, long long> x, pair<long long, long long> y)
        {return x.first*(y.second+1) > y.first*(x.second+1);});
    for (int i=0; i<n1; i++)
        a1[i] = ab[i].first,
        b1[i] = ab[i].second;

    vector<long long> X(100, T+1);
    X[0] = 0;
    for (int i=0; i<n1; i++)
    {
        for (int j=99; j>0; j--)
            if (X[j-1]<T)
                X[j] = min(X[j], X[j-1]+1+(X[j-1]+1)*a1[i]+b1[i]);
    }

    vector<long long> Y(n0+2);
    Y[0] = 0;
    for (int i=0; i<n0; i++)
        Y[i+1] = min(Y[i]+b0[i]+1, T+1);
    Y[n0+1] = T+1;

    int ans = 0;
    for (int i=0; i<100; i++)
        if (X[i]<=T)
        {
            int n = (int)(upper_bound(Y.begin(), Y.end(), T-X[i]) - Y.begin())-1;
            ans = max(ans, i+n);
        }
    cout<<ans<<endl;
}


Measured memory_bytes: 9828
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main() {
    int a[10][10]={0};
    int x,y,size;
    while(scanf("%d,%d,%d",&x,&y,&size)!=EOF){
        //size=1
        if(size >= 1){
            a[x][y]++;
            if(x-1>-1){
                a[x-1][y]++;
            }
            if(y-1>-1){
                a[x][y-1]++;
            }
            if(x+1<10){
                a[x+1][y]++;
            }
            if(y+1<10){
                a[x][y+1]++;
            }
        }
        //size=2
        if(size >= 2){
            if(x-1>-1&&y-1>-1){
                a[x-1][y-1]++;
            }
            if(x+1<10&&y-1>-1){
                a[x+1][y-1]++;
            }
            if(x+1<10&&y+1<10){
                a[x+1][y+1]++;
            }
            if(x-1>-1&&y+1<10){
                a[x-1][y+1]++;
            }
        }
        //size=3
        if(size >= 3){
            if(x-2>-1){
                a[x-2][y]++;
            }
            if(y-2>-1){
                a[x][y-2]++;
            }
            if(x+2<10){
                a[x+2][y]++;
            }
            if(y+2<10){
                a[x][y+2]++;
            }
        }
    }
    int white=0;
    int max=0;
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            if(a[i][j]==0){
                white++;
            }
            if(a[i][j]>max){
                max=a[i][j];
            }
        }
    }
    cout<<white<<endl<<max<<endl;
    return 0;
}

Measured memory_bytes: 1208
R, G, B, N = map(int, input().split())
ans = 0
for r in range(N//R + 2):
    for g in range((N-R*r)//G + 2):
        b = (N - R*r - G*g)/B
        if b == int(b) and b >= 0:
            ans += 1
print(ans)


Measured memory_bytes: 41436