akhauriyash/Code-Regression huggingface dataset:
/**
 *   created: 07 December 2019  18:00:06
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vector< vector<pii> > v(n+1);
		for(int i=1;i<=n;i++){
			int a;
			cin>>a;
			while(a--){
				int x,y;
				cin>>x>>y;
				v[i].push_back(make_pair(x,y));
			}
		}
		int maxi = pow(2,n) - 1;
		int res = 0;
		for(int i=0;i<=maxi;i++){
			vector<int> temp(n+1,-1);
			int cnt = 0;
			for(int j=n-1; j>=0; j--){
				if(!(i&(1<<j)))
					continue;
				cnt++;
				int flag = 0;
				for(int k=0; k<v[j+1].size(); k++){
					if(temp[v[j+1][k].first]==-1)
						temp[v[j+1][k].first] = v[j+1][k].second;
					else if(temp[v[j+1][k].first]!=v[j+1][k].second){
						cnt = 0;
						flag = 1;
						break;
					}
					if(temp[v[j+1][k].first]==1){
						int t = v[j+1][k].first;
						t--;
						if(i&(1<<t))
							temp[v[j+1][k].first]=1;
						else{
							cnt = 0;
							flag = 1;
							break;
						}
					}
					else if(temp[v[j+1][k].first]==0){
						int t = v[j+1][k].first;
						t--;
						if(!(i&(1<<t)))
							temp[v[j+1][k].first]=0;
						else{
							cnt = 0;
							flag = 1;
							break;
						}
					}
				}
				if(flag)
					break;
			}
			res = max(res,cnt);
		}
		cout<<res;
	}
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e8;
using vi = vector <int>;
using vvi = vector <vi>;

signed main(){
	string s;
	int a,b;
	cin >> a >> b >> s;

	if(s[a] != 45 || s.size() != a + b + 1){
		cout << "No" << endl;
		return 0;
	}
	else{
		s[a] = 50;
	}

	for(int i = 0; i < a + b + 1; i++){
		if(48 <= s[i] && s[i] <= 57){
			continue;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 256
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int r,g,b;
  cin >> r >> g >> b;

  cout << ((r*100+g*10+b)%4==0 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() {
  ll n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a[i];
  map<ll,vll> mpp;
  map<ll,vll> mpm;
  rep(i,n) {
    ll p = i + a[i];
    ll m = i - a[i];
    mpp[p].push_back(i);
    mpm[m].push_back(i);
  }
  ll ans = 0;
  for(auto q : mpp) {
    ll k = q.first;
    vll vp = q.second;
    vll vm = mpm[k];
    ll sp = vp.size();
    ll sm = vm.size();
    ans += sp*sm;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 59140
n = int(input())
alist = list(map(int, input().split(" ")))

if 0 in alist:
  print("0")
else:
  result = 1
  m = 0
  while result <= 10**18 and m < n:
    result *= alist[m]
    m += 1
  if m < n or result > 10**18:
    print("-1")
  else:
    print(result)

Measured memory_bytes: 21656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e18
#define REPL(i,a,b) for(int i=a;i<a;++i)
#define REPLE(i,a,b) for(int i=a;i<=a;++i)
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pi;

#define M_PI 3.14159265358979323846

int a[100005];
const int oo = 1e9+10;
const int mod = 7901;

ll gcd(ll a, ll b){return a==0 ? b : gcd(b%a, a);}

int dp[100005];
int n,k;
void solve(){
	cin>>n>>k;
	for(int i = 1 ; i <= n ; ++i)cin>>a[i];
	for(int i = 1 ; i <=n ; ++i)dp[i]=oo;
	dp[0] = 0;
	dp[1] = 0;
	for(int i = 2 ; i <= n ; ++i){
		for(int j = max(1, i-k) ; j < i ; ++j)
			dp[i] = min(abs(a[i]-a[j]) + dp[j] , dp[i]);
	}
	cout << dp[n] << '\n';
}
int main(){   
    ios::sync_with_stdio(0);cin.tie(0);
	int t=1;
	while(t--){
		solve();
	}
}  






Measured memory_bytes: 4404
#include<stdio.h>

int main(void){
	int a,b,add,i;

	while(scanf("%d %d",&a,&b) != EOF){
		add = a + b;
		for(i = 0;add != 0;i++){
			add /= 10;
		}
		printf("%d\n",i);
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n + 1, 0);
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        l--;
        cnt[l]++;
        cnt[r]--;
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += (cnt[i] == m);
        cnt[i + 1] += cnt[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int r, c, el,sheet[102][102], r_sum, c_sum, sum = 0;

  cin >> r >> c;

  for(int i = 1; i <= r; i++){
    for(int j = 1; j <= c; j++){
      cin >> el;
      sum += el;
      sheet[i][j] = el;
    }
  }

  for(int i = 1; i <= r; i++){
    r_sum = 0;
    for(int j = 1; j <= c; j++){
      r_sum += sheet[i][j];
    }
    sheet[i][c + 1] = r_sum;
  }

  for(int i = 1; i <= c; i++){
    c_sum = 0;
    for(int j = 1; j <= r; j++){
      c_sum += sheet[j][i];
    }
    sheet[r + 1][i] = c_sum;
  }

  sheet[ r + 1][ c + 1 ] = sum;

  for(int i = 1; i <= r + 1; i++){
    for(int j = 1; j <= c + 1; j++){
      if( j == c + 1) cout << sheet[i][j] << endl;
      else cout << sheet[i][j] << ' ';
    }
  }

  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
std::vector<int> h, w;
int tmph, tmpw;
while(1)
{
cin >> tmph >> tmpw;
if(tmph==tmpw && tmph==0) break;
h.push_back(tmph);
w.push_back(tmpw);
}

for (int t = 0; t < h.size(); t++) 
{
for (int j = 0; j < h[t]; j++) 
{
if(j==0 || j==h[t]-1)
{
for (int i = 0; i < w[t]; i++) 
{
cout << "#";
}
cout << endl;
}else
{
for (int i = 0; i < w[t]; i++) 
{
if(i==0 || i==w[t]-1)
{
cout << "#";
}
else 
{
cout << ".";
}
}
cout << endl;
}
}
cout << endl;
}

return 0;
}


Measured memory_bytes: 3068
import copy
import math
import collections
def comb(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
#A

N, M = list(map(int, input().split()))
a, b = 0, 0
if N >= 2:
    a = comb(N, 2)
if M >= 2:
    b = comb(M, 2)
ans = a + b
print(ans)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<long long> adj[n];
    vector<int> adjt[n];
    for(int i = 0; i<m; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        adjt[l].push_back(r);
        adjt[r].push_back(l);
        adj[l].push_back(d);
        adj[r].push_back(-d);
    }
    bool ok = true;
    long long v[n];
    long long maxi = 11111111111111LL;
    for(int i = 0; i<n; i++){
        v[i] = maxi;
    }
    for(int i = 0; i<n; i++){
        if(v[i]!=maxi){
            continue;
        }
        vector<int> li;
        long long s = 0LL;
        long long e = 0LL;
        v[i] = 0LL;
        li.push_back(i);
        for(int j = 0; j<li.size(); j++){
            int now = li[j];
            for(int k = 0; k<adj[now].size(); k++){
                int to = adjt[now][k];
                long long z = adj[now][k]+v[now];
                if(v[to]!=maxi){
                    ok &= v[to]==z;
                }
                else{
                    v[to] = z;
                    li.push_back(to);
                }
            }
        }
        ok &= (e-s)<=1000000000LL;
    }
    cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double res;
    if(a * b > x * 2){
        double a2 = 2 * x / b;
        res = atan(a2 / b);
    }
    else{
        x = x - a * b / 2;
        double a2 = 2 * x / a;
//        cout << a << " " << b-a2 << endl;
        res = atan(a / (b-a2));
    }

    printf("%.10f\n", 90.0 - res / M_PI * 180.0);


    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int re(int n) {
	return n % 2 ? n * 3 + 1 : n / 2;
}

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

		int ans = 0;
		while (n != 1) {
			n = re(n);
			ans++;
		}

		Cout(ans);
	}
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
string s;
string qs1,qs2;
int i,j;

int main(){
    cin>>s;
    int n=s.size();
    qs1=s.substr(0,n/2);
    qs2=s.substr(n/2+1,n/2);
    if(qs1!=qs2){
		cout<<"No"<<endl;
		return 0;
	}
    for(i=0;i<n/2+1;i++){
    	if(qs1[i]!=qs1[n/2-1-i]){
    		cout<<"No"<<endl;
    		return 0;
		}
	}
	for(j=0;j<n/2+1;j++){
    	if(qs2[j]!=qs2[n/2-1-j]){
    		cout<<"No"<<endl;
    		return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

int main(){
    
    int A,B;
    cin>>A>>B;
    int res = 0;
        if(A>=13){
            res = B;
        }else if(A>=6 && A<=120){
            res = B/2;
        }else{
            res = 0;
        }
        
        
    
    cout<<res;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define DEBUG2(x, y) cerr << #x << ": " << x << " " << #y << ": " << y << "\n"
#define DEBUG3(x, y, z) cerr << #x << ": " << x << " " << #y << ": " << y << " " << #z << ": " << z << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
#define pint pair<int, int>
#define ld long double
using namespace std;
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 <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567, INF2 = INF * INF;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string X;
  cin >> X;
  int N = X.size();
  int cnt[2] = {0, 0};  // S T

  REP(i, N) {
    if (X[i] == 'S') {
      cnt[0]++;
    } else {
      if (cnt[0] > 0) {
        cnt[0]--;
      } else {
        cnt[1]++;
      }
    }
  }
  print(cnt[0] + cnt[1]);
}

Measured memory_bytes: 720
#include <iostream>

int main() {
    int N, X;
    std::cin >> N >> X;

    int D = 0;
    int ans = 1;
    for (int i = 2; i <= N + 1; ++i) {
        int L;
        std::cin >> L;
        D += L;
        if (D <= X) {
            ans += 1;
        }
    }

    std::cout << ans << "\n";
    return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector< string > s (H + 2);
  s.at(0) = "..................................................";
  s.at(H + 1) = "..................................................";
  for(int i = 1; i <= H; i++){
    string t;
    cin >> t;
    s.at(i) = '.' + t +'.';
  }
  for(int i = 1; i <= H; i++){
    for(int j = 1; j <= W; j++){
      if(s[i][j] == '.'){
        int num = 0;
        if(s[i-1][j-1] == '#'){num++;}
        if(s[i-1][j] == '#'){num++;}
        if(s[i-1][j+1] == '#'){num++;}
        if(s[i][j-1] == '#'){num++;}
        if(s[i][j+1] == '#'){num++;}
        if(s[i+1][j-1] == '#'){num++;}
        if(s[i+1][j] == '#'){num++;}
        if(s[i+1][j+1] == '#'){num++;}
        s[i][j] = num + '0';
      }
    }
  }
  for(int i = 1; i <= H; i++){
    cout << s.at(i).substr(1, W) << endl;
  }
}

Measured memory_bytes: 256
# 2019/12/09

n,a,b=map(int,input().split())
s=input()

cnt=0
cnt_b=0
for i in range(n):
    if cnt>=(a+b):
        print('No')
        continue
    else:
        if s[i]=='c' or cnt>a+b:
            print('No')
            continue
        else:
            if s[i]=='b':
                cnt_b+=1
                if cnt_b>b:
                    print('No')
                    continue
                else:
                    print('Yes')
                    cnt+=1
            else:
                print('Yes')
                cnt+=1

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

#define _1 first
#define _2 second
#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define uni(x) (x).erase(unique(all(x)), (x).end())
#define reset(x, y) memset(x, y, sizeof(x))
#define BUG(x) cerr << #x << " = " << (x) << endl
#define BUGP(x) cout << #x << " = " << (x)._1 << ", " << (x)._2 << endl
using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
// Head

const int N = 212345;
const int MOD = 998244353;

pii a[N];
int n, maxm[N * 4];
LL dp[N];

int query(int o, int l, int r, int ql, int qr) {
    if (ql <= l && r <= qr) return maxm[o];
    int mid = l + (r - l) / 2;
    int ret = 0;
    if (ql <= mid) ret = max(ret, query(o * 2, l, mid, ql, qr));
    if (qr > mid) ret = max(ret, query(o * 2 + 1, mid + 1, r, ql, qr));
    return ret;
}

void update(int o, int l, int r, int pos, int val) {
    if (l == r) {
        maxm[o] = val;
        return;
    }

    int mid = l + (r - l) / 2;
    if (pos <= mid) update(o * 2, l, mid, pos, val);
    else update(o * 2 + 1, mid + 1, r, pos, val);
    maxm[o] = max(maxm[o * 2], maxm[o * 2 + 1]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i]._1 >> a[i]._2;
    }

    sort(a + 1, a + n + 1);

    for (int i = n; i >= 1; --i) {
        int id = upper_bound(a + 1, a + n + 1, mp(a[i]._1 + a[i]._2, 0)) - a - 1;
        if (id == i) update(1, 1, n, i, i);
        else {
            int cur = query(1, 1, n, i + 1, id);
            update(1, 1, n, i, cur);
        }
    }

    dp[n + 1] = 1;
    for (int i = n; i >= 1; --i) {
        int pos = query(1, 1, n, i, i);
        dp[i] = (dp[i + 1] + dp[pos + 1]) % MOD;
    }

    cout << dp[1] << '\n';
    return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,ans=4;
	cin>>a>>b>>c;
	if(a==b&&a==c&&b==c){
		cout<<1<<endl;
		return 0;
	}
	if(a==b||b==c||a==c){
		cout<<2<<endl;
		return 0;
	}
	cout<<3<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;
 
namespace AC
{
    public class shiokara
    {
        static void Main(string[] args)
        {
            long[] Adata = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long[] Bdata = ReadLine().Split(' ').Select(long.Parse).ToArray();
            long T = long.Parse(ReadLine());
            long diff = Math.Abs(Adata[0] - Bdata[0]), mov = Math.Abs(Adata[1] - Bdata[1]);
            if(Adata[1] < Bdata[1]){
                WriteLine("NO");
                return;
            }
            if(mov * T >= diff) WriteLine("YES");
            else WriteLine("NO");
        }
    }
}

Measured memory_bytes: 28152
#include <stdio.h>
int V[21], W[21];
int main(){
	int N;
	scanf("%d",&N);
	int sum=0;
	for(int i=0;i<N;i++) scanf("%d",V+i);
	for(int i=0;i<N;i++) scanf("%d",W+i);
	for(int i=0;i<N;i++) sum+=V[i]>W[i]?V[i]-W[i]:0;
	printf("%d",sum);
	
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>

using namespace std;

static int read(char* const a) {
  char* ptr = a;
  int len = 0;
  for (;;) {
    const int c = getchar();
    if (c == EOF || c == '\n')
      break;
    *ptr++ = c;
    ++len;
  }
  return len;
}

static bool find(int pos,
                 const char* p, int len_p,
                 const char* s, int len_s) {
  const char* q = &p[pos];
  const char* end = &p[len_p];
  int cnt = 0;
  for (int j = 0; j < len_s; ++j) {
    if (*q != s[j])
      return false;

    ++q;
    if (q == end)
      q = p;
  }
  return true;
}

int main() {
  char p[100] = {0};
  char s[100] = {0};

  const int len_p = read(p);
  const int len_s = read(s);

  bool found = false;
  const char* p_end = &p[len_p];
  for (int i = 0; i < len_p; ++i) {
    if (find(i, p, len_p, s, len_s)) {
      found = true;
      break;
    }
  }

  if (found)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}
int main() {
  int n; cin >> n;
  vector<ll> h(n);
  REP(i,n) cin >> h[i];
  h[0]--;
  FOR(i,1, n){
    if(h[i] > h[i-1]) h[i]--;
    if(h[i] < h[i-1]) no();
  }
  yes();
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair <int,int> P;
string mp[501];
int m,n,used[30],ans;
vector <P>  a[30];

int saiki(int);

bool check(int c,int s,int t,int f){
  int res=1;
  for(int i=s+1;i<t;i++){
    if(!f&&mp[i][c]!='.'&&!saiki(mp[i][c]-'A'))res=0;
    if(f&&mp[c][i]!='.'&&!saiki(mp[c][i]-'A'))res=0;
  }
  return res;
}

int saiki(int ch){
  int x1=a[ch][0].x,x2=a[ch][1].x;
  int y1=a[ch][0].y,y2=a[ch][1].y;
  int res=0;
  if(used[ch])return 0;
  used[ch]=1;
  
  if(x1==x2&&y2-y1!=1) res=check(x1,y1,y2,0);
  if(y1==y2&&x2-x1!=1) res=check(y1,x1,x2,1);
  
  if(x1!=x2&&y1!=y2) {
    if(x1<x2){
      res=check(y1,x1,x2+1,1)&check(x2,y1,y2,0);
      res|=check(x1,y1,y2+1,0)&check(y2,x1,x2,1);
    }
    else{
      swap(x1,x2);
      res=check(y1,x1-1,x2,1)&check(x1,y1,y2,0);
      res|= check(x2,y1,y2,0)&check(y2,x1,x2+1,1);
      swap(x1,x2);
    }
  }
  
  if(res) {
    mp[y1][x1]=mp[y2][x2]='.';
    a[ch].clear();
    ans+=2;
  }
  return res;
}

int main(){
  
  cin>>m>>n;
  for(int i=0;i<m;i++)cin>>mp[i];
  
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(mp[i][j]!='.')a[mp[i][j]-'A'].push_back(P(j,i));
  
  
  for(int i=0;i<30;i++){
    memset(used,0,sizeof(used));
    if(a[i].size()) saiki(i);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1484
import sys, math
input = sys.stdin.readline

def main():
    N = int(input())
    yaku = []
    for i in range(int(math.sqrt(N))+1, 0, -1):
        if N%i == 0:
            t = N//i
            print(i+t-2)
            return



if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
using namespace std;
int a[103];
int main(){
	int n,k,d,ans=0;
	scanf("%d",&n);
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		scanf("%d",&d);
		int c;
		for(int j=0;j<d;j++){
			scanf("%d",&c);
			a[c]=1;
		}		
	}
	for(int i=1;i<=n;i++){
		if(a[i]==0)ans++;
	}
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 3828
#include<bits/stdc++.h>
//#include <boost/math/common_factor.hpp>
using namespace std;
#define int long long int

  int lcm(int a, int b)  
	 {  
	    return (a*b)/__gcd(a, b);  
	 }

int countDivisibles(int A, int B, int M) 
{ 
    // Add 1 explicitly as A is divisible by M 
    if (A % M == 0) 
        return (B / M) - (A / M) + 1; 
  
    // A is not divisible by M 
    return (B / M) - (A / M); 
}


int32_t main()
{
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    int n  =b-a+1;
    int x1 = countDivisibles(a,b,c);
    int x2 = countDivisibles(a,b,d);
    //cout<<__gcd(c,d)<<endl;
    int x3 = countDivisibles(a,b,lcm(c,d));
    cout<<n-(x1+x2 - x3)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}


class comb{
  vector<ll> f,fr;
  ll MOD_;
  public:
  //a^(p-1) = 1 (mod p)(p->Prime numbers)
  //a^(p-2) = a^(-1)
  ll calc(ll a,ll b,ll p){//a^(b) mod p   
    if(b==0)return 1;
    ll y = calc(a,b/2,p);y=(y*y)%p;
    if(b & 1) y = (y * a) % p;
    return y;
  }
  void init(ll n,ll mod){//input max_n
    MOD_ = mod;
    f.resize(n+1);
    fr.resize(n+1);
    f[0]=fr[0]=1;
    for(ll i=1;i<n+1;i++){
      f[i] = (f[i-1] * i) % mod;
    }
    fr[n] = calc(f[n],mod-2,mod);
    for(ll i=n-1;i>=0;i--){
      fr[i] = fr[i+1] * (i+1) % mod;
    }
  }
  ll nCr(ll n,ll r){
    if(n<0||r<0||n<r)return 0;
    return f[n] * fr[r] % MOD_ * fr[n-r] % MOD_;
  }//nHr = n+r-1Cr
};



int main(){

  ll N,M,K;
  cin >> N >> M >> K;

  ll mod = 998244353;
  ll ans = 0;

  comb co;
  co.init(2*N,mod);

  FOR(i,0,K+1){
    ll add = M * co.calc(M-1,N-i-1,mod) % mod;
    if(i){
      add *= co.nCr(N-1,i);
    }
    ans += add;
    ans %= mod;
  }


  cout << ans << endl;
}


Measured memory_bytes: 9532
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  ll N,M;
  cin >> N >> M;
  vl A(N);
  rep(i,N) {
    cin >> A[i];
  }
  sort(rng(A));
  ll l = 0,r = A[N-1]*3;
  while(l+1<r) {
    ll m = (l+r)/2;
    ll cnt = 0;
    rep(i,N) {
      ll c = N - (lower_bound(rng(A),m-A[i]) - A.begin());
      cnt += c;
    }
    if(cnt > M) {
      l = m;
    } else {
      r = m;
    }
  }
  vl sum(N+1,0);
  rep(i,N) {
    sum[i+1] = sum[i] + A[i];
  }
  ll ans = 0;
  ll cnt = 0;
  rep(i,N) {
    ll c = (lower_bound(rng(A),r-A[i]) - A.begin());
    if(c >= N) continue;
    ans += sum[N] - sum[c];
    ans += (N-c) * A[i];
    cnt += N-c;
  }
  ans += (M-cnt) * l;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int N, K, x, min=0;
  cin >> N >>K;
  
  for(int i=0; i<N; i++){
    cin >> x;
    
    if(x<=K-x){
      min += x*2;
    }
    else{
      min += (K-x)*2;
    }
    
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,d;
  cin>>n>>d;
  long long int ans=0;
  for(long long int i=0;i<n;i++)
  {
    long long int a,b;
    cin>>a>>b;
    if(sqrt(a*a+b*b)<=d) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3616
M, D = map(int, input().split())
ans = 0
for m in range(1,M+1):
  for d in range(1,D+1):
    d1 = d % 10
    d2 = (d - d1)//10
    if d1 > 1 and d2 > 1 and m == d1 * d2:
      ans +=1
    #print(d1,d2,m)
print(ans)

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

int main(){

    int n;
    cin >> n;
    int p[n],place[n];
    for(int i=0;i<n;i++){
        place[i] = 0;
        cin >> p[i];
        if(i+1 == p[i]){
            place[i] = 1;
        }
    }
    int tempi = -1,ans = 0;
    for(int i = 0;i<n;i++){
        if(tempi == -1 && place[i] == 1){
            tempi = i;
        }
        else if (tempi != -1 && place[i] == 1){
            ans += 1;
            tempi = -1;
            
        }
        else if(tempi != -1 && place[i]==0){
            ans += 1;
            tempi = -1;
        }
    }
    
    if(tempi != -1){
        ans += 1;
    }
    cout << ans << endl;




    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s,t;
  cin>>s>>t;
  int n=s.size();
  rep(i,n){
    if(s==t) {
      cout<<"Yes"<<endl;
      return 0;
    }
    s=s.back()+s.substr(0,n-1);
  }
  cout<<"No"<<endl;
}

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

char sym[128];

void init() {
  sym['['] = ']';
  sym['{'] = '}';
  sym['('] = ')';
  sym[']'] = '[';
  sym['}'] = '{';
  sym[')'] = '(';
  sym['i'] = 'i';
  sym['w'] = 'w';
}

int main() {
  
  init();

  string str;
  cin >> str;

  int res = 3;
  
  // 全探索
  for(int i=0; i<(1<<str.size()); i++) {
    string nstr;
    for(unsigned j=0; j<str.size(); j++) {
      if((i >> j & 1)
	 || (str[j]=='i' || str[j]=='w')) nstr += str[j];
    }
    int sz = nstr.size(), cnt = 0;
    for(int j=0; j<sz/2+1; j++) {
      if(sym[(int)nstr[j]] == nstr[sz-j-1]) cnt ++;
    }
    if(cnt == sz/2+1) res = max(res, sz);
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 1188
// B - ss
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	int startlength = S.size()%2? S.size()-1: S.size()-2;
	for(int n=startlength; n>0; n-=2){//n: length to check
		int len = n/2;//len: half length
		int f;
		for(f=0; f<len; ++f) if(S[f] != S[len + f]) break;//fore half != back half -> break
		if(f >= len){//fore == back
			cout<< n <<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
def sign(a):
	if a>=0:
		return 1
	else:
		return -1

x,y=[int(i) for i in input().split()]

if x==0:
	if y>=0:
		print(y)
	else:
		print(abs(y)+1)
elif y==0:
	if x<=0:
		print(abs(x))
	else:
		print(x+1)

elif sign(x)==sign(y):
	if y>=x:
		print(abs(y-x))
	else:
		print(abs(y-x)+2)
else:
	print(abs(abs(y)-abs(x))+1)


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

int main(){
    int n, total=0;
    cin >> n;
    int score[n];
    for(int i = 0; i<n; i++){
        cin >> score[i];
    }
    
    for(int i = 0; i<n; i++){
        for(int j = i+1; j<n; j++){
            total += score[i] * score[j];
        }
    }
    cout << total << endl;
}

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

using namespace std;

typedef long long int ll;

#define FOR(i,l,r) for(i=l;i<r;i++)

#define REP(i,n) FOR(i,0,n)

#define ALL(x) x.begin(),x.end()

#define P pair<ll,ll>

#define F first

#define S second

#define VEC vector

#define V VEC<ll>

signed main(){

  double R;cin>>R; 

  cout<<2*R*3.141592<<endl;

  return 0;

}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
bool b[1000][1000][1000];
int main(){
  int n;
  cin >>n;
  int count=0;
  for(int i=0;i<n;i++){
    int p[3];
    for(int j=0;j<3;j++){
      cin >>p[j];
    }
    sort(p,p+3);
    if(b[p[0]][p[1]][p[2]]){
      count++;
    }else{
      b[p[0]][p[1]][p[2]]=true;
    }
  }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 7096
//
// Created by Ильдар Ялалов on 28.10.2019.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()
bool debug = 0;
const int MAXN = 2e5 + 100;
const int LOG = 21;
const int mod = 998244353;
const int MX = (1e7 + 100) * 1.5;
typedef long long li;
const li MOD = 1000000000949747713ll;

template<class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
    out << "( " << rhs.first << " , " << rhs.second << " )";
    return out;
}


int dis[MAXN];

ll dp[MAXN];

int cnt[MAXN];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> dis[i];
    }
    if(dis[1] != 0){
        cout << 0 << "\n";
        return;
    }
    sort(dis + 1, dis + n + 1);
    for (int i = 1; i <= n; ++i) {
        cnt[dis[i]]++;
    }
    if (cnt[0] != 1) {
        cout << 0 << "\n";
        return;
    }

    set<pii> ss;
    for(int i =1;i<=n;++i){
        ss.insert({dis[i], cnt[dis[i]]});
    }

    dp[0] = 1;
    ll ans = 1;
    for (auto x : ss) {
        int key = x.fi;
        if (key == 0)
            continue;
        if (cnt[key - 1] == 0) {
            cout << 0 << "\n";
            return;
        }
        ll val = dp[key - 1];
        ll mul = cnt[key - 1];
        for (int j = 1; j <= x.se; ++j) {
            val = (mul * val) % mod;
        }

        dp[key] = val;
        dp[key] %= mod;


        ans = dp[key];
    }
    cout << ans << "\n";


}


signed main() {
#ifdef zxc
//    debug = 1;
    freopen("../input.txt", "r", stdin);
    //  freopen("../output.txt", "w", stdout);
#else

#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(20);

    int t = 1;
    while (t--)
        solve();
    if (debug)
        cerr << endl << "time : " << (1.0 * clock() / CLOCKS_PER_SEC) << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <complex>

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

using namespace std;

typedef long double ld;
typedef complex<ld> P;
typedef vector<P> VP;

const ld EPS = 1e-10;

namespace std {
  bool operator<(const P& l, const P& r){
    return real(l) < real(r) ? true : imag(l) < imag(r);
  }
}

pair<int,int> cnt(VP& pl, P st, ld l) {
  P c = st + P(l/2.0, l/2.0);
  ld br = 1 + l / sqrt(2.0);      
  ld sr = 1 - l / sqrt(2.0);      
  int cnt1 = 0,cnt2 = 0;
  for (P p:pl){
    if(abs(c-p) <= br + EPS) ++cnt1;
    if(abs(c-p) <= sr + EPS) ++cnt2;
  }
  return make_pair(cnt2, cnt1);
}

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    VP pl;
    REP(i,n){
      ld x,y;
      scanf("%llf,%llf",&x,&y);
      pl.emplace_back(x,y);
    }
    priority_queue<tuple<int, int, int, P, ld>> q;
    int mn = 1;
    REP(i,10)REP(j,10){
      auto p = cnt(pl, P(i,j), 1.0);
      mn = max(mn, p.first);
      q.push(make_tuple(p.second, p.first, 0, P(i,j),1.0));
    }
    while(!q.empty()){
      int minn,maxn,depth;
      P st;
      ld l;
      tie(maxn,minn,depth,st,l) = q.top(); q.pop();
      if (maxn <= mn) break;
      REP(i,2)REP(j,2){
        P stq = st + P(l/2.0*i, l/2.0*j);
        auto p = cnt(pl, stq, l/2.0);
        mn = max(mn, p.first);
        if (p.second <= mn) continue;
        q.push(make_tuple(p.second, p.first, depth+1, stq, l/2.0));
      }
    }
    cout<<mn<<endl;
  }
  return 0;
}

Measured memory_bytes: 1424
import itertools
N,A,B,C = map(int,input().split())
L = [int(input()) for i in range(N)]

ptns = [L]

ans = float('inf')

for k in range(N-2):
    _ptns = []
    for ptn in ptns:
        for comb in itertools.combinations(ptn,3):
            comb = list(comb)
            comb.sort()
            tmp = abs(comb[0] - C)
            tmp += abs(comb[1] - B)
            tmp += abs(comb[2] - A)
            ans = min(ans, tmp + k*10)
        for i,j in itertools.combinations(range(len(ptn)),2):
            tmps = [ptn[i] + ptn[j]]
            for l,a in enumerate(ptn):
                if l==i or l==j: continue
                tmps.append(a)
            _ptns.append(tmps)
    ptns = _ptns
print(ans)

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

int main(){
    //a:even , b:odd
    int n,max_a=0,max_b=0,a_i,b_i;
    int a[100001]={},b[100001]={};

    cin >> n;

    for (int i = 0; i < n/2; i++){
        int x,y;
        cin >> x >> y;
        a[x]++;
        b[y]++;
    }

    for (int i = 0; i < 100001; i++){
        if(max_a < a[i]){
            max_a = a[i];
            a_i = i;
        }
        if(max_b < b[i]){
            max_b = b[i];
            b_i = i;
        }
    }

    sort(a, a+100001, greater<int>());
    sort(b, b+100001, greater<int>());

    if(a_i == b_i)
        cout << min(n - a[0] - b[1], n - a[1] - b[0]) <<endl;
    else
        cout << n - a[0] - b[0] << endl;

}

Measured memory_bytes: 1152
#include <stdio.h>
#include <math.h>

int main(void) {
    int d, t, deg;
    double rad, x, y;

    deg = 90;
    x = y = 0;
    while (scanf("%d,%d", &d, &t) != EOF && (d || t)) {
        rad = deg * M_PI / 180;
        x += cos(rad) * d;
        y += sin(rad) * d;
        deg = (deg - t + 360) % 360;
    }
    printf("%d\n%d\n", (int)x, (int)y);

    return 0;
}

Measured memory_bytes: 604
fun main(args: Array<String>) {
    val s = readLine()?.toLong() ?: return
    val sList = mutableListOf<Long>()
    var tmp = s
    while (tmp > 0) {
        sList += (tmp % 10)
        tmp /= 10
    }

    sList.reverse()

    var total = 0L
    
    for (flg in 0 until Math.pow(2.0, sList.size - 1.0).toInt()) {
        val numList = mutableListOf<Long>()
        var currentNum = 0L
        for (i in 0 until sList.size) {
            currentNum *= 10
            currentNum += sList[i]
            if (flg.and(1 shl i) == 1 shl i) {
                numList += currentNum
                currentNum = 0
            }
        }
        numList += currentNum
        total += numList.sum()
    }
    println(total)
}

Measured memory_bytes: 33652
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ++cnt;
    }
    cout << cnt;

    return 0;
}

Measured memory_bytes: 3792
/*
<問題文>
JOI氏は、自宅の敷地内にN本の木を所有している。
これらの木は一列に並んでおり、順に１からNまでの整数の番号が付けられている。
この冬、JOI氏はいくつかの木を選んで、イルミネーションを飾り付けることにした。
イルミネーションには美しさと呼ばれる値が定まっている。
木iにイルミネーションを飾り付ける場合の美しさはAiである。
JOI 氏は，あまりに近い 2 つの木の両方にイルミネーションを飾り付けてしまうと，
眩しすぎる場合があることに気がついた．
具体的には，j=1,2,…,M に対して，木 Lj, Lj+1, …, Rj のうち 2 つ以上に
イルミネーションを飾り付けるべきではないということが判明した．
この条件に従ってイルミネーションを飾り付けるときの，美しさの合計の最大値を求めよ．
<制限>
1以上N以下200000(=2×105)
1以上M以下200000(=2×105)
1以上Ai以下1000000000(=109) (1≦i≦N)
1以上Lj≦Rj≦N (1≦j≦M)
<入力>
N M
A1 A2 … AN
L1 R1
L2 R2
・・・
LM RM
*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
const int MAXN=200000;
const int MAXM=200000;
int N,M;
long long A[MAXN];
//L[MAXN]=同時につけれない位置の最初　R[]
int L[MAXM],R[MAXM];
int pre[MAXN+1];
long long dp[MAXN+1];
int main()
{
	//N=木の本数の入力　M=つけてはいけない範囲の個数の入力
	cin>>N>>M;
	//美しさの入力
	for(int i=0;i<N;i++){
		//A[i]を代入する
		cin>>A[i];
	}
	//2つ以上重ねてつけることが不能な範囲
	for(int i=0;i<M;i++){
		cin>>L[i]>>R[i];
	}
	//１～N番目まで順番に0～N-1まで値を入れる
	for(int i=1;i<=N;i++){
		pre[i]=i-1;
	}
	//for(int j=0;j<=N;j++){
			//cout<<"pre["<<j<<"]="<<pre[j]<<endl;
		//}
	for(int i=0;i<M;i++){
		pre[R[i]]/*足せる位置の値を入れる*/=min(pre[R[i]],L[i]-1);
		//for(int j=0;j<=N;j++){
			//cout<<"pre["<<j<<"]="<<pre[j]<<endl;
		//}
	}
	for(int i=N-1;i>=1;i--){
		//足せる位置の値を足す
		pre[i]=min(pre[i],pre[i+1]);
	}
	dp[0]=0;
	for(int i=1;i<=N;i++){
		//そこまでの木を使った長さを求める
		dp[i]=max(dp[i-1],dp[pre[i]]+A[i-1]);
	}
	cout<<dp[N]<<endl;
	return 0;
}


