akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a = b; a<c; a++)
using namespace std;
vector<string> str;
int main(){
    int n,m;
    string s;
    cin >> n >> m;
    rep(i,0,n){
        cin >> s;
        str.push_back(s);
    }
    rep(i,0,n+2){
        cout << "#";
        rep(j,0,m){
            if(i==0||i==(n+1)){
                cout << "#";
            }else{
                cout << str[i-1][j];
            }
        }
        cout << "#" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[150];
int b[3][30],r,n;
int main(){
	scanf("%d%*c",&n);
	scanf("%s",&a);
	r=0;
	for(int i=0;i<n;i++){
		b[0][a[i]-'a']++;
	}
	for(int i=n-1,k;i>=0;i--)
	{
		k=0;
		for(int j=0;j<26;j++){
			if(b[0][j]&&b[1][j]){
				k++;
			}
		}
		if(k>r)r=k;
		b[0][a[i]-'a']--;
		b[1][a[i]-'a']++;
	}
	printf("%d",r);
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
 
/*
 * 给出一个序列，查询区间内有多少个不相同的数
 */
const int MAXN = 5e5+10;
const int M = MAXN * 100;
int n,q,tot;
int a[MAXN];
int T[M],lson[M],rson[M],c[M];
int build(int l,int r)
{
    int root = tot++;
    c[root] = 0;
    if(l != r)
    {
        int mid = (l+r)>>1;
        lson[root] = build(l,mid);
        rson[root] = build(mid+1,r);
    }
    return root;
}
int update(int root,int pos,int val)
{
    int newroot = tot++, tmp = newroot;
    c[newroot] = c[root] + val;
    int l = 1, r = n;
    while(l < r)
    {
        int mid = (l+r)>>1;
        if(pos <= mid)
        {
            lson[newroot] = tot++; rson[newroot] = rson[root];
            newroot = lson[newroot]; root = lson[root];
            r = mid;
        }
        else
        {
            rson[newroot] = tot++; lson[newroot] = lson[root];
            newroot = rson[newroot]; root = rson[root];
            l = mid+1;
        }
        c[newroot] = c[root] + val;
    }
    return tmp;
}
int query(int root,int pos)
{
    int ret = 0;
    int l = 1, r = n;
    while(pos < r)
    {
        int mid = (l+r)>>1;
        if(pos <= mid)
        {
            r = mid;
            root = lson[root];
        }
        else
        {
            ret += c[lson[root]];
            root = rson[root];
            l = mid+1;
        }
    }
    return ret + c[root];
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d%d",&n,&q);
    
        tot = 0;
        for(int i = 1;i <= n;i++)
            scanf("%d",&a[i]);
        T[n+1] = build(1,n);//建立一颗空树
        map<int,int>mp;
        for(int i = n;i>= 1;i--)
        {
            if(mp.find(a[i]) == mp.end())
            {
                T[i] = update(T[i+1],i,1);
            }
            else
            {
                int tmp = update(T[i+1],mp[a[i]],-1);
                T[i] = update(tmp,i,1);
            }
            mp[a[i]] = i;
        } 
       
        while(q--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",query(T[l],r));
        }
    
    return 0;
}

Measured memory_bytes: 252916
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

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

  rep(i, a, b+1) {
    if (i >= a + k && i <= b - k) continue;
    printf("%d\n", i);
  }
  return 0;
}


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

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

    int n;
    cin >> n;

    vector<ll> a(n + 1), b(n);
    rep(i, 0, n + 1) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    ll ans = 0;

    rep(i, 0, n) {
        if (b[i] < a[i]) {
            ans += b[i];
        } else {
            ans += a[i];
            b[i] -= a[i];
            if (b[i] < a[i + 1]) {
                ans += b[i];
                a[i + 1] -= b[i];
            } else {
                ans += a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(all(A));

	int pre = A[0], cnt = 1;
	vector<int> C;
	// vector<pair<int, int>> C;
	REP(i, 1, A.size()) {
		if (A[i] != pre) {
			C.push_back(cnt);
			// C.push_back(make_pair(cnt, pre));
			cnt = 0;
		}
		pre = A[i];
		cnt++;
	}
	C.push_back(cnt);
	// C.push_back(make_pair(cnt, pre));
	sort(all(C));

	int ans = 0;
	rep(i, C.size() - K) {
		ans += C[i];
		// ans += C[i].first;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    string list[] = {
        "",
        "SAT",
        "FRI",
        "THU",
        "WED",
        "TUE",
        "MON",
        "SUN"
    };
    string s;
    cin>>s;
    rep(i, 1, 8) {
        if(s == list[i]) {
            cout<<i<<endl;
            return 0;
        }
    }
}


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

int main() {
  ll n;
  cin >> n;
  ll sum = 0;
  for(int i = 1; i <= n; ++i) {
    if(i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }
  cout << sum;
}


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

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

    int cnt[26] = {};

    for (int i = 0; i < s.length(); i++) {
        cnt[s[i] - 'a']++;
    }

    for (int i = 0; i < 26; i++) {
        if (cnt[i] % 2) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include <numeric>
#include<queue>
using namespace std;
int main(int argc, char const *argv[])
{
	/*
	cin>>x;
	cout<<x<<endl;
	*/
	int a,b,c,i,j=0;
	cin>>a>>b>>c;
	for(i=0;i<c/a;i++)
		j+=b;

	cout<<j<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> w(n+1,0);
    rep(i,n){
       if (s[i] == 'W') w[i+1] = w[i]+1;
       else w[i+1] = w[i];
    }
    int ans = n-1-(w[n]-w[1]);
    //cout << ans << endl;
    for (int i=1;i < n-1;i++){
       ans = min(ans, (w[i]-w[0])+ n-i-1-(w[n]-w[i+1]));
       //printf("i %d\n",i);
       //printf("l %d   r %d\n",(w[i]-w[0]),n-i-1-(w[n]-w[i+1]));
       //cout << (n-i-1)-(w[n]-w[i])+w[i]-w[0] << endl;
    }
    ans = min(ans,w[n-1]);
    //cout << w[n-1] << endl;
    cout << ans << endl;

    
    return 0;
    
}



Measured memory_bytes: 1796
#include<stdio.h>

int ways(int n,int m){
	int count=0,a,b,c;
	for(a=1;a<n-1;a++){
		for(b=a+1;b<n;b++){
			for(c=b+1;c<=n;c++){
				if(a+b+c==m)count++;
			}
		}
	}
	return count;
}

int main(){
	int i,c,a[1000],x[1000],way_count[1000];
	for(c=0;c<=1000;c++){
		int n,m;
		scanf("%d %d",&a[c],&x[c]);
		if((a[c]==0)&&(x[c]==0))break;
	}
	for(i=0;i<c;i++){
		way_count[i]=ways(a[i],x[i]);
		printf("%d\n",way_count[i]);
	}
	return 0;
}

Measured memory_bytes: 608
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = int(1E7) + 5;
const int MAXM = 100;

bool nprm[MAXN + 5];
int prm[MAXN + 5], pcnt;
void init() {
	nprm[1] = true;
	for(int i=2;i<=MAXN;i++) {
		if( !nprm[i] ) prm[++pcnt] = i;
		for(int j=1;prm[j]<=MAXN/i;j++) {
			nprm[i*prm[j]] = true;
			if( i % prm[j] == 0 ) break;
		}
	}
}

int a[MAXN + 5], b[2][MAXM + 5], cnt[2];

int G[MAXM + 5][MAXM + 5], lnk[MAXM + 5];
bool vis[MAXM + 5];
bool dfs(int x) {
	for(int i=1;i<=cnt[1];i++) {
		if( !vis[i] && G[x][i] ) {
			vis[i] = true;
			if( !lnk[i] || dfs(lnk[i]) ) {
				lnk[i] = x;
				return true;
			}
		}
	}
	return false;
}

int abs(int x) {return x >= 0 ? x : -x;}
int main() {
	init();
	int N; scanf("%d", &N);
	for(int i=1;i<=N;i++) {
		int x; scanf("%d", &x);
		a[x] = 1;
	}
	for(int i=1;i<=MAXN;i++)
		if( a[i] != a[i-1] ) b[i%2][++cnt[i%2]] = i;
	int ans = 0;
	for(int i=1;i<=cnt[0];i++)
		for(int j=1;j<=cnt[1];j++)
			G[i][j] = (!nprm[abs(b[0][i] - b[1][j])]);
	for(int i=1;i<=cnt[0];i++) {
		for(int j=1;j<=cnt[1];j++) vis[j] = false;
		if( dfs(i) ) ans++;
	}
	ans += (cnt[0] - ans)/2*2 + (cnt[1] - ans)/2*2;
	if( (cnt[0] - ans) & 1 ) ans += 3;
	printf("%d\n", ans);
}

Measured memory_bytes: 51328
X, K, D = map(int, input().split())

X = abs(X)

if K*D < X:
    ret = X - K*D
else:
    j = X//D
    if (K - j) % 2 == 0:
        ret = X - j*D
    else:
        ret = (j+1)*D - X

print(ret)

Measured memory_bytes: 9184
n,m,*ab=map(int,open(0).read().split())
path={}
for i in range(n):
  path[i]=[]
for i in range(m):
  a,b=ab[i*2]-1,ab[i*2+1]-1
  path[a].append(b)
  path[b].append(a)
direction=[i for i in range(n)]
fin=[False for i in range(n)]
fin[0]=True
i=0
queue=[0]
while i<n:
  i+=1
  queue2=queue.copy()
  queue.clear()
  if len(queue2)==0:
    break
  for j in queue2:
    fin[j]=True
    for k in path[j]:
      if not fin[k]:
        direction[k]=j
        fin[k]=True
        queue.append(k)
print('Yes')
for i in range(1,n):
  print(direction[i]+1)

Measured memory_bytes: 63520
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

void print(vector<ll> &dp) {
    for (int i = 0; i < dp.size(); ++i) {
        cout << "i = " << i << " fac[i] = " << dp[i] << endl;
    }
}

int main(int argc, char const *argv[]) {
    ll n;
    cin >> n;
    vector<ll> fac;
    ll y = sqrtl(n);
    for (int i = 1; i <= y; ++i) {
        if (n%i == 0) {
            fac.push_back(i);
            if (i == n/i) continue;
            fac.push_back(n/i);
        }
    }
    sort(fac.begin(), fac.end());
    // print(fac);
    int X = (fac.size()+2-1)/2;
    ll ans = 0;
    for (int i = X; i < fac.size(); ++i) {
        if (fac[i-1] == fac[i]-1) continue;
        // cout << fac[i] << endl;
        ans += fac[i]-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string n;
    cin >> n;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
    {
        puts("Yes");
    }
    else
        puts("No");
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        // type: コンテスト種類数
        int type = 26;
        
        // n: 1～n日目まで開催
        int n = sc.nextInt();
        
        // c[t]: コンテストtのマイナス係数
        int[] c = new int[type];
        for (int i = 0; i < type; i++) {
            c[i] = sc.nextInt();
        }
        
        // s[d][t]: コンテストtをd日目に開くと増加する満足度
        int[][] s = new int[n+1][type];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < type; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        
        // last[t]: コンテストtが最近何日目に開催されたか
        int[] last = new int[type];
        
        // t[d]: d日目に開催するコンテストは何か
        int[] t = new int[n+1];
        
        for (int i = 0; i < n; i++) {
            System.out.println(1);
        }
    }
}


Measured memory_bytes: 46792
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n,dy[]={-1,0,1,0},dx[]={0,1,0,-1};
char c[100][100];

int main(){
	cin>>n;
	int f=0;
	while(cin>>n){
		if(f)cout<<endl;
		if(n==1){cout<<"#"<<endl;f=1;continue;}
		for(int i=0;i<n*n;i++)c[i/n][i%n]=' ';
		int y=n-1,x=0,u=0,d=n-1,l=0,r=n-1;
		c[y][x]='#';
		for(int i=0;i<n;i++){
			while(1){
				y+=dy[i%4];x+=dx[i%4];
				c[y][x]='#';
				if(i%4==0&&y==u||i%4==1&&x==r||i%4==2&&y==d||i%4==3&&x==l)break;
			}
			if(i%4==0)l+=2;
			if(i%4==1)u+=2;
			if(i%4==2)r-=2;
			if(i%4==3)d-=2;
		}
		for(int i=0;i<n*n;i++){
			cout<<c[i/n][i%n];
			if(i%n==n-1)cout<<endl;
		}
		f=1;
	}
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
    ll n, m;
    while (cin >> n >> m) {
        if (n==0 && m==0) {
            break;
        } else {
            ll res = 0;
            rep(i, n) {
                ll a;
                cin >> a;
                if (a >= m/n) {
                    res += m/n;
                } else {
                    res += a;
                }
            }
            cout << res << endl;
        }
    }
}


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

#define ll long long int

static const auto _____ = []() {
    // fast IO code : this I understand
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(0);
    return 0;
}();

int main(){
	int n;
	cin>>n;
	int a[n][2];
	int cnt = 0;
	int flag = 0;
	for(int i=0;i<n;i++){
		cin>>a[i][0]>>a[i][1];
		if(a[i][0]==a[i][1] ){
			cnt++;
			if(cnt == 3)
				flag = 1;
		}
		else 
			cnt = 0;
	}
	if(flag)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);
using namespace std;
int mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 // OJ;
  string s,t;
  cin>>s>>t;
  int ans=t.size();
  for(int i=0;i<=s.size()-t.size();i++)
  {
      int diff=0;
      for(int j=0;j<t.size();j++)
      {
         if(s[j+i]!=t[j])
         {
             diff++;
         }
      }
      ans=min(ans,diff);
  }
  cout<<ans;
}

Measured memory_bytes: 3652
class dice_2:
    def __init__(self,label):
        self.spots = label

    def result(self,top,front):
        if self.spots.index(top)+1 == 1:
            self.order=[2,3,5,4,2]
        elif self.spots.index(top)+1 == 2:
            self.order=[6,3,1,4,6]
        elif self.spots.index(top)+1 == 3:
            self.order=[2,6,5,1,2]
        elif self.spots.index(top)+1 == 4:
            self.order=[2,1,5,6,2]
        elif self.spots.index(top)+1 == 5:
            self.order=[1,3,6,4,1]
        elif self.spots.index(top)+1 == 6:
            self.order=[2,4,5,3,2]

        for i in range(4):
            if self.order[i] == self.spots.index(front)+1:
                self.right = self.order[i+1]

    def output(self):
        print(self.spots[self.right-1])

label = list(map(int,input().split()))
dice = dice_2(label)
for i in range(int(input())):
    top,front = map(int,(input().split()))
    dice.result(top,front)
    dice.output()

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

int f(int x){
  int sum = 0;
  while(true){
    int a = 10;
    sum += x % a;
    x = x / a;
    a = a * 10;
    if (x == 0){
      return sum;
    }
  }
}

int main(){
  int N;
  cin >> N;
  
  string ans = "No";
  if(N % f(N) == 0){
    ans = "Yes";
  }
  cout << ans << endl;  
}

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

int main(){
    int n;
    cin >> n;
    double ans = 0;
    double x;
    string u;
    for (int i = 0; i < n; i++){
        cin >> x >> u;
        if (u == "JPY"){
            ans += x;
        }else{
            ans += 380000.0*x;
        }
    }

    cout << fixed << setprecision(12) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

void dfs(int v, vvt<int> &edge, vt<int> &cnt, int p = -1) {
  for(auto &nxt : edge[v]) {
    if(nxt == p) continue;

    cnt[nxt] += cnt[v];
    dfs(nxt, edge, cnt, v);
  }
}

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

  int n, q;
  cin >> n >> q;
  vvt<int> edge(n);
  rep(i, 0, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  vt<int> cnt(n, 0);
  rep(i, 0, q) {
    int p, x;
    cin >> p >> x;
    cnt[p - 1] += x;
  }

  dfs(0, edge, cnt);
  rep(i, 0, n) cout << cnt[i] << " \n"[i + 1 == n];
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

const int N = 1e3 + 5;
int dist[N][N];

int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
int h, w;
string s[N];

bool ok(int r, int c) {
    return r >= 0 && r < h && c >= 0 && c < w;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> h >> w;
    int sr, sc, er, ec;
    cin >> sr >> sc >> er >> ec;
    sr--, sc--, er--, ec--;
    int inf = h * w + 69;
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            dist[i][j] = inf;
        }
    }

    deque<pii> q;
    dist[sr][sc] = 0;
    q.push_front(mp(sr, sc));
    while (!q.empty()) {
        pii cur = q.front();
        q.pop_front();
        for (int i = 0; i < 4; i++) {
            int nr = cur.fi + dr[i], nc = cur.se + dc[i];
            if (ok(nr, nc)) {
                if (s[nr][nc] == '.' && dist[cur.fi][cur.se] < dist[nr][nc]) {
                    dist[nr][nc] = dist[cur.fi][cur.se];
                    q.push_front(mp(nr, nc));
                }
            }
        }
        for (int i = -2; i <= 2; i++) {
            for (int j = -2; j <= 2; j++) {
                if (i == j && j == 0) continue;
                int a = abs(i), b = abs(j);
                if (a > b) swap(a, b);
                if (a == 0 && b == 1) continue;

                int nr = cur.fi + i, nc = cur.se + j;
                if (ok(nr, nc) && s[nr][nc] == '.' && dist[cur.fi][cur.se] + 1 < dist[nr][nc]) {
                    dist[nr][nc] = dist[cur.fi][cur.se] + 1;
                    q.push_back(mp(nr, nc));
                }
            }
        }
    }
    if (dist[er][ec] == inf) dist[er][ec] = -1;
    cout << dist[er][ec] << '\n';
    return 0;
}


Measured memory_bytes: 8756
//h
#include <stdio.h>

int main(){
	int n, k, result = 1;
	
	scanf ("%d %d", &n, &k);
	for (int i = 0; i<n; i++)
	{
		if (result*2 < result +k)
		{
			result = result*2;
		}
		else if (result*2 > result +k)
		{
			result= result+k;
		}
		else if (result*2 == result+k)
		{
			result = result+k;
		}
	}
	printf ("%d\n",result);
	return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

char get_op(int i){
    if(i==1){
        return '+';
    }else{
        return '-';
    }
}


int main()
{

    int A=0,B=0,C=0,D=0,tmp;
    string S,ans;
    cin >> S;

    A=S[0]-'0';
    B=S[1]-'0';
    C=S[2]-'0';
    D=S[3]-'0';

    for(int i=1;i<=2;i++){
        for(int j=1;j<=2;j++){
            for(int k=1;k<=2;k++){
                tmp =A;
                if(i==1){
                    tmp+=B;
                }else{
                    tmp-=B;
                }

                if(j==1){
                    tmp+=C;
                }else{
                    tmp-=C;
                }

                if(k==1){
                    tmp+=D;
                }else{
                    tmp-=D;
                }

                if(tmp==7){
                    ans = to_string(A) + get_op(i) + to_string(B) + get_op(j) + to_string(C) + get_op(k) + to_string(D) + "=7";
                }
            }
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

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


int main(){
    int n;
    cin>>n;
    cout<<(n*n*n)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using v = vector<ll>;
void a(){
    string s,t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(u==s){
        cout << a-1 << " "<<b;
    }else{
        cout << a << " "<<b-1;
    }
}

void b(){
    string s;
    cin >> s;
    for(auto i:s){
        cout << 'x';
    }
}

void c(){
    int n;
    cin >> n;
    auto a = map<int,int>();
    for(ll i=0;i<n;i++){
        int t;
        cin >> t;
        if(a[t]!=0){
            cout << "NO";
            return;
        }
        a[t]++;
    }
    cout << "YES";
}
int main(){
    c();
    return 0;
}

Measured memory_bytes: 9600
n = int(input())
p = list(map(int,input().split()))
counter = 0
for i in range(len(p) - 2):
  if (p[i] < p[i+1] and p[i+1] < p[i+2]) or (p[i] > p[i+1] and p[i+1] > p[i+2]):
    counter += 1
print(counter)

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

int main()
{
	string s;
	cin>>s;
	
	int v0=0,v1=0;
	for(int i=0;i<s.length();i++){
		if(i%2==0&&s[i]=='1') v0++;
		if(i%2==1&&s[i]=='0') v0++;
	}
	for(int i=0;i<s.length();i++){
		if(i%2==0&&s[i]=='0') v1++;
		if(i%2==1&&s[i]=='1') v1++;
	}
	
	cout<<min(v0,v1)<<endl;
	
	return 0;
}


Measured memory_bytes: 512
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

getNum :: IO Int
getNum = fst . fromJust . B.readInt <$> B.getLine

getNums :: IO [Int]
getNums = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]

main :: IO ()
main = do
    -- n <- getNum
    -- ns <- getNums
    -- print n
    -- print ns
    [c1,_,_] <-getLine
    [_,c2,_] <-getLine
    [_,_,c3] <-getLine
    putStrLn [c1,c2,c3]


Measured memory_bytes: 380
def inpl(): return list(map(int, input().split()))

N, L = inpl()
DP = [0]*(L+1)
for i in range(N):
    DP2 = [0]*(L+1)
    w, v = inpl()
    for i in range(w):
        DP2[i] = DP[i]
    for j in range(L-w+1):
        DP2[j+w] = max(DP[j] + v, DP2[j+w-1], DP[j+w])
    DP = DP2
print(DP2[-1])

Measured memory_bytes: 70688
n = int(input())
Jobs = []
for i in range(n):
    Jobs.append(list(map(int, input().split())))

Jobs.sort(key=lambda x: x[1], reverse=True)
#print(Jobs)
now = Jobs[0][1]
for time, deadline in Jobs:
    if now < deadline:
        now -= time
    else:
        now = deadline
        now -= time
    #print(now)
if now < 0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 88152
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  string a, b, c;
  cin >> a >> b >> c;

  if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES";
  else cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,test,x;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    //cin>>test;
    test=1;
    while (test--)
    {
        cin>>n;
        x=1000-(n%1000);
        if (x==1000) x=0;
        cout<<x;
    }


 }

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


void solve(long long n, std::vector<long long> a){
    vector<int> b;
    for(int i = 0; i < (int)n; ++i){
        if(i % 2 == 0) b.push_back((int)a[i]);
        else b.insert(b.begin(), (int)a[i]);
        //reverse(b.begin(), b.end());
    }
    if(n % 2 != 0) reverse(b.begin(), b.end());
    cout << b[0];
    for(int i = 1; i < (int)n; ++i) cout << " " << b[i];
    cout << endl;
}

int main(){
    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    solve(n, std::move(a));
    return 0;
}


Measured memory_bytes: 4596
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>

#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rep0(i, n) for(ll i = (0); i < (n); i++)
#define repd(i,m,n) for(ll i=(m); i > (n); i--)
#define iter(el, arr) for(auto& el : arr)
#define FOR(i,a,b) for(ll i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(ll i = (b) - 1; i >= (a); --i)
#define REPEAT(i) FOR(counter1234,0,i)
#define ALL(a) a.begin(), a.end()

#define ld long double
#define ll long long
#define ull unsigned ll
#define pii pair<int, int>
#define pll pair<ll,ll>
#define plli pair<pll,ll>
#define MP make_pair
#define SZ(a) ll((a).size())
#define X first
#define Y second

#define endl '\n'
#define PB push_back
#define has(i, m) (m.find(i) != m.end())

#define vi vector<int>
#define vll vector<ll>
#define vch vector<char>
#define vvi vector<vi>
#define vvll vector<vll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vb vector<bool>
#define vvb vector<vb>
#define pdd pair<ld, ld>
#define vpll vector<pll>
#define vpdd vector<pdd>
#define pq priority_queue
#define mod 1000000007
using namespace std;

const ll INF = 1e18;
const ll MAXN = 100001;

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	int h;
	int w;
	int n;
	cin >> h >> w >> n;

	vi a(n + 1);
	FOR(i, 0, n)
		cin >> a[i + 1];


	vvi c;
	vi vvv(w + 1);
	c.assign(h + 1, vvv);

	pii next = MP(1, 1);
	bool right = true;
	int curr = 1;

	vi colors;
	colors.push_back(0);
	FOR(i, 1, n + 1)
		FOR(j, 0, a[i])
		colors.push_back(i);
		

	FOR(i, 1, h + 1)
	{
		if (i % 2 == 1)
		{
			FOR(j, 1 + (i - 1)*w, i*w + 1)
				cout << colors[j] << " ";
		}
		else
		{
			RFOR(j, i*w + 1, 1 + (i - 1)*w)
				cout << colors[j] << " ";
		}
		cout << endl;
	}
	

	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

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

  rep(i, n - 1) a[i + 1] += a[i];
  int p = 0, r = 2;
  ll ans = INF;
  FOR(q, 1, n - 2) {
    while (abs(a[q] - a[p] * 2) >= abs(a[q] - a[p + 1] * 2) && p < q) p++;
    while (abs(a[n - 1] + a[q] - 2 * a[r]) >= abs(a[n - 1] + a[q] - 2 * a[r + 1]) || r <= q) r++;

    vector<ll> res(4);
    res[0] = a[p], res[1] = a[q] - a[p], res[2] = a[r] - a[q], res[3] = a[n - 1] - a[r];
    sort(res.begin(), res.end());
    ans = min(ans, res[3] - res[0]);
  }
  cout << ans << endl;



  
  return 0;
}

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

#define PI 3.141592653589793238

int main(void) {
  int r;
  scanf("%d", &r);
  printf("%f\n", (float) r * (float) 2 * (float) PI);

  return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

struct DisjointSet{
    vector<int> p;
    DisjointSet(int n) : p(n){
        rep(i,n) p[i] = -1;
    }

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

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

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        if(rx > ry) swap(rx,ry);
        p[rx] += p[ry];
        p[ry] = rx;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main()
{
    int n, m, k; cin >> n >> m >> k;
    int a[m], b[m];
    rep(i,m) cin >> a[i] >> b[i], --a[i], --b[i];
    int c[k], d[k];
    rep(i,k) cin >> c[i] >> d[i], --c[i], --d[i];

    DisjointSet fdis = DisjointSet(n);
    DisjointSet bdis = DisjointSet(n);

    int fnum[n]; rep(i,n) fnum[i] = 0;
    int bnum[n]; rep(i,n) bnum[i] = 0;

    rep(i,m){
        fdis.unite(a[i], b[i]);
        fnum[a[i]]++;
        fnum[b[i]]++;
    }
    rep(i,k){
        if(fdis.same(c[i], d[i])){
            bnum[c[i]]++;
            bnum[d[i]]++;
        }
    }

    rep(i,n){
        cout << (fdis.size(i)-1 - fnum[i] - bnum[i]);
        if(i != n-1) cout << " ";
    }cout << endl;
}

Measured memory_bytes: 6328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<pii> at(n);
    for(int i=0;i<n;i++){
        int j;
        cin >> j;

        at[i].first=j;
        at[i].second=i+1;
    }

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

    for(auto x:at){
        cout << x.second << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3944
m, d = map(int, input().split())

res = 0
for month in range(1, m + 1):
    for day in range(1, d + 1):
        d10 = day // 10
        d1 = day % 10
        if d1 >= 2 and d10 >= 2 and d1 * d10 == month:
            res += 1

print(int(res))

Measured memory_bytes: 38896
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#define pb push_back
#define mp make_pair
using namespace std;
const int N=2e5+5;

int n,k;
int a[N];

map <int,int> my_map;
map <int,int>::iterator it;

vector <int> v;

int ans;

int main()
{
   int i;

   scanf("%d%d", &n, &k);
   for(i=1;i<=n;i++)
   {
       scanf("%d", &a[i]);
       my_map[a[i]]++;
   }

   for(it=my_map.begin();it!=my_map.end();++it)
   {
       v.pb(it->second);
   }
   sort(v.begin(),v.end());

   int need=v.size()-k;

   for(i=0;i<need;i++)
   {
       ans+=v[i];
   }

   printf("%d\n", ans);

   return 0;
}


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

const int MAX_N = 10000;
int Par[MAX_N];
int Rank[MAX_N];

void init_union_find(int n){
	for(int i=0; i<n; ++i){
		Par[i] = i;
		Rank[i] = 0;
	}
}

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

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

	if(x == y)
		return ;

	if(Rank[x] < Rank[y]){
		Par[x] = y;
	} else{
		Par[y] = x;
		if(Rank[x] == Rank[y]){
			++Rank[x];
		}
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

struct edge {
	int from,
		to,
		cost;
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

const int MAX_E = 10000;
edge es[MAX_E];
int V, E;

int kruskal(void){
	sort(es, es + E, comp);
	init_union_find(V);

	int res = 0;
	for(int i=0; i<E; ++i){
		edge e = es[i];
		if(!same(e.from, e.to)){
			unite(e.from, e.to);
			res += e.cost;
		}
	}

	return res;
}

int main(void){
	while(true){
		cin >> V >> E;
		if( V == 0 && E == 0 )
			break;
		for(int i=0; i<E; i++){
			cin >> es[i].from >> es[i].to >> es[i].cost;
		}

		cout << kruskal() << endl;
	}
}

Measured memory_bytes: 1192
h,w,a,b=map(int,input().split())

lista=[]

for i in range(h):
    lista.append([0]*w)

if (a>w/2)|(b>h/2):
    print("No")

else:
    if h==1:
        for i in range(w-a):
            lista[0][a+i]=1
    elif w==1:
        for i in range(h-b):
            lista[b+i][0]=1

    elif (a==0)&(b==0):
        lista=lista

    else:  
        for i in range(w-a):
            lista[0][a+i]=1
        
           
        if a==0:    
            for i in range(w):
                for j in range(b):
                    lista[j][i]=1 
        elif b==0:    
            for i in range(h):
                for j in range(w-a):
                    lista[i][j+a]=1                         
        else:    
            for i in range(a):
                for j in range(h-b):
                    lista[b+j][i]=1 
            for i in range(b):
                for j in range(w-a):
                    lista[i][a+j]=1


 

    for i in range(h):
        row = ""
        for j in range(w):
            row += str(lista[i][j])
        print(row)

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

using namespace std;
int main() {
  int n, d, x;
  cin >> n >> d >> x;
  int eat = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    int day = 0;
    for (int j = 0; j < 100; j++) {
      day = j * a + 1;
      if (day <= d)
        eat++;
      else
        break;
    }
  }
  cout << eat+ x << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 6005;
const ll mod = 1e9+7;
const ll inf = 0x3f3f3f3f3f3f3f;
#define ms(a,k)  memset(a,k,sizeof(a))
map<int,int>vis;
int main()
{
    int n,m,k,a;
    cin>>n>>m;
    int t=n;
    while(t--)
    {
       cin>>k;
       for(int i=0;i<k;i++)
       {
           cin>>a;
           vis[a]++;
       }
    }
    int cntt=0;
    //for(int i=1;i<=m;i++)printf("%d ",vis[i]);
    for(int i=1;i<=m;i++)if(vis[i]==n)cntt++;

    printf("%d\n",cntt);

    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 a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();
        System.out.println(socialGame(a,b,c));
    }

public static int socialGame(int coinPerDay, int coinBonusWeek, int totalCoin){
        int dayPaid = 0;
        int coinInWeek = 7*coinPerDay + coinBonusWeek;
        int redundant = totalCoin%coinInWeek;
        int weekPaid = totalCoin/coinInWeek;


        if (redundant == 0){
            dayPaid = 7*weekPaid;
        }else if (redundant > 7*coinPerDay){
            dayPaid = 7*(weekPaid+1);
        }else {
            dayPaid = 7*weekPaid + redundant/coinPerDay;
            if (redundant % coinPerDay != 0){
                dayPaid++;
            }
        }

        return dayPaid;
    }

}


Measured memory_bytes: 26348
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cmath>
#include<iterator>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	vector< vector<int> >vec;
	int i,j,v;
	for(i=0; i<n; i++)
	{
		vector<int>temp;
		for(j=0; j<3; j++)
		{
			cin>>v;
			temp.push_back(v);
		}
		vec.push_back(temp);
	}
	ll dp[n][3];
	for(i=0; i<n; i++)
	{
		for(j=0; j<3; j++)
		{
			dp[i][j]=0;
		}
	}
	dp[0][0]=vec[0][0];
	dp[0][1]=vec[0][1];
	dp[0][2]=vec[0][2];
	for(i=1; i<n; i++)
	{
		for(j=0; j<3; j++)
		{
			if(j==0)
			{
				dp[i][0]=vec[i][0]+max(dp[i-1][1],dp[i-1][2]);	
			}
			else if(j==1)
			{
				dp[i][1]=vec[i][1]+max(dp[i-1][0],dp[i-1][2]);
			}
			else
			{
				dp[i][2]=vec[i][2]+max(dp[i-1][0],dp[i-1][1]);
			}
		}
	}
	ll max1=max(dp[n-1][0],dp[n-1][1]);
	max1=max(max1,dp[n-1][2]);
	cout<<max1<<"\n";
	return 0;
}


Measured memory_bytes: 8240
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n,k;
    scanf("%d %d",&n,&k);
    vector<int> p(n,0),t(n-k+1,0),sm(n-k+1,0);
    for (int i = 0; i < n; i++) scanf("%d",&p[i]);
    int cnt = 0, j = 1;
    for (int i = 0; i < n - k + 1; i++) {
        while (j < i + k) {
            if (p[j-1]>p[j]) cnt++;
            j++;
        }
        t[i] = cnt;
        if (p[i] > p[i+1]) cnt--;
    }
    set<int> s;
    int  l = 0;
    for (int i = 0; i < n - k; i++) {
        while (l < i + k + 1) s.insert(p[l++]);
        if (*s.begin() == p[i] && *prev(s.end()) == p[l - 1]) sm[i + 1] = 1;
        s.erase(p[i]);
    }
    int ans = 0, z = 0;
    for (int i = 0; i < n - k + 1; i++) if (!sm[i]) {
        if (t[i]) ans++;
        else z++;
    }
    ans += bool(z);
    printf("%d\n",ans);
}

Measured memory_bytes: 10368
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int N,a[20],i,max,H;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&a[i]);
	max=a[0];
	for(H=1,i=1;i<N;i++)
	{
		if(a[i]>=max)
		{H++;max=a[i];}
	}
	printf("%d\n",H);
	return 0;
}


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

using namespace std;

int n,m,a,b;

int main(){
    int i,j;
    cin>>n>>m>>a>>b;
    if(a<=m && b<=n){
        for(i=0;i<n;++i){
            for(j=0;j<m;++j){
                if(i>=b){
                    if(j>=a)
                        cout<<0;
                    else
                        cout<<1;
                }else if(j>=a){
                    if(i>=b)
                        cout<<0;
                    else
                        cout<<1;
                }else
                    cout<<0;
            }cout<<'\n';
        }
    }else
        cout<<-1;
    return 0;
}


Measured memory_bytes: 1280
import sys
from math import sqrt, gcd, ceil, log
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

def main():
	n, k = read(); arr = read()
	for i in range(k, n):
		print("YNeos"[arr[i] <= arr[i-k]::2])






if __name__ == "__main__":
	main()

Measured memory_bytes: 94260
import sys
sys.setrecursionlimit(100100)


S=input()
N=len(S)

table=[-1 for i in range(N)]

def dp(n):
  if S[n]=='R' and S[n+1]=='L':
    return n;
  if S[n]=='L' and S[n-1]=='R':
    return n;
  if table[n]>-1:
    return table[n]
  
  if S[n]=='R':
    if S[dp(n+1)]=='R':
      table[n]=dp(n+1)+1
    else:
      table[n]=dp(n+1)-1
  else:
    if S[dp(n-1)]=='R':
      table[n]=dp(n-1)+1
    else:
      table[n]=dp(n-1)-1
  
  
  return table[n]





list=[0 for i in range(N)]
for i in range(N):
  list[dp(i)]+=1
  
for ans in list:
  print(ans,end=" ")
print()
  

Measured memory_bytes: 92448
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 100000;
int n;
vector<pair<pair<int, int>, int> > ed, p;
int parent[N];
int find(int u) {
	if (parent[u] == u)
		return u;
	return parent[u] = find(parent[u]);
}
int main() {
	scanf("%d", &n);
	p.resize(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", &p[i].first.first, &p[i].first.second);
		p[i].second = i;
	}
	sort(p.begin(), p.end());
	for (int i = 0; i + 1 < p.size(); ++i)
		ed.push_back(make_pair(make_pair(p[i + 1].first.first - p[i].first.first, p[i].second), p[i + 1].second));
	for (int i = 0; i < p.size(); ++i)
		swap(p[i].first.first, p[i].first.second);
	sort(p.begin(), p.end());
	for (int i = 0; i + 1 < p.size(); ++i)
		ed.push_back(make_pair(make_pair(p[i + 1].first.first - p[i].first.first, p[i].second), p[i + 1].second));
	sort(ed.begin(), ed.end());
	for (int i = 0; i < n; ++i)
		parent[i] = i;
	ll res = 0;
	for (int i = 0; i < ed.size(); ++i) {
		int a = ed[i].first.second;
		int b = ed[i].second;
		a = find(a);
		b = find(b);
		if (a != b) {
			res += ed[i].first.first;
			parent[a] = b;
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5876
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
        static string[] Grid;
        static int H,W;
  
        static void Main(string[] args)
        {
          //入力を受け取る
          int[] HW = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          H = HW[0];
          W = HW[1];
          Grid = new string[H];
          
          //グリッドを初期化
          for(int i = 0;i < H ; i++){
            //行の情報を受け取る
            Grid[i] = Console.ReadLine();
          }
          
          //行の情報を登録する
          int[,] Row = new int[H,W];
          
          for(int i = 0;i < H ; i++){
            for(int j = 0;j < W ; j++){
              if(Grid[i][j] == '#'){
                  //対象の列に-1を登録
                  Row[i,j] = -1;
              }else{
                  //次の#にあたるまでの.の数を求める
                  var next = RowNext(i,j);
                  for(int k = 0; k < next ; k++){
                    Row[i,j+k] = next;
                  }
                  j += next-1;
                }
            }
          }
          
          //列の情報を登録する
          int[,] Column = new int[H,W];
          
          for(int i = 0;i < W ; i++){
            for(int j = 0;j < H ; j++){
              if(Grid[j][i] == '#'){
                  //対象の行に-1を登録
                  Column[j,i] = -1;
              }else{
                  //次の#にあたるまでの.の数を求める
                  
                  var next = ColumnNext(j,i);
                
                  for(int k = 0; k < next ; k++){
                    
                    Column[j+k,i] = next;
                  }
                  //Console.WriteLine("Row:"+j+"Column:"+i+"next:"+next);
                  j += next-1;
                }
            }
          }
          
          int[,] Result = new int[H,W];
          var max = 0;
          
          for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
              if(!(Row[i,j] == -1 || Column[i,j] == -1)){
                if(max < Row[i,j]+Column[i,j]-1){
                  max = Row[i,j]+Column[i,j]-1;
                }
              }
            }
          }
          
          for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
              //Console.WriteLine(Result[i,j]);
            }
          }
          Console.WriteLine(max);
          //Console.WriteLine(Column[0,1]);
        }
  

  
  static int RowNext(int Row,int Column){
    int count = 0;
    while(Column < W && Grid[Row][Column] == '.'){
      count++;
      Column++;
    }
    return count;
  }
  
  static int ColumnNext(int Row,int Column){
    int count = 0;
    while(Row < H && Grid[Row][Column] == '.'){
      count++;
      Row++;
    }
    return count;
  }
  
 }

Measured memory_bytes: 61128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << 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; }

int main(){
  ll a, b, k;
  cin >> a >> b >> k;
  ll c = min(a, b);
  ll count = 0;
  while(count<k){
    if(a%c==0&&b%c==0){
      count++;
    }
    c--;
  }
  print(c + 1);
}

Measured memory_bytes: 256
n=int(input())
squre=int(n**0.5)

A=[0 for _ in range(10**6)]
for x in range(1,squre+1):
    for y in range(1,squre+1):
        for z in range(1,squre+1):
            num=x**2+y**2+z**2+x*y+y*z+z*x
            A[num] +=1

for i in range(n):
    print(A[i+1])

Measured memory_bytes: 142168