akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;

#define say(obj) (cout << (obj) << endl)
#define endline (cout << endl)
#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template <typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const vector<vector<T>>& mat) {
	for (const vector<T>& m : mat) os << m << endl;
	return os;
}

template <typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template <typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll N, T;
	cin >> N >> T;
	vll t(N);
	cin >> t;

	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		if (t[i + 1] - t[i] < T) {
			ans += t[i + 1] - t[i];
		}
		else {
			ans += T;
		}
	}

	say(ans + T);

	return 0;
}

Measured memory_bytes: 1792
import math
import collections
from operator import mul
from functools import reduce
import bisect
import string
import copy


d,g=map(int,input().split())
p=[0]*d
c=[0]*d
for i in range(d):
    p[i],c[i]=map(int,input().split())

y=1000000000000000
for i in range(2**d):
    yi=0
    pi=copy.copy(p)
    gi=copy.copy(g)
    for j in range(d):
        if (i >> j) & 1:
            gi-=c[j]
            gi-=pi[j]*100*(j+1)
            yi+=pi[j]
            pi[j]=0
    ind=copy.copy(d-1)
    while gi>0 and ind>=0:
        if pi[ind]>=2:
            gi-=100*(ind+1)
            yi+=1
            pi[ind]-=1
        else: 
            ind-=1

    if gi<=0 :
        y=min(y,yi)

print(y)

Measured memory_bytes: 42096
#include <bits/stdc++.h>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vb=vector<bool>;
int n,q,m,k,l,ans;
vi a,b;
ll llans;
vll lla,llb;
string s;
map<int, vi> friends;
map<int, vi> blocks;

struct UnionFind{
    vector<int> parent;// 各元の親を表す配列
    vector<int> rank; //素集合の深さを表す
    vector<int> siz; // 素集合のサイズを表す配列(1 で初期化)
;
    UnionFind(int n){
        parent.resize(n,-1);
        rank.resize(n,1);
        siz.resize(n,1);
    }

    // xの根を返す
    int find(int x){
        if(parent[x]==-1) return x;
        return parent[x] = find(parent[x]); 
    }

    //yにxを結合する(yがxの根となる)
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(rank[x]>rank[y]) swap(x,y);
        if(rank[x]==rank[y]) rank[y]++;
        parent[x] = y;
        siz[y]+=siz[x];
    }

    // xとyの根が等しいかを返す
    bool same(int x, int y) {return find(x)==find(y);}

    // xが属する素集合のサイズを返す
    int size(int x){return siz[find(x)];}
};

int main() {
    cin >> n >> m >> k;
    rep(i,m){
        int A,B;cin >> A >> B;
        A--;B--;
        friends[A].pb(B);
        friends[B].pb(A);
    }
    rep(i,k){
        int C,D;cin >> C >> D;
        C--;D--;
        blocks[C].pb(D);
        blocks[D].pb(C);
    }

    UnionFind uf = UnionFind(n);
    for(auto &f:friends) 
        for(auto &c:f.second) 
            uf.unite(c,f.first);
    // rep(i,n)
    //     printf("i:%d ufsize:%d fresize:%d blosize:%d\n",i,uf.size(i),(int)friends[i].size(),(int)blocks[i].size());
    rep(i,n){
        int block_in_conn = 0;
        for(auto &b:blocks[i]){
            if(uf.same(i,b)) block_in_conn++;
        }
        if(i!=0) cout << " ";
        cout << (uf.size(i) - 1 - friends[i].size() - block_in_conn);
    }
    cout << endl;
    return 0;
}

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

void change(int *x, int *y);

int a,b,c;
int ans=0;

int main(void){
	scanf("%d %d %d", &a, &b, &c);

	//大きい順に並び変える
	if(a<b)	change(&a, &b);
	if(b<c)	change(&b, &c);
	if(a<b)	change(&a, &b);
	if(b<c)	change(&b, &c);
	if(a<b)	change(&a, &b);
	if(b<c)	change(&b, &c);

	ans += a-b;
	c += a-b;
	b += a-b;
	if( (a-c) % 2 == 0)	ans += (a-c)/2;
	else	ans += ((a+1-c)/2 + 1); 
 		
	printf("%d", ans);

	return 0;
}

void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}

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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for(long i = 0; i < N; i++) cin >> A.at(i);
  long M = 0, ans = 0;
  for(long i = 0; i < N-1; i++){
    if(A.at(i) > A.at(i+1)){
    M = A.at(i) - A.at(i+1);
    A.at(i+1) += M;
    ans +=M;
    }
  }
  cout << ans << endl; 
}