Measured memory_bytes: 8440
#include <stdio.h>

int main() {
    int A, B, pos = 0;
    char S[20];
    scanf("%d %d %s", &A, &B, S);
    for (int i = 0; S[i] != '\0'; i++) {
        if (S[i] == '-') {
            pos += i;
        }
    }
    pos == A ? puts("Yes") : puts("No");
    return 0;
}


Measured memory_bytes: 1644
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_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(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int mi = inf;
    for(int p = 1; p <= 100; p++) {
        int sum = 0;
        rep(i, N) sum += (p - A[i]) * (p - A[i]);
        mi = min(sum, mi);
    }
    output(mi);
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int x, y, d;
    int rect, lozen;
    char comma;

    rect = lozen = 0;
    while (cin >> x >> comma >> y >> comma >> d) {
        if (x * x + y * y == d * d)
            rect++;
        else if (x == y)
            lozen++;
    }
    cout << rect << '\n' << lozen << endl;

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (ll i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

struct City {
    string name;
    ll point;
    ll ini;

    City(string inputted_name, ll inputted_point, ll inputted_ini) {
        name = inputted_name;
        point = inputted_point;
        ini = inputted_ini;
    }

    bool operator<(const City &another) const {
        if (name < another.name) {
            return true;
        } else if (name == another.name) {
            if (point > another.point) {
                return true;
            }
            return false;
        }
        return false;
    };
};


int main() {
    ll N;
    cin >> N;
    vector<City> p;

    ll P;
    string S;
    rep (i, N) {
        cin >> S >> P;
        p.push_back(City(S, P, i + 1));
    }


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

    rep(i, p.size()) {
        cout << p[i].ini << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
n,k=map(int,input().split())
ab=[[0,0]for i in range(n)]
for i in range(n):
  ab[i][0],ab[i][1]=map(int,input().split())
ab.sort()
x=0
for i in range(n):
  x+=ab[i][1]
  if(x>=k):
    print(ab[i][0])
    sys.exit()
print(ab[-1][0])


Measured memory_bytes: 20144
#!/usr/bin/env python

n, x = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)
if x < a[0]:
    print(0)
    exit()

cnt = 0 
al = False
for i in range(n):
    if x >= a[i]:
        x -= a[i]
        cnt += 1
    else:
        break
    if i == n-1:
        al = True

if al: 
    if x > 0:
        ans = cnt-1
    else:
        ans = cnt 
else:
    ans = cnt 

print(ans)


Measured memory_bytes: 9200
#include<iostream>
#include<math.h>
#include<algorithm>

#define long long long

using namespace std;

long n, k;
long a[100001], dp[100001];

long cal(int idx) {
    if (idx > n) return 1e18;
    if (idx == n) return 0;
    if (dp[idx] != -1) return dp[idx];
    dp[idx] = 1e18;

    for (int i = idx + 1; i <= idx + k; i ++) {
        if (i <= n) dp[idx] = min(cal(i) + abs(a[i] - a[idx]), dp[idx]);
        else break;
    }
    return dp[idx];
}

void FastInput()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
}

void Input()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i ++) cin >> a[i];
    for (int i = 1; i <= n; i ++)
        dp[i] = -1;
}

