akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int N;
    cin >> N;
    int H[N];
    int temp=0;
    int count=0;
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> H[i];
        if(temp>=H[i]){
            count++;
        }else{
            count=0;
        }
        if(count>=ans){
            ans=count;
        }
        temp=H[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int h,w,k;
    cin>>h>>w>>k;
    char s[h][w];
    rep(i,h){
        rep(j,w)cin>>s[i][j];
    }
    int ans=0;
    rep(i,(1<<h)){
        rep(j,(1<<w)){
            int cnt=0;
            rep(I,h){
                rep(J,w){
                    if((i>>I&1)||(j>>J&1))continue;
                    else if(s[I][J]=='#')cnt++;
                }
            }
            if(cnt==k)ans++;
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3648
#include <stdio.h>

int main(void){

   int k,x,i,s;
   scanf("%d %d",&k,&x);
   s=k-1;
   for(i=-s;i<=s;i++){
   if(-1000000<=x+i && x+i<=1000000)
   printf("%d ",x+i);
   }   
}
    

Measured memory_bytes: 128
#include<stdio.h>  
    main(){  
      int a,b,e;  
      for(e=0;e<4;e++){  
        scanf("%d %d",&a,&b);  
        if(a==1){  
          printf("%d\n",b*6000);  
        }  
        else if(a==2){  
          printf("%d\n",b*4000);  
        }  
        else if(a==3){  
          printf("%d\n",b*3000);  
        }  
        else if(a==4){  
          printf("%d\n",b*2000);  
        }  
      }  
      return 0;  
    }  

Measured memory_bytes: 1028
#include<queue>
#include<cstdio>
#include<algorithm>

#define	mp	make_pair

using namespace std;

typedef	pair<int,int>	pii;
typedef	pair<pii,int>	ppiii;

const int inf=1<<29,dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int inst[30][30],memo[30][30][4];

int main(){
	for(int w,h;scanf("%d%d",&w,&h),w;){
		int cost[4];
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)	scanf("%d",inst[i]+j),inst[i][j];
		for(int i=0;i<4;i++)	scanf("%d",cost+i);

		for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int k=0;k<4;k++)	memo[i][j][k]=inf;

		priority_queue< pair<int,ppiii> > pq;
		pq.push(mp(0,mp(mp(0,0),0)));
		while(!pq.empty()){
			pair<int,ppiii> a=pq.top();	pq.pop();
			int nowcost=-a.first;
			int y=a.second.first.first;
			int x=a.second.first.second;
			int dir=a.second.second;
			if(y==h-1 && x==w-1)	break;

			for(int i=0;i<4;i++){
				int nextdir=(dir+4-i)%4;
				int yy=y+dy[nextdir],xx=x+dx[nextdir];
				if(yy<0 || h<=yy || xx<0 || w<=xx)	continue;

				int nextcost=nowcost+(inst[y][x]==i?0:cost[i]);
				if(nextcost<memo[yy][xx][nextdir]){
					memo[yy][xx][nextdir]=nextcost;
					pq.push(mp(-nextcost,mp(mp(yy,xx),nextdir)));
				}
			}
		}

		printf("%d\n",min(memo[h-1][w-1][0],memo[h-1][w-1][3]));
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define M 100005
#define rint register int
LL Ans;
struct Node {
	int a,b;
	bool operator <(const Node &_)const {
		return a<_.a;
	}
} A[M];
priority_queue<int>Q;
int n,m;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i)scanf("%d%d",&A[i].a,&A[i].b);
	sort(A+1,A+1+n);
	for(int i=1,j=1; i<=m; ++i) {
		while(A[j].a<=i&&j<=n)Q.push(A[j].b),++j;
		if(!Q.empty()) {
			Ans+=Q.top();
			Q.pop();
		}
	}
	printf("%lld",Ans);
}


Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef long long ll;
#define endl '\n'

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

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

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

	int N; cin >> N;
	vector<ll> v(N);

	const ll MAX = 1000000000000000000LL;

	for (int i = 0; i < N; i++) {
		cin >> v[i];
		if (v[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	ll ans = 1;
	for (int i = 0; i < N; i++) {
		ll m = MAX / ans;
		if (v[i] > m) {
			cout << -1 << endl;
			return 0;
		}
		ans *= v[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3552
'''
Date         : 2020-08-08 22:19:33
Author       : ssyze
Description  : 
'''
from math import *
n, d = map(int, input().split())
n = int(n)
ans = 0
for i in range(n):
    x, y = map(int, input().split())
    if x * x + y * y <= d * d:
        ans += 1
print(ans)


Measured memory_bytes: 69840
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

struct Data
{
	int b, c;

	Data()
	{

	}

	Data(int b, int c)
	{
		this->b = b;
		this->c = c;
	}
};

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

	vector<int> a(n);

	map<int, int> x;

	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
	}
	for (int i = 0; i < m; i++)
	{
		int b, c;
		cin >> b >> c;

		x[c] += b;
	}

	vector<Data> d;
	for (map<int, int>::iterator it = x.begin(); it != x.end(); it++)
	{
		pair<int, int> i = *it;
		d.push_back(Data(i.second, i.first));
	}

	sort(a.begin(), a.end());
	sort(d.begin(), d.end(), [](const Data &a, const Data &b)
	{
		return a.c < b.c;
	});

	uint64_t sum = 0;
	int di = d.size() - 1;
	for (int i = 0; i < a.size(); i++)
	{
		if (di >= 0)
		{
			if (a.at(i) < d.at(di).c)
			{
				a.at(i) = d.at(di).c;
			}

			d.at(di).b--;

			if (d.at(di).b == 0)
			{
				di--;
			}
		}

		sum += a.at(i);
	}

	cout << sum << endl;
}

Measured memory_bytes: 6520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}


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

  int N; cin >> N;
  for(ll n = 1LL; n <= 3500; n++) for(ll w = 1LL; w <= 3500; w++) {
    ll s = (4 * n * w - ( n + w ) * N );
    ll t = ( N * n * w );
    if( s > 0 and t % s == 0 ){
      ll h = t / s;
      cout << h << " " << n << " " << w << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <tuple>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int N;
vector<ii> adj_list[100001];
int color[100001];

int dfs(int curr)
{
    // cerr << "curr: " << curr << endl;

    for (auto &pair : adj_list[curr])
    {
        int node = pair.first;
        int dist = pair.second;
        if (color[node] == 0)
        {
            int c = 2 - (dist + color[curr]) % 2;
            color[node] = c;
            dfs(node);
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> N;

    int u, v, w;
    rep(i, N - 1)
    {
        cin >> u >> v >> w;
        adj_list[u].emplace_back(v, w);
        adj_list[v].emplace_back(u, w);
    }

    color[1] = 2;
    dfs(1);

    for (int i = 1; i <= N; ++i)
        cout << color[i] % 2 << endl;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

// https://ferin-tech.hatenablog.com/entry/2017/01/24/184750

vvll g(10010, vll());
queue<ll> q;
vll pl(10010, 0);
vi visited(10010, 0);
vll score;
ll cnt = 0;

// https://pyteyon.hatenablog.com/entry/2019/03/01/211133
void bfs(){
    while (!q.empty()) {
        // キューの先頭の要素を取り出す dequeue(pop)
        ll now = q.front(); q.pop();
        visited[now] = 1;
        pl[now] = score[cnt];
        cnt++;

        // 停止条件
        // if (now.hoge == target) return ~;  // 探索対象

        // BFS
        for (int i = 0; i < SZ(g[now]); ++i) {
            ll next = g[now][i];  // 深さ（ステップ数）を一つ足す
            if (!visited[next]) {
                // 条件を満たしたら enqueue(push)
                // 問題により，同じ状態に戻らないようにする処理を書く（無限ループを防ぐ）
                q.push(next);
            }
        }
    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll a, b;
    rep(i, n-1){
        cin >> a >> b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    rep(i, n){
        ll c;
        cin >> c;
        score.emplace_back(c);
    }
    sort(ALL(score));
    ll maxscore = accumulate(score.begin(), --score.end(), 0LL);
    cout << maxscore << endl;
    reverse(ALL(score));
    
    q.push(1);
    bfs();
    
    rea(i, 1, n+1){
        if(pl[i]) cout << pl[i] << (i < n ? " " : "\n");
    }
    
    return 0;
    
}

Measured memory_bytes: 1280
#include<iostream>
#include<string.h>
using namespace std;
#define WHITE 0
#define GLAY 1
#define BLACK 2
#define INFTY 1000000
int MAP[100][100],color[100],d[100];
int main()
{
	memset(MAP,INFTY,sizeof(MAP));
	int n,u,k,v,c;
	int minv;
	cin >> n ;
	for(int i = 0; i < n; i++){
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			cin >> v >> c;
			MAP[u][v] = c;
		}
	}
	for(int i=0;i<n;i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	d[0] = 0;
	color[0] = GLAY;
	while(1){
		minv = INFTY;
		int u = -1;
		for(int i=0;i<n;i++){
			if(minv > d[i] && color[i] != BLACK ){
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		for(int v=0;v<n;v++){
			if(color[v] != BLACK && MAP[u][v] != INFTY){
				if(d[v] > d[u] + MAP[u][v]){	//d[v]:??????
					d[v] = d[u] + MAP[u][v];
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << i << " " << ( d[i]==INFTY ? -1 : d[i]) << endl;
	}
 	return 0;
}

Measured memory_bytes: 1208
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        n = n % k;

        while (true) {
            if (n <= Math.abs(n - k)) {
                break;
            }
            n = Math.abs(n - k);
        }
        System.out.println(n);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;

int main() {
    int N;cin>>N;
    vi A(N),B(N),C(N-1);
    for (int i = 0; i < N; i++){
        cin>>A[i]; A[i]--;
    }
    for (int i = 0; i < N; i++){
        cin>>B[i];
    }
    for (int i = 0; i < N-1; i++){
        cin>>C[i];
    }
    int ans=0;
    for (int i = 0; i < N; i++){
        ans+=B[i];
        if(i!=N-1 && A[i+1]==A[i]+1)ans+=C[A[i]];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
// Author :
// Date :
// Problem:
// Solution:
// Comment:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstring>

#define pp push
#define pb push_back
#define mp make_pair
#define xx first
#define yy second

using namespace std;

main(){
    vector <string> name;
    int n,m;
    string q;
    
    cin >> n;
    
    for(int i = 0 ; i < n ; i++){
        cin >> q;
        name.pb(q);
    }
    
    cin >> m;
    
    int condition = 0;
    for(int i = 0 ; i < m ; i++){
        cin >> q;
    
        int flag = 0;    
        for(int i = 0 ; i < n ; i++){
            if(q == name[i]) flag = 1;
        }
        
        if(flag == 1){
            if(condition == 0){
                cout << "Opened by " << q << endl;
                condition = 1;
            }
            else{
                cout << "Closed by " << q << endl;
                condition = 0;
            }
        }
        else{
            cout << "Unknown " << q << endl;
        }
    }
    #ifdef GEREL
        for(;;);
    #endif

    return 0;
}

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

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

using namespace std;
using lint=long long;

class mint{
	static const int MOD=1e9+7; // 998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	mint ans=0;
	rep(i,60){
		int cnt[2]={};
		rep(j,n) cnt[a[j]>>i&1]++;
		ans+=mint(1LL<<i)*cnt[0]*cnt[1];
	}
	printf("%d\n",ans.to_int());

	return 0;
}


Measured memory_bytes: 2560
str=input()
q = int(input())
for i in range(q):
    s = input().split()

    command = s[0]
    a=int(s[1])
    b=int(s[2])

    if command=="print":
        print(str[a:b+1])
    elif command=="reverse":
        restr=str[a:b+1]
        restr=restr[::-1]
        str = str[:a]+restr+str[b+1:]
        #print(str)
    elif command=="replace":
        p=s[3]
        str = str[:a]+p+str[b+1:]
        #print(str)



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

int main()
{
  int n;
  cin>>n;
  string s;
  set<string> ss;
  for(int i = 0; i < n; ++i)
  {
      cin>>s;
      ss.insert(s);
  }
  cout<<ss.size();
  return 0;
}


Measured memory_bytes: 15640
# coding: utf-8
# Your code here!

h,w,k = map(int,input().split())
x = []
for i in range(h):
    x.append(list(map(int,list(input().rstrip().replace(".","0").replace("#","1")))))
#print(x)
#h,w = 2,3
count = 0
for i in range(1,max(2,2**h)):
    y = list(map(int,format(i,"0"+str(h)+"b")))
    for j in range(1,max(2,2**w)):
        z = list(map(int,format(j,"0"+str(w)+"b")))
        #print(i,j,y,z)
        sum0 = 0
        for l in range(w):
            for m in range(h):
                sum0 += y[m] * z[l] * x[m][l]
        if sum0 ==k:
            count += 1
print(count)        


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

int main() {
  int N, M, C = 0;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  vector<vector<int>> A(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }
  int a = 0;
  int count = 0;
  for(int i = 0; i < N; i++) {
    a = C;
    for(int j = 0; j < M; j++) {
      a += A.at(i).at(j) * B.at(j);
    }
    if(a > 0) {
      count++;
    }
  }
  cout << count << endl;
}


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

using namespace std;

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

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

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

//container util
//------------------------------------------
#define ALL(d)  (d).begin(),(d).end()
#define RALL(d) (d).rbegin(), (d).rend()
#define PB push_back
#define MP make_pair
#define SZ(d) int((d).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,d,b) for(int i=(d);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(d) memset((d), 0 ,sizeof(d))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main()
{
	int n, ma, mb;
	cin >> n >> ma >> mb;
	VI a(n), b(n), c(n);
	REP(i, n) cin >> a[i] >> b[i] >> c[i];
	auto dp = vector<vector<vector<int>>>(n + 1);
	const int w = 400;
	REP(i, n + 1) {
		dp[i] = VVI(w + 1);
		REP(j, w + 1) {
			dp[i][j] = VI(w + 1);
			REP(k, w + 1) dp[i][j][k] = 10001;
		}
	}
	dp[0][0][0] = 0;	
	REP(i, n) REP(j, w + 1) REP(k, w + 1) {
		dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
		if(j + a[i] < w && j + b[i] < 400)
			dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
	}
	int ans = 10001;
	FOR(i, 1, w + 1) FOR(j, 1, w + 1) {
		if (i * mb == j * ma) ans = min(dp[n][i][j], ans);
	}
	if(ans != 10001) cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 26624
#include <iostream>
#include <cstring>
using namespace std;
int n,m,q;
char s[100005],t[100005];
int sa[100005],ta[100005];
int main(void){
    cin>>s>>t>>q;
    n=strlen(s);
    m=strlen(t);
    for(int i=1;i<=n;i++){
        if(s[i-1]=='A')sa[i]+=2;
        else sa[i]++;
        sa[i+1]+=sa[i];
    }
    for(int i=1;i<=m;i++){
        if(t[i-1]=='A')ta[i]+=2;
        else ta[i]++;
        ta[i+1]+=ta[i];
    }
    for(int i=0;i<q;i++){
        int r,l,x,y;
        scanf("%d%d%d%d",&r,&l,&x,&y);
        int o=sa[l]-sa[r-1],p=ta[y]-ta[x-1];
        if(abs(o-p)%3==0)cout<<"YES\n";
        else cout<<"NO\n";
    }
}


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

using namespace std;

const int maxn = 105;

int arr [maxn], actual [maxn];

int main () {
  int childc, candyc;
  cin >> childc >> candyc;

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

  sort(arr, arr + childc);

  for (int i = 0; i < childc; i++) {
    int add = min(candyc, arr[i]);
    actual[i] = add;
    candyc -= add;
  }

  arr[childc - 1] += candyc;

  int ans = 0;
  for (int i = 0; i < childc; i++) {
    ans += (int) (arr[i] == actual[i]);
  }
  cout << ans << endl;
}

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

int main() {

	unsigned long long N;
	vector<unsigned long long>A;

	cin >> N;

	unsigned long long B;

	for (unsigned long long i = 0; i < N; i++) {
		cin >> B;
		A.push_back(B);
	}

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

	bool jdg = true;
	for (unsigned long long i = 1; i < N; i++) {
		if (A[i - 1] == A[i]) {
			jdg = false;
			break;
		}
	}

	if (jdg == true){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static IEnumerable<string> EnumerateSubstrings(string str, int maxLength)
        {
            maxLength = Min(str.Length, maxLength);
            for (int length = 1; length <= maxLength; length++)
            {
                for (int startIndex = 0; startIndex < str.Length - length + 1; startIndex++)
                {
                    yield return str.Substring(startIndex, length);
                }
            }
        }

        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int k = int.Parse(Console.ReadLine());
            string ans = EnumerateSubstrings(s, k).Distinct().OrderBy(x => x).ElementAt(k - 1);
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 14944
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n,m;
	int a[101];

	cin>>n>>m;

	int t=0;
	rep(i,n){
		cin>>a[i];
		t+=a[i];
	}

	double x=double(t)/(4*m);
	int t2=0;
	rep(i,n){
		if(x<=a[i])t2++;
	}
	if(t2>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
def main():
    N,X = map(int,input().split())
    x = list(map(int,input().split()))
    for i in range(N):
        x[i] = abs(x[i]-X)
    from math import gcd
    g = x[0]
    for i in range(1,N):
        g = gcd(g,x[i])
    print(g)
main()

Measured memory_bytes: 85268
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
//string b="12345";
//a = int(b[4]-48);
using namespace std;
int main()
{
	long long H,cnts=0,cnt1=1,cnt2=1;
	vector<long long> M;
	cin >> H;

	while (H > 1) {
		H = ceil(H/2);
		cnts++;
	}
	
	for (int i = 0; i < cnts; i++) {
		cnt1 =  cnt1*2;
	}
	for (int i = 0; i < cnts; i++) {
		cnt2 = cnt2 * 2;
	}
	cout << cnt1+cnt2-1 << endl;
}

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

#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//map<int, int>::iterator itr; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        int n,k;cin>>n>>k;
        int arr[n+1],brr[n+1];
        for(int i=0;i<n;i++){
            cin>>arr[i];
            brr[i]=0;
        }
        int count=0;
        while(k--){
            for(int i=0;i<n;i++){
                int p=max(0,i-arr[i]);
                brr[p]+=1;
                p=min(n-1,i+arr[i]);
                brr[p+1]-=1;
            }
            for(int i=1;i<n;i++){
                brr[i]+=brr[i-1];
            }
            int f=1;
            for(int i=0;i<n;i++){
                arr[i]=brr[i];
                brr[i]=0;
                if(arr[i]!=n)
                f=0;
            }
            if(f==1)
            break;
        }
            for(int i=0;i<n;i++){
                cout<<arr[i]<<" ";
            }
    }
    return 0;
}


Measured memory_bytes: 5152
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  
  int h;
  int max=0,cnt=0;
  rep(i,n){
    cin>>h;
    if(h>=max) cnt++;
    if(h>max) max=h;
  }
  
  cout<<cnt<<endl;
  
  return 0;
}

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

using lint = long long;

const long long mod = 998244353;

template<class T>
struct SegTree {
	int n;
	vector<T> node;
	function<T(T, T)> f;
	T iniV;
	SegTree(vector<T> v, function<T(T, T)> f, T iniV): iniV(iniV), f(f) {
		int sz = v.size();
		n = 1; while (n < sz) n *= 2;
		node.resize(n * 2 - 1, iniV);
		for (int i = 0; i < sz; i++) node[i + n - 1] = v[i];
		for (int i = n - 2; i >= 0; i--) {
			node[i] = f(node[i * 2 + 1], node[i * 2 + 2]);
		}
	}
	T getOneVal(int x) {
		return node[x + n - 1];
	}
	void update(int x, T val) {
		x += n - 1;
		node[x] = val;
		while (x > 0) {
			x = (x - 1) / 2;
			node[x] = f(node[x * 2 + 1], node[x * 2 + 2]);
		}
	}
	T getval(int a, int b, int k = 0, int l = 0, int r = -1) {
		if (r < 0) r = n;
		if (r <= a || b <= l) return iniV;
		if (a <= l && r <= b) return node[k];
		T vl = getval(a, b, k * 2 + 1, l, (l + r) / 2);
		T vr = getval(a, b, k * 2 + 2, (l + r) / 2, r);
		return f(vl, vr);
	}
};

long long ff(long long a, long long b) {
	return (a + b) % mod;
}


int main() {
	int N, K;
	cin >> N >> K;
	int L[K], R[K];
	for (int i = 0; i < K; i++) cin >> L[i] >> R[i];

	
	vector<long long> dp(N + 1, 0LL);
	
	SegTree<long long> seg(dp, ff, 0LL);
	seg.update(1, 1LL);
	for (int i = 2; i <= N; i++) {
		lint val = 0LL;
		for (int j = 0; j < K; j++) {
			int idl;
			int idr;
			
			val += seg.getval(i - R[j], i - L[j] + 1);
			val %= mod;
		}
		seg.update(i, val);
	}

	cout << seg.getOneVal(N) << endl;
	return 0;
}


Measured memory_bytes: 10400
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
	public static final int TARO=0;
	public static final int HANAKO=1;
	public void exec() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        int[] point = new int[2];
        for(int i=0; i<n; i++) {
        	String[] cards = br.readLine().split(" ");
        	int cmp = cards[TARO].compareTo(cards[HANAKO]);
        	if (cmp < 0){
        		point[HANAKO] += 3;
        	} else if (0 < cmp) {
        		point[TARO] += 3;
        	} else {
        		point[TARO] ++;
        		point[HANAKO] ++;
        	}
        }
        out.printf("%d %d\n",point[TARO], point[HANAKO]);
        out.flush();
    }
  
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

Measured memory_bytes: 25612
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}


int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  if(A+B+C!=17)
  {
    cout<<"NO"<<endl;
    return 0;
  }
  if(A+B+C==17)
  {
    if(A*B*C==175)
    {
      cout<<"YES"<<endl;
      return 0;
    }
    else
    {
      cout<<"NO"<<endl;
    }
  }

}

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

int gcd(int a, int b) {
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

void Main() {
    // input
    int K;
    cin >> K;

    // translate
    // int gcds[K+1][K+1][K+1];
    u_int64_t ans = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                ans += gcd(gcd(i, j), k);
            }
        }    
    }

    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    string s;
    cin >> s;
    if (s[1] == 'B') 
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;

    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define IN freopen("pieaters.in","r",stdin)
#define OUT freopen("pieaters.out","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;

#define INF 2000000000
#define alpha 26

#define maxn 300010
#define LOG 18

vector <int> g[maxn] ;

i64 a[maxn] ;
int fl = 1 ;

void dfs( int u , int par )
{
    vector <int> vec ;

    i64 sum = 0 ;
    for(int v: g[u])
    {
        if( v==par ) continue ;
        dfs(v,u) ;
        vec.pb( a[v] ) ;
        sum += a[v] ;
    }
    sort(vec.begin(),vec.end()) ;
    reverse(vec.begin(),vec.end()) ;

    if(vec.size()==0) return ;

    if( vec.size() == 1 )
    {
        if( vec[0] != a[u] )
        {
            printf("NO\n") ;
            exit(0) ;
        }
        return ;
    }

    i64 x = sum - a[u] , y = a[u] - x ;

    if( sum-vec[0] < x || x<0 || y<0 )
    {
        printf("NO\n") ;
        exit(0) ;
    }
    a[u] = y ;

    return ;
}

int main()
{
    int n ;

    scanf("%d",&n) ;
    for(int i=1 ; i<=n ; i++) scanf("%lld",&a[i]) ;

    for(int i=1 ; i<n ; i++)
    {
        int u , v ;
        scanf("%d %d",&u,&v) ;
        g[u].pb(v) ; g[v].pb(u) ;
    }

    int root = 0 ;

    if( n==2 )
    {
        if( a[1] == a[2] ) printf("YES\n") ;
        else printf("NO\n") ;
        return 0 ;
    }

    for(int i=1 ; i<=n ; i++)
    {
        if( (int)g[i].size() > 1 ) root = i ;
    }

    dfs(root,0) ;

    if( a[root] == 0 ) printf("YES\n") ;
    else printf("NO\n") ;

    return 0 ;
}


Measured memory_bytes: 22912
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k;cin>>n>>k;
  V<ll> v(n);
  rep(i,0,n)cin>>v[i];
  rep(i,k,n){
    if(v[i-k]<v[i])cout<<"Yes"<<ENDL;
    else cout<<"No"<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4780
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
P goods[4];
ll dp[5][25000010];
int main(){
    cin>>N;
    for(ll i=0;i<3;i++){
        cin>>goods[i].first;
    }
    for(ll i=0;i<3;i++){
        cin>>goods[i].second;
    }
    goods[3]=P(1,1);
    for(ll i=0;i<4;i++){
        for(ll j=0;j<=N;j++){
            ll w=goods[i].first;
            ll v=goods[i].second;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j+w>N)continue;
            dp[i][j+w]=max(dp[i][j+w],dp[i][j]+v);
            dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v);
        }
    }
    N=dp[4][N];
    for(ll i=0;i<4;i++){
        for(ll j=0;j<=N;j++){
            dp[i][j]=0;
        }
    }
    for(ll i=0;i<3;i++){
        swap(goods[i].first , goods[i].second);
    }

    for(ll i=0;i<4;i++){
        for(ll j=0;j<=N;j++){
            ll w=goods[i].first;
            ll v=goods[i].second;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            if(j+w>N)continue;
            dp[i][j+w]=max(dp[i][j+w],dp[i][j]+v);
            dp[i+1][j+w]=max(dp[i+1][j+w],dp[i][j]+v);
        }
    }
    cout<<dp[4][N];
    return 0;
}

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

#define ll long long

ll h,w,x;
vector<string> v;
ll c[11][1010];
ll sum[15];

ll cnt(int z){
	ll cnt=__builtin_popcount(z)+1;
	memset(c,0,sizeof(c));
	int cur=0,ret=0;
	for (int j=0; j<h; j++){
		for (int k=0; k<w; k++) 
			c[cur][k]+=(v[j][k]=='1');
		if (z & (1<<j)) cur++;
	}
	for (int j=0; j<cnt; j++) 
		for (int k=0; k<w; k++) 
			if (c[j][k]>x) return 2e18;
	
	memset(sum,0,sizeof(sum));
	for (int k=0; k<w; k++){
		int f=0;
		for (int j=0; j<cnt; j++) 
			if (sum[j]+c[j][k]>x) f=1;
		if (f){
			ret++;
			memset(sum,0,sizeof(sum));
		}	
		for (int j=0; j<cnt; j++) sum[j]+=c[j][k];
	}
	
	return cnt+ret-1;
}

int main(){
	cin>>h>>w>>x;
	for (int i=0; i<h; i++){
		string s;
		cin>>s;
		v.push_back(s);
	}
	ll ans=2e18;
	for (ll mask=0; mask<(1<<h-1); mask++){
		//cout<<mask<<":"<<cnt(mask)<<endl;
		ans=min(ans,cnt(mask));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=inf; cin>>n;
    vector<int> w(n,0),sum(n+1,0);
    rep(i,n){
        cin>>w[i];
        sum[i+1]=sum[i]+w[i];
    }
    rep(i,n) ans=min(ans,abs(sum[n]-2*sum[i]));
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pb push_back
#define mp make_pair
#define ii pair<int,int>
#define vi vector<int>
#define iii pair<int,pair<int,int>>
#define INF 1<<30

using namespace std;
ll getd(ll x, ll y)
{
	if(x>y)
		return x-y;
	else
		return y-x;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m;
	cin>>n>>m;
	char str[100][100];
	int t,T;
	int N = 512;
	int M = 512;
	for (int i = 0; i < 100; ++i)
	{
		for (int j = 0; j < 100; ++j)
		{
			if(i<50){
				str[i][j] = '.';
			}
			else
			{
				str[i][j] = '#';
			}
		}
	}
	n--;
	m--;
	bool b=true;
	for (int i = 0; i < 49 && b; i+=2)
	{
		for (int j = 0; j < 100; j+=2)
		{

			if(m--)
			{
				str[i][j]='#';
			}	
			else{
				b=false;
				break;
			}
		}
	}
	b=true;
	for (int i = 51; i < 100 && b; i+=2)
	{
		for (int j = 0; j < 100; j+=2)
		{

			if(n--)
			{
				str[i][j]='.';
			}	
			else{
				b=false;
				break;
			}
		}
	}
	cout<<"100 100\n";
	for (int i = 0; i < 100; ++i)
	{
		for (int j = 0; j < 100; ++j)
		{
			cout<<str[i][j];
		}
		cout<<"\n";
	}
}

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

using namespace std;

int main()
{
	for(string s1,s2;cin>>s1>>s2;){
		int len1=s1.length(),len2=s2.length();
		int lcslen=0;
		for(int i=-len2+1;i<len1+len2;i++){
			int cnt=0;
			for(int j=0;j<len1;j++){
				if(0<=i+j && i+j<len2 && s1[j]==s2[i+j])	cnt++;
				else	lcslen=max(lcslen,cnt),cnt=0;
			}
			lcslen=max(lcslen,cnt);
		}
		cout<<lcslen<<endl;
	}

	return 0;
}

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

int main() {
    string S;
    cin >> S;
    int count = 0;
    int answer = 0;
    for(int i=0;i<3;i++){
        if(S.at(i)=='R'){
            count++;
        }
        if(count > answer){
            answer = count;
        }
        else{
            count = 0;

        }

    }
    cout << answer << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define int long
#define mod (1000000007)
main(){
  int n,m,c;
  cin>>n>>m;
  vector<int> dp(n+1,0);
  map<int,bool> a;
  for(int i=0;i<m;++i){
    cin>>c;
    a[c]=true;
  }
  dp[0]=1;
  for(int i=0;i<=n;++i){
    if(i+2<=n&&!a[i+2])dp[i+2]+=dp[i]%mod;
    if(i+1<=n&&!a[i+1])dp[i+1]+=dp[i]%mod;
  }
  cout<<dp[n]%mod;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;


int main()
{
	boost;
	string s,t; cin>>s>>t;
	int n=s.size(),m=t.size();
	int ans=1e9,cnt=0;
	for(int i=0;i<(n-m+1);i++){
		
		cnt=0;
		for(int j=0;j<m;j++){
			if(s[i+j]!=t[j]) cnt++;
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<endl;
	
	

return 0;
}


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
	int n;
	int color[8] = {};
	int cnt = 0;
	int ans = 0;
	int x;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> x;
		if (x>=3200){
			cnt++;
		}
		else if (color[x / 400] == 0){
			ans++;
			color[x / 400] = 1;
		}
	}
	if (ans == 0){
		cout << 1 << " " << cnt << endl;
		return 0;
	}
	cout << ans << " " << ans + cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,x,c=0,sum=0;
  int a[100];
  scanf("%d%d",&n,&x);
  
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  
  for (int i=0;i<n;i++){
    sum+=a[i];
    if(sum<=x)c++;
  }
  printf("%d",c+1);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;
VI pena;
VVI gain;
int pena_sum;
int eval(VI &order)
{
    VI last(26, -1);
    int ret = 0;
    int cur_pena = pena_sum;
    rep(i, n)
    {
        ret += gain[i][order[i]];
        cur_pena -= pena[order[i]] * (i - last[order[i]]);
        last[order[i]] = i;
        ret -= cur_pena;
        cur_pena += pena_sum;
    }
    return ret;
}
int eval_diff(VI &order, int start, VVI &log)
{
}
void print(VI &order)
{
    for (auto &&x : order)
    {
        cout << x + 1 << endl;
    }
}

int choice_weighted()
{
    int r = mt() % pena_sum;
    rep(i, 26)
    {
        r -= pena[i];
        if (r <= 0)
            return i;
    }
}

void search()
{
    auto starttime = clock();
    typedef pair<int, VI> Tact;
    priority_queue<Tact> pque;
    VI base(n);
    VI last(26, -1);
    rep(i, n)
    {
        int cur = -IINF;
        int penasum = 0;
        rep(j, 26)
        {
            penasum += pena[j] * (i - last[j]);
        }
        rep(j, 26)
        {
            if (cur < gain[i][j] - penasum + pena[j] * (i - last[j]))
            {
                base[i] = j;
                cur = gain[i][j] - penasum + pena[j] * (i - last[j]);
            }
        }
        last[base[i]] = i;
    }
    auto best = base;
    int bscore = eval(base);
    //pque.push({eval(base), base});
    cerr << bscore << endl;
    int loopnum = 0;
    while (double(clock() - starttime) / CLOCKS_PER_SEC < 1.9)
    {
        rep(i, 2)
            base[mt() % n] = choice_weighted();
        int cscore = eval(base);
        if (cscore > bscore)
        {
            best = base;
            bscore = cscore;
        }
        else
        {
            base = best;
        }
        loopnum++;
    }
    print(best);
    cerr << bscore << endl;
    cerr << loopnum << endl;
}
int main()
{
    cin >> n;
    pena = VI(26);
    gain = VVI(n, VI(26));
    rep(i, 26)
    {
        cin >> pena[i];
        pena_sum += pena[i];
    }
    rep(i, n)
    {
        rep(j, 26)
        {
            cin >> gain[i][j];
        }
    }
    search();
    return 0;
}

Measured memory_bytes: 3712
import sys

readline = sys.stdin.readline

def main():
    N = int(readline())
    A = []
    for _ in range(N):
        A.append(int(readline())-1)
    check = [0]*N
    check[0] = 1
    nxt = 0
    ans = 1
    while True:
        nxt = A[nxt]
        if check[nxt] == 1:
            ans = -1
            break
        if nxt == 1:
            break
        check[nxt] = 1
        ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 7852