Measured memory_bytes: 4784
#include <stdio.h>

int main() {
    int N, i, zero_num=0;
    scanf("%d", &N);

    long int a[N];
    for(i=0; i<N; i++) {
        scanf("%ld", &a[i]);
        if(a[i]==0) {
            zero_num += 1;
        }
    }

    // printf("%ld\n", a[0]);

    if(zero_num==N) {
        printf("Yes\n");
        return 0;
    }

    if(N%3) {
        printf("No\n");
        return 0;
    }

    long int b[3] = {-1, -1, -1};
    b[0] = a[0];

    if(zero_num!=0) {
        for(i=0; i<N; i++) {
            if(a[i]!=0) {
                b[0] = a[i];
                break;
            }
        }
        b[1] = 0;
    }

    if(b[1]==-1) {
        for(i=0; i<N; i++) {
            if(b[0]!=a[i]) {
                b[1] = a[i];
                break;
            }
        }
    }


    for(i=1; i<N; i++) {
        if((b[0]!=a[i])&&(b[1]!=a[i])&&((b[0]^b[1])==a[i])) {
            b[2] = a[i];
            if(N==3) {
                printf("Yes\n");
                return 0;
            }
            break;
        }
    }

    if(((b[1]==-1) || (b[2]==-1)) && (zero_num==0)) {
        printf("No\n");
        return 0;
    }


    int count, j, flag=0;

    if(zero_num != 0) {
        if(b[2]==-1) {
            b[2] = b[0];

            j = 0;
            count = 0;
            for(i=0; i<N; i++) {
                if(b[j]==a[i]) {
                    count += 1;
                }
            }
            if(count==2*(N/3)) {
                if(b[0] == 0) {
                    printf("No\n");
                    return 0;
                } else {
                    flag = 3;
                }
            } else {
                flag = -1;
            }

        } else {
            for(j=0; j<3; j++) {
                count = 0;
                for(i=0; i<N; i++) {
                    if(b[j]==a[i]) {
                        count += 1;
                    }
                }
                if(count==(N/3)) {
                    flag += 1;
                } else {
                    flag = -1;
                    break;
                }
            }
        }
    } else {
        for(j=0; j<3; j++) {
            count = 0;
            for(i=0; i<N; i++) {
                if(b[j]==a[i]) {
                    count += 1;
                }
            }
            if(count==(N/3)) {
                flag += 1;
            } else {
                flag = -1;
                break;
            }
        }
    }


    

    if(flag == 3) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }



    return 0;

}

Measured memory_bytes: 896
import bisect
INF=10**18
n=int(input())
a=[int(input()) for _ in range(n)]
dp=[]
for i in a:
  if bisect.bisect_left(dp,i)==len(dp):
    dp.append(i)
  else:
    dp[bisect.bisect_left(dp,i)]=i
print(len(dp))


Measured memory_bytes: 10344
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
}node;
typedef node * NodePointer;
NodePointer root, nil;
NodePointer make(int key, NodePointer p){
  NodePointer n;
  n = malloc(sizeof(struct node));
  n->key = key;
  n->parent = p;
  n->left = p;
  n->right = p;
  return n;
}