void Solve()
{
    cout << cal(1);
}

int main()
{
    FastInput();
    Input();
    Solve();
}


Measured memory_bytes: 6528
<?php
define('MOD', 10**9+7);

//error_reporting(0);
//$N = trim(fgets(STDIN));
//list($n,$k) = explode(" ",trim(fgets(STDIN)));
$a[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
$a[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
$a[] = array_map('intval',explode(" ",trim(fgets(STDIN))));
$N = (int)trim(fgets(STDIN));
//function chmax(&$a,$b) {if ($a<$b){$a=$b;return true;}return false;}
//function chmix(&$a,$b) {if ($a>$b){$a=$b;return true;}return false;}
//

for($i=0;$i<$N;$i++) {
  $b=(int)trim(fgets(STDIN));
  for($j=0;$j<3;$j++) {
    for($k=0;$k<3;$k++) {
      if ($a[$j][$k]==$b) {
        $a[$j][$k]="*";
      }
    }
  }
}
printf("%s\n",isbingo()?"Yes":"No");

function isbingo()
{
  global $a;
  //横
  for($i=0;$i<3;$i++) {
    for($j=0;$j<3;$j++) {
      if ($a[$i][$j]!="*") {
        break;
      }
    }
    if ($j==3) return true;
  }
  //縦
  for($i=0;$i<3;$i++) {
    for($j=0;$j<3;$j++) {
      if ($a[$j][$i]!="*") {
        break;
      }
    }
    if ($j==3) return true;
  }
  //斜め
  if ($a[0][0]=="*" && $a[1][1]=="*" && $a[2][2]=="*") return true;
  if ($a[2][0]=="*" && $a[1][1]=="*" && $a[0][2]=="*") return true;

  return false;
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
//freopen("transmitters.in","r",stdin);
//cout<<fixed<<setprecision(6)<<n<<endl;
// transform(s.begin(), s.end(), s.begin(), ::tolower);
//double PI=3.14159265359,c=0;
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ll long long
//#define f(n) for(int i=;i<n;i++)
double PI = acos(-1);
using namespace std;
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
ll arr[100000];
int main()
{
    fast();
    ll n,t,x,mn=0,k;
    cin>>n>>k;
    vector<ll>v(n,1e12);
    for(int i=0; i<n; i++)
        cin>>arr[i];

    for(int i=0; i<n; i++)
    {
        x=v[i];
        for(int j=0; j<k; j++)
        {
           if(i+j+1<n)
           {
                if(i==0)
                    x=0;
                mn=x+abs(arr[i]-arr[i+j+1]);
                v[i+1+j]=min(v[j+i+1],mn);

           }

        }
        //cout<<v[i]<<" ";
    }
    cout<<v[v.size()-1]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ABS(a) (((a) >= 0) ? (a) : -(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define POW_10_5 100000
#define POW_10_9 1000000000
#define MOD 1000000007
#define INF (numeric_limits<int>::max()/2)
#define int long long

typedef pair<int, int> Pair;
typedef unordered_map<int, int> Hash;

// ---
int N, K;

int Ans() {
  return N - K + 1;
}

signed main() {
  cin >> N >> K;

  auto ans = Ans();

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()

# print(eval(s[:1]+'+'+s[1:]))

n = len(s)
ans = 0

for m_i in range(2**(n-1)):
  temp = ''
  for n_i in range(n):
    temp += s[n_i]
    if m_i & (1 << n_i):
      temp += '+'
  # print(temp)
  ans += eval(temp)
  
print(ans)

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

int main(){
	int a,b,t=0;

	while(++t){
		vector<int> leap;
		cin>>a>>b;
		
		if(a==0&&b==0) break;
		if(t>1) cout<<endl;

		for(int i=a;i<=b;i++){
			if( i%400==0 || (i%4==0 && i%100!=0)) leap.push_back(i);
		}

		if(leap.size()==0){
			cout<<"NA"<<endl;
		}
		else{
			for(int i=0;i<leap.size();i++){
				cout<<leap[i]<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228