void insert(int key){
  NodePointer n, x, z;
  z = make(key, nil);
  n = root;
  x = nil;
  while(n != nil){
    x = n;
    if(n->key < key) n = n->right;
    else n = n->left;
  }
  z->parent = x;
  if(x == nil) root = z;
  if(x->key < z->key) x->right = z;
  if(x->key > z->key) x->left = z;
}
void find(NodePointer T, int key){
  if(T == nil){
    printf("no\n");
    return;
  }
  else if(T->key == key){
    printf("yes\n");
    return ;
  }
  else if(T->key < key) find(T->right, key);
  else if(T->key > key) find(T->left, key);
  return ;
}
void inorder(NodePointer T){
  if(T->left->key != 0) inorder(T->left);
  printf(" %d",T->key);
  if(T->right->key != 0) inorder(T->right);
}
void preorder(NodePointer T){
  printf(" %d",T->key);
  if(T->left != nil) preorder(T->left);
  if(T->right != nil) preorder(T->right);
}
void fre(NodePointer T){
  free(T);
  if(T->left != nil) fre(T->left);
  if(T->right != nil) fre(T->right);
}
int main(){
  int i ,n, key;
  char s[20];
  nil = make(0, nil);
  root = make(0, nil);
  root = nil;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%s", s);
    if(s[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else if(s[0] == 'f'){
      scanf("%d",&key);
      find(root, key);
    }
    else if(s[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");  
    }
  }
  fre(root);
  free(nil);
  return 0;
}

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

int main()
{
	int m, f, r;

	while(cin >> m >> f >> r)
	{
		if (m == -1 && f == -1 && r == -1) break;
		else if (m + f < 30 || m == -1 || f == -1) cout << "F" << endl;
		else if (80 <= m + f) cout << "A" << endl;
		else if (65 <= m + f && m + f < 80) cout << "B" << endl;
		else if (50 <= m + f && m + f < 65) cout << "C" << endl;
		else if (30 <= m + f && m + f < 50)
			if (50 <= r) cout << "C" << endl;
			else cout << "D" << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
#include<stdio.h>
#include<stdlib.h>
#define N 200
#define TRUE 1
#define FALSE 0


int isEmpty(void);
int isFull(void);
void push(int);
int pop(void);

int top=0;
int stack[N];


int main(){
  int tmp,num,m,i=0;
  char cn[100];

  while(scanf("%s",cn)!=EOF){
    if(cn[0]=='+'){
      push(pop()+pop());
      
    }else if(cn[0]=='-'){
      tmp = pop();
      push(pop()-tmp);
      
    }else if(cn[0]=='*'){
      push(pop()*pop());
      
      
    }else{
      num = atoi(cn);
      push(num);
    }
  }

  printf("%d\n",pop());
  return 0;
}



void push(int num){
  top++;
  stack[top]=num;
}


int pop(){
  top--;
  return stack[top+1];
}
  



Measured memory_bytes: 2100
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

string trans(string s) {
    string ans;
    int cnt = 0;
    unordered_map<int, int> _id;
    for(char c: s) {
        if (_id.count(c) == 0) {
            _id[c] = cnt++;
        }
        ans += 'a' + _id[c];
    }
    return ans;
}
int main() {
    string s, t;
    cin >> s >> t;
    if (trans(s) == trans(t))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 1684
// AtCoder My Practice
// author: Leonardone @ NEETSDKASU
 
// 解説読後
// https://img.atcoder.jp/abc100/editorial.pdf
 
fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let m = get!(usize);
    let mut vs = vec![];
    for _ in 0..n {
    	let x = get!();
        let y = get!();
        let z = get!();
        vs.push((x, y, z));
	}
    let mut ans = 0;
    for p in 0..8 {
    	let mut es = vec![];
        for i in 0..vs.len() {
        	let (x, y, z) = vs[i];
            let mut s = 0;
            if (p&1)==0 { s+=x; } else { s-=x; }
            if (p&2)==0 { s+=y; } else { s-=y; }
            if (p&4)==0 { s+=z; } else { s-=z; }
            es.push(s);
        }
        es.sort();
        es.reverse();
        let mut tmp = 0;
        for i in 0..m {
        	tmp += es[i];
        }
        if tmp > ans {
        	ans = tmp;
        }
    }
    println!("{}", ans);
}

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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
bool compare_by(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second > b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int counter(int x){
    if(!x)return 0;
    return counter(x>>1)+(x&1);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int P[N];
    REP(i,N){
        cin>>P[i];
    }
    int m;m=N+1;
    int ans=0;
    REP(i,N){
        if(P[i]<m){
            ans++;
            m=P[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 1000
#define MAX_E 2000
#define INF 1e9
struct edge {
  int from, to, cost;
};
int V, E, d[MAX_V];
edge es[MAX_E];
bool find_negative_loop(int s)
{
    int cnt = 0;
    for (int i = 0; i < V; i++) {
	d[i] = INF;
    }
    d[s] = 0;
    while (true) {
	bool update = false;
	cnt++;
	for (int i = 0; i < E; i++) {
	    edge e = es[i];
	    if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
		d[e.to] = d[e.from] + e.cost;
		if (cnt == V) {
                    return true;
                }
		update = true;
	    }
	}
	if (!update) {
            break;
        }
    }
    return false;
}

int main()
{
    int r;
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
	cin >> es[i].from >> es[i].to >> es[i].cost;
    }
    if (find_negative_loop(r)) {
	cout << "NEGATIVE CYCLE" << endl;
    } else {
	for (int i = 0; i < V; i++) {
	    if (d[i] == INF) {
		cout << "INF" << endl;
	    } else {
		cout << d[i] << endl;
	    }
	}
    }
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  if(S == "SUN"){
    cout << "7" << endl;
  } else if(S == "MON"){
    cout << "6" << endl;
  } else if(S == "TUE"){
    cout << "5" << endl;
  } else if(S == "WED"){
    cout << "4" << endl;
  } else if(S == "THU"){
    cout << "3" << endl;
  } else if(S == "FRI"){
    cout << "2" << endl;
  } else if(S == "SAT"){
    cout << "1" << endl;
  }

  return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int score=0;
  string s;
  int n,out=0,runner = 0;
  cin >> n;
  rep(i,n){
    out = runner = 0,score=0;
    while(1){
      cin >> s;
      if(s == "HIT"){
        if(runner & 4){
          score++;
        }
        runner = runner<<1;
        runner &= 7;
        runner |= 1;
      }
      else if(s == "OUT"){
        ++out;
      }
      else{
        if((runner & 7) == 7){
          score += 4;
          runner = 0;
        }
        else if((runner & 7) == 3){
          score += 3;
          runner = 0;
        }
        else if((runner & 7) == 1){
          score += 2;
          runner = 0;
        }
        else{
          score++;
        }
      }
//       cout << runner << " "<< score << " " << out << endl;
      if(out == 3) break;
    }
    cout << score<<endl;
  }
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  vector<string> divide={"maerd","remaerd","esare","resare"};
  reverse(S.begin(),S.end());
  bool can=true;
  for(int i=0;i<S.size();){
    bool can2=false;
    for(int j=0;j<4;j++){
      string d=divide.at(j);
      if(S.substr(i,d.size())==d){
        can2=true;
        i+=d.size();
      }
    }
    if(!can2){
      can=false;
      break;
    }
  }
  if(can){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

typedef pair<int, int> P;
ll mod = 1e9+7;

int main() {

    int n[3][3];
    bool b[3][3];
    rep(i,3){
        rep(j,3){
            cin >> n[i][j];
            b[i][j] = false;
        }
    }

    int num;
    cin >> num;
    rep(i,num){
        int tmp;
        cin >> tmp;
        rep(j,3)rep(k,3){
            if(n[j][k]==tmp){
                b[j][k]=true;
            }
        }
    }

    bool ok = false;

    rep(i,3){
        if(b[i][0]&&b[i][1]&&b[i][2]) ok = true;
        if(b[0][i]&&b[1][i]&&b[2][i]) ok = true;
    }
    if(b[0][0]&&b[1][1]&&b[2][2]) ok = true;
    if(b[0][2]&&b[1][1]&&b[2][0]) ok = true;

    if(ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// clang-format off
#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 eb emplace_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, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int K, A, B;
  cin >> K >> A >> B;
  rep(i, A, B + 1) if (i % K == 0) {
    cout << "OK" << endl;
    return 0;
  }
  cout << "NG" << endl;
  return (0 ^ _ ^ 0);
}



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

//#define kk
#define int long long
#define FOR(i, n) for(int i=1; i<=n; i++)
#define ff first
#define ss second
#define ll int
#define inf 1000000000
typedef pair<int, int> pi;

int wt[101];
int val[101];
int dp[101][100001];

void solve(){
	int n, w;
	cin>>n>>w;
	
	for(int i=1; i<=n; i++){
		cin>>wt[i]>>val[i];
	}
	
	for(int i=1; i<=n; i++){
		for(int j=1; j<=w; j++){
			if(wt[i]<=j) dp[i][j]=max(val[i]+dp[i-1][j-wt[i]], dp[i-1][j]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	
	cout<<dp[n][w]<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


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

int main(){
  ll n;cin>>n;
  if(n%2)cout<<0;
  else {
    n/=2;ll sum=0;
    while(n){
      sum+=n/5;
      n/=5;
    }
     cout<<sum;
  }
 	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

var N, M int

func main() {
	fmt.Scan(&N, &M)

	if N < M/2 {
		s := N
		s_add := floor((M - 2*N) / 4)
		fmt.Println(s + s_add)
	} else {
		c := M / 2
		fmt.Println(c)
	}
}

/*  ----------------------------------------  */

func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007
#define MEM_SIZE = 1e5+5;

// vector<int> DP[MEM_SIZE]

void solve(void)
{

  int N;
  cin>>N;
  vector<int> vec1(N);
  vector<int> vec2(N);

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

  for (int i = 0; i < N; i++)
  {
    cin>>vec2[i];
  }
  vector<int> ref(N);
  int STOP = 1;
  for (int i = 0; i < N; i++)
  {
    ref[i] = i + 1;
    STOP *= (i+1);
  }
  int count = 1;
  int ANS1, ANS2;
  
  while(true)
  {
    if(vec1 == ref) 
    {
      ANS1 = count;
    }

    if(vec2 == ref)
    {
      ANS2 = count;
      
    }
    count++;
    next_permutation(ref.begin(),ref.end());

    
    if(count == STOP+1) break;
  }

  // cout<<ANS1<<" "<<ANS2<<endl;

  cout<<abs(ANS2 - ANS1)<<endl;


  
  return;
  
}



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

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 256
import math


N, K = map(int, input().split())
MOD = 10 ** 9 + 7

def comb(n, k):
    return math.factorial(n) // math.factorial(k) // math.factorial(n - k)

for i in range(1, K + 1):
    if i > N-K+1:
        print(0)
        continue
    blue = comb(N-K+1, i) % MOD
    red = comb(K-1, i-1) % MOD

    ans = blue * red % MOD
    print(ans)


Measured memory_bytes: 69976
#include <cstdio>

int main()
{
    int a, b, c;
    bool hoge;
    scanf("%d", &a);
    scanf("%d", &c);
    scanf("%d", &b);

    if (a < b) {
        if (b < c) {
            hoge = true;
        } else {
            hoge = false;
        }
    } else {
        if (c < b) {
            hoge = true;
        } else {

            hoge = false;
        }
    }

    if (hoge) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


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

using namespace std;

#define ll long long

int main ()
{

    ll a, b, k; cin >> a >> b >> k;

    //If A >= 1, A--
    //elseif B >= 1, B--
    //if A == 0 and B == 0, do nothing

    if (a > 0)
    {
        if (k > a)
        {
            k -= a;
            a = 0;
        } else //k <= a
        {
            a -= k;
            k = 0;
        }
    }

    if (b > 0)
    {
        if (k > b)
        {
            k -= b;
            b = 0;
        } else {
            b -= k;
            k = 0;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}


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

int comp(const void *a, const void *b){ return *(int*)a-*(int*)b; }
int main(){
  int i, n, a[200000], b;
  long int ans=0;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
    a[i] -= i+1;
  }
  qsort(a,n,sizeof(int),comp);
  b=a[n/2];
  for(i=0;i<n;i++) ans += abs(a[i] - b);
  printf("%ld\n", ans);
  return 0;
}

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main()
{
	long long int a,b,v,w,t;
	cin>>a>>v>>b>>w>>t;
   long long int i=1;
	int f=2;
  if(a<b)
  {
	while(i<=t)
	{
		a=a+v;
		b=b+w;
		if(a>=b)
		{
			f=1;
			break;
		}
		i++;
	}
  }
  else
  {
    
    while(i<=t)
	{
		a=a-v;
		b=b-w;
		if(a<=b)
		{
			f=1;
			break;
		}
		i++;
	}
    
  }
	if(f==1)
	cout<<"YES"<<endl;
	else
	cout<<"NO"<<endl;
}

Measured memory_bytes: 3624
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')

def main():
	n,m,k=MI()
	mod=998244353
	
	f=[1]
	for i in range(1,2*10**5+100):
		f.append((f[-1]*i)%mod)
	finv=[]
	for i in f:
		finv.append(pow(i,mod-2,mod))
	
	mp=[1]
	for i in range(1,2*10**5+100):
		mp.append((mp[-1]*(m-1))%mod)
		
	
	ans=0
	for kk in range(k+1):
		cnt=f[n-1]*finv[kk]*finv[n-1-kk]*m*mp[n-kk-1]
		ans+=cnt
		ans%mod
	print(ans%mod)













if __name__=="__main__":
	main()


Measured memory_bytes: 113528
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	if(n >= 30)
		puts("Yes");
	else
		puts("No");
	return 0;
}

Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		sa = br.readLine().split(" ");
		Obj[] arr = new Obj[n];
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.i = i;
			o.a = Integer.parseInt(sa[i]);
			arr[i] = o;
		}
		br.close();

		Arrays.sort(arr, (o1, o2) -> o2.a - o1.a);
		long[][] dp = new long[n + 1][n + 1];
		for (int i = 0; i < n; i++) {
//			for (int j = 0; j <= n; j++) {
//				System.out.print(dp[i][j] + "\t");
//			}
//			System.out.println();
			for (int j = 0; j <= i; j++) {
				long val1 = (long) Math.abs(n - 1 - (i - j) - arr[i].i) * arr[i].a;
				dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + val1);
				long val2 = (long) Math.abs(arr[i].i - j) * arr[i].a;
				dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + val2);
			}
		}

		long ans = 0;
		for (int j = 0; j <= n; j++) {
			ans = Math.max(ans, dp[n][j]);
		}
		System.out.println(ans);
	}

	static class Obj {
		int i, a;
	}
}


Measured memory_bytes: 82540
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int  N = sc.nextInt();
	
	if(N%10 == 3){
		System.out.println("bon");
	}else if(N%10==0 || N%10==1 || N%10==6 || N%10==8){
		System.out.println("pon");
	}else{
		System.out.println("hon");
	}      
	}
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int REMOVE = 0, MONSTER = 1;
const ll MOD { 1000000007 }, oo { 1LL << 62 };

struct Event {
    ll type, x, v;

    bool operator<(const Event& e) const
    {
        if (x != e.x)
            return x < e.x;

        if (type != e.type)
            return type < e.type;

        return v > e.v;
    }

    bool operator>(const Event& e) const
    {
        return not (*this < e);
    }
};

ll solve(int, ll D, ll A, const vector<ii>& xs)
{
    priority_queue<Event, vector<Event>, greater<Event>> pq;

    for (auto x : xs)
        pq.push(Event { MONSTER, x.first, x.second });

    ll damage = 0, ans = 0;

    while (not pq.empty())
    {
        auto e = pq.top();
        pq.pop();

#ifdef DEBUG
    cout << "--- Event: " << (e.type ? "MONSTER" : "REMOVE") << " at " << e.x << ", v = " << e.v << endl;
    cout << "    damage = " << damage << ", ans = " << ans << endl;
#endif
        switch (e.type) {
        case REMOVE:

            damage -= e.v;
            break;

        default:
            if (e.v <= damage)
                break;

            {
                e.v -= damage;
                ll hits = (e.v + A - 1)/A;

                ans += hits;
                damage += (A*hits);
                pq.push(Event { REMOVE, e.x + 2*D + 1, A*hits});
            }
        }
    }

    return ans;
}


int main()
{
    ios::sync_with_stdio(false);

    int N, D, A;
    cin >> N >> D >> A;

    vector<ii> xs(N);

    for (int i = 0; i < N; ++i)
        cin >> xs[i].first >> xs[i].second;

    auto ans = solve(N, D, A, xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 11376
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
/*
template <typename T>  using ordered_set =
    tree<T, null_type, less<T>,   /// greater<T> for sorting decreasingly
    rb_tree_tag, tree_order_statistics_node_update>;
*/

#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         mod                         1000000007
#define         INF                         2e18
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;


int main(){
    ll n,m;
    sfl(n),sfl(m);
    if(n==1 or m==1){
        pfl(m);
    }
    else{
        ll ans=1;
        for(ll i=2;pow(i,n)<=m;i++){
            ll t=pow(i,n);
            if(m%t==0){
                ans = i;
            }
        }
        pfl(ans);
    }
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vl a(n);
  rep(i,0,n) cin >> a[i];
  vl p = a;
  rep(i,1,n) p[i] += p[i-1];

  const ll inf = 1e18;
  vvl dp(n, vl(n+1, inf));

  auto qsum = [&](int l, int r) {
    ll ans = p[r];
    if (l>0) ans -= p[l-1];
    return ans;
  };

  rep(i,0,n) dp[i][1] = 0;
  rep(l,2,n+1) {
    rep(i,0,n-l+1) {
      rep(j,i+1,i+l) ckmin(dp[i][l], dp[i][j-i] + dp[j][l-(j-i)] + qsum(i,j-1) + qsum(j, i+l-1));
    }
  }

  cout << dp[0][n] << '\n';

}

Measured memory_bytes: 1536
import java.util.*;
public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int t=0;
		for(int i=0;i<s.length();i++){
		int f=0;
      if(s.charAt(i)=='A'||s.charAt(i)=='C'||s.charAt(i)=='G'||s.charAt(i)=='T'){
			for(int j=i+1;j<s.length();j++){
			if(s.charAt(j)=='A'||s.charAt(j)=='C'||s.charAt(j)=='G'||s.charAt(j)=='T')
				f++;
			else break;
			}
			if(t<f+1)
		t=f+1;
	}
	else continue;
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e6;
int x,y,ans,top,n;
int a[MAXN],b[MAXN],count1[MAXN],count2[MAXN],fa[MAXN];
map<int,int>mapp;
void push(int x) {if(!mapp.count(x)) mapp[x]=++top;}
int find(int x){if (x==fa[x]) return x; else return fa[x]=find(fa[x]);}
int main() {
	cin>>n;
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		x^=a[i];
	}
	
	for (int i=1;i<=n;++i){
		scanf("%d",&b[i]);
		y^=b[i];
	}
	bool flag=true;
	for (int i=1;i<=n;++i)
		if (a[i]!=b[i]){
			flag=false;
			break;
		}
	if (flag){printf("0");exit(0);}
	for (int i=1;i<=n;++i) {
		if (a[i]==b[i])continue;
		ans++;push(a[i]);push(b[i]);
		count1[mapp[a[i]]]++;count2[mapp[b[i]]]++;
	}
	push(x);push(y);
	count1[mapp[x]]++;count2[mapp[y]]++;
	for(int i=1;i<=top;i++){
		if (count1[i]==count2[i]) continue;
		printf("-1");
		exit(0);
	}
	for(int i=1;i<=top;i++)fa[i]=i;
	for (int i=1;i<=n;++i) if(a[i]!=b[i]) fa[find(mapp[a[i]])]=find(mapp[b[i]]);
	if(x!=y) fa[find(mapp[x])]=find(mapp[y]);
	 
	for(int i=1;i<=top;i++)
		if(i==find(i)) ans++;
	printf("%d",ans-1);
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
        double[] a = Console.ReadLine().Split().Select(double.Parse).ToArray();
            Console.WriteLine(1/(double)((1/(double)a[1])+(1/(double)a[0])));
        }
    }
}


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

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

  //しゃくとり法　ポイント：条件をみたす区間の部分空間も条件を満たす
  long long ans = 0;
  int j = 0;
  int sum = 0;
  for(int i = 0; i < n ; i++ ){
    while( j < n && (sum ^ a[j]) == (sum + a[j]) ){ // ^ 各ビットに置ける排他的論理和
      sum += a[j];
      j++;
    }
    ans += j - i;
    if(i == j) j++;
    else sum -= a[i]; //ケツだけひとつ縮む（次のiからj-i+1まで分の組はすでに条件を満たすことがわかっている為jの更新はその場から行う）
  }
  cout << ans << endl;
}


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

int main() {
	cin >> n;

	for (int i = 1; i < 10; i++) {
		if (n % i == 0 && n / i <= 9) {
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair
#define INF 9999999
#define LINF 9999999999999999
#define SINF "%"
#define uint unsigned int
#define msn(a,v) memset(a,v,sizeof(a))
#define ms(a) msn(a,0)
#define NONE -1
#define ll long long
#define uchar unsigned char
#define sint short int
#define usint unsigned sint
#define xsize(a) sizeof(a)/1024/1024
#define fr(aaaaa,bbbbb) for(aaaaa = 1;aaaaa <= bbbbb;aaaaa++)
#define frr(aaaaa,bbbbb,ccccc) for(aaaaa = ccccc;aaaaa <= bbbbb;aaaaa++)
using namespace std;
#define MAXN 5100
int a,b,w;
int main(){
	scanf("%d %d %d",&w,&a,&b);
	if((a <= b  &&  b <= a+w)||(a <= b+w  &&  b+w <= a+w)) printf("0\n");
	else printf("%d\n",max(b-a-w,a-b-w));
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
public class Main{

    static long M=(long)1e9+7;
    
    public static void main(String[] args) {
        FastReader fs=new FastReader();
        int n=fs.nextInt();
        int w=fs.nextInt();
        long[] wei=new long[n+1];
        long[] val=new long[n+1];
        wei[0]=0;
        val[0]=0;
        for(int i=1;i<n+1;i++){
        	wei[i]=fs.nextLong();
        	val[i]=fs.nextLong();
        }
        long[][]dp=new long[n+1][w+1];

        for(int i=1;i<n+1;i++){
        	for(int j=1;j<w+1;j++){
        		if(wei[i]>j){
        			dp[i][j]=dp[i-1][j];
        		}
        		else{
        			dp[i][j]=Math.max(dp[i-1][j-(int)wei[i]]+val[i],dp[i-1][j]);
        		}
        	}
        }
        System.out.println(dp[n][w]);
    }
    public static void p(long[][]dp){
    	for(long[]i:dp){
    		for(long j:i){
    			System.out.print(j+" ");
    		}
    		System.out.println();
    	}
    }
    
    public static long inv(long a, long mod){
        return pow(a, mod-2,mod);
    }
    public static long mul(long a,long b,long mod){
        long res=0;
        while(b!=0){
            if ((b & 1) == 1){ res = (res + a) % mod;}
            a = (a + a) % mod;
            b >>= 1;
        }
        return res;
    }
    
    public static long pow(long a, long n, long mod){
        long res=1;
        while(n != 0){
            if ((n & 1) == 1) res = mul(res, a, mod)%mod;
            a = mul(a , a, mod)%mod;
            n >>= 1;
        }
        return res;
    }
    
    public static long gcd(long a, long b){
        if(a == 0) return b;
        return b == 0 ? a: gcd(b, a % b);
    }

    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
    if (p.at(i) != (i + 1)) {
      p.at(i) = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < N - 1; i++) {
    if (p.at(i) != 0) {
      if (p.at(i + 1) != 0) {
        ans++;
        p.at(i) = 0;
        p.at(i + 1) = 0;
      }
      else {
        ans++;
        p.at(i) = 0;
      }
    }
  }
  if (p.at(N - 1) != 0) {
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3720
module Main where

import Data.Int
import Control.Monad
import Control.Applicative
import Data.Array.IO

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  es <- replicateM m ((\[a, b] -> (a, b)) . map read . words <$> getLine) :: IO [(Int, Int)]
  let len = fromIntegral n :: Int64
  let numOfEdges = len * (len - 1) `div` 2
  uf <- initUf n
  ans <- solve numOfEdges uf 0 [] $ reverse es
  mapM_ print ans

solve :: Int64 -> UnionFind -> Int64 -> [Int64] -> [(Int, Int)] -> IO [Int64]
solve noe uf cnt acc [] = return $ map (noe -) acc
solve noe uf cnt acc ((a, b):edges) = do
  -- update uf
  (uf', isSame) <- sameUf uf a b
  if isSame
  then solve noe uf' cnt (cnt:acc) edges
  else do
    sizeA <- sizeUf uf' a
    sizeB <- sizeUf uf' b
    uf'' <- uniteUf uf' a b
    let cnt' = cnt + fromIntegral (sizeA * sizeB)
    solve noe uf'' cnt' (cnt:acc) edges

-- unionfind

data UnionFind = UnionFind
  { parent :: IOUArray Int Int
  , size :: IOUArray Int Int
  }

initUf :: Int -> IO UnionFind
initUf n = UnionFind
  <$> newListArray (1, n) [1..n]
  <*> newArray (1, n) 1

rootUf :: UnionFind -> Int -> IO (UnionFind, Int)
rootUf uf x = do
  px <- readArray (parent uf) x
  if px == x 
  then return (uf, x)
  else do
    (UnionFind parent' size', rx) <- rootUf uf px
    writeArray parent' x rx
    return (UnionFind parent' size', rx)

sameUf :: UnionFind -> Int -> Int -> IO (UnionFind, Bool)
sameUf uf x y = do
  (uf', rx) <- rootUf uf x
  (uf'', ry) <- rootUf uf' y
  return (uf'', rx == ry)

uniteUf :: UnionFind -> Int -> Int -> IO UnionFind
uniteUf uf x y = do
  (uf', x') <- rootUf uf x
  (uf''@(UnionFind parent' size'), y') <- rootUf uf' y
  if x' == y'
  then return uf''
  else do
    sizeX <- readArray size' x'
    sizeY <- readArray size' y'
    if sizeX < sizeY
    then do
      writeArray parent' x' y'
      writeArray size' y' (sizeX + sizeY)
      return $ UnionFind parent' size'
    else do
      writeArray parent' y' x'
      writeArray size' x' (sizeX + sizeY)
      return $ UnionFind parent' size'
    
sizeUf :: UnionFind -> Int -> IO Int
sizeUf uf x = do
  (UnionFind _ size', x') <- rootUf uf x
  readArray size' x'


Measured memory_bytes: 78204